Changeset 10312 in josm
- Timestamp:
- 2016-06-02T01:31:16+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/osm/visitor/paint
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
r10307 r10312 659 659 } 660 660 drawArea(r, p, 661 pd. selected? paintSettings.getRelationSelectedColor(color.getAlpha()) : color,661 pd.isSelected() ? paintSettings.getRelationSelectedColor(color.getAlpha()) : color, 662 662 fillImage, extent, pfClip, disabled, text); 663 663 } -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/relations/Multipolygon.java
r10216 r10312 124 124 } 125 125 126 publicboolean isOuterRole(String role) {126 boolean isOuterRole(String role) { 127 127 if (role == null) return false; 128 128 for (String candidate: outerExactRoles) { … … 135 135 } 136 136 137 publicboolean isInnerRole(String role) {137 boolean isInnerRole(String role) { 138 138 if (role == null) return false; 139 139 for (String candidate: innerExactRoles) { … … 164 164 165 165 public static class JoinedWay { 166 private final List<Node> nodes; 167 private final Collection<Long> wayIds; 168 private final boolean selected; 169 166 protected final List<Node> nodes; 167 protected final Collection<Long> wayIds; 168 protected boolean selected; 169 170 /** 171 * Constructs a new {@code JoinedWay}. 172 * @param nodes list of nodes 173 * @param wayIds list of way IDs 174 * @param selected whether joined way is selected or not 175 */ 170 176 public JoinedWay(List<Node> nodes, Collection<Long> wayIds, boolean selected) { 171 this.nodes = n odes;172 this.wayIds = wayIds;177 this.nodes = new ArrayList<>(nodes); 178 this.wayIds = new ArrayList<>(wayIds); 173 179 this.selected = selected; 174 180 } 175 181 182 /** 183 * Replies the list of nodes. 184 * @return the list of nodes 185 */ 176 186 public List<Node> getNodes() { 177 return nodes; 178 } 179 187 return Collections.unmodifiableList(nodes); 188 } 189 190 /** 191 * Replies the list of way IDs. 192 * @return the list of way IDs 193 */ 180 194 public Collection<Long> getWayIds() { 181 return wayIds; 182 } 183 184 public boolean isSelected() { 195 return Collections.unmodifiableCollection(wayIds); 196 } 197 198 /** 199 * Determines if this is selected. 200 * @return {@code true} if this is selected 201 */ 202 public final boolean isSelected() { 185 203 return selected; 186 204 } 187 205 206 /** 207 * Sets whether this is selected 208 * @param selected {@code true} if this is selected 209 * @since 10312 210 */ 211 public final void setSelected(boolean selected) { 212 this.selected = selected; 213 } 214 215 /** 216 * Determines if this joined way is closed. 217 * @return {@code true} if this joined way is closed 218 */ 188 219 public boolean isClosed() { 189 return nodes.isEmpty() || nodes.get(nodes.size() - 1).equals(nodes.get(0)); 190 } 191 } 192 193 public static class PolyData { 220 return nodes.isEmpty() || getLastNode().equals(getFirstNode()); 221 } 222 223 /** 224 * Returns the first node. 225 * @return the first node 226 * @since 10312 227 */ 228 public Node getFirstNode() { 229 return nodes.get(0); 230 } 231 232 /** 233 * Returns the last node. 234 * @return the last node 235 * @since 10312 236 */ 237 public Node getLastNode() { 238 return nodes.get(nodes.size() - 1); 239 } 240 } 241 242 public static class PolyData extends JoinedWay { 194 243 public enum Intersection { 195 244 INSIDE, … … 199 248 200 249 private final Path2D.Double poly; 201 public boolean selected;202 250 private Rectangle2D bounds; 203 private final Collection<Long> wayIds;204 private final List<Node> nodes;205 251 private final List<PolyData> inners; 206 252 253 /** 254 * Constructs a new {@code PolyData} from a closed way. 255 * @param closedWay closed way 256 */ 207 257 public PolyData(Way closedWay) { 208 258 this(closedWay.getNodes(), closedWay.isSelected(), Collections.singleton(closedWay.getUniqueId())); 209 259 } 210 260 261 /** 262 * Constructs a new {@code PolyData} from a {@link JoinedWay}. 263 * @param joinedWay joined way 264 */ 211 265 public PolyData(JoinedWay joinedWay) { 212 this(joinedWay. getNodes(), joinedWay.isSelected(), joinedWay.getWayIds());266 this(joinedWay.nodes, joinedWay.selected, joinedWay.wayIds); 213 267 } 214 268 215 269 private PolyData(List<Node> nodes, boolean selected, Collection<Long> wayIds) { 216 this.wayIds = Collections.unmodifiableCollection(wayIds); 217 this.nodes = new ArrayList<>(nodes); 218 this.selected = selected; 270 super(nodes, wayIds, selected); 219 271 this.inners = new ArrayList<>(); 220 272 this.poly = new Path2D.Double(); 221 273 this.poly.setWindingRule(Path2D.WIND_EVEN_ODD); 222 274 buildPoly(); 275 } 276 277 /** 278 * Constructs a new {@code PolyData} from an existing {@code PolyData}. 279 * @param copy existing instance 280 */ 281 public PolyData(PolyData copy) { 282 super(copy.nodes, copy.wayIds, copy.selected); 283 this.poly = (Path2D.Double) copy.poly.clone(); 284 this.inners = new ArrayList<>(copy.inners); 223 285 } 224 286 … … 242 304 appendInner(inner.poly); 243 305 } 244 }245 246 public PolyData(PolyData copy) {247 this.selected = copy.selected;248 this.poly = (Path2D.Double) copy.poly.clone();249 this.wayIds = Collections.unmodifiableCollection(copy.wayIds);250 this.nodes = new ArrayList<>(copy.nodes);251 this.inners = new ArrayList<>(copy.inners);252 306 } 253 307 … … 293 347 } 294 348 295 public Collection<Long> getWayIds() {296 return wayIds;297 }298 299 public List<Node> getNodes() {300 return nodes;301 }302 303 349 public List<PolyData> getInners() { 304 return inners;350 return Collections.unmodifiableList(inners); 305 351 } 306 352 … … 370 416 } 371 417 418 @Override 372 419 public boolean isClosed() { 373 if (nodes.size() < 3 || nodes.get(0) != nodes.get(nodes.size() - 1)) return false; 420 if (nodes.size() < 3 || !getFirstNode().equals(getLastNode())) 421 return false; 374 422 for (PolyData inner : inners) { 375 if (!inner.isClosed()) return false; 423 if (!inner.isClosed()) 424 return false; 376 425 } 377 426 return true; … … 404 453 private boolean incomplete; 405 454 455 /** 456 * Constructs a new {@code Multipolygon} from a relation. 457 * @param r relation 458 */ 406 459 public Multipolygon(Relation r) { 407 460 load(r); … … 415 468 if (m.getMember().isIncomplete()) { 416 469 this.incomplete = true; 417 } else if (m.getMember().isDrawable()) { 418 if (m.isWay()) { 419 Way w = m.getWay(); 420 421 if (w.getNodesCount() < 2) { 422 continue; 423 } 424 425 if (matcher.isInnerRole(m.getRole())) { 426 innerWays.add(w); 427 } else if (matcher.isOuterRole(m.getRole())) { 428 outerWays.add(w); 429 } else if (!m.hasRole()) { 430 outerWays.add(w); 431 } // Remaining roles ignored 432 } // Non ways ignored 433 } 470 } else if (m.getMember().isDrawable() && m.isWay()) { 471 Way w = m.getWay(); 472 473 if (w.getNodesCount() < 2) { 474 continue; 475 } 476 477 if (matcher.isInnerRole(m.getRole())) { 478 innerWays.add(w); 479 } else if (!m.hasRole() || matcher.isOuterRole(m.getRole())) { 480 outerWays.add(w); 481 } // Remaining roles ignored 482 } // Non ways ignored 434 483 } 435 484 … … 443 492 } 444 493 494 /** 495 * Determines if this multipolygon is incomplete. 496 * @return {@code true} if this multipolygon is incomplete 497 */ 445 498 public final boolean isIncomplete() { 446 499 return incomplete; … … 460 513 result.add(new PolyData(jw)); 461 514 if (!jw.isClosed()) { 462 openEnds.add(jw.get Nodes().get(0));463 openEnds.add(jw.get Nodes().get(jw.getNodes().size() - 1));515 openEnds.add(jw.getFirstNode()); 516 openEnds.add(jw.getLastNode()); 464 517 } 465 518 } … … 560 613 561 614 public PolyData findOuterPolygon(PolyData inner, List<PolyData> outerPolygons) { 562 563 615 // First try to test only bbox, use precise testing only if we don't get unique result 564 616 Rectangle2D innerBox = inner.getBounds(); … … 595 647 596 648 private void addInnerToOuters(List<PolyData> innerPolygons, List<PolyData> outerPolygons) { 597 598 649 if (innerPolygons.isEmpty()) { 599 650 combinedPolygons.addAll(outerPolygons); … … 624 675 */ 625 676 public List<Way> getOuterWays() { 626 return outerWays;677 return Collections.unmodifiableList(outerWays); 627 678 } 628 679 … … 632 683 */ 633 684 public List<Way> getInnerWays() { 634 return innerWays; 635 } 636 685 return Collections.unmodifiableList(innerWays); 686 } 687 688 /** 689 * Replies the list of combined polygons. 690 * @return the list of combined polygons 691 */ 637 692 public List<PolyData> getCombinedPolygons() { 638 return combinedPolygons; 639 } 640 693 return Collections.unmodifiableList(combinedPolygons); 694 } 695 696 /** 697 * Replies the list of inner polygons. 698 * @return the list of inner polygons 699 */ 641 700 public List<PolyData> getInnerPolygons() { 642 701 final List<PolyData> innerPolygons = new ArrayList<>(); … … 645 704 } 646 705 706 /** 707 * Replies the list of outer polygons. 708 * @return the list of outer polygons 709 */ 647 710 public List<PolyData> getOuterPolygons() { 648 711 final List<PolyData> outerPolygons = new ArrayList<>(); … … 656 719 */ 657 720 public List<Node> getOpenEnds() { 658 return openEnds;721 return Collections.unmodifiableList(openEnds); 659 722 } 660 723 } -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/relations/MultipolygonCache.java
r10247 r10312 97 97 map2.put(r, multipolygon); 98 98 for (PolyData pd : multipolygon.getCombinedPolygons()) { 99 if (pd. selected) {99 if (pd.isSelected()) { 100 100 selectedPolyData.add(pd); 101 101 } … … 311 311 312 312 for (Iterator<PolyData> it = selectedPolyData.iterator(); it.hasNext();) { 313 it.next().se lected = false;313 it.next().setSelected(false); 314 314 it.remove(); 315 315 } … … 332 332 for (PolyData pd : multipolygon.getCombinedPolygons()) { 333 333 if (pd.getWayIds().contains(p.getUniqueId())) { 334 pd.se lected = true;334 pd.setSelected(true); 335 335 selectedPolyData.add(pd); 336 336 }
Note:
See TracChangeset
for help on using the changeset viewer.