Ignore:
Timestamp:
2009-01-25T00:20:25+01:00 (15 years ago)
Author:
ulfl
Message:

some improvements in mappaints elemstyles.xml handling:

  • add console messages, if unknown elements/attributes found in the elemstyles.xml
  • make "dashed" an int, so we can have different dash lengths (down to 1 for being dotted) - "yes" still defaults to 9 as before
Location:
trunk/src/org/openstreetmap/josm/gui/mappaint
Files:
2 edited

Legend:

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

    r1241 r1333  
    6868    }
    6969
     70    private void error(String message) {
     71        System.out.println(styleName + " (" + rule.key + "=" + rule.value + "): " + message);
     72    }
     73   
     74    private void startElementLine(String qName, Attributes atts, LineElemStyle line) {
     75        for (int count=0; count<atts.getLength(); count++)
     76        {
     77            if(atts.getQName(count).equals("width"))
     78            {
     79                String val = atts.getValue(count);
     80                if(val.startsWith("+"))
     81                {
     82                    line.width = Integer.parseInt(val.substring(1));
     83                    line.widthMode = LineElemStyle.WidthMode.OFFSET;
     84                }
     85                else if(val.startsWith("-"))
     86                {
     87                    line.width = Integer.parseInt(val);
     88                    line.widthMode = LineElemStyle.WidthMode.OFFSET;
     89                }
     90                else if(val.endsWith("%"))
     91                {
     92                    line.width = Integer.parseInt(val.substring(0, val.length()-1));
     93                    line.widthMode = LineElemStyle.WidthMode.PERCENT;
     94                }
     95                else
     96                    line.width = Integer.parseInt(val);
     97            }
     98            else if (atts.getQName(count).equals("colour"))
     99                line.color=convertColor(atts.getValue(count));
     100            else if (atts.getQName(count).equals("realwidth"))
     101                line.realWidth=Integer.parseInt(atts.getValue(count));
     102            else if (atts.getQName(count).equals("dashed")) {
     103                try
     104                {
     105                    line.dashed=Integer.parseInt(atts.getValue(count));
     106                } catch (NumberFormatException nfe) {
     107                    boolean dashed=Boolean.parseBoolean(atts.getValue(count));
     108                    if(dashed) {
     109                        line.dashed = 9;
     110                    }               
     111                }
     112            } else if(atts.getQName(count).equals("priority"))
     113                line.priority = Integer.parseInt(atts.getValue(count));
     114            else if(atts.getQName(count).equals("mode"))
     115                line.over = !atts.getValue(count).equals("under");
     116            else
     117                error("The element \"" + qName + "\" has unknown attribute \"" + atts.getQName(count) + "\"!");
     118        }
     119    }
     120
    70121    @Override public void startElement(String uri,String name, String qName, Attributes atts) {
    71122        if (inDoc==true)
     
    97148                    else if(atts.getQName(count).equals("b"))
    98149                        rule.boolValue = atts.getValue(count);
     150                    else
     151                        error("The element \"" + qName + "\" has unknown attribute \"" + atts.getQName(count) + "\"!");
    99152                }
    100153            }
     
    102155            {
    103156                hadLine = inLine = true;
    104                 for (int count=0; count<atts.getLength(); count++)
    105                 {
    106                     if(atts.getQName(count).equals("width"))
    107                         rule.line.width = Integer.parseInt(atts.getValue(count));
    108                     else if (atts.getQName(count).equals("colour"))
    109                         rule.line.color=convertColor(atts.getValue(count));
    110                     else if (atts.getQName(count).equals("realwidth"))
    111                         rule.line.realWidth=Integer.parseInt(atts.getValue(count));
    112                     else if (atts.getQName(count).equals("dashed"))
    113                         rule.line.dashed=Boolean.parseBoolean(atts.getValue(count));
    114                     else if(atts.getQName(count).equals("priority"))
    115                         rule.line.priority = Integer.parseInt(atts.getValue(count));
     157                startElementLine(qName, atts, rule.line);
     158                if(rule.line.widthMode != LineElemStyle.WidthMode.ABSOLUTE) {
     159                    error("Relative widths are not possible for normal lines");
     160                    rule.line.widthMode = LineElemStyle.WidthMode.ABSOLUTE;
    116161                }
    117162            }
     
    119164            {
    120165                hadLineMod = inLineMod = true;
    121                 for (int count=0; count<atts.getLength(); count++)
    122                 {
    123                     if(atts.getQName(count).equals("width"))
    124                     {
    125                         String val = atts.getValue(count);
    126                         if(val.startsWith("+"))
    127                         {
    128                             rule.linemod.width = Integer.parseInt(val.substring(1));
    129                             rule.linemod.widthMode = LineElemStyle.WidthMode.OFFSET;
    130                         }
    131                         else if(val.startsWith("-"))
    132                         {
    133                             rule.linemod.width = Integer.parseInt(val);
    134                             rule.linemod.widthMode = LineElemStyle.WidthMode.OFFSET;
    135                         }
    136                         else if(val.endsWith("%"))
    137                         {
    138                             rule.linemod.width = Integer.parseInt(val.substring(0, val.length()-1));
    139                             rule.linemod.widthMode = LineElemStyle.WidthMode.PERCENT;
    140                         }
    141                         else
    142                             rule.linemod.width = Integer.parseInt(val);
    143                     }
    144                     else if (atts.getQName(count).equals("colour"))
    145                         rule.linemod.color=convertColor(atts.getValue(count));
    146                     else if (atts.getQName(count).equals("realwidth"))
    147                         rule.linemod.realWidth=Integer.parseInt(atts.getValue(count));
    148                     else if (atts.getQName(count).equals("dashed"))
    149                         rule.linemod.dashed=Boolean.parseBoolean(atts.getValue(count));
    150                     else if(atts.getQName(count).equals("priority"))
    151                         rule.linemod.priority = Integer.parseInt(atts.getValue(count));
    152                     else if(atts.getQName(count).equals("mode"))
    153                         rule.linemod.over = !atts.getValue(count).equals("under");
    154                 }
     166                startElementLine(qName, atts, rule.linemod);
    155167            }
    156168            else if (qName.equals("icon"))
     
    165177                    else if(atts.getQName(count).equals("priority"))
    166178                        rule.icon.priority = Integer.parseInt(atts.getValue(count));
     179                    else
     180                        error("The element \"" + qName + "\" has unknown attribute \"" + atts.getQName(count) + "\"!");
    167181                }
    168182            }
     
    176190                    else if(atts.getQName(count).equals("priority"))
    177191                        rule.area.priority = Integer.parseInt(atts.getValue(count));
    178                 }
    179             }
     192                    else
     193                        error("The element \"" + qName + "\" has unknown attribute \"" + atts.getQName(count) + "\"!");
     194                }
     195            }
     196            else
     197                error("The element \"" + qName + "\" is unknown!");
    180198        }
    181199    }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java

    r1204 r1333  
    99    public int realWidth; //the real width of this line in meter
    1010    public Color color;
    11     public boolean dashed;
     11    public int dashed;
    1212
    1313    public boolean over;
     
    5454        width = 1;
    5555        realWidth = 0;
    56         dashed = false;
     56        dashed = 0;
    5757        priority = 0;
    5858        color = null;
Note: See TracChangeset for help on using the changeset viewer.