- Timestamp:
- 2009-01-11T11:20:44+01:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java
r1236 r1240 47 47 protected Stroke currentStroke = null; 48 48 protected Font orderFont; 49 protected ElemStyles styles;49 protected ElemStyles.StyleSet styles; 50 50 protected double circum; 51 51 protected String regionalNameOrder[]; … … 78 78 // check, if the node is visible at all 79 79 Point p = nc.getPoint(n.eastNorth); 80 if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) || (p.y > nc.getHeight())) return; 81 82 IconElemStyle nodeStyle = (IconElemStyle)styles.get(n); 80 if ((!selectedCall && n.selected) || (p.x < 0) || (p.y < 0) 81 || (p.x > nc.getWidth()) || (p.y > nc.getHeight())) return; 82 83 IconElemStyle nodeStyle = styles != null ? (IconElemStyle)styles.get(n) : null; 83 84 if (nodeStyle != null && isZoomOk(nodeStyle)) 84 85 drawNode(n, nodeStyle.icon, nodeStyle.annotate, n.selected); … … 96 97 */ 97 98 public void visit(Way w) { 98 if(w.nodes.size() < 2 )99 if(w.nodes.size() < 2 && (!selectedCall && w.selected)) 99 100 return; 100 101 … … 104 105 return; 105 106 106 ElemStyle wayStyle = styles .get(w);107 ElemStyle wayStyle = styles != null ? styles.get(w) : null; 107 108 108 109 if(!isZoomOk(wayStyle)) … … 322 323 /* nodes drawn on second call */ 323 324 if(!(m.member instanceof Node)) 324 drawSelected(m.member, styles.get(m.member), true, true); 325 drawSelected(m.member, styles != null ? styles.get(m.member) 326 : null, true, true); 325 327 alreadyDrawn.add(m.member); 326 328 } … … 368 370 && m.member instanceof Node) 369 371 { 370 drawSelected(m.member, styles .get(m.member), true, true);372 drawSelected(m.member, styles != null ? styles.get(m.member) : null, true, true); 371 373 alreadyDrawn.add(m.member); 372 374 } … … 420 422 outer.add(w); 421 423 else if(r.selected) 422 drawSelected(m.member, styles .get(m.member), true, true);424 drawSelected(m.member, styles != null ? styles.get(m.member) : null, true, true); 423 425 } 424 426 } … … 432 434 } 433 435 434 ElemStyle wayStyle = styles .get(r);436 ElemStyle wayStyle = styles != null ? styles.get(r) : null; 435 437 /* find one wayStyle, prefer the style from Relation or take the first 436 438 one of outer rings */ 437 if( wayStyle == null || !(wayStyle instanceof AreaElemStyle))439 if(styles != null && (wayStyle == null || !(wayStyle instanceof AreaElemStyle))) 438 440 { 439 441 for (Way w : outer) … … 779 781 } 780 782 781 // NW 111106 Overridden from SimplePaintVisitor in josm-1.4-nw1782 783 // Shows areas before non-areas 783 784 public void visitAll(DataSet data, Boolean virtual) { … … 798 799 fillAlpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fillalpha", 50)))); 799 800 circum = Main.map.mapView.getScale()*100*Main.proj.scaleFactor()*40041455; // circumference of the earth in meter 800 styles = MapPaintStyles.getStyles() ;801 styles = MapPaintStyles.getStyles().getStyleSet(); 801 802 drawMultipolygon = Main.pref.getBoolean("mappaint.multipolygon",false); 802 803 orderFont = new Font(Main.pref.get("mappaint.font","Helvetica"), Font.PLAIN, Main.pref.getInteger("mappaint.fontsize", 8)); … … 808 809 selectedCall = false; 809 810 810 // update the style name, just in case the user changed it in the meantime811 styles.updateStyleName();812 813 811 if(profiler) 814 812 { … … 817 815 } 818 816 819 if (fillAreas && styles .hasAreas()) {817 if (fillAreas && styles != null && styles.hasAreas()) { 820 818 Collection<Way> noAreaWays = new LinkedList<Way>(); 821 819 -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
r1235 r1240 17 17 public class ElemStyles 18 18 { 19 p rivateclass StyleSet {20 HashMap<String, IconElemStyle> icons;21 HashMap<String, LineElemStyle> lines;22 HashMap<String, AreaElemStyle> areas;23 HashMap<String, LineElemStyle> modifiers;19 public class StyleSet { 20 private HashMap<String, IconElemStyle> icons; 21 private HashMap<String, LineElemStyle> lines; 22 private HashMap<String, AreaElemStyle> areas; 23 private HashMap<String, LineElemStyle> modifiers; 24 24 public StyleSet() 25 25 { … … 29 29 areas = new HashMap<String, AreaElemStyle>(); 30 30 } 31 } 31 private ElemStyle getNode(Map<String, String> keys) 32 { 33 IconElemStyle ret = null; 34 Iterator<String> iterator = keys.keySet().iterator(); 35 while(iterator.hasNext()) 36 { 37 String key = iterator.next(); 38 String val = keys.get(key); 39 IconElemStyle style; 40 if((style = icons.get("n" + key + "=" + val)) != null) 41 { 42 if(ret == null || style.priority > ret.priority) 43 ret = style; 44 } 45 if((style = icons.get("b" + key + "=" + OsmUtils.getNamedOsmBoolean(val))) != null) 46 { 47 if(ret == null || style.priority > ret.priority) 48 ret = style; 49 } 50 if((style = icons.get("x" + key)) != null) 51 { 52 if(ret == null || style.priority > ret.priority) 53 ret = style; 54 } 55 } 56 return ret; 57 } 58 private ElemStyle get(Map<String, String> keys) 59 { 60 AreaElemStyle retArea = null; 61 LineElemStyle retLine = null; 62 String linestring = null; 63 HashMap<String, LineElemStyle> over = new HashMap<String, LineElemStyle>(); 64 Iterator<String> iterator = keys.keySet().iterator(); 65 while(iterator.hasNext()) 66 { 67 String key = iterator.next(); 68 String val = keys.get(key); 69 AreaElemStyle styleArea; 70 LineElemStyle styleLine; 71 String idx = "n" + key + "=" + val; 72 if((styleArea = areas.get(idx)) != null && (retArea == null || styleArea.priority > retArea.priority)) 73 retArea = styleArea; 74 if((styleLine = lines.get(idx)) != null && (retLine == null || styleLine.priority > retLine.priority)) 75 { 76 retLine = styleLine; 77 linestring = idx; 78 } 79 if((styleLine = modifiers.get(idx)) != null) 80 over.put(idx, styleLine); 81 idx = "b" + key + "=" + OsmUtils.getNamedOsmBoolean(val); 82 if((styleArea = areas.get(idx)) != null && (retArea == null || styleArea.priority > retArea.priority)) 83 retArea = styleArea; 84 if((styleLine = lines.get(idx)) != null && (retLine == null || styleLine.priority > retLine.priority)) 85 { 86 retLine = styleLine; 87 linestring = idx; 88 } 89 if((styleLine = modifiers.get(idx)) != null) 90 over.put(idx, styleLine); 91 idx = "x" + key; 92 if((styleArea = areas.get(idx)) != null && (retArea == null || styleArea.priority > retArea.priority)) 93 retArea = styleArea; 94 if((styleLine = lines.get(idx)) != null && (retLine == null || styleLine.priority > retLine.priority)) 95 { 96 retLine = styleLine; 97 linestring = idx; 98 } 99 if((styleLine = modifiers.get(idx)) != null) 100 over.put(idx, styleLine); 101 } 102 over.remove(linestring); 103 if(over.size() != 0 && retLine != null) 104 { 105 List<LineElemStyle> s = new LinkedList<LineElemStyle>(over.values()); 106 Collections.sort(s); 107 retLine = new LineElemStyle(retLine, s); 108 } 109 if(retArea != null) 110 { 111 if(retLine != null) 112 return new AreaElemStyle(retArea, retLine); 113 else 114 return retArea; 115 } 116 return retLine; 117 } 118 119 public ElemStyle get(OsmPrimitive osm) 120 { 121 return (osm.keys == null) ? null : 122 ((osm instanceof Node) ? getNode(osm.keys) : get(osm.keys)); 123 } 124 125 public boolean isArea(OsmPrimitive o) 126 { 127 if(o.keys != null && !(o instanceof Node)) 128 { 129 Iterator<String> iterator = o.keys.keySet().iterator(); 130 while(iterator.hasNext()) 131 { 132 String key = iterator.next(); 133 String val = o.keys.get(key); 134 if(areas.containsKey("n" + key + "=" + val) 135 || areas.containsKey("b" + key + "=" + OsmUtils.getNamedOsmBoolean(val)) 136 || areas.containsKey("x" + key)) 137 return true; 138 } 139 } 140 return false; 141 } 142 143 public boolean hasAreas() 144 { 145 return areas.size() > 0; 146 } 147 } 148 32 149 HashMap<String, StyleSet> styleSet; 33 String styleName;34 35 150 public ElemStyles() 36 151 { 37 152 styleSet = new HashMap<String, StyleSet>(); 38 updateStyleName();39 }40 41 public void updateStyleName() {42 // Main.pref.get() is slow when done thousands of times, do it once here and cache it43 styleName = Main.pref.get("mappaint.style", "standard");44 153 } 45 154 … … 85 194 { 86 195 if(name == null) 87 name = styleName; 196 name = Main.pref.get("mappaint.style", "standard"); 197 88 198 StyleSet s = styleSet.get(name); 89 199 if(create && s == null) … … 95 205 } 96 206 97 private ElemStyle getNode(Map<String, String> keys, StyleSet ss) 98 { 99 IconElemStyle ret = null; 100 Iterator<String> iterator = keys.keySet().iterator(); 101 while(iterator.hasNext()) 102 { 103 String key = iterator.next(); 104 String val = keys.get(key); 105 IconElemStyle style; 106 if((style = ss.icons.get("n" + key + "=" + val)) != null) 107 { 108 if(ret == null || style.priority > ret.priority) 109 ret = style; 110 } 111 if((style = ss.icons.get("b" + key + "=" + OsmUtils.getNamedOsmBoolean(val))) != null) 112 { 113 if(ret == null || style.priority > ret.priority) 114 ret = style; 115 } 116 if((style = ss.icons.get("x" + key)) != null) 117 { 118 if(ret == null || style.priority > ret.priority) 119 ret = style; 120 } 121 } 122 return ret; 123 } 124 125 private ElemStyle get(Map<String, String> keys, StyleSet ss) 126 { 127 AreaElemStyle retArea = null; 128 LineElemStyle retLine = null; 129 String linestring = null; 130 HashMap<String, LineElemStyle> over = new HashMap<String, LineElemStyle>(); 131 Iterator<String> iterator = keys.keySet().iterator(); 132 while(iterator.hasNext()) 133 { 134 String key = iterator.next(); 135 String val = keys.get(key); 136 AreaElemStyle styleArea; 137 LineElemStyle styleLine; 138 String idx = "n" + key + "=" + val; 139 if((styleArea = ss.areas.get(idx)) != null && (retArea == null || styleArea.priority > retArea.priority)) 140 retArea = styleArea; 141 if((styleLine = ss.lines.get(idx)) != null && (retLine == null || styleLine.priority > retLine.priority)) 142 { 143 retLine = styleLine; 144 linestring = idx; 145 } 146 if((styleLine = ss.modifiers.get(idx)) != null) 147 over.put(idx, styleLine); 148 idx = "b" + key + "=" + OsmUtils.getNamedOsmBoolean(val); 149 if((styleArea = ss.areas.get(idx)) != null && (retArea == null || styleArea.priority > retArea.priority)) 150 retArea = styleArea; 151 if((styleLine = ss.lines.get(idx)) != null && (retLine == null || styleLine.priority > retLine.priority)) 152 { 153 retLine = styleLine; 154 linestring = idx; 155 } 156 if((styleLine = ss.modifiers.get(idx)) != null) 157 over.put(idx, styleLine); 158 idx = "x" + key; 159 if((styleArea = ss.areas.get(idx)) != null && (retArea == null || styleArea.priority > retArea.priority)) 160 retArea = styleArea; 161 if((styleLine = ss.lines.get(idx)) != null && (retLine == null || styleLine.priority > retLine.priority)) 162 { 163 retLine = styleLine; 164 linestring = idx; 165 } 166 if((styleLine = ss.modifiers.get(idx)) != null) 167 over.put(idx, styleLine); 168 } 169 over.remove(linestring); 170 if(over.size() != 0 && retLine != null) 171 { 172 List<LineElemStyle> s = new LinkedList<LineElemStyle>(over.values()); 173 Collections.sort(s); 174 retLine = new LineElemStyle(retLine, s); 175 } 176 if(retArea != null) 177 { 178 if(retLine != null) 179 return new AreaElemStyle(retArea, retLine); 180 else 181 return retArea; 182 } 183 return retLine; 184 } 185 186 public ElemStyle get(OsmPrimitive osm) 187 { 188 StyleSet ss = getStyleSet(null, false); 189 return (ss == null || osm.keys == null) ? null : 190 ((osm instanceof Node) ? getNode(osm.keys, ss) : get(osm.keys, ss)); 191 } 192 193 private boolean isArea(Map<String, String> keys, StyleSet ss) 194 { 195 Iterator<String> iterator = keys.keySet().iterator(); 196 while(iterator.hasNext()) 197 { 198 String key = iterator.next(); 199 String val = keys.get(key); 200 if(ss.areas.containsKey("n" + key + "=" + val) 201 || ss.areas.containsKey("b" + key + "=" + OsmUtils.getNamedOsmBoolean(val)) 202 || ss.areas.containsKey("x" + key)) 203 return true; 204 } 205 return false; 206 } 207 208 public boolean isArea(OsmPrimitive o) 209 { 210 StyleSet ss = getStyleSet(null, false); 211 return (ss != null && o.keys != null && !(o instanceof Node)) 212 ? isArea(o.keys, ss) : false; 213 } 214 215 public boolean hasAreas() 216 { 217 StyleSet ss = getStyleSet(null, false); 218 return ss != null && ss.areas.size() > 0; 207 /* called from class users, never return null */ 208 public StyleSet getStyleSet() 209 { 210 return getStyleSet(null, false); 219 211 } 220 212 }
Note:
See TracChangeset
for help on using the changeset viewer.