Changeset 4934 in josm


Ignore:
Timestamp:
2012-02-15T02:44:53+01:00 (13 years ago)
Author:
xeen
Message:

likely fix #7315’s cursor issues and related target-highlight ones

File:
1 edited

Legend:

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

    r4904 r4934  
    213213
    214214            if(dragInProgress()) {
    215                 c = ctrl ? "merge" : "move";
    216                 if(osm != null && osm instanceof Node && ctrl) {
    217                     c += "_to_node";
    218                 }
     215                // only consider merge if ctrl is pressed and there are nodes in
     216                // the selection that could be merged
     217                if(!ctrl || getCurrentDataSet().getSelectedNodes().isEmpty()) {
     218                    c = "move";
     219                    break;
     220                }
     221                // only show merge to node cursor if nearby node and that node is currently
     222                // not being dragged
     223                final boolean hasTarget = osm != null && osm instanceof Node && !osm.isSelected();
     224                c = hasTarget ? "merge_to_node" : "merge";
    219225                break;
    220226            }
     
    310316            return needsRepaint;
    311317
     318        // CTRL toggles selection, but if while dragging CTRL means merge
     319        final boolean isToggleMode = ctrl && !dragInProgress();
    312320        for(OsmPrimitive x : c) {
    313321            // only highlight primitives that will change the selection
    314322            // when clicked. I.e. don't highlight selected elements unless
    315323            // we are in toggle mode.
    316             if(ctrl || !x.isSelected()) {
     324            if(isToggleMode || !x.isSelected()) {
    317325                x.setHighlighted(true);
    318326                oldHighlights.add(x);
     
    344352        if (!mv.isActiveLayerVisible())
    345353            return;
    346        
     354
    347355        // Swing sends random mouseDragged events when closing dialogs by double-clicking their top-left icon on Windows
    348356        // Ignore such false events to prevent issues like #7078
    349         if (mouseDownButton == MouseEvent.BUTTON1 && mouseReleaseTime > mouseDownTime) {
    350             return;
    351         }
     357        if (mouseDownButton == MouseEvent.BUTTON1 && mouseReleaseTime > mouseDownTime)
     358            return;
    352359
    353360        cancelDrawMode = true;
     
    368375            // If ctrl is pressed we are in merge mode. Look for a nearby node,
    369376            // highlight it and adjust the cursor accordingly.
    370             final OsmPrimitive p = ctrl ? (OsmPrimitive)findNodeToMergeTo(e) : null;
     377            final boolean canMerge = ctrl && !getCurrentDataSet().getSelectedNodes().isEmpty();
     378            final OsmPrimitive p = canMerge ? (OsmPrimitive)findNodeToMergeTo(e) : null;
    371379            boolean needsRepaint = removeHighlighting();
    372380            if(p != null) {
     
    376384            }
    377385            mv.setNewCursor(getCursor(MapView.asColl(p)), this);
     386            // also update the stored mouse event, so we can display the correct cursor
     387            // when dragging a node onto another one and then press CTRL to merge
     388            oldEvent = e;
    378389            if(needsRepaint) {
    379390                mv.repaint();
     
    636647     * selectables nearby. Everything has to be pre-determined for this
    637648     * function; its main purpose is to centralize what the modifiers do.
    638      * @param nearSelectables
     649     * @param hasSelectionNearby
    639650     */
    640651    private void determineMapMode(boolean hasSelectionNearby) {
     
    935946        if (mode == Mode.select)
    936947            return tr("Release the mouse button to select the objects in the rectangle.");
    937         else if (mode == Mode.move)
    938             return tr("Release the mouse button to stop moving. Ctrl to merge with nearest node.");
    939         else if (mode == Mode.rotate)
     948        else if (mode == Mode.move) {
     949            final boolean canMerge = !getCurrentDataSet().getSelectedNodes().isEmpty();
     950            final String mergeHelp = canMerge ? (" " + tr("Ctrl to merge with nearest node.")) : "";
     951            return tr("Release the mouse button to stop moving.") + mergeHelp;
     952        } else if (mode == Mode.rotate)
    940953            return tr("Release the mouse button to stop rotating.");
    941954        else if (mode == Mode.scale)
Note: See TracChangeset for help on using the changeset viewer.