Changeset 3805 in josm
- Timestamp:
- 2011-01-23T13:17:10+01:00 (14 years ago)
- 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 19 19 this.maxScale = maxScale; 20 20 this.minScale = minScale; 21 this. rules = a.rules;21 this.conditions = a.conditions; 22 22 this.line = new LineElemStyle(); 23 23 this.line.color = a.color; … … 31 31 this.maxScale = a.maxScale; 32 32 this.minScale = a.minScale; 33 this. rules = a.rules;33 this.conditions = a.conditions; 34 34 this.line = l; 35 35 this.code = a.code; -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java
r3719 r3805 8 8 import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings; 9 9 import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter; 10 import org.openstreetmap.josm.gui.mappaint.xml.XmlCondition; 10 11 11 12 abstract public class ElemStyle { … … 16 17 public int priority; 17 18 public String code; 18 Collection< Rule> rules = null;19 Collection<XmlCondition> conditions = null; 19 20 20 21 @Override … … 29 30 30 31 public String getCode() { 31 if(code == null) { 32 if (code == null) { 32 33 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(); 36 37 } 37 38 } … … 41 42 public boolean check(OsmPrimitive primitive) 42 43 { 43 if( rules == null)44 if(conditions == null) 44 45 return true; 45 for( Rule r : rules)46 for(XmlCondition c : conditions) 46 47 { 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)) 50 51 || (bv != null && !bv.equals(OsmUtils.getNamedOsmBoolean(k)))) 51 52 return false; -
trunk/src/org/openstreetmap/josm/gui/mappaint/IconElemStyle.java
r3719 r3805 22 22 this.maxScale = maxScale; 23 23 this.minScale = minScale; 24 this. rules = i.rules;24 this.conditions = i.conditions; 25 25 } 26 26 public IconElemStyle() { init(); } -
trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java
r3804 r3805 45 45 this.maxScale = maxScale; 46 46 this.minScale = minScale; 47 this. rules = s.rules;47 this.conditions = s.conditions; 48 48 } 49 49 … … 60 60 this.maxScale = s.maxScale; 61 61 this.minScale = s.minScale; 62 this. rules = s.rules;62 this.conditions = s.conditions; 63 63 64 64 this.overlays = overlays; -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r3803 r3805 2 2 package org.openstreetmap.josm.gui.mappaint; 3 3 4 import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSourceHandler; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 … … 78 79 StyleSource style = new StyleSource(entry); 79 80 try { 80 XmlObjectParser parser = new XmlObjectParser(new ElemStyleHandler(style));81 XmlObjectParser parser = new XmlObjectParser(new XmlStyleSourceHandler(style)); 81 82 MirroredInputStream in = new MirroredInputStream(entry.url); 82 83 InputStream zip = in.getZipEntry("xml","style"); -
trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java
r3803 r3805 10 10 import java.util.regex.Matcher; 11 11 import java.util.regex.Pattern; 12 12 13 import org.openstreetmap.josm.data.osm.Node; 13 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 15 import org.openstreetmap.josm.data.osm.OsmUtils; 15 16 import org.openstreetmap.josm.data.osm.Way; 17 import org.openstreetmap.josm.gui.mappaint.xml.XmlCondition; 16 18 import org.openstreetmap.josm.gui.preferences.SourceEntry; 17 19 … … 172 174 } 173 175 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; 178 180 linesList.add(style); 179 181 } 180 182 else { 181 String key = r.getKey();183 String key = c.getKey(); 182 184 style.code = key; 183 185 lines.put(key, style); … … 185 187 } 186 188 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; 191 193 modifiersList.add(style); 192 194 } 193 195 else 194 196 { 195 String key = r.getKey();197 String key = c.getKey(); 196 198 style.code = key; 197 199 modifiers.put(key, style); … … 199 201 } 200 202 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; 205 207 areasList.add(style); 206 208 } 207 209 else 208 210 { 209 String key = r.getKey();211 String key = c.getKey(); 210 212 style.code = key; 211 213 areas.put(key, style); … … 213 215 } 214 216 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; 219 221 iconsList.add(style); 220 222 } 221 223 else 222 224 { 223 String key = r.getKey();225 String key = c.getKey(); 224 226 style.code = key; 225 227 icons.put(key, style); -
trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlCondition.java
r3803 r3805 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.gui.mappaint; 2 package org.openstreetmap.josm.gui.mappaint.xml; 3 3 4 4 import org.openstreetmap.josm.data.osm.OsmUtils; 5 5 6 public class Rule6 public class XmlCondition 7 7 { 8 String key; 9 String value; 10 String boolValue; 8 public String key; 9 public String value; 10 public String boolValue; 11 11 12 public Rule()12 public XmlCondition() 13 13 { 14 14 init(); 15 15 } 16 public Rule(Rule r)16 public XmlCondition(XmlCondition c) 17 17 { 18 key = r.key;19 value = r.value;20 boolValue = r.boolValue;18 key = c.key; 19 value = c.value; 20 boolValue = c.boolValue; 21 21 } 22 22 public String getKey() -
trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSourceHandler.java
r3803 r3805 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.gui.mappaint; 2 package org.openstreetmap.josm.gui.mappaint.xml; 3 3 4 4 import java.awt.Color; … … 9 9 10 10 import org.openstreetmap.josm.Main; 11 import org.openstreetmap.josm.gui.mappaint.AreaElemStyle; 12 import org.openstreetmap.josm.gui.mappaint.IconElemStyle; 13 import org.openstreetmap.josm.gui.mappaint.LineElemStyle; 14 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 15 import org.openstreetmap.josm.gui.mappaint.StyleSource; 11 16 import org.openstreetmap.josm.tools.ColorHelper; 12 17 import org.xml.sax.Attributes; 13 18 import org.xml.sax.helpers.DefaultHandler; 14 19 15 public class ElemStyleHandler extends DefaultHandler20 public class XmlStyleSourceHandler extends DefaultHandler 16 21 { 17 22 private boolean inDoc, inRule, inCondition, inLine, inLineMod, inIcon, inArea, inScaleMax, inScaleMin; … … 22 27 23 28 static class RuleElem { 24 Rule rule= newRule();25 Collection< Rule> rules;29 XmlCondition cond = new XmlCondition(); 30 Collection<XmlCondition> conditions; 26 31 long scaleMax; 27 32 long scaleMin; … … 32 37 public void init() 33 38 { 34 rules = null;39 conditions = null; 35 40 scaleMax = 1000000000; 36 41 scaleMin = 0; 37 42 line.init(); 38 rule.init();43 cond.init(); 39 44 linemod.init(); 40 45 area.init(); … … 43 48 } 44 49 45 public ElemStyleHandler(StyleSource style) {50 public XmlStyleSourceHandler(StyleSource style) { 46 51 this.style = style; 47 52 inDoc=inRule=inCondition=inLine=inIcon=inArea=false; … … 73 78 74 79 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); 76 81 } 77 82 … … 154 159 { 155 160 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(newRule(rule.rule));163 r= newRule();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); 165 170 } 166 171 for (int count=0; count<atts.getLength(); count++) 167 172 { 168 173 if(atts.getQName(count).equals("k")) { 169 r.key = atts.getValue(count);174 c.key = atts.getValue(count); 170 175 } else if(atts.getQName(count).equals("v")) { 171 r.value = atts.getValue(count);176 c.value = atts.getValue(count); 172 177 } else if(atts.getQName(count).equals("b")) { 173 r.boolValue = atts.getValue(count);178 c.boolValue = atts.getValue(count); 174 179 } else { 175 180 error("The element \"" + qName + "\" has unknown attribute \"" + atts.getQName(count) + "\"!"); 176 181 } 177 182 } 178 if( r.key == null) {183 if(c.key == null) { 179 184 error("The condition has no key!"); 180 185 } … … 239 244 if(hadLine) 240 245 { 241 style.add(rule. rule, rule.rules,246 style.add(rule.cond, rule.conditions, 242 247 new LineElemStyle(rule.line, rule.scaleMax, rule.scaleMin)); 243 248 } 244 249 if(hadLineMod) 245 250 { 246 style.addModifier(rule. rule, rule.rules,251 style.addModifier(rule.cond, rule.conditions, 247 252 new LineElemStyle(rule.linemod, rule.scaleMax, rule.scaleMin)); 248 253 } 249 254 if(hadIcon) 250 255 { 251 style.add(rule. rule, rule.rules,256 style.add(rule.cond, rule.conditions, 252 257 new IconElemStyle(rule.icon, rule.scaleMax, rule.scaleMin)); 253 258 } 254 259 if(hadArea) 255 260 { 256 style.add(rule. rule, rule.rules,261 style.add(rule.cond, rule.conditions, 257 262 new AreaElemStyle(rule.area, rule.scaleMax, rule.scaleMin)); 258 263 }
Note:
See TracChangeset
for help on using the changeset viewer.