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


Ignore:
Timestamp:
2011-01-22T19:27:33+01:00 (13 years ago)
Author:
bastiK
Message:

Don't merge all mappaitn style rules into one StyleSet, but keep them as separate StyleSources. This allows switching styles on and off at runtime.

Location:
trunk/src/org/openstreetmap/josm
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintVisitor.java

    r3800 r3803  
    3434import org.openstreetmap.josm.gui.mappaint.AreaElemStyle;
    3535import org.openstreetmap.josm.gui.mappaint.ElemStyle;
     36import org.openstreetmap.josm.gui.mappaint.ElemStyles;
    3637import org.openstreetmap.josm.gui.mappaint.IconElemStyle;
    3738import org.openstreetmap.josm.gui.mappaint.LineElemStyle;
    3839import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
    3940import org.openstreetmap.josm.gui.mappaint.SimpleNodeElemStyle;
    40 import org.openstreetmap.josm.gui.mappaint.StyleSource;
    4141
    4242public class MapPaintVisitor implements PaintVisitor {
     
    4949    private boolean drawRestriction;
    5050    private boolean leftHandTraffic;
    51     private StyleSource styles;
     51    private ElemStyles styles;
    5252    private double circum;
    5353    private double dist;
     
    535535        zoomLevelDisplay = Main.pref.getBoolean("mappaint.zoomLevelDisplay", false);
    536536        circum = nc.getDist100Pixel();
    537         styles = MapPaintStyles.getStyles().getStyleSet();
     537        styles = MapPaintStyles.getStyles();
    538538        drawMultipolygon = Main.pref.getBoolean("mappaint.multipolygon", true);
    539539        drawRestriction = Main.pref.getBoolean("mappaint.restriction", true);
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java

    r3799 r3803  
    2424import org.openstreetmap.josm.gui.mappaint.AreaElemStyle;
    2525import org.openstreetmap.josm.gui.mappaint.ElemStyle;
     26import org.openstreetmap.josm.gui.mappaint.ElemStyles;
    2627import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
    27 import org.openstreetmap.josm.gui.mappaint.StyleSource;
    2828
    2929public class MultipolygonTest extends Test {
     
    4141    protected static final int NO_STYLE_POLYGON = 1611;
    4242
    43     private static StyleSource styles;
     43    private static ElemStyles styles;
    4444
    4545    private final List<List<Node>> nonClosedWays = new ArrayList<List<Node>>();
     
    5252    @Override
    5353    public void initialize() throws Exception {
    54         styles = MapPaintStyles.getStyles().getStyleSet();
     54        styles = MapPaintStyles.getStyles();
    5555    }
    5656
  • trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java

    r3719 r3803  
    4545    }
    4646
    47     public ElemStyle getLineStyle() {
     47    public LineElemStyle getLineStyle() {
    4848        return line;
    4949    }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyleHandler.java

    r3719 r3803  
    1515public class ElemStyleHandler extends DefaultHandler
    1616{
    17     boolean inDoc, inRule, inCondition, inLine, inLineMod, inIcon, inArea, inScaleMax, inScaleMin;
    18     boolean hadLine, hadLineMod, hadIcon, hadArea;
    19     ElemStyles styles;
    20     String styleName;
    21     RuleElem rule = new RuleElem();
     17    private boolean inDoc, inRule, inCondition, inLine, inLineMod, inIcon, inArea, inScaleMax, inScaleMin;
     18    private boolean hadLine, hadLineMod, hadIcon, hadArea;
     19    private RuleElem rule = new RuleElem();
     20
     21    StyleSource style;
    2222
    2323    static class RuleElem {
     
    4343    }
    4444
    45     public ElemStyleHandler(String name) {
    46         styleName = name;
     45    public ElemStyleHandler(StyleSource style) {
     46        this.style = style;
    4747        inDoc=inRule=inCondition=inLine=inIcon=inArea=false;
    4848        rule.init();
    49         styles = MapPaintStyles.getStyles();
    5049    }
    5150
     
    5453        int i = colString.indexOf("#");
    5554        Color ret;
    56         if(i < 0) {
    57             ret = Main.pref.getColor("mappaint."+styleName+"."+colString, Color.red);
     55        if (i < 0) {
     56            ret = Main.pref.getColor("mappaint."+style.getPrefName()+"."+colString, Color.red);
    5857        } else if(i == 0) {
    5958            ret = ColorHelper.html2color(colString);
    6059        } else {
    61             ret = Main.pref.getColor("mappaint."+styleName+"."+colString.substring(0,i),
     60            ret = Main.pref.getColor("mappaint."+style.getPrefName()+"."+colString.substring(0,i),
    6261                    ColorHelper.html2color(colString.substring(i)));
    6362        }
     
    7473
    7574    private void error(String message) {
    76         System.out.println(styleName + " (" + rule.rule.key + "=" + rule.rule.value + "): " + message);
     75        System.out.println(style.getDisplayString() + " (" + rule.rule.key + "=" + rule.rule.value + "): " + message);
    7776    }
    7877
     
    141140            } else if (qName.equals("rules"))
    142141            {
    143                 if(styleName == null)
    144                 {
    145                     String n = atts.getValue("name");
    146                     if(n == null) {
    147                         n = "standard";
    148                     }
    149                     styleName = n;
     142                if (style.name == null) {
     143                    style.name = atts.getValue("name");
     144                }
     145                if (style.shortdescription == null) {
     146                    style.shortdescription = atts.getValue("shortdescription");
    150147                }
    151148            }
     
    203200                {
    204201                    if (atts.getQName(count).equals("src")) {
    205                         ImageIcon icon = MapPaintStyles.getIcon(atts.getValue(count), styleName);
     202                        ImageIcon icon = MapPaintStyles.getIcon(atts.getValue(count), style.getPrefName());
    206203                        hadIcon = (icon != null);
    207204                        rule.icon.icon = icon;
     
    242239            if(hadLine)
    243240            {
    244                 styles.add(styleName, rule.rule, rule.rules,
     241                style.add(rule.rule, rule.rules,
    245242                        new LineElemStyle(rule.line, rule.scaleMax, rule.scaleMin));
    246243            }
    247244            if(hadLineMod)
    248245            {
    249                 styles.addModifier(styleName, rule.rule, rule.rules,
     246                style.addModifier(rule.rule, rule.rules,
    250247                        new LineElemStyle(rule.linemod, rule.scaleMax, rule.scaleMin));
    251248            }
    252249            if(hadIcon)
    253250            {
    254                 styles.add(styleName, rule.rule, rule.rules,
     251                style.add(rule.rule, rule.rules,
    255252                        new IconElemStyle(rule.icon, rule.scaleMax, rule.scaleMin));
    256253            }
    257254            if(hadArea)
    258255            {
    259                 styles.add(styleName, rule.rule, rule.rules,
     256                style.add(rule.rule, rule.rules,
    260257                        new AreaElemStyle(rule.area, rule.scaleMax, rule.scaleMin));
    261258            }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

    r3799 r3803  
    22package org.openstreetmap.josm.gui.mappaint;
    33
     4import static org.openstreetmap.josm.tools.Utils.equal;
     5
     6import java.util.ArrayList;
    47import java.util.Collection;
    5 import java.util.Collections;
    6 import java.util.HashMap;
    7 import java.util.Iterator;
    8 import java.util.LinkedList;
     8import java.util.HashSet;
    99import java.util.List;
     10import java.util.Set;
    1011
    1112import org.openstreetmap.josm.Main;
    1213import org.openstreetmap.josm.data.osm.Node;
    1314import org.openstreetmap.josm.data.osm.OsmPrimitive;
    14 import org.openstreetmap.josm.data.osm.OsmUtils;
    1515import org.openstreetmap.josm.data.osm.Way;
     16import org.openstreetmap.josm.tools.FilteredCollection;
     17import org.openstreetmap.josm.tools.Predicate;
    1618
    17 public class ElemStyles
    18 {
    19     HashMap<String, StyleSource> styleSet;
     19public class ElemStyles {
     20    private List<StyleSource> styleSources;
     21
    2022    public ElemStyles()
    2123    {
    22         styleSet = new HashMap<String, StyleSource>();
     24        styleSources = new ArrayList<StyleSource>();
    2325    }
    2426
    25     public void add(String name, Rule r, Collection<Rule> rules, LineElemStyle style)
    26     {
    27         if(rules != null)
    28         {
    29             style.rules = rules;
    30             getStyleSet(name, true).linesList.add(style);
    31         }
    32         else
    33         {
    34             String key = r.getKey();
    35             style.code = key;
    36             getStyleSet(name, true).lines.put(key, style);
     27    public void add(StyleSource style) {
     28        styleSources.add(style);
     29    }
     30
     31    public Collection<StyleSource> getStyleSources() {
     32        return new FilteredCollection<StyleSource>(styleSources, new Predicate<StyleSource>() {
     33
     34            String name = Main.pref.get("mappaint.style", "standard");
     35
     36            @Override
     37            public boolean evaluate(StyleSource s) {
     38                return equal(s.getPrefName(), name);
     39            }
     40
     41        });
     42    }
     43
     44    public ElemStyle get(OsmPrimitive osm) {
     45        return get(osm, false);
     46    }
     47
     48    public ElemStyle get(OsmPrimitive osm, boolean forceArea) {
     49        if (!osm.hasKeys())
     50            return null;
     51
     52        if (osm instanceof Node) {
     53            IconElemStyle icon = null;
     54            for (StyleSource s : getStyleSources()) {
     55                icon = s.getNode(osm, icon);
     56            }
     57            return icon;
     58        } else {
     59            boolean noclosed;
     60            if (forceArea) {
     61                noclosed = false;
     62            } else {
     63                noclosed = osm instanceof Way && !((Way) osm).isClosed();
     64            }
     65            AreaElemStyle area = null;
     66            LineElemStyle line = null;
     67            ElemStyle result = null;
     68            for (StyleSource s : getStyleSources()) {
     69                result = s.get(osm, noclosed, area, line);
     70                if (result instanceof LineElemStyle) {
     71                    area = null;
     72                    line = (LineElemStyle) result;
     73                } else if (result instanceof AreaElemStyle) {
     74                    area = (AreaElemStyle) result;
     75                    if (area.getLineStyle() != null) {
     76                        line = area.getLineStyle();
     77                    }
     78                } else if (result != null)
     79                    throw new AssertionError();
     80            }
     81            return result;
    3782        }
    3883    }
    3984
    40     public void addModifier(String name, Rule r, Collection<Rule> rules, LineElemStyle style)
    41     {
    42         if(rules != null)
    43         {
    44             style.rules = rules;
    45             getStyleSet(name, true).modifiersList.add(style);
     85    public boolean hasAreas() {
     86        for (StyleSource s : getStyleSources()) {
     87            if (s.hasAreas())
     88                return true;
    4689        }
    47         else
    48         {
    49             String key = r.getKey();
    50             style.code = key;
    51             getStyleSet(name, true).modifiers.put(key, style);
    52         }
     90        return false;
    5391    }
    5492
    55     public void add(String name, Rule r, Collection<Rule> rules, AreaElemStyle style)
    56     {
    57         if(rules != null)
    58         {
    59             style.rules = rules;
    60             getStyleSet(name, true).areasList.add(style);
     93    public boolean isArea(OsmPrimitive osm) {
     94        for (StyleSource s : getStyleSources()) {
     95            if (s.isArea(osm))
     96                return true;
    6197        }
    62         else
    63         {
    64             String key = r.getKey();
    65             style.code = key;
    66             getStyleSet(name, true).areas.put(key, style);
    67         }
     98        return false;
    6899    }
    69100
    70     public void add(String name, Rule r, Collection<Rule> rules, IconElemStyle style)
    71     {
    72         if(rules != null)
    73         {
    74             style.rules = rules;
    75             getStyleSet(name, true).iconsList.add(style);
     101    public ElemStyle getArea(Way osm) {
     102        if (osm.hasKeys()) {
     103            /* force area mode also for unclosed ways */
     104            ElemStyle style = get(osm, true);
     105            if (style != null && style instanceof AreaElemStyle) {
     106                return style;
     107            }
    76108        }
    77         else
    78         {
    79             String key = r.getKey();
    80             style.code = key;
    81             getStyleSet(name, true).icons.put(key, style);
    82         }
     109        return null;
    83110    }
    84111
    85     private StyleSource getStyleSet(String name, boolean create)
    86     {
    87         if(name == null) {
    88             name = Main.pref.get("mappaint.style", "standard");
    89         }
    90 
    91         StyleSource s = styleSet.get(name);
    92         if(create && s == null)
    93         {
    94             s = new StyleSource();
    95             styleSet.put(name, s);
    96         }
    97         return s;
     112    public IconElemStyle getIcon(OsmPrimitive osm) {
     113        return osm.hasKeys() ? (IconElemStyle) get(osm) : null;
    98114    }
    99115
    100     /* called from class users, never return null */
    101     public StyleSource getStyleSet()
    102     {
    103         return getStyleSet(null, true);
    104     }
    105 
    106     public Collection<String> getStyleNames()
    107     {
    108         return styleSet.keySet();
     116    public Collection<String> getStyleNames() {
     117        Set<String> names = new HashSet<String>();
     118        names.add("standard");
     119        for (StyleSource s : styleSources) {
     120            if (s.name != null) {
     121                names.add(s.name);
     122            }
     123        }
     124        return names;
    109125    }
    110126}
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java

    r3796 r3803  
    7676
    7777        for (SourceEntry entry : sourceEntries) {
     78            StyleSource style = new StyleSource(entry);
    7879            try {
    79                 XmlObjectParser parser = new XmlObjectParser(new ElemStyleHandler(entry.name));
     80                XmlObjectParser parser = new XmlObjectParser(new ElemStyleHandler(style));
    8081                MirroredInputStream in = new MirroredInputStream(entry.url);
    8182                InputStream zip = in.getZipEntry("xml","style");
     
    9596                System.err.println(tr("Warning: failed to load Mappaint styles from ''{0}''. Exception was: {1}", entry.url, e.toString()));
    9697                e.printStackTrace();
     98                style.hasError = true;
    9799            } catch(SAXParseException e) {
    98100                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()));
    99101                e.printStackTrace();
     102                style.hasError = true;
    100103            } catch(SAXException e) {
    101104                System.err.println(tr("Warning: failed to parse Mappaint styles from ''{0}''. Error was: {1}", entry.url, e.getMessage()));
    102105                e.printStackTrace();
     106                style.hasError = true;
    103107            }
     108            styles.add(style);
    104109        }
    105110        iconDirs = null;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java

    r3799 r3803  
    22package org.openstreetmap.josm.gui.mappaint;
    33
     4import java.util.Collection;
    45import java.util.Collections;
    56import java.util.HashMap;
     
    78import java.util.LinkedList;
    89import java.util.List;
     10import java.util.regex.Matcher;
     11import java.util.regex.Pattern;
    912import org.openstreetmap.josm.data.osm.Node;
    1013import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1114import org.openstreetmap.josm.data.osm.OsmUtils;
    1215import org.openstreetmap.josm.data.osm.Way;
    13 
    14 public class StyleSource {
    15 
    16     public HashMap<String, IconElemStyle> icons;
    17     public HashMap<String, LineElemStyle> lines;
    18     public HashMap<String, AreaElemStyle> areas;
    19     public HashMap<String, LineElemStyle> modifiers;
    20     public LinkedList<IconElemStyle> iconsList;
    21     public LinkedList<LineElemStyle> linesList;
    22     public LinkedList<AreaElemStyle> areasList;
    23     public LinkedList<LineElemStyle> modifiersList;
    24 
    25     public StyleSource() {
    26         icons = new HashMap<String, IconElemStyle>();
    27         lines = new HashMap<String, LineElemStyle>();
    28         modifiers = new HashMap<String, LineElemStyle>();
    29         areas = new HashMap<String, AreaElemStyle>();
    30         iconsList = new LinkedList<IconElemStyle>();
    31         linesList = new LinkedList<LineElemStyle>();
    32         modifiersList = new LinkedList<LineElemStyle>();
    33         areasList = new LinkedList<AreaElemStyle>();
    34     }
    35 
    36     private IconElemStyle getNode(OsmPrimitive primitive) {
    37         IconElemStyle ret = null;
     16import org.openstreetmap.josm.gui.preferences.SourceEntry;
     17
     18public class StyleSource extends SourceEntry {
     19
     20    public final HashMap<String, IconElemStyle> icons = new HashMap<String, IconElemStyle>();
     21    public final HashMap<String, LineElemStyle> lines = new HashMap<String, LineElemStyle>();
     22    public final HashMap<String, LineElemStyle> modifiers = new HashMap<String, LineElemStyle>();
     23    public final HashMap<String, AreaElemStyle> areas = new HashMap<String, AreaElemStyle>();
     24    public final LinkedList<IconElemStyle> iconsList = new LinkedList<IconElemStyle>();
     25    public final LinkedList<LineElemStyle> linesList = new LinkedList<LineElemStyle>();
     26    public final LinkedList<LineElemStyle> modifiersList = new LinkedList<LineElemStyle>();
     27    public final LinkedList<AreaElemStyle> areasList = new LinkedList<AreaElemStyle>();
     28
     29    public boolean hasError = false;
     30
     31    public StyleSource(String url, String name, String shortdescription) {
     32        super(url, name, shortdescription, true);
     33    }
     34
     35    public StyleSource(SourceEntry entry) {
     36        super(entry.url, entry.name, entry.shortdescription, entry.active);
     37    }
     38
     39    public IconElemStyle getNode(OsmPrimitive primitive, IconElemStyle icon) {
    3840        for (String key : primitive.keySet()) {
    3941            String val = primitive.get(key);
    4042            IconElemStyle style;
    4143            if ((style = icons.get("n" + key + "=" + val)) != null) {
    42                 if (ret == null || style.priority > ret.priority) {
    43                     ret = style;
     44                if (icon == null || style.priority > icon.priority) {
     45                    icon = style;
    4446                }
    4547            }
    4648            if ((style = icons.get("b" + key + "=" + OsmUtils.getNamedOsmBoolean(val))) != null) {
    47                 if (ret == null || style.priority > ret.priority) {
    48                     ret = style;
     49                if (icon == null || style.priority > icon.priority) {
     50                    icon = style;
    4951                }
    5052            }
    5153            if ((style = icons.get("x" + key)) != null) {
    52                 if (ret == null || style.priority > ret.priority) {
    53                     ret = style;
     54                if (icon == null || style.priority > icon.priority) {
     55                    icon = style;
    5456                }
    5557            }
    5658        }
    5759        for (IconElemStyle s : iconsList) {
    58             if ((ret == null || s.priority > ret.priority) && s.check(primitive)) {
    59                 ret = s;
    60             }
    61         }
    62         return ret;
    63     }
    64 
    65     private ElemStyle get(OsmPrimitive primitive, boolean noclosed) {
    66         AreaElemStyle retArea = null;
    67         LineElemStyle retLine = null;
    68         String linestring = null;
    69         HashMap<String, LineElemStyle> over = new HashMap<String, LineElemStyle>();
     60            if ((icon == null || s.priority > icon.priority) && s.check(primitive)) {
     61                icon = s;
     62            }
     63        }
     64        return icon;
     65    }
     66
     67    public ElemStyle get(OsmPrimitive primitive, boolean noclosed, AreaElemStyle area, LineElemStyle line) {
     68        String lineIdx = null;
     69        HashMap<String, LineElemStyle> overlayMap = new HashMap<String, LineElemStyle>();
    7070        for (String key : primitive.keySet()) {
    7171            String val = primitive.get(key);
     
    7373            LineElemStyle styleLine;
    7474            String idx = "n" + key + "=" + val;
    75             if ((styleArea = areas.get(idx)) != null && (retArea == null || styleArea.priority > retArea.priority) && (!noclosed || !styleArea.closed)) {
    76                 retArea = styleArea;
    77             }
    78             if ((styleLine = lines.get(idx)) != null && (retLine == null || styleLine.priority > retLine.priority)) {
    79                 retLine = styleLine;
    80                 linestring = idx;
     75            if ((styleArea = areas.get(idx)) != null && (area == null || styleArea.priority > area.priority) && (!noclosed || !styleArea.closed)) {
     76                area = styleArea;
     77            }
     78            if ((styleLine = lines.get(idx)) != null && (line == null || styleLine.priority > line.priority)) {
     79                line = styleLine;
     80                lineIdx = idx;
    8181            }
    8282            if ((styleLine = modifiers.get(idx)) != null) {
    83                 over.put(idx, styleLine);
     83                overlayMap.put(idx, styleLine);
    8484            }
    8585            idx = "b" + key + "=" + OsmUtils.getNamedOsmBoolean(val);
    86             if ((styleArea = areas.get(idx)) != null && (retArea == null || styleArea.priority > retArea.priority) && (!noclosed || !styleArea.closed)) {
    87                 retArea = styleArea;
    88             }
    89             if ((styleLine = lines.get(idx)) != null && (retLine == null || styleLine.priority > retLine.priority)) {
    90                 retLine = styleLine;
    91                 linestring = idx;
     86            if ((styleArea = areas.get(idx)) != null && (area == null || styleArea.priority > area.priority) && (!noclosed || !styleArea.closed)) {
     87                area = styleArea;
     88            }
     89            if ((styleLine = lines.get(idx)) != null && (line == null || styleLine.priority > line.priority)) {
     90                line = styleLine;
     91                lineIdx = idx;
    9292            }
    9393            if ((styleLine = modifiers.get(idx)) != null) {
    94                 over.put(idx, styleLine);
     94                overlayMap.put(idx, styleLine);
    9595            }
    9696            idx = "x" + key;
    97             if ((styleArea = areas.get(idx)) != null && (retArea == null || styleArea.priority > retArea.priority) && (!noclosed || !styleArea.closed)) {
    98                 retArea = styleArea;
    99             }
    100             if ((styleLine = lines.get(idx)) != null && (retLine == null || styleLine.priority > retLine.priority)) {
    101                 retLine = styleLine;
    102                 linestring = idx;
     97            if ((styleArea = areas.get(idx)) != null && (area == null || styleArea.priority > area.priority) && (!noclosed || !styleArea.closed)) {
     98                area = styleArea;
     99            }
     100            if ((styleLine = lines.get(idx)) != null && (line == null || styleLine.priority > line.priority)) {
     101                line = styleLine;
     102                lineIdx = idx;
    103103            }
    104104            if ((styleLine = modifiers.get(idx)) != null) {
    105                 over.put(idx, styleLine);
     105                overlayMap.put(idx, styleLine);
    106106            }
    107107        }
    108108        for (AreaElemStyle s : areasList) {
    109             if ((retArea == null || s.priority > retArea.priority) && (!noclosed || !s.closed) && s.check(primitive)) {
    110                 retArea = s;
     109            if ((area == null || s.priority > area.priority) && (!noclosed || !s.closed) && s.check(primitive)) {
     110                area = s;
    111111            }
    112112        }
    113113        for (LineElemStyle s : linesList) {
    114             if ((retLine == null || s.priority > retLine.priority) && s.check(primitive)) {
    115                 retLine = s;
     114            if ((line == null || s.priority > line.priority) && s.check(primitive)) {
     115                line = s;
    116116            }
    117117        }
    118118        for (LineElemStyle s : modifiersList) {
    119119            if (s.check(primitive)) {
    120                 over.put(s.getCode(), s);
    121             }
    122         }
    123         over.remove(linestring);
    124         if (over.size() != 0 && retLine != null) {
    125             List<LineElemStyle> s = new LinkedList<LineElemStyle>(over.values());
    126             Collections.sort(s);
    127             retLine = new LineElemStyle(retLine, s);
    128         }
    129         if (retArea != null) {
    130             if (retLine != null) {
    131                 return new AreaElemStyle(retArea, retLine);
     120                overlayMap.put(s.getCode(), s);
     121            }
     122        }
     123        overlayMap.remove(lineIdx); // do not use overlay if linestyle is from the same rule (example: railway=tram)
     124        if (!overlayMap.isEmpty() && line != null) {
     125            List<LineElemStyle> tmp = new LinkedList<LineElemStyle>();
     126            if (line.overlays != null) {
     127                tmp.addAll(line.overlays);
     128            }
     129            tmp.addAll(overlayMap.values());
     130            Collections.sort(tmp);
     131            line = new LineElemStyle(line, tmp);
     132        }
     133        if (area != null) {
     134            if (line != null) {
     135                return new AreaElemStyle(area, line);
    132136            } else {
    133                 return retArea;
    134             }
    135         }
    136         return retLine;
    137     }
    138 
    139     public ElemStyle get(OsmPrimitive osm) {
    140         return (!osm.hasKeys()) ? null : ((osm instanceof Node) ? getNode(osm) : get(osm, osm instanceof Way && !((Way) osm).isClosed()));
    141     }
    142 
    143     public ElemStyle getArea(Way osm) {
    144         if (osm.hasKeys()) {
    145             /* force area mode also for unclosed ways */
    146             ElemStyle style = get(osm, false);
    147             if (style != null && style instanceof AreaElemStyle) {
    148                 return style;
    149             }
    150         }
    151         return null;
    152     }
    153 
    154     public IconElemStyle getIcon(OsmPrimitive osm) {
    155         return osm.hasKeys() ? getNode(osm) : null;
     137                return area;
     138            }
     139        }
     140        return line;
    156141    }
    157142
     
    186171        return areas.size() > 0;
    187172    }
     173
     174    public void add(Rule r, Collection<Rule> rules, LineElemStyle style) {
     175        if(rules != null)
     176        {
     177            style.rules = rules;
     178            linesList.add(style);
     179        }
     180        else {
     181            String key = r.getKey();
     182            style.code = key;
     183            lines.put(key, style);
     184        }
     185    }
     186
     187    public void addModifier(Rule r, Collection<Rule> rules, LineElemStyle style) {
     188        if(rules != null)
     189        {
     190            style.rules = rules;
     191            modifiersList.add(style);
     192        }
     193        else
     194        {
     195            String key = r.getKey();
     196            style.code = key;
     197            modifiers.put(key, style);
     198        }
     199    }
     200
     201    public void add(Rule r, Collection<Rule> rules, AreaElemStyle style) {
     202        if(rules != null)
     203        {
     204            style.rules = rules;
     205            areasList.add(style);
     206        }
     207        else
     208        {
     209            String key = r.getKey();
     210            style.code = key;
     211            areas.put(key, style);
     212        }
     213    }
     214
     215    public void add(Rule r, Collection<Rule> rules, IconElemStyle style) {
     216        if(rules != null)
     217        {
     218            style.rules = rules;
     219            iconsList.add(style);
     220        }
     221        else
     222        {
     223            String key = r.getKey();
     224            style.code = key;
     225            icons.put(key, style);
     226        }
     227    }
     228
     229    /**
     230     * the name / identifier that should be used to save custom color values
     231     * and similar stuff to the preference file
     232     * @return the identifier; never null. Usually the result is "standard"
     233     */
     234    public String getPrefName() {
     235        return name == null ? "standard" : name;
     236    }
     237
     238    /**
     239     * String to show in menus and error messages.
     240     * @return Usually the shortdescription, but can be the file name
     241     * if no shortdescription is available.
     242     */
     243    public String getDisplayString() {
     244        if (shortdescription != null)
     245            return shortdescription;
     246        /**
     247         * extract file part from url, e.g.:
     248         * http://www.test.com/file.xml?format=text  --> file.xml
     249         */
     250        Pattern p = Pattern.compile("([^/\\\\]*?)([?].*)?$");
     251        Matcher m = p.matcher(url);
     252        if (m.find()) {
     253            return m.group(1);
     254        } else {
     255            System.err.println("Warning: Unexpected URL format: "+url);
     256            return url;
     257        }
     258    }
    188259}
Note: See TracChangeset for help on using the changeset viewer.