Changeset 987 in josm for trunk/src/org
- Timestamp:
- 2008-09-18T13:22:53+02:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java
r976 r987 31 31 import org.openstreetmap.josm.gui.mappaint.AreaElemStyle; 32 32 import org.openstreetmap.josm.gui.mappaint.ElemStyle; 33 import org.openstreetmap.josm.gui.mappaint.ElemStyles; 33 34 import org.openstreetmap.josm.gui.mappaint.IconElemStyle; 34 35 import org.openstreetmap.josm.gui.mappaint.LineElemStyle; … … 46 47 protected Stroke currentStroke = null; 47 48 protected static final Font orderFont = new Font("Helvetica", Font.PLAIN, 8); 49 protected ElemStyles styles; 50 protected double circum; 48 51 49 52 protected boolean isZoomOk(ElemStyle e) { 50 53 if (!zoomLevelDisplay) /* show everything if the user wishes so */ 51 54 return true; 52 53 double circum = Main.map.mapView.getScale()*100*Main.proj.scaleFactor()*40041455; // circumference of the earth in meter54 55 55 56 if(e == null) /* the default for things that don't have a rule (show, if scale is smaller than 1500m) */ … … 71 72 */ 72 73 public void visit(Node n) { 73 IconElemStyle nodeStyle = MapPaintStyles.getStyles().get(n);74 IconElemStyle nodeStyle = styles.get(n); 74 75 if (nodeStyle != null && isZoomOk(nodeStyle)) 75 76 drawNode(n, nodeStyle.icon, nodeStyle.annotate); 76 else { 77 if (n.selected) 78 drawNode(n, selectedColor, selectedNodeSize, selectedNodeRadius, fillSelectedNode); 79 else if (n.tagged) 80 drawNode(n, nodeColor, taggedNodeSize, taggedNodeRadius, fillUnselectedNode); 81 else 82 drawNode(n, nodeColor, unselectedNodeSize, unselectedNodeRadius, fillUnselectedNode); 83 } 77 else if (n.selected) 78 drawNode(n, selectedColor, selectedNodeSize, selectedNodeRadius, fillSelectedNode); 79 else if (n.tagged) 80 drawNode(n, nodeColor, taggedNodeSize, taggedNodeRadius, fillUnselectedNode); 81 else 82 drawNode(n, nodeColor, unselectedNodeSize, unselectedNodeRadius, fillUnselectedNode); 84 83 } 85 84 … … 89 88 */ 90 89 public void visit(Way w) { 91 double circum = Main.map.mapView.getScale()*100*Main.proj.scaleFactor()*40041455; // circumference of the earth in meter 90 if(w.nodes.size() < 2) 91 return; 92 92 // show direction arrows, if draw.segment.relevant_directions_only is not set, the way is tagged with a direction key 93 93 // (even if the tag is negated as in oneway=false) or the way is selected … … 96 96 97 97 Color color = untaggedColor; 98 Color areacolor = untaggedColor;99 98 int width = defaultSegmentWidth; 100 99 int realWidth = 0; //the real width of the element in meters 101 100 boolean dashed = false; 102 boolean area = false; 103 ElemStyle wayStyle = MapPaintStyles.getStyles().get(w); 101 ElemStyle wayStyle = styles.get(w); 104 102 105 103 if(!isZoomOk(wayStyle)) 106 104 return; 107 if(w.nodes.size() < 2)108 return;109 105 110 106 LineElemStyle l = null; 111 107 if(wayStyle!=null) 112 108 { 109 Color areacolor = untaggedColor; 110 boolean area = false; 113 111 if(wayStyle instanceof LineElemStyle) 114 112 l = (LineElemStyle)wayStyle; … … 127 125 dashed = l.dashed; 128 126 } 129 }130 131 if (area && fillAreas)132 drawWayAsArea(w, areacolor); 127 if (area && fillAreas) 128 drawWayAsArea(w, areacolor); 129 } 130 133 131 if (realWidth > 0 && useRealWidth && !showDirection) 134 132 { … … 194 192 } 195 193 } 194 displaySegments(); 196 195 } 197 196 … … 317 316 fillAreas = Main.pref.getBoolean("mappaint.fillareas", true); 318 317 fillAlpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fillalpha", 50)))); 319 320 Collection<Way> noAreaWays = new LinkedList<Way>(); 321 322 for (final OsmPrimitive osm : data.ways) 323 if (!osm.incomplete && !osm.deleted && MapPaintStyles.getStyles().isArea((Way)osm)) 318 circum = Main.map.mapView.getScale()*100*Main.proj.scaleFactor()*40041455; // circumference of the earth in meter 319 styles = MapPaintStyles.getStyles(); 320 321 if(styles.hasAreas()) 322 { 323 Collection<Way> noAreaWays = new LinkedList<Way>(); 324 325 for (final OsmPrimitive osm : data.ways) 326 if (!osm.incomplete && !osm.deleted && styles.isArea((Way)osm)) 327 osm.visit(this); 328 else if (!osm.deleted && !osm.incomplete) 329 noAreaWays.add((Way)osm); 330 331 for (final OsmPrimitive osm : noAreaWays) 324 332 osm.visit(this); 325 else if (!osm.deleted && !osm.incomplete) 326 noAreaWays.add((Way)osm); 327 328 for (final OsmPrimitive osm : noAreaWays) 329 osm.visit(this); 333 } 334 else 335 { 336 for (final OsmPrimitive osm : data.ways) 337 if (!osm.incomplete && !osm.deleted) 338 osm.visit(this); 339 } 330 340 331 341 for (final OsmPrimitive osm : data.getSelected()) -
trunk/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java
r976 r987 72 72 protected int selectedNodeSize; 73 73 protected int unselectedNodeSize; 74 protected int defaultSegmentWidth = 2;74 protected int defaultSegmentWidth; 75 75 protected int virtualNodeSize; 76 76 protected int virtualNodeSpace; -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyleHandler.java
r885 r987 14 14 boolean hadLine, hadLineMod, hadIcon, hadArea; 15 15 ElemStyles styles; 16 String styleName; 16 17 RuleElem rule = new RuleElem(); 17 18 … … 38 39 }; 39 40 40 public ElemStyleHandler() { 41 public ElemStyleHandler(String name) { 42 styleName = name; 41 43 inDoc=inRule=inCondition=inElemStyle=inLine=inIcon=inArea=false; 42 44 rule.init(); … … 174 176 { 175 177 if(hadLine) 176 styles.add( rule.key, rule.value, rule.boolValue,178 styles.add(styleName, rule.key, rule.value, rule.boolValue, 177 179 new LineElemStyle(rule.line, rule.scaleMax, rule.scaleMin)); 178 180 if(hadLineMod) 179 styles.addModifier( rule.key, rule.value, rule.boolValue,181 styles.addModifier(styleName, rule.key, rule.value, rule.boolValue, 180 182 new LineElemStyle(rule.line, rule.scaleMax, rule.scaleMin)); 181 183 if(hadIcon) 182 styles.add( rule.key, rule.value, rule.boolValue,184 styles.add(styleName, rule.key, rule.value, rule.boolValue, 183 185 new IconElemStyle(rule.icon, rule.scaleMax, rule.scaleMin)); 184 186 if(hadArea) 185 styles.add( rule.key, rule.value, rule.boolValue,187 styles.add(styleName, rule.key, rule.value, rule.boolValue, 186 188 new AreaElemStyle(rule.area, rule.scaleMax, rule.scaleMin)); 187 189 inRule = false; -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
r947 r987 11 11 import org.openstreetmap.josm.data.osm.OsmUtils; 12 12 import org.openstreetmap.josm.data.osm.Way; 13 import org.openstreetmap.josm.Main; 13 14 14 15 public class ElemStyles 15 16 { 16 private HashMap<String, IconElemStyle> icons; 17 private HashMap<String, LineElemStyle> lines; 18 private HashMap<String, AreaElemStyle> areas; 19 private HashMap<String, LineElemStyle> modifiers; 17 private class StyleSet { 18 HashMap<String, IconElemStyle> icons; 19 HashMap<String, LineElemStyle> lines; 20 HashMap<String, AreaElemStyle> areas; 21 HashMap<String, LineElemStyle> modifiers; 22 public StyleSet() 23 { 24 icons = new HashMap<String, IconElemStyle>(); 25 lines = new HashMap<String, LineElemStyle>(); 26 modifiers = new HashMap<String, LineElemStyle>(); 27 areas = new HashMap<String, AreaElemStyle>(); 28 } 29 } 30 HashMap<String, StyleSet> styleSet; 20 31 21 32 public ElemStyles() 22 33 { 23 icons = new HashMap<String, IconElemStyle>(); 24 lines = new HashMap<String, LineElemStyle>(); 25 modifiers = new HashMap<String, LineElemStyle>(); 26 areas = new HashMap<String, AreaElemStyle>(); 34 styleSet = new HashMap<String, StyleSet>(); 27 35 } 28 36 … … 37 45 } 38 46 39 public void add(String k, String v, String b, LineElemStyle style)47 public void add(String name, String k, String v, String b, LineElemStyle style) 40 48 { 41 lines.put(getKey(k,v,b), style);49 getStyleSet(name, true).lines.put(getKey(k,v,b), style); 42 50 } 43 51 44 public void addModifier(String k, String v, String b, LineElemStyle style)52 public void addModifier(String name, String k, String v, String b, LineElemStyle style) 45 53 { 46 modifiers.put(getKey(k,v,b), style);54 getStyleSet(name, true).modifiers.put(getKey(k,v,b), style); 47 55 } 48 56 49 public void add(String k, String v, String b, AreaElemStyle style)57 public void add(String name, String k, String v, String b, AreaElemStyle style) 50 58 { 51 areas.put(getKey(k,v,b), style);59 getStyleSet(name, true).areas.put(getKey(k,v,b), style); 52 60 } 53 61 54 public void add(String k, String v, String b, IconElemStyle style)62 public void add(String name, String k, String v, String b, IconElemStyle style) 55 63 { 56 icons.put(getKey(k,v,b), style); 64 getStyleSet(name, true).icons.put(getKey(k,v,b), style); 65 } 66 67 private StyleSet getStyleSet(String name, boolean create) 68 { 69 if(name == null) 70 name = Main.pref.get("mappaint.style", "standard"); 71 StyleSet s = styleSet.get(name); 72 if(create && s == null) 73 { 74 s = new StyleSet(); 75 styleSet.put(name, s); 76 } 77 return s; 57 78 } 58 79 59 80 public IconElemStyle get(Node n) 60 81 { 82 StyleSet ss = getStyleSet(null, false); 61 83 IconElemStyle ret = null; 62 if( n.keys != null)84 if(ss != null && n.keys != null) 63 85 { 64 86 Iterator<String> iterator = n.keys.keySet().iterator(); … … 68 90 String val = n.keys.get(key); 69 91 IconElemStyle style; 70 if((style = icons.get("n" + key + "=" + val)) != null)92 if((style = ss.icons.get("n" + key + "=" + val)) != null) 71 93 { 72 94 if(ret == null || style.priority > ret.priority) 73 95 ret = style; 74 96 } 75 if((style = icons.get("b" + key + "=" + OsmUtils.getNamedOsmBoolean(val))) != null)97 if((style = ss.icons.get("b" + key + "=" + OsmUtils.getNamedOsmBoolean(val))) != null) 76 98 { 77 99 if(ret == null || style.priority > ret.priority) 78 100 ret = style; 79 101 } 80 if((style = icons.get("x" + key)) != null)102 if((style = ss.icons.get("x" + key)) != null) 81 103 { 82 104 if(ret == null || style.priority > ret.priority) … … 90 112 public ElemStyle get(Way w) 91 113 { 114 StyleSet ss = getStyleSet(null, false); 115 if(ss == null || w.keys == null) 116 return null; 92 117 AreaElemStyle retArea = null; 93 118 LineElemStyle retLine = null; 94 119 List<LineElemStyle> over = new LinkedList<LineElemStyle>(); 95 if(w.keys != null) 120 Iterator<String> iterator = w.keys.keySet().iterator(); 121 while(iterator.hasNext()) 96 122 { 97 Iterator<String> iterator = w.keys.keySet().iterator(); 98 while(iterator.hasNext()) 99 { 100 String key = iterator.next(); 101 String val = w.keys.get(key); 102 AreaElemStyle styleArea; 103 LineElemStyle styleLine; 104 String idx = "n" + key + "=" + val; 105 if((styleArea = areas.get(idx)) != null && (retArea == null || styleArea.priority > retArea.priority)) 106 retArea = styleArea; 107 if((styleLine = lines.get(idx)) != null && (retLine == null || styleLine.priority > retLine.priority)) 108 retLine = styleLine; 109 if((styleLine = modifiers.get(idx)) != null) 110 over.add(styleLine); 111 idx = "b" + key + "=" + OsmUtils.getNamedOsmBoolean(val); 112 if((styleArea = areas.get(idx)) != null && (retArea == null || styleArea.priority > retArea.priority)) 113 retArea = styleArea; 114 if((styleLine = lines.get(idx)) != null && (retLine == null || styleLine.priority > retLine.priority)) 115 retLine = styleLine; 116 if((styleLine = modifiers.get(idx)) != null) 117 over.add(styleLine); 118 idx = "x" + key; 119 if((styleArea = areas.get(idx)) != null && (retArea == null || styleArea.priority > retArea.priority)) 120 retArea = styleArea; 121 if((styleLine = lines.get(idx)) != null && (retLine == null || styleLine.priority > retLine.priority)) 122 retLine = styleLine; 123 if((styleLine = modifiers.get(idx)) != null) 124 over.add(styleLine); 125 } 123 String key = iterator.next(); 124 String val = w.keys.get(key); 125 AreaElemStyle styleArea; 126 LineElemStyle styleLine; 127 String idx = "n" + key + "=" + val; 128 if((styleArea = ss.areas.get(idx)) != null && (retArea == null || styleArea.priority > retArea.priority)) 129 retArea = styleArea; 130 if((styleLine = ss.lines.get(idx)) != null && (retLine == null || styleLine.priority > retLine.priority)) 131 retLine = styleLine; 132 if((styleLine = ss.modifiers.get(idx)) != null) 133 over.add(styleLine); 134 idx = "b" + key + "=" + OsmUtils.getNamedOsmBoolean(val); 135 if((styleArea = ss.areas.get(idx)) != null && (retArea == null || styleArea.priority > retArea.priority)) 136 retArea = styleArea; 137 if((styleLine = ss.lines.get(idx)) != null && (retLine == null || styleLine.priority > retLine.priority)) 138 retLine = styleLine; 139 if((styleLine = ss.modifiers.get(idx)) != null) 140 over.add(styleLine); 141 idx = "x" + key; 142 if((styleArea = ss.areas.get(idx)) != null && (retArea == null || styleArea.priority > retArea.priority)) 143 retArea = styleArea; 144 if((styleLine = ss.lines.get(idx)) != null && (retLine == null || styleLine.priority > retLine.priority)) 145 retLine = styleLine; 146 if((styleLine = ss.modifiers.get(idx)) != null) 147 over.add(styleLine); 126 148 } 127 149 if(over.size() != 0 && retLine != null) … … 142 164 public boolean isArea(Way w) 143 165 { 144 if(w.keys != null) 166 StyleSet ss = getStyleSet(null, false); 167 if(ss != null && w.keys != null) 145 168 { 146 169 Iterator<String> iterator = w.keys.keySet().iterator(); … … 149 172 String key = iterator.next(); 150 173 String val = w.keys.get(key); 151 if( areas.containsKey("n" + key + "=" + val)152 || areas.containsKey("n" + key + "=" + OsmUtils.getNamedOsmBoolean(val))153 || areas.containsKey("x" + key))174 if(ss.areas.containsKey("n" + key + "=" + val) 175 || ss.areas.containsKey("n" + key + "=" + OsmUtils.getNamedOsmBoolean(val)) 176 || ss.areas.containsKey("x" + key)) 154 177 return true; 155 178 } … … 157 180 return false; 158 181 } 182 public boolean hasAreas() 183 { 184 StyleSet ss = getStyleSet(null, false); 185 return ss != null && ss.areas.size() > 0; 186 } 159 187 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r935 r987 80 80 // System.out.println("mappaint: Using style file: \"" + f + "\""); 81 81 XMLReader xmlReader = XMLReaderFactory.createXMLReader(); 82 ElemStyleHandler handler = new ElemStyleHandler( );82 ElemStyleHandler handler = new ElemStyleHandler(styleName); 83 83 xmlReader.setContentHandler(handler); 84 84 xmlReader.setErrorHandler(handler); … … 101 101 { 102 102 XMLReader xmlReader = XMLReaderFactory.createXMLReader(); 103 ElemStyleHandler handler = new ElemStyleHandler( );103 ElemStyleHandler handler = new ElemStyleHandler(internalStyleName); 104 104 xmlReader.setContentHandler(handler); 105 105 xmlReader.setErrorHandler(handler);
Note:
See TracChangeset
for help on using the changeset viewer.