Changeset 12317 in josm


Ignore:
Timestamp:
2017-06-04T21:33:56+02:00 (2 years ago)
Author:
michael2402
Message:

Remove dupplicate code/state in MapMover

File:
1 edited

Legend:

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

    r11713 r12317  
    2323import org.openstreetmap.josm.data.coor.EastNorth;
    2424import org.openstreetmap.josm.data.preferences.BooleanProperty;
     25import org.openstreetmap.josm.gui.MapViewState.MapViewPoint;
    2526import org.openstreetmap.josm.tools.Destroyable;
    2627import org.openstreetmap.josm.tools.Pair;
     
    3536public class MapMover extends MouseAdapter implements Destroyable {
    3637
     38    /**
     39     * Zoom wheel is reversed.
     40     */
    3741    public static final BooleanProperty PROP_ZOOM_REVERSE_WHEEL = new BooleanProperty("zoom.reverse-wheel", false);
    3842
     
    104108     * The point in the map that was the under the mouse point
    105109     * when moving around started.
    106      */
    107     private EastNorth mousePosMove;
     110     *
     111     * This is <code>null</code> if movement is not active
     112     */
     113    private MapViewPoint mousePosMoveStart;
     114
    108115    /**
    109116     * The map to move around.
    110117     */
    111118    private final NavigatableComponent nc;
    112 
    113     private boolean movementInPlace;
    114119
    115120    private final ArrayList<Pair<ZoomerAction, Shortcut>> registeredShortcuts = new ArrayList<>();
     
    152157    }
    153158
     159    private boolean movementInProgress() {
     160        return mousePosMoveStart != null;
     161    }
     162
    154163    /**
    155164     * If the right (and only the right) mouse button is pressed, move the map.
     
    158167    public void mouseDragged(MouseEvent e) {
    159168        int offMask = MouseEvent.BUTTON1_DOWN_MASK | MouseEvent.BUTTON2_DOWN_MASK;
    160         int macMouseMask = MouseEvent.CTRL_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK;
    161         boolean stdMovement = (e.getModifiersEx() & (MouseEvent.BUTTON3_DOWN_MASK | offMask)) == MouseEvent.BUTTON3_DOWN_MASK;
    162         boolean macMovement = Main.isPlatformOsx() && e.getModifiersEx() == macMouseMask;
    163         boolean allowedMode = !Main.map.mapModeSelect.equals(Main.map.mapMode)
    164                           || SelectAction.Mode.SELECT.equals(Main.map.mapModeSelect.getMode());
    165         if (stdMovement || (macMovement && allowedMode)) {
    166             if (mousePosMove == null)
    167                 startMovement(e);
    168             EastNorth center = nc.getCenter();
    169             EastNorth mouseCenter = nc.getEastNorth(e.getX(), e.getY());
    170             nc.zoomTo(new EastNorth(
    171                     mousePosMove.east() + center.east() - mouseCenter.east(),
    172                     mousePosMove.north() + center.north() - mouseCenter.north()));
     169        boolean allowMovement = (e.getModifiersEx() & (MouseEvent.BUTTON3_DOWN_MASK | offMask)) == MouseEvent.BUTTON3_DOWN_MASK;
     170        if (Main.isPlatformOsx()) {
     171            int macMouseMask = MouseEvent.CTRL_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK;
     172            boolean macMovement = true && e.getModifiersEx() == macMouseMask;
     173            boolean allowedMode = !Main.map.mapModeSelect.equals(Main.map.mapMode)
     174                              || SelectAction.Mode.SELECT.equals(Main.map.mapModeSelect.getMode());
     175            allowMovement |= macMovement && allowedMode;
     176        }
     177        if (allowMovement) {
     178            doMoveForDrag(e);
    173179        } else {
    174180            endMovement();
    175181        }
     182    }
     183
     184    private void doMoveForDrag(MouseEvent e) {
     185        if (!movementInProgress()) {
     186            startMovement(e);
     187        }
     188        EastNorth center = nc.getCenter();
     189        EastNorth mouseCenter = nc.getEastNorth(e.getX(), e.getY());
     190        nc.zoomTo(mousePosMoveStart.getEastNorth().add(center).subtract(mouseCenter));
    176191    }
    177192
     
    205220     */
    206221    private void startMovement(MouseEvent e) {
    207         if (movementInPlace)
     222        if (movementInProgress()) {
    208223            return;
    209         movementInPlace = true;
    210         mousePosMove = nc.getEastNorth(e.getX(), e.getY());
     224        }
     225        mousePosMoveStart = nc.getState().getForView(e.getX(), e.getY());
    211226        nc.setNewCursor(Cursor.MOVE_CURSOR, this);
    212227    }
     
    216231     */
    217232    private void endMovement() {
    218         if (!movementInPlace)
     233        if (!movementInProgress()) {
    219234            return;
    220         movementInPlace = false;
     235        }
    221236        nc.resetCursor(this);
    222         mousePosMove = null;
     237        mousePosMoveStart = null;
    223238    }
    224239
     
    238253    @Override
    239254    public void mouseMoved(MouseEvent e) {
    240         if (!movementInPlace)
     255        if (!movementInProgress()) {
    241256            return;
     257        }
    242258        // Mac OSX simulates with  ctrl + mouse 1  the second mouse button hence no dragging events get fired.
    243259        // Is only the selected mouse button pressed?
    244260        if (Main.isPlatformOsx()) {
    245261            if (e.getModifiersEx() == MouseEvent.CTRL_DOWN_MASK) {
    246                 if (mousePosMove == null) {
    247                     startMovement(e);
    248                 }
    249                 EastNorth center = nc.getCenter();
    250                 EastNorth mouseCenter = nc.getEastNorth(e.getX(), e.getY());
    251                 nc.zoomTo(new EastNorth(mousePosMove.east() + center.east() - mouseCenter.east(), mousePosMove.north()
    252                         + center.north() - mouseCenter.north()));
     262                doMoveForDrag(e);
    253263            } else {
    254264                endMovement();
Note: See TracChangeset for help on using the changeset viewer.