Changeset 3805 in josm


Ignore:
Timestamp:
2011-01-23T13:17:10+01:00 (14 years ago)
Author:
bastiK
Message:

some renaming (to make future commits easier to read)

Location:
trunk/src/org/openstreetmap/josm/gui/mappaint
Files:
1 added
6 edited
2 moved

Legend:

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

    r3803 r3805  
    1919        this.maxScale = maxScale;
    2020        this.minScale = minScale;
    21         this.rules = a.rules;
     21        this.conditions = a.conditions;
    2222        this.line = new LineElemStyle();
    2323        this.line.color = a.color;
     
    3131        this.maxScale = a.maxScale;
    3232        this.minScale = a.minScale;
    33         this.rules = a.rules;
     33        this.conditions = a.conditions;
    3434        this.line = l;
    3535        this.code = a.code;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java

    r3719 r3805  
    88import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
    99import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter;
     10import org.openstreetmap.josm.gui.mappaint.xml.XmlCondition;
    1011
    1112abstract public class ElemStyle {
     
    1617    public int priority;
    1718    public String code;
    18     Collection<Rule> rules = null;
     19    Collection<XmlCondition> conditions = null;
    1920
    2021    @Override
     
    2930
    3031    public String getCode() {
    31         if(code == null) {
     32        if (code == null) {
    3233            code = "";
    33             if (rules != null) {
    34                 for(Rule r: rules) {
    35                     code += r.toCode();
     34            if (conditions != null) {
     35                for (XmlCondition c: conditions) {
     36                    code += c.toCode();
    3637                }
    3738            }
     
    4142    public boolean check(OsmPrimitive primitive)
    4243    {
    43         if(rules == null)
     44        if(conditions == null)
    4445            return true;
    45         for(Rule r : rules)
     46        for(XmlCondition c : conditions)
    4647        {
    47             String k = primitive.get(r.key);
    48             String bv = OsmUtils.getNamedOsmBoolean(r.boolValue);
    49             if(k == null || (r.value != null && !k.equals(r.value))
     48            String k = primitive.get(c.key);
     49            String bv = OsmUtils.getNamedOsmBoolean(c.boolValue);
     50            if(k == null || (c.value != null && !k.equals(c.value))
    5051                    || (bv != null && !bv.equals(OsmUtils.getNamedOsmBoolean(k))))
    5152                return false;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/IconElemStyle.java

    r3719 r3805  
    2222        this.maxScale = maxScale;
    2323        this.minScale = minScale;
    24         this.rules = i.rules;
     24        this.conditions = i.conditions;
    2525    }
    2626    public IconElemStyle() { init(); }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java

    r3804 r3805  
    4545        this.maxScale = maxScale;
    4646        this.minScale = minScale;
    47         this.rules = s.rules;
     47        this.conditions = s.conditions;
    4848    }
    4949
     
    6060        this.maxScale = s.maxScale;
    6161        this.minScale = s.minScale;
    62         this.rules = s.rules;
     62        this.conditions = s.conditions;
    6363
    6464        this.overlays = overlays;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java

    r3803 r3805  
    22package org.openstreetmap.josm.gui.mappaint;
    33
     4import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSourceHandler;
    45import static org.openstreetmap.josm.tools.I18n.tr;
    56
     
    7879            StyleSource style = new StyleSource(entry);
    7980            try {
    80                 XmlObjectParser parser = new XmlObjectParser(new ElemStyleHandler(style));
     81                XmlObjectParser parser = new XmlObjectParser(new XmlStyleSourceHandler(style));
    8182                MirroredInputStream in = new MirroredInputStream(entry.url);
    8283                InputStream zip = in.getZipEntry("xml","style");
  • trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java

    r3803 r3805  
    1010import java.util.regex.Matcher;
    1111import java.util.regex.Pattern;
     12
    1213import org.openstreetmap.josm.data.osm.Node;
    1314import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1415import org.openstreetmap.josm.data.osm.OsmUtils;
    1516import org.openstreetmap.josm.data.osm.Way;
     17import org.openstreetmap.josm.gui.mappaint.xml.XmlCondition;
    1618import org.openstreetmap.josm.gui.preferences.SourceEntry;
    1719
     
    172174    }
    173175
    174     public void add(Rule r, Collection<Rule> rules, LineElemStyle style) {
    175         if(rules != null)
    176         {
    177             style.rules = rules;
     176    public void add(XmlCondition c, Collection<XmlCondition> conditions, LineElemStyle style) {
     177        if(conditions != null)
     178        {
     179            style.conditions = conditions;
    178180            linesList.add(style);
    179181        }
    180182        else {
    181             String key = r.getKey();
     183            String key = c.getKey();
    182184            style.code = key;
    183185            lines.put(key, style);
     
    185187    }
    186188
    187     public void addModifier(Rule r, Collection<Rule> rules, LineElemStyle style) {
    188         if(rules != null)
    189         {
    190             style.rules = rules;
     189    public void addModifier(XmlCondition c, Collection<XmlCondition> conditions, LineElemStyle style) {
     190        if(conditions != null)
     191        {
     192            style.conditions = conditions;
    191193            modifiersList.add(style);
    192194        }
    193195        else
    194196        {
    195             String key = r.getKey();
     197            String key = c.getKey();
    196198            style.code = key;
    197199            modifiers.put(key, style);
     
    199201    }
    200202
    201     public void add(Rule r, Collection<Rule> rules, AreaElemStyle style) {
    202         if(rules != null)
    203         {
    204             style.rules = rules;
     203    public void add(XmlCondition c, Collection<XmlCondition> conditions, AreaElemStyle style) {
     204        if(conditions != null)
     205        {
     206            style.conditions = conditions;
    205207            areasList.add(style);
    206208        }
    207209        else
    208210        {
    209             String key = r.getKey();
     211            String key = c.getKey();
    210212            style.code = key;
    211213            areas.put(key, style);
     
    213215    }
    214216
    215     public void add(Rule r, Collection<Rule> rules, IconElemStyle style) {
    216         if(rules != null)
    217         {
    218             style.rules = rules;
     217    public void add(XmlCondition c, Collection<XmlCondition> conditions, IconElemStyle style) {
     218        if(conditions != null)
     219        {
     220            style.conditions = conditions;
    219221            iconsList.add(style);
    220222        }
    221223        else
    222224        {
    223             String key = r.getKey();
     225            String key = c.getKey();
    224226            style.code = key;
    225227            icons.put(key, style);
  • trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlCondition.java

    r3803 r3805  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.gui.mappaint;
     2package org.openstreetmap.josm.gui.mappaint.xml;
    33
    44import org.openstreetmap.josm.data.osm.OsmUtils;
    55
    6 public class Rule
     6public class XmlCondition
    77{
    8     String key;
    9     String value;
    10     String boolValue;
     8    public String key;
     9    public String value;
     10    public String boolValue;
    1111
    12     public Rule()
     12    public XmlCondition()
    1313    {
    1414      init();
    1515    }
    16     public Rule(Rule r)
     16    public XmlCondition(XmlCondition c)
    1717    {
    18       key = r.key;
    19       value = r.value;
    20       boolValue = r.boolValue;
     18      key = c.key;
     19      value = c.value;
     20      boolValue = c.boolValue;
    2121    }
    2222    public String getKey()
  • trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSourceHandler.java

    r3803 r3805  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.gui.mappaint;
     2package org.openstreetmap.josm.gui.mappaint.xml;
    33
    44import java.awt.Color;
     
    99
    1010import org.openstreetmap.josm.Main;
     11import org.openstreetmap.josm.gui.mappaint.AreaElemStyle;
     12import org.openstreetmap.josm.gui.mappaint.IconElemStyle;
     13import org.openstreetmap.josm.gui.mappaint.LineElemStyle;
     14import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
     15import org.openstreetmap.josm.gui.mappaint.StyleSource;
    1116import org.openstreetmap.josm.tools.ColorHelper;
    1217import org.xml.sax.Attributes;
    1318import org.xml.sax.helpers.DefaultHandler;
    1419
    15 public class ElemStyleHandler extends DefaultHandler
     20public class XmlStyleSourceHandler extends DefaultHandler
    1621{
    1722    private boolean inDoc, inRule, inCondition, inLine, inLineMod, inIcon, inArea, inScaleMax, inScaleMin;
     
    2227
    2328    static class RuleElem {
    24         Rule rule = new Rule();
    25         Collection<Rule> rules;
     29        XmlCondition cond = new XmlCondition();
     30        Collection<XmlCondition> conditions;
    2631        long scaleMax;
    2732        long scaleMin;
     
    3237        public void init()
    3338        {
    34             rules = null;
     39            conditions = null;
    3540            scaleMax = 1000000000;
    3641            scaleMin = 0;
    3742            line.init();
    38             rule.init();
     43            cond.init();
    3944            linemod.init();
    4045            area.init();
     
    4348    }
    4449
    45     public ElemStyleHandler(StyleSource style) {
     50    public XmlStyleSourceHandler(StyleSource style) {
    4651        this.style = style;
    4752        inDoc=inRule=inCondition=inLine=inIcon=inArea=false;
     
    7378
    7479    private void error(String message) {
    75         System.out.println(style.getDisplayString() + " (" + rule.rule.key + "=" + rule.rule.value + "): " + message);
     80        System.out.println(style.getDisplayString() + " (" + rule.cond.key + "=" + rule.cond.value + "): " + message);
    7681    }
    7782
     
    154159            {
    155160                inCondition=true;
    156                 Rule r = rule.rule;
    157                 if(r.key != null)
    158                 {
    159                     if(rule.rules == null) {
    160                         rule.rules = new LinkedList<Rule>();
    161                     }
    162                     rule.rules.add(new Rule(rule.rule));
    163                     r = new Rule();
    164                     rule.rules.add(r);
     161                XmlCondition c = rule.cond;
     162                if(c.key != null)
     163                {
     164                    if(rule.conditions == null) {
     165                        rule.conditions = new LinkedList<XmlCondition>();
     166                    }
     167                    rule.conditions.add(new XmlCondition(rule.cond));
     168                    c = new XmlCondition();
     169                    rule.conditions.add(c);
    165170                }
    166171                for (int count=0; count<atts.getLength(); count++)
    167172                {
    168173                    if(atts.getQName(count).equals("k")) {
    169                         r.key = atts.getValue(count);
     174                        c.key = atts.getValue(count);
    170175                    } else if(atts.getQName(count).equals("v")) {
    171                         r.value = atts.getValue(count);
     176                        c.value = atts.getValue(count);
    172177                    } else if(atts.getQName(count).equals("b")) {
    173                         r.boolValue = atts.getValue(count);
     178                        c.boolValue = atts.getValue(count);
    174179                    } else {
    175180                        error("The element \"" + qName + "\" has unknown attribute \"" + atts.getQName(count) + "\"!");
    176181                    }
    177182                }
    178                 if(r.key == null) {
     183                if(c.key == null) {
    179184                    error("The condition has no key!");
    180185                }
     
    239244            if(hadLine)
    240245            {
    241                 style.add(rule.rule, rule.rules,
     246                style.add(rule.cond, rule.conditions,
    242247                        new LineElemStyle(rule.line, rule.scaleMax, rule.scaleMin));
    243248            }
    244249            if(hadLineMod)
    245250            {
    246                 style.addModifier(rule.rule, rule.rules,
     251                style.addModifier(rule.cond, rule.conditions,
    247252                        new LineElemStyle(rule.linemod, rule.scaleMax, rule.scaleMin));
    248253            }
    249254            if(hadIcon)
    250255            {
    251                 style.add(rule.rule, rule.rules,
     256                style.add(rule.cond, rule.conditions,
    252257                        new IconElemStyle(rule.icon, rule.scaleMax, rule.scaleMin));
    253258            }
    254259            if(hadArea)
    255260            {
    256                 style.add(rule.rule, rule.rules,
     261                style.add(rule.cond, rule.conditions,
    257262                        new AreaElemStyle(rule.area, rule.scaleMax, rule.scaleMin));
    258263            }
Note: See TracChangeset for help on using the changeset viewer.