Changeset 12317 in josm
- Timestamp:
- 2017-06-04T21:33:56+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MapMover.java
r11713 r12317 23 23 import org.openstreetmap.josm.data.coor.EastNorth; 24 24 import org.openstreetmap.josm.data.preferences.BooleanProperty; 25 import org.openstreetmap.josm.gui.MapViewState.MapViewPoint; 25 26 import org.openstreetmap.josm.tools.Destroyable; 26 27 import org.openstreetmap.josm.tools.Pair; … … 35 36 public class MapMover extends MouseAdapter implements Destroyable { 36 37 38 /** 39 * Zoom wheel is reversed. 40 */ 37 41 public static final BooleanProperty PROP_ZOOM_REVERSE_WHEEL = new BooleanProperty("zoom.reverse-wheel", false); 38 42 … … 104 108 * The point in the map that was the under the mouse point 105 109 * 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 108 115 /** 109 116 * The map to move around. 110 117 */ 111 118 private final NavigatableComponent nc; 112 113 private boolean movementInPlace;114 119 115 120 private final ArrayList<Pair<ZoomerAction, Shortcut>> registeredShortcuts = new ArrayList<>(); … … 152 157 } 153 158 159 private boolean movementInProgress() { 160 return mousePosMoveStart != null; 161 } 162 154 163 /** 155 164 * If the right (and only the right) mouse button is pressed, move the map. … … 158 167 public void mouseDragged(MouseEvent e) { 159 168 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); 173 179 } else { 174 180 endMovement(); 175 181 } 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)); 176 191 } 177 192 … … 205 220 */ 206 221 private void startMovement(MouseEvent e) { 207 if (movementInP lace)222 if (movementInProgress()) { 208 223 return; 209 movementInPlace = true;210 mousePosMove = nc.getEastNorth(e.getX(), e.getY());224 } 225 mousePosMoveStart = nc.getState().getForView(e.getX(), e.getY()); 211 226 nc.setNewCursor(Cursor.MOVE_CURSOR, this); 212 227 } … … 216 231 */ 217 232 private void endMovement() { 218 if (!movementInP lace)233 if (!movementInProgress()) { 219 234 return; 220 movementInPlace = false;235 } 221 236 nc.resetCursor(this); 222 mousePosMove = null;237 mousePosMoveStart = null; 223 238 } 224 239 … … 238 253 @Override 239 254 public void mouseMoved(MouseEvent e) { 240 if (!movementInP lace)255 if (!movementInProgress()) { 241 256 return; 257 } 242 258 // Mac OSX simulates with ctrl + mouse 1 the second mouse button hence no dragging events get fired. 243 259 // Is only the selected mouse button pressed? 244 260 if (Main.isPlatformOsx()) { 245 261 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); 253 263 } else { 254 264 endMovement();
Note:
See TracChangeset
for help on using the changeset viewer.