Ignore:
Timestamp:
2010-04-11T15:29:02+02:00 (16 years ago)
Author:
bastiK
Message:

Filter: improved selection handling. (Don't allow to select filtered or disabled objects by clicking on them. Don't connect to hidden ways in add mode.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r3116 r3177  
    3232import org.openstreetmap.josm.data.projection.Projection;
    3333import org.openstreetmap.josm.gui.help.Helpful;
     34import org.openstreetmap.josm.tools.Predicate;
    3435
    3536/**
     
    426427    }
    427428
    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
    432430    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) {
    433443        DataSet ds = getCurrentDataSet();
    434444        if (ds == null)
     
    438448        Node minPrimitive = null;
    439449        for (Node n : ds.searchNodes(getSnapDistanceBBox(p))) {
    440             if (!n.isUsable()) {
     450            if (! predicate.evaluate(n))
    441451                continue;
    442             }
    443452            Point sp = getPoint(n);
    444453            double dist = p.distanceSq(sp);
     
    462471     *
    463472     * @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) {
    466476        TreeMap<Double, List<WaySegment>> nearest = new TreeMap<Double, List<WaySegment>>();
    467477        DataSet ds = getCurrentDataSet();
     
    470480
    471481        for (Way w : ds.searchWays(getSnapDistanceBBox(p))) {
    472             if (!w.isUsable()) {
     482            if (!predicate.evaluate(w))
    473483                continue;
    474             }
    475484            Node lastN = null;
    476485            int i = -2;
    477486            for (Node n : w.getNodes()) {
    478487                i++;
    479                 if (n.isDeleted() || n.isIncomplete()) {
     488                if (n.isDeleted() || n.isIncomplete()) {//FIXME: This shouldn't happen, raise exception?
    480489                    continue;
    481490                }
     
    521530     * @param p the point for which to search the nearest segment.
    522531     * @param ignore a collection of segments which are not to be returned.
     532     * @param predicate the returned object has to fulfill certain properties.
    523533     * May be null.
    524534     */
    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);
    527538        if(nearest == null)
    528539            return null;
     
    536547     * @return the nearest way segment to the screen point given.
    537548     */
    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);
    540556    }
    541557
     
    543559     * @return the nearest way to the screen point given.
    544560     */
    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);
    547563        return nearestWaySeg == null ? null : nearestWaySeg.way;
    548564    }
     
    559575     *
    560576     * @param p The point on screen.
     577     * @param predicate the returned object has to fulfill certain properties.
    561578     * @return  The primitive that is nearest to the point p.
    562579     */
    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);
    565582        if (osm == null)
    566583        {
    567             osm = getNearestWay(p);
     584            osm = getNearestWay(p, predicate);
    568585        }
    569586        return osm;
     
    573590     * Returns a singleton of the nearest object, or else an empty collection.
    574591     */
    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);
    577594        if (osm == null)
    578595            return Collections.emptySet();
     
    588605     *      list is never empty.
    589606     */
    590     public Collection<OsmPrimitive> getAllNearest(Point p) {
     607    public Collection<OsmPrimitive> getAllNearest(Point p, Predicate<OsmPrimitive> predicate) {
    591608        Collection<OsmPrimitive> nearest = new HashSet<OsmPrimitive>();
    592609        DataSet ds = getCurrentDataSet();
     
    594611            return null;
    595612        for (Way w : ds.searchWays(getSnapDistanceBBox(p))) {
    596             if (!w.isUsable()) {
     613            if (!predicate.evaluate(w))
    597614                continue;
    598             }
    599615            Node lastN = null;
    600616            for (Node n : w.getNodes()) {
    601                 if (!n.isUsable()) {
     617                if (!predicate.evaluate(n))
    602618                    continue;
    603                 }
    604619                if (lastN == null) {
    605620                    lastN = n;
     
    636651     *      list is never empty.
    637652     */
    638     public Collection<Node> getNearestNodes(Point p) {
     653    public Collection<Node> getNearestNodes(Point p, Predicate<OsmPrimitive> predicate) {
    639654        Collection<Node> nearest = new HashSet<Node>();
    640655        DataSet ds = getCurrentDataSet();
     
    643658
    644659        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) {
    647663                nearest.add(n);
    648664            }
     
    657673     * @param p the point for which to search the nearest segment.
    658674     * @param ignore a collection of nodes which are not to be returned.
     675     * @param predicate the returned objects have to fulfill certain properties.
    659676     * May be null.
    660677     */
    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);
    663680        if (nearest == null) return null;
    664681        if (ignore != null) {
Note: See TracChangeset for help on using the changeset viewer.