Changeset 7543 in josm for trunk/src/org


Ignore:
Timestamp:
2014-09-16T03:29:51+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #9897, see #10455 - fix map moving issue when moving node with ctrl

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

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

    r7389 r7543  
    6767 */
    6868public class SelectAction extends MapMode implements ModifierListener, KeyPressReleaseListener, SelectionEnded {
    69     // "select" means the selection rectangle and "move" means either dragging
    70     // or select if no mouse movement occurs (i.e. just clicking)
    71     enum Mode { move, rotate, scale, select }
     69
     70    /**
     71     * Select action mode.
     72     * @since 7543
     73     */
     74    public enum Mode {
     75        /** "MOVE" means either dragging or select if no mouse movement occurs (i.e. just clicking) */
     76        MOVE,
     77        /** "ROTATE" allows to apply a rotation transformation on the selected object (see {@link RotateCommand}) */
     78        ROTATE,
     79        /** "SCALE" allows to apply a scaling transformation on the selected object (see {@link ScaleCommand}) */
     80        SCALE,
     81        /** "SELECT" means the selection rectangle */
     82        SELECT
     83    }
    7284
    7385    // contains all possible cases the cursor can be in the SelectAction
     
    241253
    242254        virtualManager.clear();
    243         if(mode == Mode.move) {
     255        if(mode == Mode.MOVE) {
    244256            if (!dragInProgress() && virtualManager.activateVirtualNodeNearPoint(e.getPoint())) {
    245257                DataSet ds = getCurrentDataSet();
     
    256268
    257269        // return early if there can't be any highlights
    258         if(!drawTargetHighlight || mode != Mode.move || c.isEmpty())
     270        if(!drawTargetHighlight || mode != Mode.MOVE || c.isEmpty())
    259271            return repaintIfRequired(newHighlights);
    260272
     
    282294        String c = "rect";
    283295        switch(mode) {
    284         case move:
     296        case MOVE:
    285297            if(virtualManager.hasVirtualNode()) {
    286298                c = "virtual_node";
     
    312324            }
    313325            break;
    314         case rotate:
     326        case ROTATE:
    315327            c = "rotate";
    316328            break;
    317         case scale:
     329        case SCALE:
    318330            c = "scale";
    319331            break;
    320         case select:
     332        case SELECT:
    321333            if (lassoMode) {
    322334                c = "lasso";
     
    411423
    412424        switch(mode) {
    413         case rotate:
    414         case scale:
     425        case ROTATE:
     426        case SCALE:
    415427            //  if nothing was selected, select primitive under cursor for scaling or rotating
    416428            if (getCurrentDataSet().getSelected().isEmpty()) {
     
    423435            // Mode.scale redraws here
    424436            break;
    425         case move:
     437        case MOVE:
    426438            // also include case when some primitive is under cursor and no shift+ctrl / alt+ctrl is pressed
    427439            // so this is not movement, but selection on primitive under cursor
     
    440452            }, false);
    441453            break;
    442         case select:
     454        case SELECT:
    443455        default:
    444456            if (!(ctrl && Main.isPlatformOsx())) {
     
    457469    @Override
    458470    public void mouseMoved(MouseEvent e) {
    459         // Mac OSX simulates with  ctrl + mouse 1 the second mouse button hence no dragging events get fired.
    460         if (Main.isPlatformOsx() && (mode == Mode.rotate || mode == Mode.scale)) {
     471        // Mac OSX simulates with ctrl + mouse 1 the second mouse button hence no dragging events get fired.
     472        if (Main.isPlatformOsx() && (mode == Mode.ROTATE || mode == Mode.SCALE)) {
    461473            mouseDragged(e);
    462474            return;
     
    484496
    485497        cancelDrawMode = true;
    486         if (mode == Mode.select) {
     498        if (mode == Mode.SELECT) {
    487499            // Unregisters selectionManager if ctrl has been pressed after mouse click on Mac OS X in order to move the map
    488500            if (ctrl && Main.isPlatformOsx()) {
     
    496508
    497509        // do not count anything as a move if it lasts less than 100 milliseconds.
    498         if ((mode == Mode.move) && (System.currentTimeMillis() - mouseDownTime < initialMoveDelay))
     510        if ((mode == Mode.MOVE) && (System.currentTimeMillis() - mouseDownTime < initialMoveDelay))
    499511            return;
    500512
    501         if (mode != Mode.rotate && mode != Mode.scale) // button is pressed in rotate mode
     513        if (mode != Mode.ROTATE && mode != Mode.SCALE) // button is pressed in rotate mode
    502514        {
    503515            if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == 0)
     
    505517        }
    506518
    507         if (mode == Mode.move) {
     519        if (mode == Mode.MOVE) {
    508520            // If ctrl is pressed we are in merge mode. Look for a nearby node,
    509521            // highlight it and adjust the cursor accordingly.
     
    552564
    553565        mv.repaint();
    554         if (mode != Mode.scale) {
     566        if (mode != Mode.SCALE) {
    555567            lastMousePos = e.getPoint();
    556568        }
     
    574586        mouseReleaseTime = System.currentTimeMillis();
    575587
    576         if (mode == Mode.select) {
     588        if (mode == Mode.SELECT) {
    577589            selectionManager.unregister(mv);
    578590
     
    585597        }
    586598
    587         if (mode == Mode.move && e.getButton() == MouseEvent.BUTTON1) {
     599        if (mode == Mode.MOVE && e.getButton() == MouseEvent.BUTTON1) {
    588600            if (!didMouseDrag) {
    589601                // only built in move mode
     
    658670    private void determineMapMode(boolean hasSelectionNearby) {
    659671        if (shift && ctrl) {
    660             mode = Mode.rotate;
     672            mode = Mode.ROTATE;
    661673        } else if (alt && ctrl) {
    662             mode = Mode.scale;
     674            mode = Mode.SCALE;
    663675        } else if (hasSelectionNearby || dragInProgress()) {
    664             mode = Mode.move;
     676            mode = Mode.MOVE;
    665677        } else {
    666             mode = Mode.select;
     678            mode = Mode.SELECT;
    667679        }
    668680    }
     
    693705        Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(selection);
    694706        // for these transformations, having only one node makes no sense - quit silently
    695         if (affectedNodes.size() < 2 && (mode == Mode.rotate || mode == Mode.scale)) {
     707        if (affectedNodes.size() < 2 && (mode == Mode.ROTATE || mode == Mode.SCALE)) {
    696708            return false;
    697709        }
    698710        Command c = getLastCommand();
    699         if (mode == Mode.move) {
     711        if (mode == Mode.MOVE) {
    700712            if (startEN == null) return false; // fix #8128
    701713            getCurrentDataSet().beginUpdate();
     
    725737            startEN = currentEN; // drag can continue after scaling/rotation
    726738
    727             if (mode != Mode.rotate && mode != Mode.scale) {
     739            if (mode != Mode.ROTATE && mode != Mode.SCALE) {
    728740                return false;
    729741            }
     
    731743            getCurrentDataSet().beginUpdate();
    732744
    733             if (mode == Mode.rotate) {
     745            if (mode == Mode.ROTATE) {
    734746                if (c instanceof RotateCommand && affectedNodes.equals(((RotateCommand) c).getTransformedNodes())) {
    735747                    ((RotateCommand) c).handleEvent(currentEN);
     
    737749                    Main.main.undoRedo.add(new RotateCommand(selection, currentEN));
    738750                }
    739             } else if (mode == Mode.scale) {
     751            } else if (mode == Mode.SCALE) {
    740752                if (c instanceof ScaleCommand && affectedNodes.equals(((ScaleCommand) c).getTransformedNodes())) {
    741753                    ((ScaleCommand) c).handleEvent(currentEN);
     
    897909    }
    898910
     911    /**
     912     * Returns the current select mode.
     913     * @return the select mode
     914     * @since 7543
     915     */
     916    public final Mode getMode() {
     917        return mode;
     918    }
     919
    899920    @Override
    900921    public String getModeHelpText() {
    901922        if (mouseDownButton == MouseEvent.BUTTON1 && mouseReleaseTime < mouseDownTime) {
    902             if (mode == Mode.select)
     923            if (mode == Mode.SELECT)
    903924                return tr("Release the mouse button to select the objects in the rectangle.");
    904             else if (mode == Mode.move && (System.currentTimeMillis() - mouseDownTime >= initialMoveDelay)) {
     925            else if (mode == Mode.MOVE && (System.currentTimeMillis() - mouseDownTime >= initialMoveDelay)) {
    905926                final boolean canMerge = getCurrentDataSet()!=null && !getCurrentDataSet().getSelectedNodes().isEmpty();
    906927                final String mergeHelp = canMerge ? (" " + tr("Ctrl to merge with nearest node.")) : "";
    907928                return tr("Release the mouse button to stop moving.") + mergeHelp;
    908             } else if (mode == Mode.rotate)
     929            } else if (mode == Mode.ROTATE)
    909930                return tr("Release the mouse button to stop rotating.");
    910             else if (mode == Mode.scale)
     931            else if (mode == Mode.SCALE)
    911932                return tr("Release the mouse button to stop scaling.");
    912933        }
  • trunk/src/org/openstreetmap/josm/gui/MapMover.java

    r7509 r7543  
    2222
    2323import org.openstreetmap.josm.Main;
     24import org.openstreetmap.josm.actions.mapmode.SelectAction;
    2425import org.openstreetmap.josm.data.coor.EastNorth;
    2526import org.openstreetmap.josm.tools.Destroyable;
     
    8384
    8485    /**
    85      * COnstructs a new {@code MapMover}.
     86     * Constructs a new {@code MapMover}.
     87     * @param navComp the navigatable component
     88     * @param contentPane the content pane
    8689     */
    8790    public MapMover(NavigatableComponent navComp, JPanel contentPane) {
     
    126129
    127130    /**
    128      * If the right (and only the right) mouse button is pressed, move the map
     131     * If the right (and only the right) mouse button is pressed, move the map.
    129132     */
    130133    @Override
     
    132135        int offMask = MouseEvent.BUTTON1_DOWN_MASK | MouseEvent.BUTTON2_DOWN_MASK;
    133136        int macMouseMask = MouseEvent.CTRL_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK;
    134         if ((e.getModifiersEx() & (MouseEvent.BUTTON3_DOWN_MASK | offMask)) == MouseEvent.BUTTON3_DOWN_MASK ||
    135                 Main.isPlatformOsx() && e.getModifiersEx() == macMouseMask) {
     137        boolean stdMovement = (e.getModifiersEx() & (MouseEvent.BUTTON3_DOWN_MASK | offMask)) == MouseEvent.BUTTON3_DOWN_MASK;
     138        boolean macMovement = Main.isPlatformOsx() && e.getModifiersEx() == macMouseMask;
     139        boolean allowedMode = !Main.map.mapModeSelect.equals(Main.map.mapMode)
     140                          || Main.map.mapModeSelect.getMode().equals(SelectAction.Mode.SELECT);
     141        if (stdMovement || (macMovement && allowedMode)) {
    136142            if (mousePosMove == null)
    137143                startMovement(e);
Note: See TracChangeset for help on using the changeset viewer.