Changeset 9278 in josm for trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
- Timestamp:
- 2016-01-03T15:50:53+01:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
r9239 r9278 23 23 import org.openstreetmap.josm.gui.mappaint.StyleCache.StyleList; 24 24 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; 25 import org.openstreetmap.josm.gui.mappaint.styleelement.AreaElement; 26 import org.openstreetmap.josm.gui.mappaint.styleelement.BoxTextElement; 27 import org.openstreetmap.josm.gui.mappaint.styleelement.LineElement; 28 import org.openstreetmap.josm.gui.mappaint.styleelement.LineTextElement; 29 import org.openstreetmap.josm.gui.mappaint.styleelement.NodeElement; 30 import org.openstreetmap.josm.gui.mappaint.styleelement.RepeatImageElement; 31 import org.openstreetmap.josm.gui.mappaint.styleelement.StyleElement; 32 import org.openstreetmap.josm.gui.mappaint.styleelement.TextLabel; 25 33 import org.openstreetmap.josm.gui.util.GuiHelper; 26 34 import org.openstreetmap.josm.tools.Pair; … … 97 105 if (osm instanceof Node && isDefaultNodes()) { 98 106 if (p.a.isEmpty()) { 99 if (Text Element.AUTO_LABEL_COMPOSITION_STRATEGY.compose(osm) != null) {100 p.a = NodeElem Style.DEFAULT_NODE_STYLELIST_TEXT;107 if (TextLabel.AUTO_LABEL_COMPOSITION_STRATEGY.compose(osm) != null) { 108 p.a = NodeElement.DEFAULT_NODE_STYLELIST_TEXT; 101 109 } else { 102 p.a = NodeElem Style.DEFAULT_NODE_STYLELIST;110 p.a = NodeElement.DEFAULT_NODE_STYLELIST; 103 111 } 104 112 } else { 105 113 boolean hasNonModifier = false; 106 114 boolean hasText = false; 107 for ( ElemStyles : p.a) {108 if (s instanceof BoxTextElem Style) {115 for (StyleElement s : p.a) { 116 if (s instanceof BoxTextElement) { 109 117 hasText = true; 110 118 } else { … … 115 123 } 116 124 if (!hasNonModifier) { 117 p.a = new StyleList(p.a, NodeElem Style.SIMPLE_NODE_ELEMSTYLE);125 p.a = new StyleList(p.a, NodeElement.SIMPLE_NODE_ELEMSTYLE); 118 126 if (!hasText) { 119 if (Text Element.AUTO_LABEL_COMPOSITION_STRATEGY.compose(osm) != null) {120 p.a = new StyleList(p.a, BoxTextElem Style.SIMPLE_NODE_TEXT_ELEMSTYLE);127 if (TextLabel.AUTO_LABEL_COMPOSITION_STRATEGY.compose(osm) != null) { 128 p.a = new StyleList(p.a, BoxTextElement.SIMPLE_NODE_TEXT_ELEMSTYLE); 121 129 } 122 130 } … … 125 133 } else if (osm instanceof Way && isDefaultLines()) { 126 134 boolean hasProperLineStyle = false; 127 for ( ElemStyles : p.a) {135 for (StyleElement s : p.a) { 128 136 if (s.isProperLineStyle()) { 129 137 hasProperLineStyle = true; … … 132 140 } 133 141 if (!hasProperLineStyle) { 134 AreaElem Style area = Utils.find(p.a, AreaElemStyle.class);135 LineElem Style line = area == null ? LineElemStyle.UNTAGGED_WAY : LineElemStyle.createSimpleLineStyle(area.color, true);142 AreaElement area = Utils.find(p.a, AreaElement.class); 143 LineElement line = area == null ? LineElement.UNTAGGED_WAY : LineElement.createSimpleLineStyle(area.color, true); 136 144 p.a = new StyleList(p.a, line); 137 145 } … … 197 205 boolean hasIndependentLineStyle = false; 198 206 if (!isOuterWayOfSomeMP) { // do this only one time 199 List< ElemStyle> tmp = new ArrayList<>(p.a.size());200 for ( ElemStyles : p.a) {201 if (s instanceof AreaElem Style) {202 wayColor = ((AreaElem Style) s).color;207 List<StyleElement> tmp = new ArrayList<>(p.a.size()); 208 for (StyleElement s : p.a) { 209 if (s instanceof AreaElement) { 210 wayColor = ((AreaElement) s).color; 203 211 } else { 204 212 tmp.add(s); … … 217 225 mpElemStyles = getStyleCacheWithRange(r, scale, nc); 218 226 } 219 ElemStylempLine = null;220 for ( ElemStyles : mpElemStyles.a) {227 StyleElement mpLine = null; 228 for (StyleElement s : mpElemStyles.a) { 221 229 if (s.isProperLineStyle()) { 222 230 mpLine = s; … … 229 237 break; 230 238 } else if (wayColor == null && isDefaultLines()) { 231 AreaElem Style mpArea = Utils.find(mpElemStyles.a, AreaElemStyle.class);239 AreaElement mpArea = Utils.find(mpElemStyles.a, AreaElement.class); 232 240 if (mpArea != null) { 233 241 wayColor = mpArea.color; … … 240 248 if (isDefaultLines()) { 241 249 boolean hasLineStyle = false; 242 for ( ElemStyles : p.a) {250 for (StyleElement s : p.a) { 243 251 if (s.isProperLineStyle()) { 244 252 hasLineStyle = true; … … 247 255 } 248 256 if (!hasLineStyle) { 249 p.a = new StyleList(p.a, LineElem Style.createSimpleLineStyle(wayColor, true));257 p.a = new StyleList(p.a, LineElement.createSimpleLineStyle(wayColor, true)); 250 258 } 251 259 } … … 265 273 p = generateStyles(osm, scale, false); 266 274 boolean hasIndependentElemStyle = false; 267 for ( ElemStyles : p.a) {268 if (s.isProperLineStyle() || s instanceof AreaElem Style) {275 for (StyleElement s : p.a) { 276 if (s.isProperLineStyle() || s instanceof AreaElement) { 269 277 hasIndependentElemStyle = true; 270 278 break; … … 277 285 mpElemStyles = get(ref, scale, nc); 278 286 } 279 for ( ElemStylempS : mpElemStyles) {280 if (mpS instanceof AreaElem Style) {281 mpColor = ((AreaElem Style) mpS).color;287 for (StyleElement mpS : mpElemStyles) { 288 if (mpS instanceof AreaElement) { 289 mpColor = ((AreaElement) mpS).color; 282 290 break; 283 291 } 284 292 } 285 p.a = new StyleList(p.a, LineElem Style.createSimpleLineStyle(mpColor, true));293 p.a = new StyleList(p.a, LineElement.createSimpleLineStyle(mpColor, true)); 286 294 } 287 295 return p; … … 292 300 Pair<StyleList, Range> p = generateStyles(osm, scale, true); 293 301 if (drawMultipolygon && ((Relation) osm).isMultipolygon()) { 294 if (!Utils.exists(p.a, AreaElem Style.class) && Main.pref.getBoolean("multipolygon.deprecated.outerstyle", true)) {302 if (!Utils.exists(p.a, AreaElement.class) && Main.pref.getBoolean("multipolygon.deprecated.outerstyle", true)) { 295 303 // look at outer ways to find area style 296 304 Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, (Relation) osm); … … 298 306 Pair<StyleList, Range> wayStyles = generateStyles(w, scale, false); 299 307 p.b = Range.cut(p.b, wayStyles.b); 300 ElemStyle area = Utils.find(wayStyles.a, AreaElemStyle.class);308 StyleElement area = Utils.find(wayStyles.a, AreaElement.class); 301 309 if (area != null) { 302 310 p.a = new StyleList(p.a, area); … … 326 334 public Pair<StyleList, Range> generateStyles(OsmPrimitive osm, double scale, boolean pretendWayIsClosed) { 327 335 328 List< ElemStyle> sl = new ArrayList<>();336 List<StyleElement> sl = new ArrayList<>(); 329 337 MultiCascade mc = new MultiCascade(); 330 338 Environment env = new Environment(osm, mc, null, null); … … 342 350 env.layer = e.getKey(); 343 351 if (osm instanceof Way) { 344 addIfNotNull(sl, AreaElem Style.create(env));345 addIfNotNull(sl, RepeatImageElem Style.create(env));346 addIfNotNull(sl, LineElem Style.createLine(env));347 addIfNotNull(sl, LineElem Style.createLeftCasing(env));348 addIfNotNull(sl, LineElem Style.createRightCasing(env));349 addIfNotNull(sl, LineElem Style.createCasing(env));350 addIfNotNull(sl, LineTextElem Style.create(env));352 addIfNotNull(sl, AreaElement.create(env)); 353 addIfNotNull(sl, RepeatImageElement.create(env)); 354 addIfNotNull(sl, LineElement.createLine(env)); 355 addIfNotNull(sl, LineElement.createLeftCasing(env)); 356 addIfNotNull(sl, LineElement.createRightCasing(env)); 357 addIfNotNull(sl, LineElement.createCasing(env)); 358 addIfNotNull(sl, LineTextElement.create(env)); 351 359 } else if (osm instanceof Node) { 352 NodeElem Style nodeStyle = NodeElemStyle.create(env);360 NodeElement nodeStyle = NodeElement.create(env); 353 361 if (nodeStyle != null) { 354 362 sl.add(nodeStyle); 355 addIfNotNull(sl, BoxTextElem Style.create(env, nodeStyle.getBoxProvider()));363 addIfNotNull(sl, BoxTextElement.create(env, nodeStyle.getBoxProvider())); 356 364 } else { 357 addIfNotNull(sl, BoxTextElem Style.create(env, NodeElemStyle.SIMPLE_NODE_ELEMSTYLE_BOXPROVIDER));365 addIfNotNull(sl, BoxTextElement.create(env, NodeElement.SIMPLE_NODE_ELEMSTYLE_BOXPROVIDER)); 358 366 } 359 367 } else if (osm instanceof Relation) { 360 368 if (((Relation) osm).isMultipolygon()) { 361 addIfNotNull(sl, AreaElem Style.create(env));362 addIfNotNull(sl, RepeatImageElem Style.create(env));363 addIfNotNull(sl, LineElem Style.createLine(env));364 addIfNotNull(sl, LineElem Style.createCasing(env));365 addIfNotNull(sl, LineTextElem Style.create(env));369 addIfNotNull(sl, AreaElement.create(env)); 370 addIfNotNull(sl, RepeatImageElement.create(env)); 371 addIfNotNull(sl, LineElement.createLine(env)); 372 addIfNotNull(sl, LineElement.createCasing(env)); 373 addIfNotNull(sl, LineTextElement.create(env)); 366 374 } else if ("restriction".equals(osm.get("type"))) { 367 addIfNotNull(sl, NodeElem Style.create(env));375 addIfNotNull(sl, NodeElement.create(env)); 368 376 } 369 377 } … … 448 456 449 457 /** 450 * Returns the first AreaElem Stylefor a given primitive.458 * Returns the first AreaElement for a given primitive. 451 459 * @param p the OSM primitive 452 460 * @param pretendWayIsClosed For styles that require the way to be closed, 453 461 * we pretend it is. This is useful for generating area styles from the (segmented) 454 462 * outer ways of a multipolygon. 455 * @return first AreaElem Stylefound or {@code null}.456 */ 457 public static AreaElem StylegetAreaElemStyle(OsmPrimitive p, boolean pretendWayIsClosed) {463 * @return first AreaElement found or {@code null}. 464 */ 465 public static AreaElement getAreaElemStyle(OsmPrimitive p, boolean pretendWayIsClosed) { 458 466 MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().lock(); 459 467 try { 460 468 if (MapPaintStyles.getStyles() == null) 461 469 return null; 462 for ( ElemStyles : MapPaintStyles.getStyles().generateStyles(p, 1.0, pretendWayIsClosed).a) {463 if (s instanceof AreaElem Style)464 return (AreaElem Style) s;470 for (StyleElement s : MapPaintStyles.getStyles().generateStyles(p, 1.0, pretendWayIsClosed).a) { 471 if (s instanceof AreaElement) 472 return (AreaElement) s; 465 473 } 466 474 return null; … … 471 479 472 480 /** 473 * Determines whether primitive has an AreaElem Style.481 * Determines whether primitive has an AreaElement. 474 482 * @param p the OSM primitive 475 483 * @param pretendWayIsClosed For styles that require the way to be closed, 476 484 * we pretend it is. This is useful for generating area styles from the (segmented) 477 485 * outer ways of a multipolygon. 478 * @return {@code true} if primitive has an AreaElem Style486 * @return {@code true} if primitive has an AreaElement 479 487 */ 480 488 public static boolean hasAreaElemStyle(OsmPrimitive p, boolean pretendWayIsClosed) { … … 483 491 484 492 /** 485 * Determines whether primitive has <b>only</b> an AreaElem Style.493 * Determines whether primitive has <b>only</b> an AreaElement. 486 494 * @param p the OSM primitive 487 * @return {@code true} if primitive has only an AreaElem Style495 * @return {@code true} if primitive has only an AreaElement 488 496 * @since 7486 489 497 */ … … 497 505 return false; 498 506 } 499 for ( ElemStyles : styles) {500 if (!(s instanceof AreaElem Style)) {507 for (StyleElement s : styles) { 508 if (!(s instanceof AreaElement)) { 501 509 return false; 502 510 }
Note:
See TracChangeset
for help on using the changeset viewer.