- Timestamp:
- 2011-12-21T10:37:23+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java
r4431 r4682 5 5 6 6 import java.text.MessageFormat; 7 import java.util.Arrays; 7 8 import java.util.Collection; 8 9 import java.util.Collections; … … 693 694 } 694 695 696 /** 697 * Tests whether this primitive contains a tag consisting of {@code key} and any of {@code values}. 698 * @param key the key forming the tag. 699 * @param values one or many values forming the tag. 700 * @return true iff primitive contains a tag consisting of {@code key} and any of {@code values}. 701 */ 702 public boolean hasTag(String key, String... values) { 703 return hasTag(key, Arrays.asList(values)); 704 } 705 706 /** 707 * Tests whether this primitive contains a tag consisting of {@code key} and any of {@code values}. 708 * @param key the key forming the tag. 709 * @param values one or many values forming the tag. 710 * @return true iff primitive contains a tag consisting of {@code key} and any of {@code values}. 711 */ 712 public boolean hasTag(String key, Collection<String> values) { 713 return values.contains(get(key)); 714 } 695 715 } -
trunk/src/org/openstreetmap/josm/data/osm/Way.java
r4671 r4682 448 448 } 449 449 450 /** 451 * Returns the last node of this way. 452 * The result equals <tt>{@link #getNode getNode}({@link #getNodesCount getNodesCount} - 1)</tt>. 453 * @return the last node of this way 454 */ 450 455 public Node lastNode() { 451 456 Node[] nodes = this.nodes; … … 454 459 } 455 460 461 /** 462 * Returns the first node of this way. 463 * The result equals {@link #getNode getNode}{@code (0)}. 464 * @return the first node of this way 465 */ 456 466 public Node firstNode() { 457 467 Node[] nodes = this.nodes; -
trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java
r4448 r4682 48 48 import org.openstreetmap.josm.data.validation.tests.UntaggedNode; 49 49 import org.openstreetmap.josm.data.validation.tests.UntaggedWay; 50 import org.openstreetmap.josm.data.validation.tests.WayConnectedToArea; 50 51 import org.openstreetmap.josm.data.validation.tests.WronglyOrderedWays; 51 52 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; … … 102 103 DeprecatedTags.class, // ID 2101 .. 2199 103 104 OverlappingAreas.class, // ID 2201 .. 2299 105 WayConnectedToArea.class, // ID 2301 .. 2399 104 106 }; 105 107 -
trunk/src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java
r4627 r4682 26 26 import org.openstreetmap.josm.data.validation.TestError; 27 27 import org.openstreetmap.josm.gui.mappaint.AreaElemStyle; 28 import org.openstreetmap.josm.gui.mappaint.ElemStyle;29 28 import org.openstreetmap.josm.gui.mappaint.ElemStyles; 30 29 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; … … 117 116 @Override 118 117 public void visit(Way w) { 119 if (styles != null && !w.isClosed()) { 120 for (ElemStyle s : styles.generateStyles(w, SCALE, null, false).a) { 121 if (s instanceof AreaElemStyle) { 122 List<Node> nodes = w.getNodes(); 123 errors.add(new TestError(this, Severity.WARNING, tr("Area style way is not closed"), NOT_CLOSED, 124 Collections.singletonList(w), Arrays.asList(nodes.get(0), nodes.get(nodes.size() - 1)))); 125 break; 126 } 127 } 118 if (!w.isClosed() && ElemStyles.hasAreaElemStyle(w, false)) { 119 List<Node> nodes = w.getNodes(); 120 errors.add(new TestError(this, Severity.WARNING, tr("Area style way is not closed"), NOT_CLOSED, 121 Collections.singletonList(w), Arrays.asList(nodes.get(0), nodes.get(nodes.size() - 1)))); 128 122 } 129 123 } … … 157 151 if (styles != null) { 158 152 159 AreaElemStyle area = null; 160 boolean areaStyle = false; 161 for (ElemStyle s : styles.generateStyles(r, SCALE, null, false).a) { 162 if (s instanceof AreaElemStyle) { 163 area = (AreaElemStyle) s; 164 areaStyle = true; 165 break; 166 } 167 } 153 AreaElemStyle area = ElemStyles.getAreaElemStyle(r, false); 154 boolean areaStyle = area != null; 168 155 // If area style was not found for relation then use style of ways 169 156 if (area == null) { 170 157 for (Way w : polygon.getOuterWays()) { 171 172 for (ElemStyle s : styles.generateStyles(w, SCALE, null, true).a) { 173 if (s instanceof AreaElemStyle) { 174 area = (AreaElemStyle) s; 175 break; 176 } 177 } 158 area = ElemStyles.getAreaElemStyle(w, true); 178 159 if (area != null) { 179 160 break; … … 189 170 if (area != null) { 190 171 for (Way wInner : polygon.getInnerWays()) { 191 AreaElemStyle areaInner = null; 192 for (ElemStyle s : styles.generateStyles(wInner, SCALE, null, false).a) { 193 if (s instanceof AreaElemStyle) { 194 areaInner = (AreaElemStyle) s; 195 break; 196 } 197 } 172 AreaElemStyle areaInner = ElemStyles.getAreaElemStyle(wInner, false); 198 173 199 174 if (areaInner != null && area.equals(areaInner)) { … … 207 182 if(!areaStyle) { 208 183 for (Way wOuter : polygon.getOuterWays()) { 209 AreaElemStyle areaOuter = null; 210 for (ElemStyle s : styles.generateStyles(wOuter, SCALE, null, false).a) { 211 if (s instanceof AreaElemStyle) { 212 areaOuter = (AreaElemStyle) s; 213 break; 214 } 215 } 184 AreaElemStyle areaOuter = ElemStyles.getAreaElemStyle(wOuter, false); 216 185 if (areaOuter != null && !area.equals(areaOuter)) { 217 186 List<OsmPrimitive> l = new ArrayList<OsmPrimitive>(); -
trunk/src/org/openstreetmap/josm/data/validation/tests/OverlappingAreas.java
r4448 r4682 5 5 import java.util.Collection; 6 6 import java.util.Collections; 7 import org.openstreetmap.josm.data.osm.OsmPrimitive;8 7 import org.openstreetmap.josm.data.osm.QuadBuckets; 9 8 import org.openstreetmap.josm.data.osm.Way; … … 11 10 import org.openstreetmap.josm.data.validation.Test; 12 11 import org.openstreetmap.josm.data.validation.TestError; 13 import org.openstreetmap.josm.gui.mappaint.AreaElemStyle;14 import org.openstreetmap.josm.gui.mappaint.ElemStyle;15 12 import org.openstreetmap.josm.gui.mappaint.ElemStyles; 16 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;17 13 import org.openstreetmap.josm.tools.Geometry; 18 14 import org.openstreetmap.josm.tools.Predicate; … … 23 19 protected static int OVERLAPPING_AREAS = 2201; 24 20 protected QuadBuckets<Way> index = new QuadBuckets<Way>(); 25 private static ElemStyles styles = MapPaintStyles.getStyles();26 21 27 22 public OverlappingAreas() { … … 31 26 @Override 32 27 public void visit(Way w) { 33 if (w.isUsable() && w.isClosed() && hasAreaElemStyle(w)) {28 if (w.isUsable() && w.isClosed() && ElemStyles.hasAreaElemStyle(w, false)) { 34 29 index.add(w); 35 30 } … … 60 55 } 61 56 62 private boolean hasAreaElemStyle(OsmPrimitive p) {63 for (ElemStyle s : styles.generateStyles(p, 1.0, null, false).a) {64 if (s instanceof AreaElemStyle) {65 return true;66 }67 }68 return false;69 }70 57 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
r4623 r4682 410 410 styleSources.addAll(sources); 411 411 } 412 413 /** 414 * Returns the first AreaElemStyle for a given primitive. 415 * @param p the OSM primitive 416 * @param pretendWayIsClosed For styles that require the way to be closed, 417 * we pretend it is. This is useful for generating area styles from the (segmented) 418 * outer ways of a multipolygon. 419 * @return first AreaElemStyle found or {@code null}. 420 */ 421 public static AreaElemStyle getAreaElemStyle(OsmPrimitive p, boolean pretendWayIsClosed) { 422 if (MapPaintStyles.getStyles() == null) { 423 return null; 424 } 425 for (ElemStyle s : MapPaintStyles.getStyles().generateStyles(p, 1.0, null, pretendWayIsClosed).a) { 426 if (s instanceof AreaElemStyle) { 427 return (AreaElemStyle) s; 428 } 429 } 430 return null; 431 } 432 433 /** 434 * Determines whether primitive has an AreaElemStyle. 435 * @param p the OSM primitive 436 * @param pretendWayIsClosed For styles that require the way to be closed, 437 * we pretend it is. This is useful for generating area styles from the (segmented) 438 * outer ways of a multipolygon. 439 * @return {@code true} iff primitive has an AreaElemStyle 440 */ 441 public static boolean hasAreaElemStyle(OsmPrimitive p, boolean pretendWayIsClosed) { 442 return getAreaElemStyle(p, pretendWayIsClosed) != null; 443 } 412 444 }
Note:
See TracChangeset
for help on using the changeset viewer.