Changeset 3177 in josm for trunk/src/org
- Timestamp:
- 2010-04-11T15:29:02+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java
r2431 r3177 41 41 42 42 List<WaySegment> wss = Main.map.mapView.getNearestWaySegments( 43 Main.map.mapView.getPoint(node) );43 Main.map.mapView.getPoint(node), OsmPrimitive.isSelectablePredicate); 44 44 HashMap<Way, List<Integer>> insertPoints = new HashMap<Way, List<Integer>>(); 45 45 for (WaySegment ws : wss) { -
trunk/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java
r2986 r3177 19 19 import org.openstreetmap.josm.command.DeleteCommand; 20 20 import org.openstreetmap.josm.data.osm.Node; 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 21 22 import org.openstreetmap.josm.data.osm.Relation; 22 23 import org.openstreetmap.josm.data.osm.WaySegment; … … 286 287 DeleteParameters result = new DeleteParameters(); 287 288 288 result.nearestNode = Main.map.mapView.getNearestNode(e.getPoint() );289 result.nearestNode = Main.map.mapView.getNearestNode(e.getPoint(), OsmPrimitive.isSelectablePredicate); 289 290 if (result.nearestNode == null) { 290 result.nearestSegment = Main.map.mapView.getNearestWaySegment(e.getPoint() );291 result.nearestSegment = Main.map.mapView.getNearestWaySegment(e.getPoint(), OsmPrimitive.isSelectablePredicate); 291 292 if (result.nearestSegment != null) { 292 293 if (shift) { -
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r3116 r3177 164 164 if (mouseOnExistingNode == null && getCurrentDataSet().getSelected().size() == 0 165 165 && mousePos != null) { 166 mouseOnExistingNode = Main.map.mapView.getNearestNode(mousePos );166 mouseOnExistingNode = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive.isSelectablePredicate); 167 167 } 168 168 … … 332 332 333 333 if (!ctrl) { 334 n = Main.map.mapView.getNearestNode(mousePos );334 n = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive.isSelectablePredicate); 335 335 } 336 336 … … 366 366 if (!ctrl) { 367 367 // Insert the node into all the nearby way segments 368 List<WaySegment> wss = Main.map.mapView.getNearestWaySegments(e.getPoint() );368 List<WaySegment> wss = Main.map.mapView.getNearestWaySegments(e.getPoint(), OsmPrimitive.isSelectablePredicate); 369 369 Map<Way, List<Integer>> insertPoints = new HashMap<Way, List<Integer>>(); 370 370 for (WaySegment ws : wss) { … … 681 681 682 682 if (!ctrl && mousePos != null) { 683 currentMouseNode = mv.getNearestNode(mousePos );683 currentMouseNode = mv.getNearestNode(mousePos, OsmPrimitive.isSelectablePredicate); 684 684 } 685 685 … … 687 687 // *and* there is no node nearby (because nodes beat ways when re-using) 688 688 if(!ctrl && currentMouseNode == null) { 689 List<WaySegment> wss = mv.getNearestWaySegments(mousePos );689 List<WaySegment> wss = mv.getNearestWaySegments(mousePos, OsmPrimitive.isSelectablePredicate); 690 690 for(WaySegment ws : wss) { 691 691 mouseOnExistingWays.add(ws.way); -
trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java
r2990 r3177 308 308 // boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 309 309 310 selectedSegment = Main.map.mapView.getNearestWaySegment(e.getPoint() );310 selectedSegment = Main.map.mapView.getNearestWaySegment(e.getPoint(), OsmPrimitive.isSelectablePredicate); 311 311 312 312 if (selectedSegment == null) { -
trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
r2719 r3177 285 285 int snapDistance = Main.pref.getInteger("mappaint.node.virtual-snap-distance", 8); 286 286 snapDistance *= snapDistance; 287 OsmPrimitive osm = c.getNearestNode(p );287 OsmPrimitive osm = c.getNearestNode(p, OsmPrimitive.isSelectablePredicate); 288 288 virtualWays.clear(); 289 289 virtualNode = null; … … 293 293 { 294 294 Collection<WaySegment> nearestWaySegs = allSegements 295 ? c.getNearestWaySegments(p )296 : Collections.singleton(c.getNearestWaySegment(p ));295 ? c.getNearestWaySegments(p, OsmPrimitive.isSelectablePredicate) 296 : Collections.singleton(c.getNearestWaySegment(p, OsmPrimitive.isSelectablePredicate)); 297 297 298 298 for(WaySegment nearestWS : nearestWaySegs) { … … 435 435 if (!didMove) { 436 436 selectPrims( 437 Main.map.mapView.getNearestCollection(e.getPoint() ),437 Main.map.mapView.getNearestCollection(e.getPoint(), OsmPrimitive.isSelectablePredicate), 438 438 shift, ctrl, true, false); 439 439 … … 485 485 if (ctrl) { 486 486 Collection<Node> affectedNodes = OsmPrimitive.getFilteredSet(selection, Node.class); 487 Collection<Node> nn = Main.map.mapView.getNearestNodes(e.getPoint(), affectedNodes );487 Collection<Node> nn = Main.map.mapView.getNearestNodes(e.getPoint(), affectedNodes, OsmPrimitive.isSelectablePredicate); 488 488 if (nn != null) { 489 489 Node targetNode = nn.iterator().next(); -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r3166 r3177 20 20 import org.openstreetmap.josm.data.SelectionChangedListener; 21 21 import org.openstreetmap.josm.data.coor.LatLon; 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 23 import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent; 23 24 import org.openstreetmap.josm.data.osm.event.ChangesetIdChangedEvent; … … 174 175 */ 175 176 public Collection<OsmPrimitive> allNonDeletedPrimitives() { 176 return new DatasetCollection .AllNonDeleted(allPrimitives);177 return new DatasetCollection(allPrimitives, OsmPrimitive.nonDeletedPredicate); 177 178 } 178 179 179 180 public Collection<OsmPrimitive> allNonDeletedCompletePrimitives() { 180 return new DatasetCollection .AllNonDeletedComplete(allPrimitives);181 return new DatasetCollection(allPrimitives, OsmPrimitive.nonDeletedCompletePredicate); 181 182 } 182 183 183 184 public Collection<OsmPrimitive> allNonDeletedPhysicalPrimitives() { 184 return new DatasetCollection.AllNonDeletedPhysical(allPrimitives); 185 } 186 187 /** 188 * @return A collection containing all modified primitives 189 */ 185 return new DatasetCollection(allPrimitives, OsmPrimitive.nonDeletedPhysicalPredicate); 186 } 187 190 188 public Collection<OsmPrimitive> allModifiedPrimitives() { 191 return new DatasetCollection .AllModified(allPrimitives);189 return new DatasetCollection(allPrimitives, OsmPrimitive.modifiedPredicate); 192 190 } 193 191 -
trunk/src/org/openstreetmap/josm/data/osm/DatasetCollection.java
r3147 r3177 6 6 import java.util.Iterator; 7 7 8 abstract class DatasetCollection extends AbstractCollection<OsmPrimitive> { 8 import org.openstreetmap.josm.tools.Predicate; 9 10 class DatasetCollection extends AbstractCollection<OsmPrimitive> { 9 11 10 12 private class FilterIterator implements Iterator<OsmPrimitive> { … … 21 23 while (iterator.hasNext()) { 22 24 current = iterator.next(); 23 if ( filter(current))25 if (predicate.evaluate(current)) 24 26 return; 25 27 } … … 46 48 47 49 private final Collection<OsmPrimitive> primitives; 50 private final Predicate<OsmPrimitive> predicate; 48 51 49 public DatasetCollection(Collection<OsmPrimitive> primitives ) {52 public DatasetCollection(Collection<OsmPrimitive> primitives, Predicate<OsmPrimitive> predicate) { 50 53 this.primitives = primitives; 54 this.predicate = predicate; 51 55 } 52 53 protected abstract boolean filter(OsmPrimitive primitive);54 56 55 57 @Override … … 73 75 return !iterator().hasNext(); 74 76 } 75 76 public static class AllNonDeleted extends DatasetCollection {77 78 public AllNonDeleted(Collection<OsmPrimitive> primitives) {79 super(primitives);80 }81 82 @Override83 protected boolean filter(OsmPrimitive primitive) {84 return primitive.isVisible() && !primitive.isDeleted();85 }86 87 }88 89 public static class AllNonDeletedComplete extends DatasetCollection {90 91 public AllNonDeletedComplete(Collection<OsmPrimitive> primitives) {92 super(primitives);93 }94 95 @Override96 protected boolean filter(OsmPrimitive primitive) {97 return primitive.isVisible() && !primitive.isDeleted() && !primitive.isIncomplete();98 }99 100 }101 102 public static class AllNonDeletedPhysical extends DatasetCollection {103 104 public AllNonDeletedPhysical(Collection<OsmPrimitive> primitives) {105 super(primitives);106 }107 108 @Override109 protected boolean filter(OsmPrimitive primitive) {110 return primitive.isVisible() && !primitive.isDeleted() && !primitive.isIncomplete() && !(primitive instanceof Relation);111 }112 113 }114 115 public static class AllModified extends DatasetCollection {116 117 public AllModified(Collection<OsmPrimitive> primitives) {118 super(primitives);119 }120 121 @Override122 protected boolean filter(OsmPrimitive primitive) {123 return primitive.isVisible() && primitive.isModified();124 }125 126 }127 128 77 } -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r3149 r3177 28 28 import org.openstreetmap.josm.gui.mappaint.ElemStyle; 29 29 import org.openstreetmap.josm.tools.CheckParameterUtil; 30 import org.openstreetmap.josm.tools.Predicate; 30 31 31 32 /** … … 47 48 } 48 49 50 /** 51 * This flag shows, that the properties have been changed by the user 52 * and on upload the object will be send to the server 53 */ 49 54 private static final int FLAG_MODIFIED = 1 << 0; 55 56 /** 57 * The visible flag indicates, that an object is marked 58 * as deleted on the server. 59 */ 50 60 private static final int FLAG_VISIBLE = 1 << 1; 61 62 /** 63 * An object can be disabled by the filter mechanism. 64 * Then it will show in a shade of grey on the map. 65 * Disabled objects usually cannot be selected or modified 66 * while the filter is active. 67 */ 51 68 private static final int FLAG_DISABLED = 1 << 2; 69 70 /** 71 * An object that was deleted by the user. 72 * Deleted objects are usually hidden on the map and a request 73 * for deletion will be send to the server on upload. 74 * An object usually cannot be deleted if it has non-deleted 75 * objects still referring to it. 76 */ 52 77 private static final int FLAG_DELETED = 1 << 3; 78 79 /** 80 * An object can be filtered by the filter mechanism. 81 * Then it will be hidden on the map and usually 82 * cannot be selected or modified while the filter is active. 83 */ 53 84 private static final int FLAG_FILTERED = 1 << 4; 85 86 /** 87 * This flag is set if the primitive is a way and 88 * according to the tags, the direction of the way is important. 89 * (e.g. one way street.) 90 */ 54 91 private static final int FLAG_HAS_DIRECTIONS = 1 << 5; 92 93 /** 94 * If the primitive is tagged. 95 * Some trivial tags like source=* are ignored here. 96 */ 55 97 private static final int FLAG_TAGGED = 1 << 6; 98 99 /** 100 * This flag is only relevant if FLAG_HAS_DIRECTIONS is set. 101 * It shows, that direction of the arrows should be reversed. 102 * (E.g. oneway=-1.) 103 */ 56 104 private static final int FLAG_DIRECTION_REVERSED = 1 << 7; 105 106 /** 107 * When hovering over ways and nodes in add mode, the 108 * "target" objects are visually highlighted. This flag indicates 109 * that the primitive is currently highlighted. 110 */ 57 111 private static final int FLAG_HIGHLIGHTED = 1 << 8; 112 113 /** 114 * A primitive is incomplete if we know its id and type, but nothing more. 115 * Typically some members of a relation are incomplete until they are 116 * fetched from the server. 117 */ 58 118 private static final int FLAG_INCOMPLETE = 1 << 9; 59 119 … … 329 389 */ 330 390 public boolean isUsable() { 331 return (flags & (FLAG_DELETED + FLAG_INCOMPLETE + FLAG_DISABLED)) == 0; 391 return (flags & (FLAG_DELETED + FLAG_INCOMPLETE)) == 0; 392 } 393 394 public boolean isSelectable() { 395 return (flags & (FLAG_DELETED + FLAG_INCOMPLETE + FLAG_DISABLED + FLAG_FILTERED)) == 0; 332 396 } 333 397 … … 335 399 return (flags & (FLAG_DELETED + FLAG_INCOMPLETE + FLAG_FILTERED)) == 0; 336 400 } 401 402 /** 403 * Some predicates, that describe conditions on primitives. 404 */ 405 public static Predicate<OsmPrimitive> isUsablePredicate = new Predicate<OsmPrimitive>() { 406 public boolean evaluate(OsmPrimitive primitive) { 407 return primitive.isUsable(); 408 } 409 }; 410 411 public static Predicate<OsmPrimitive> isSelectablePredicate = new Predicate<OsmPrimitive>() { 412 public boolean evaluate(OsmPrimitive primitive) { 413 return primitive.isSelectable(); 414 } 415 }; 416 417 public static Predicate<OsmPrimitive> nonDeletedPredicate = new Predicate<OsmPrimitive>() { 418 public boolean evaluate(OsmPrimitive primitive) { 419 return primitive.isVisible() && !primitive.isDeleted(); 420 } 421 }; 422 423 public static Predicate<OsmPrimitive> nonDeletedCompletePredicate = new Predicate<OsmPrimitive>() { 424 public boolean evaluate(OsmPrimitive primitive) { 425 return primitive.isVisible() && !primitive.isDeleted() && !primitive.isIncomplete(); 426 } 427 }; 428 429 public static Predicate<OsmPrimitive> nonDeletedPhysicalPredicate = new Predicate<OsmPrimitive>() { 430 public boolean evaluate(OsmPrimitive primitive) { 431 return primitive.isVisible() && !primitive.isDeleted() && !primitive.isIncomplete() && !(primitive instanceof Relation); 432 } 433 }; 434 435 public static Predicate<OsmPrimitive> modifiedPredicate = new Predicate<OsmPrimitive>() { 436 public boolean evaluate(OsmPrimitive primitive) { 437 return primitive.isVisible() && primitive.isModified(); 438 } 439 }; 337 440 338 441 /** -
trunk/src/org/openstreetmap/josm/gui/MapStatus.java
r2906 r3177 193 193 if (middleMouseDown || isAtOldPosition) 194 194 { 195 Collection<OsmPrimitive> osms = mv.getAllNearest(ms.mousePos );195 Collection<OsmPrimitive> osms = mv.getAllNearest(ms.mousePos, OsmPrimitive.isUsablePredicate); 196 196 197 197 if (osms == null) { … … 292 292 */ 293 293 private final void statusBarElementUpdate(MouseState ms) { 294 final OsmPrimitive osmNearest = mv.getNearest(ms.mousePos );294 final OsmPrimitive osmNearest = mv.getNearest(ms.mousePos, OsmPrimitive.isUsablePredicate); 295 295 if (osmNearest != null) { 296 296 nameText.setText(osmNearest.getDisplayName(DefaultNameFormatter.getInstance())); -
trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
r3116 r3177 32 32 import org.openstreetmap.josm.data.projection.Projection; 33 33 import org.openstreetmap.josm.gui.help.Helpful; 34 import org.openstreetmap.josm.tools.Predicate; 34 35 35 36 /** … … 426 427 } 427 428 428 /** 429 * Return the nearest point to the screen point given. 430 * If a node within snapDistance pixel is found, the nearest node is returned. 431 */ 429 @Deprecated 432 430 public final Node getNearestNode(Point p) { 431 return getNearestNode(p, OsmPrimitive.isUsablePredicate); 432 } 433 434 /** 435 * Return the nearest node to the screen point given. 436 * If more then one node within snapDistance pixel is found, 437 * the nearest node is returned. 438 * @param p the screen point 439 * @param predicate this parameter imposes a condition on the returned object, e.g. 440 * give the nearest node that is tagged. 441 */ 442 public final Node getNearestNode(Point p, Predicate<OsmPrimitive> predicate) { 433 443 DataSet ds = getCurrentDataSet(); 434 444 if (ds == null) … … 438 448 Node minPrimitive = null; 439 449 for (Node n : ds.searchNodes(getSnapDistanceBBox(p))) { 440 if (! n.isUsable()) {450 if (! predicate.evaluate(n)) 441 451 continue; 442 }443 452 Point sp = getPoint(n); 444 453 double dist = p.distanceSq(sp); … … 462 471 * 463 472 * @param p the point for which to search the nearest segment. 464 */ 465 public final List<WaySegment> getNearestWaySegments(Point p) { 473 * @param predicate the returned objects have to fulfill certain properties. 474 */ 475 public final List<WaySegment> getNearestWaySegments(Point p, Predicate<OsmPrimitive> predicate) { 466 476 TreeMap<Double, List<WaySegment>> nearest = new TreeMap<Double, List<WaySegment>>(); 467 477 DataSet ds = getCurrentDataSet(); … … 470 480 471 481 for (Way w : ds.searchWays(getSnapDistanceBBox(p))) { 472 if (! w.isUsable()) {482 if (!predicate.evaluate(w)) 473 483 continue; 474 }475 484 Node lastN = null; 476 485 int i = -2; 477 486 for (Node n : w.getNodes()) { 478 487 i++; 479 if (n.isDeleted() || n.isIncomplete()) { 488 if (n.isDeleted() || n.isIncomplete()) {//FIXME: This shouldn't happen, raise exception? 480 489 continue; 481 490 } … … 521 530 * @param p the point for which to search the nearest segment. 522 531 * @param ignore a collection of segments which are not to be returned. 532 * @param predicate the returned object has to fulfill certain properties. 523 533 * May be null. 524 534 */ 525 public final WaySegment getNearestWaySegment(Point p, Collection<WaySegment> ignore) { 526 List<WaySegment> nearest = getNearestWaySegments(p); 535 public final WaySegment getNearestWaySegment 536 (Point p, Collection<WaySegment> ignore, Predicate<OsmPrimitive> predicate) { 537 List<WaySegment> nearest = getNearestWaySegments(p, predicate); 527 538 if(nearest == null) 528 539 return null; … … 536 547 * @return the nearest way segment to the screen point given. 537 548 */ 538 public final WaySegment getNearestWaySegment(Point p) { 539 return getNearestWaySegment(p, null); 549 public final WaySegment getNearestWaySegment(Point p, Predicate<OsmPrimitive> predicate) { 550 return getNearestWaySegment(p, null, predicate); 551 } 552 553 @Deprecated 554 public final Way getNearestWay(Point p) { 555 return getNearestWay(p, OsmPrimitive.isUsablePredicate); 540 556 } 541 557 … … 543 559 * @return the nearest way to the screen point given. 544 560 */ 545 public final Way getNearestWay(Point p ) {546 WaySegment nearestWaySeg = getNearestWaySegment(p );561 public final Way getNearestWay(Point p, Predicate<OsmPrimitive> predicate) { 562 WaySegment nearestWaySeg = getNearestWaySegment(p, predicate); 547 563 return nearestWaySeg == null ? null : nearestWaySeg.way; 548 564 } … … 559 575 * 560 576 * @param p The point on screen. 577 * @param predicate the returned object has to fulfill certain properties. 561 578 * @return The primitive that is nearest to the point p. 562 579 */ 563 public OsmPrimitive getNearest(Point p ) {564 OsmPrimitive osm = getNearestNode(p );580 public OsmPrimitive getNearest(Point p, Predicate<OsmPrimitive> predicate) { 581 OsmPrimitive osm = getNearestNode(p, predicate); 565 582 if (osm == null) 566 583 { 567 osm = getNearestWay(p );584 osm = getNearestWay(p, predicate); 568 585 } 569 586 return osm; … … 573 590 * Returns a singleton of the nearest object, or else an empty collection. 574 591 */ 575 public Collection<OsmPrimitive> getNearestCollection(Point p ) {576 OsmPrimitive osm = getNearest(p );592 public Collection<OsmPrimitive> getNearestCollection(Point p, Predicate<OsmPrimitive> predicate) { 593 OsmPrimitive osm = getNearest(p, predicate); 577 594 if (osm == null) 578 595 return Collections.emptySet(); … … 588 605 * list is never empty. 589 606 */ 590 public Collection<OsmPrimitive> getAllNearest(Point p ) {607 public Collection<OsmPrimitive> getAllNearest(Point p, Predicate<OsmPrimitive> predicate) { 591 608 Collection<OsmPrimitive> nearest = new HashSet<OsmPrimitive>(); 592 609 DataSet ds = getCurrentDataSet(); … … 594 611 return null; 595 612 for (Way w : ds.searchWays(getSnapDistanceBBox(p))) { 596 if (! w.isUsable()) {613 if (!predicate.evaluate(w)) 597 614 continue; 598 }599 615 Node lastN = null; 600 616 for (Node n : w.getNodes()) { 601 if (! n.isUsable()) {617 if (!predicate.evaluate(n)) 602 618 continue; 603 }604 619 if (lastN == null) { 605 620 lastN = n; … … 636 651 * list is never empty. 637 652 */ 638 public Collection<Node> getNearestNodes(Point p ) {653 public Collection<Node> getNearestNodes(Point p, Predicate<OsmPrimitive> predicate) { 639 654 Collection<Node> nearest = new HashSet<Node>(); 640 655 DataSet ds = getCurrentDataSet(); … … 643 658 644 659 for (Node n : ds.searchNodes(getSnapDistanceBBox(p))) { 645 if (n.isUsable() 646 && getPoint(n).distanceSq(p) < snapDistanceSq) { 660 if (!predicate.evaluate(n)) 661 continue; 662 if (getPoint(n).distanceSq(p) < snapDistanceSq) { 647 663 nearest.add(n); 648 664 } … … 657 673 * @param p the point for which to search the nearest segment. 658 674 * @param ignore a collection of nodes which are not to be returned. 675 * @param predicate the returned objects have to fulfill certain properties. 659 676 * May be null. 660 677 */ 661 public final Collection<Node> getNearestNodes(Point p, Collection<Node> ignore ) {662 Collection<Node> nearest = getNearestNodes(p );678 public final Collection<Node> getNearestNodes(Point p, Collection<Node> ignore, Predicate<OsmPrimitive> predicate) { 679 Collection<Node> nearest = getNearestNodes(p, predicate); 663 680 if (nearest == null) return null; 664 681 if (ignore != null) { -
trunk/src/org/openstreetmap/josm/gui/SelectionManager.java
r2578 r3177 277 277 278 278 if (clicked) { 279 OsmPrimitive osm = nc.getNearest(center );279 OsmPrimitive osm = nc.getNearest(center, OsmPrimitive.isSelectablePredicate); 280 280 if (osm != null) { 281 281 selection.add(osm);
Note:
See TracChangeset
for help on using the changeset viewer.