Changeset 3843 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2011-02-01T22:15:06+01:00 (13 years ago)
Author:
bastiK
Message:

first version of mapstyle dialog; still hidden because its unfinished (set mappaintdialog.show=true in advanced pref to show it). switching styles on/off and reload from file is supported at the moment.

Location:
trunk/src/org/openstreetmap/josm
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r3836 r3843  
    300300     *--------*/
    301301    public StyleCache mappaintStyle = null;
     302    public int mappaintCacheIdx;
    302303
    303304    /* This should not be called from outside. Fixing the UI to add relevant
  • trunk/src/org/openstreetmap/josm/gui/MapFrame.java

    r3669 r3843  
    5151import org.openstreetmap.josm.gui.dialogs.HistoryDialog;
    5252import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
     53import org.openstreetmap.josm.gui.dialogs.MapPaintDialog;
    5354import org.openstreetmap.josm.gui.dialogs.RelationListDialog;
    5455import org.openstreetmap.josm.gui.dialogs.SelectionListDialog;
     
    185186        addToggleDialog(filterDialog = new FilterDialog());
    186187        addToggleDialog(new ChangesetDialog(this));
     188        if (Main.pref.getBoolean("mappaintdialog.show", false)) {
     189            addToggleDialog(new MapPaintDialog());
     190        }
    187191
    188192        // status line below the map
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

    r3836 r3843  
    1919import org.openstreetmap.josm.gui.NavigatableComponent;
    2020import org.openstreetmap.josm.gui.mappaint.StyleCache.StyleList;
    21 import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSource;
    2221import org.openstreetmap.josm.tools.FilteredCollection;
    2322import org.openstreetmap.josm.tools.Pair;
     
    2625
    2726public class ElemStyles {
    28     private List<XmlStyleSource> styleSources;
     27    private List<StyleSource> styleSources;
    2928    private boolean drawMultipolygon;
     29
     30    public static int cacheIdx;
    3031
    3132    public ElemStyles()
    3233    {
    33         styleSources = new ArrayList<XmlStyleSource>();
    34     }
    35 
    36     public void add(XmlStyleSource style) {
     34        styleSources = new ArrayList<StyleSource>();
     35    }
     36
     37    public void add(StyleSource style) {
    3738        styleSources.add(style);
    3839    }
    3940
    40     public Collection<XmlStyleSource> getStyleSources() {
    41         return new FilteredCollection<XmlStyleSource>(styleSources, new Predicate<XmlStyleSource>() {
     41    public Collection<StyleSource> getStyleSources() {
     42        return new FilteredCollection<StyleSource>(styleSources, new Predicate<StyleSource>() {
    4243
    4344            String name = Main.pref.get("mappaint.style", "standard");
    4445
    4546            @Override
    46             public boolean evaluate(XmlStyleSource s) {
     47            public boolean evaluate(StyleSource s) {
    4748                return Utils.equal(s.getPrefName(), name);
    4849            }
     
    5455        Set<String> names = new HashSet<String>();
    5556        names.add("standard");
    56         for (XmlStyleSource s : styleSources) {
     57        for (StyleSource s : styleSources) {
    5758            if (s.name != null) {
    5859                names.add(s.name);
     
    6768
    6869    public Pair<StyleList, Range> getStyleCacheWithRange(OsmPrimitive osm, double scale, NavigatableComponent nc) {
    69         if (osm.mappaintStyle == null) {
     70        if (osm.mappaintStyle == null || osm.mappaintCacheIdx != cacheIdx) {
    7071            osm.mappaintStyle = StyleCache.EMPTY_STYLECACHE;
    7172        } else {
     
    8384        }
    8485        osm.mappaintStyle = osm.mappaintStyle.put(p.a, p.b);
     86        osm.mappaintCacheIdx = cacheIdx;
    8587        return p;
    8688    }
     
    9092        {
    9193            return generateStyles(osm, scale, null, false);
    92         } 
     94        }
    9395        else if (osm instanceof Way)
    9496        {
     
    178180            }
    179181            return p;
    180         } 
     182        }
    181183        else if (osm instanceof Relation)
    182184        {
     
    216218        MultiCascade mc = new MultiCascade();
    217219
    218         for (XmlStyleSource s : styleSources) {
    219             s.apply(mc, osm, scale, multipolyOuterWay, pretendWayIsClosed);
     220        for (StyleSource s : styleSources) {
     221            if (s.active) {
     222                s.apply(mc, osm, scale, multipolyOuterWay, pretendWayIsClosed);
     223            }
    220224        }
    221225
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java

    r3827 r3843  
    22package org.openstreetmap.josm.gui.mappaint;
    33
    4 import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSource;
    5 import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSourceHandler;
    64import static org.openstreetmap.josm.tools.I18n.tr;
    75
    8 import java.io.File;
    96import java.io.IOException;
    107import java.io.InputStream;
    11 import java.io.InputStreamReader;
    128import java.util.Collection;
    139import java.util.Collections;
     
    1814
    1915import org.openstreetmap.josm.Main;
     16import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSource;
    2017import org.openstreetmap.josm.gui.preferences.SourceEntry;
    2118import org.openstreetmap.josm.gui.preferences.MapPaintPreference.MapPaintPrefMigration;
    2219import org.openstreetmap.josm.io.MirroredInputStream;
    2320import org.openstreetmap.josm.tools.ImageProvider;
    24 import org.openstreetmap.josm.tools.XmlObjectParser;
    25 import org.openstreetmap.josm.tools.Utils;
    26 import org.xml.sax.SAXException;
    27 import org.xml.sax.SAXParseException;
    2821
    2922public class MapPaintStyles {
     
    9083
    9184        for (SourceEntry entry : sourceEntries) {
    92             XmlStyleSource style = new XmlStyleSource(entry);
     85            StyleSource style = new XmlStyleSource(entry);
    9386            try {
    94                 XmlObjectParser parser = new XmlObjectParser(new XmlStyleSourceHandler(style));
    9587                MirroredInputStream in = new MirroredInputStream(entry.url);
    9688                InputStream zip = in.getZipEntry("xml","style");
    97                 InputStreamReader ins;
    98                 if(zip != null)
    99                 {
     89                if (zip != null) {
    10090                    style.zipIcons = in.getFile();
    101                     ins = new InputStreamReader(zip);
    102                 } else {
    103                     ins = new InputStreamReader(in);
    104                 }
    105                 parser.startWithValidation(ins, "http://josm.openstreetmap.de/mappaint-style-1.0",
    106                 "resource://data/mappaint-style.xsd");
    107                 while(parser.hasNext()) {
    108                 }
     91                }
    10992            } catch(IOException e) {
    11093                System.err.println(tr("Warning: failed to load Mappaint styles from ''{0}''. Exception was: {1}", entry.url, e.toString()));
    111                 e.printStackTrace();
    112                 style.hasError = true;
    113             } catch(SAXParseException e) {
    114                 System.err.println(tr("Warning: failed to parse Mappaint styles from ''{0}''. Error was: [{1}:{2}] {3}", entry.url, e.getLineNumber(), e.getColumnNumber(), e.getMessage()));
    115                 e.printStackTrace();
    116                 style.hasError = true;
    117             } catch(SAXException e) {
    118                 System.err.println(tr("Warning: failed to parse Mappaint styles from ''{0}''. Error was: {1}", entry.url, e.getMessage()));
    11994                e.printStackTrace();
    12095                style.hasError = true;
     
    12297            styles.add(style);
    12398        }
     99        for (StyleSource s : styles.getStyleSources()) {
     100            s.loadStyleSource();
     101        }
    124102    }
    125103}
  • trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSource.java

    r3836 r3843  
    22package org.openstreetmap.josm.gui.mappaint.xml;
    33
    4 import java.io.File;
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5
     6import java.io.InputStream;
     7import java.io.InputStreamReader;
     8import java.io.IOException;
    59import java.util.Collection;
    610import java.util.Collections;
    711import java.util.HashMap;
    8 import java.util.Iterator;
    912import java.util.LinkedList;
    1013import java.util.List;
     
    1922import org.openstreetmap.josm.gui.mappaint.MultiCascade;
    2023import org.openstreetmap.josm.gui.mappaint.Range;
     24import org.openstreetmap.josm.gui.mappaint.StyleSource;
    2125import org.openstreetmap.josm.gui.preferences.SourceEntry;
     26import org.openstreetmap.josm.io.MirroredInputStream;
    2227import org.openstreetmap.josm.tools.Utils;
    23 
    24 public class XmlStyleSource extends SourceEntry {
     28import org.openstreetmap.josm.tools.XmlObjectParser;
     29import org.xml.sax.SAXException;
     30import org.xml.sax.SAXParseException;
     31
     32public class XmlStyleSource extends StyleSource {
    2533
    2634    public final HashMap<String, IconPrototype> icons = new HashMap<String, IconPrototype>();
     
    3341    public final LinkedList<AreaPrototype> areasList = new LinkedList<AreaPrototype>();
    3442
    35     public boolean hasError = false;
    36     public File zipIcons;
    37 
    3843    public XmlStyleSource(String url, String name, String shortdescription) {
    39         super(url, name, shortdescription, true);
     44        super(url, name, shortdescription);
    4045    }
    4146
    4247    public XmlStyleSource(SourceEntry entry) {
    43         super(entry.url, entry.name, entry.shortdescription, entry.active);
     48        super(entry);
     49    }
     50
     51    @Override
     52    public void loadStyleSource() {
     53        try {
     54            MirroredInputStream in = new MirroredInputStream(url);
     55            InputStream zip = in.getZipEntry("xml", "style");
     56            InputStreamReader reader = null;
     57            if (zip != null) {
     58                reader = new InputStreamReader(zip);
     59            } else {
     60                reader = new InputStreamReader(in);
     61            }
     62
     63            XmlObjectParser parser = new XmlObjectParser(new XmlStyleSourceHandler(this));
     64            parser.startWithValidation(reader,
     65                    "http://josm.openstreetmap.de/mappaint-style-1.0",
     66                    "resource://data/mappaint-style.xsd");
     67            while(parser.hasNext()) {
     68            }
     69           
     70        } catch(IOException e) {
     71            System.err.println(tr("Warning: failed to load Mappaint styles from ''{0}''. Exception was: {1}", url, e.toString()));
     72            e.printStackTrace();
     73            hasError = true;
     74        } catch(SAXParseException e) {
     75            System.err.println(tr("Warning: failed to parse Mappaint styles from ''{0}''. Error was: [{1}:{2}] {3}", url, e.getLineNumber(), e.getColumnNumber(), e.getMessage()));
     76            e.printStackTrace();
     77            hasError = true;
     78        } catch(SAXException e) {
     79            System.err.println(tr("Warning: failed to parse Mappaint styles from ''{0}''. Error was: {1}", url, e.getMessage()));
     80            e.printStackTrace();
     81            hasError = true;
     82        }
    4483    }
    4584
     
    220259     }
    221260
     261    @Override
    222262    public void apply(MultiCascade mc, OsmPrimitive osm, double scale, OsmPrimitive multipolyOuterWay, boolean pretendWayIsClosed) {
    223263        Cascade def = mc.getCascade("default");
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEntry.java

    r3827 r3843  
    104104        return name == null ? "standard" : name;
    105105    }
     106
     107    public boolean isLocal() {
     108        if (url.startsWith("http://") || url.startsWith("resource://"))
     109            return false;
     110        return true;
     111    }
    106112}
Note: See TracChangeset for help on using the changeset viewer.