Changeset 3799 in josm for trunk/src/org
- Timestamp:
- 2011-01-22T00:04:51+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintVisitor.java
r3653 r3799 52 52 private boolean drawRestriction; 53 53 private boolean leftHandTraffic; 54 private ElemStyles.StyleSet styles;54 private StyleSet styles; 55 55 private double circum; 56 56 private double dist; -
trunk/src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java
r3673 r3799 24 24 import org.openstreetmap.josm.gui.mappaint.AreaElemStyle; 25 25 import org.openstreetmap.josm.gui.mappaint.ElemStyle; 26 import org.openstreetmap.josm.gui.mappaint.ElemStyles;27 26 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 27 import org.openstreetmap.josm.gui.mappaint.StyleSource; 28 28 29 29 public class MultipolygonTest extends Test { … … 41 41 protected static final int NO_STYLE_POLYGON = 1611; 42 42 43 private static ElemStyles.StyleSetstyles;43 private static StyleSource styles; 44 44 45 45 private final List<List<Node>> nonClosedWays = new ArrayList<List<Node>>(); -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
r3719 r3799 17 17 public class ElemStyles 18 18 { 19 public static 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 private LinkedList<IconElemStyle> iconsList; 25 private LinkedList<LineElemStyle> linesList; 26 private LinkedList<AreaElemStyle> areasList; 27 private LinkedList<LineElemStyle> modifiersList; 28 public StyleSet() 29 { 30 icons = new HashMap<String, IconElemStyle>(); 31 lines = new HashMap<String, LineElemStyle>(); 32 modifiers = new HashMap<String, LineElemStyle>(); 33 areas = new HashMap<String, AreaElemStyle>(); 34 iconsList = new LinkedList<IconElemStyle>(); 35 linesList = new LinkedList<LineElemStyle>(); 36 modifiersList = new LinkedList<LineElemStyle>(); 37 areasList = new LinkedList<AreaElemStyle>(); 38 } 39 private IconElemStyle getNode(OsmPrimitive primitive) 40 { 41 IconElemStyle ret = null; 42 for (String key: primitive.keySet()) { 43 String val = primitive.get(key); 44 IconElemStyle style; 45 if((style = icons.get("n" + key + "=" + val)) != null) 46 { 47 if(ret == null || style.priority > ret.priority) { 48 ret = style; 49 } 50 } 51 if((style = icons.get("b" + key + "=" + OsmUtils.getNamedOsmBoolean(val))) != null) 52 { 53 if(ret == null || style.priority > ret.priority) { 54 ret = style; 55 } 56 } 57 if((style = icons.get("x" + key)) != null) 58 { 59 if(ret == null || style.priority > ret.priority) { 60 ret = style; 61 } 62 } 63 } 64 for(IconElemStyle s : iconsList) 65 { 66 if((ret == null || s.priority > ret.priority) && s.check(primitive)) { 67 ret = s; 68 } 69 } 70 return ret; 71 } 72 private ElemStyle get(OsmPrimitive primitive, boolean noclosed) 73 { 74 AreaElemStyle retArea = null; 75 LineElemStyle retLine = null; 76 String linestring = null; 77 HashMap<String, LineElemStyle> over = new HashMap<String, LineElemStyle>(); 78 for (String key: primitive.keySet()) { 79 String val = primitive.get(key); 80 AreaElemStyle styleArea; 81 LineElemStyle styleLine; 82 String idx = "n" + key + "=" + val; 83 if((styleArea = areas.get(idx)) != null && (retArea == null 84 || styleArea.priority > retArea.priority) && (!noclosed 85 || !styleArea.closed)) { 86 retArea = styleArea; 87 } 88 if((styleLine = lines.get(idx)) != null && (retLine == null 89 || styleLine.priority > retLine.priority)) 90 { 91 retLine = styleLine; 92 linestring = idx; 93 } 94 if((styleLine = modifiers.get(idx)) != null) { 95 over.put(idx, styleLine); 96 } 97 idx = "b" + key + "=" + OsmUtils.getNamedOsmBoolean(val); 98 if((styleArea = areas.get(idx)) != null && (retArea == null 99 || styleArea.priority > retArea.priority) && (!noclosed 100 || !styleArea.closed)) { 101 retArea = styleArea; 102 } 103 if((styleLine = lines.get(idx)) != null && (retLine == null 104 || styleLine.priority > retLine.priority)) 105 { 106 retLine = styleLine; 107 linestring = idx; 108 } 109 if((styleLine = modifiers.get(idx)) != null) { 110 over.put(idx, styleLine); 111 } 112 idx = "x" + key; 113 if((styleArea = areas.get(idx)) != null && (retArea == null 114 || styleArea.priority > retArea.priority) && (!noclosed 115 || !styleArea.closed)) { 116 retArea = styleArea; 117 } 118 if((styleLine = lines.get(idx)) != null && (retLine == null 119 || styleLine.priority > retLine.priority)) 120 { 121 retLine = styleLine; 122 linestring = idx; 123 } 124 if((styleLine = modifiers.get(idx)) != null) { 125 over.put(idx, styleLine); 126 } 127 } 128 for(AreaElemStyle s : areasList) 129 { 130 if((retArea == null || s.priority > retArea.priority) 131 && (!noclosed || !s.closed) && s.check(primitive)) { 132 retArea = s; 133 } 134 } 135 for(LineElemStyle s : linesList) 136 { 137 if((retLine == null || s.priority > retLine.priority) 138 && s.check(primitive)) { 139 retLine = s; 140 } 141 } 142 for(LineElemStyle s : modifiersList) 143 { 144 if(s.check(primitive)) { 145 over.put(s.getCode(), s); 146 } 147 } 148 over.remove(linestring); 149 if(over.size() != 0 && retLine != null) 150 { 151 List<LineElemStyle> s = new LinkedList<LineElemStyle>(over.values()); 152 Collections.sort(s); 153 retLine = new LineElemStyle(retLine, s); 154 } 155 if(retArea != null) 156 { 157 if(retLine != null) 158 return new AreaElemStyle(retArea, retLine); 159 else 160 return retArea; 161 } 162 return retLine; 163 } 164 165 public ElemStyle get(OsmPrimitive osm) 166 { 167 return (!osm.hasKeys()) ? null : 168 ((osm instanceof Node) ? getNode(osm) : get(osm, 169 osm instanceof Way && !((Way)osm).isClosed())); 170 } 171 172 public ElemStyle getArea(Way osm) 173 { 174 if(osm.hasKeys()) 175 { 176 /* force area mode also for unclosed ways */ 177 ElemStyle style = get(osm, false); 178 if(style != null && style instanceof AreaElemStyle) 179 return style; 180 } 181 return null; 182 } 183 184 public IconElemStyle getIcon(OsmPrimitive osm) 185 { 186 return osm.hasKeys() ? getNode(osm): null; 187 } 188 189 public boolean isArea(OsmPrimitive o) 190 { 191 if(o.hasKeys() && !(o instanceof Node)) 192 { 193 boolean noclosed = o instanceof Way && !((Way)o).isClosed(); 194 Iterator<String> iterator = o.keySet().iterator(); 195 while(iterator.hasNext()) 196 { 197 String key = iterator.next(); 198 String val = o.get(key); 199 AreaElemStyle s = areas.get("n" + key + "=" + val); 200 if(s == null || (s.closed && noclosed)) { 201 s = areas.get("b" + key + "=" + OsmUtils.getNamedOsmBoolean(val)); 202 } 203 if(s == null || (s.closed && noclosed)) { 204 s = areas.get("x" + key); 205 } 206 if(s != null && !(s.closed && noclosed)) 207 return true; 208 } 209 for(AreaElemStyle s : areasList) 210 { 211 if(!(s.closed && noclosed) && s.check(o)) 212 return true; 213 } 214 } 215 return false; 216 } 217 218 public boolean hasAreas() 219 { 220 return areas.size() > 0; 221 } 222 } 223 224 HashMap<String, StyleSet> styleSet; 19 HashMap<String, StyleSource> styleSet; 225 20 public ElemStyles() 226 21 { 227 styleSet = new HashMap<String, StyleS et>();22 styleSet = new HashMap<String, StyleSource>(); 228 23 } 229 24 … … 288 83 } 289 84 290 private StyleS etgetStyleSet(String name, boolean create)85 private StyleSource getStyleSet(String name, boolean create) 291 86 { 292 87 if(name == null) { … … 294 89 } 295 90 296 StyleS ets = styleSet.get(name);91 StyleSource s = styleSet.get(name); 297 92 if(create && s == null) 298 93 { 299 s = new StyleS et();94 s = new StyleSource(); 300 95 styleSet.put(name, s); 301 96 } … … 304 99 305 100 /* called from class users, never return null */ 306 public StyleS etgetStyleSet()101 public StyleSource getStyleSet() 307 102 { 308 103 return getStyleSet(null, true);
Note:
See TracChangeset
for help on using the changeset viewer.