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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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            }
Note: See TracChangeset for help on using the changeset viewer.