Ignore:
Timestamp:
2011-02-02T23:03:00+01:00 (13 years ago)
Author:
bastiK
Message:

Experimental mapcss support. All *.java files in the gui/mappaint/mapcss/parser folder are generated from the javacc source file MapCSSParser.jj in the same folder. The generated code sums up to 2700 lines, there is no further build dependency.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java

    r3843 r3848  
    1414
    1515import org.openstreetmap.josm.Main;
     16import org.openstreetmap.josm.gui.PleaseWaitRunnable;
     17import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
    1618import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSource;
    1719import org.openstreetmap.josm.gui.preferences.SourceEntry;
    1820import org.openstreetmap.josm.gui.preferences.MapPaintPreference.MapPaintPrefMigration;
     21import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    1922import org.openstreetmap.josm.io.MirroredInputStream;
    2023import org.openstreetmap.josm.tools.ImageProvider;
     
    8386
    8487        for (SourceEntry entry : sourceEntries) {
    85             StyleSource style = new XmlStyleSource(entry);
     88            StyleSource style = null;
    8689            try {
    8790                MirroredInputStream in = new MirroredInputStream(entry.url);
    8891                InputStream zip = in.getZipEntry("xml","style");
    8992                if (zip != null) {
    90                     style.zipIcons = in.getFile();
    91                 }
     93                    style = new XmlStyleSource(entry);
     94                    continue;
     95                }
     96                zip = in.getZipEntry("mapcss","style");
     97                if (zip != null) {
     98                    style = new MapCSSStyleSource(entry);
     99                    continue;
     100                }
     101                if (entry.url.toLowerCase().endsWith(".mapcss")) {
     102                    style = new MapCSSStyleSource(entry);
     103                } else {
     104                    style = new XmlStyleSource(entry);
     105                }
    92106            } catch(IOException e) {
    93107                System.err.println(tr("Warning: failed to load Mappaint styles from ''{0}''. Exception was: {1}", entry.url, e.toString()));
    94108                e.printStackTrace();
    95                 style.hasError = true;
     109                if (style != null) {
     110                    style.hasError = true;
     111                }
    96112            }
    97             styles.add(style);
     113            if (style != null) {
     114                styles.add(style);
     115            }
    98116        }
    99117        for (StyleSource s : styles.getStyleSources()) {
     
    101119        }
    102120    }
     121
     122    public static class MapPaintStyleLoader extends PleaseWaitRunnable {
     123        private boolean canceled;
     124        private List<StyleSource> sources;
     125
     126        public MapPaintStyleLoader(List<StyleSource> sources) {
     127            super(tr("Reloading style sources"));
     128            this.sources = sources;
     129        }
     130
     131        @Override
     132        protected void cancel() {
     133            canceled = true;
     134        }
     135
     136        @Override
     137        protected void finish() {
     138        }
     139
     140        @Override
     141        protected void realRun() {
     142            ProgressMonitor monitor = getProgressMonitor();
     143            monitor.setTicksCount(sources.size());
     144            for (StyleSource s : sources) {
     145                if (canceled)
     146                    return;
     147                monitor.subTask(tr("loading style ''{0}''...", s.getDisplayString()));
     148                s.loadStyleSource();
     149                monitor.worked(1);
     150            }
     151        }
     152    }
     153
    103154}
Note: See TracChangeset for help on using the changeset viewer.