Changeset 3177 in josm for trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
- Timestamp:
- 2010-04-11T15:29:02+02:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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) {
Note:
See TracChangeset
for help on using the changeset viewer.
