Changeset 3555 in josm for trunk/src


Ignore:
Timestamp:
2010-09-22T23:03:40+02:00 (14 years ago)
Author:
bastiK
Message:

applied #5480 (patch by Christian Müller) - some cleanup in selectaction and fix a minor cosmetic bug

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

    r3550 r3555  
    275275
    276276        MapView c = Main.map.mapView;
    277 
    278277        Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected();
     278
     279        // take nearest node
    279280        OsmPrimitive osm = c.getNearestNode(p, OsmPrimitive.isSelectablePredicate);
    280281
     
    282283            for (Node n : c.getNearestNodes(p, OsmPrimitive.isSelectablePredicate)) {
    283284                if (sel.contains(n)) {
     285                    // take nearest selected node
    284286                    osm = n;
     287                    break;
    285288                }
    286289            }
     
    290293
    291294            Collection<WaySegment> virtualWaysInSel = new ArrayList<WaySegment>();
    292             osm = c.getNearestWay(p, OsmPrimitive.isSelectablePredicate);
    293 
    294             for(WaySegment nearestWS : c.getNearestWaySegments(p, OsmPrimitive.isSelectablePredicate)) {
     295            Collection<WaySegment> wss = c.getNearestWaySegments(p, OsmPrimitive.isSelectablePredicate);
     296            for(WaySegment nearestWS : wss) {
    295297                if (nearestWS == null) {
    296298                    continue;
    297299                }
    298                 if (sel.contains(w = nearestWS.way)) {
     300
     301                w = nearestWS.way;
     302                if (osm == null && sel.contains(w)) {
     303                    // take nearest selected way
    299304                    osm = w;
    300305                }
     
    330335
    331336            if (virtualNode != null) {
     337                // insert virtualNode into all segments if nothing was selected,
     338                // else only into the (previously) selected segments
    332339                virtualWays = virtualWaysInSel.isEmpty() ? virtualWays : virtualWaysInSel;
    333                 osm = virtualWays.iterator().next().way;
     340            }
     341
     342            if (osm == null && !wss.isEmpty()) {
     343                // take nearest way
     344                osm = wss.iterator().next().way;
    334345            }
    335346        }
     
    435446            boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0;
    436447            boolean alt = (e.getModifiers() & (ActionEvent.ALT_MASK|InputEvent.ALT_GRAPH_MASK)) != 0
    437                             || Main.pref.getBoolean("selectaction.rotates", false);
     448                            || Main.pref.getBoolean("selectaction.cycles.multiple.matches", false);
    438449
    439450            virtualWays.clear();
     
    444455                if (!c.isEmpty() && alt) {
    445456                    if (c.iterator().next() instanceof Node) {
    446                         // there is at least one node under the cursor:
    447                         //   - make sure (first element of new list) equals (result of getNearestCollection)
    448                         //   - do not consider ways at all, but all nearest nodes
     457                        // consider all nearest nodes
    449458                        c = new ArrayList<OsmPrimitive>(Main.map.mapView.getNearestNodes(e.getPoint(), OsmPrimitive.isSelectablePredicate));
    450459                    } else {
    451                         // consider all ways..
     460                        // consider all nearest primitives (should be only ways at this point..)
    452461                        c = Main.map.mapView.getAllNearest(e.getPoint(), OsmPrimitive.isSelectablePredicate);
    453462                    }
     
    536545            boolean ctrl, boolean released, boolean area) {
    537546        DataSet ds = getCurrentDataSet();
     547
     548        // decides on mousePressed whether
     549        //      to cycle on mouseReleased (selList already selected)
     550        //      or not                    (selList is a new selection)
     551        selMorePrims = (released || area) ? selMorePrims : ds.getSelected().containsAll(selectionList);
     552
     553        // not allowed together: do not change dataset selection, return early
    538554        if ((shift && ctrl) || (ctrl && !released) || (!virtualWays.isEmpty()))
    539             return; // not allowed together
     555            return;
    540556
    541557        // toggle through possible objects on mouse release
     
    589605        }
    590606
    591         // hard-wiring to false due to performance reasons, should do w/out
    592         selMorePrims = (released || area) ? false : ds.getSelected().containsAll(selectionList);
    593 
    594607        if (ctrl) {
    595608            // Ctrl on an item toggles its selection status,
Note: See TracChangeset for help on using the changeset viewer.