Changeset 7543 in josm
- Timestamp:
- 2014-09-16T03:29:51+02:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
r7389 r7543 67 67 */ 68 68 public 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 } 72 84 73 85 // contains all possible cases the cursor can be in the SelectAction … … 241 253 242 254 virtualManager.clear(); 243 if(mode == Mode. move) {255 if(mode == Mode.MOVE) { 244 256 if (!dragInProgress() && virtualManager.activateVirtualNodeNearPoint(e.getPoint())) { 245 257 DataSet ds = getCurrentDataSet(); … … 256 268 257 269 // 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()) 259 271 return repaintIfRequired(newHighlights); 260 272 … … 282 294 String c = "rect"; 283 295 switch(mode) { 284 case move:296 case MOVE: 285 297 if(virtualManager.hasVirtualNode()) { 286 298 c = "virtual_node"; … … 312 324 } 313 325 break; 314 case rotate:326 case ROTATE: 315 327 c = "rotate"; 316 328 break; 317 case scale:329 case SCALE: 318 330 c = "scale"; 319 331 break; 320 case select:332 case SELECT: 321 333 if (lassoMode) { 322 334 c = "lasso"; … … 411 423 412 424 switch(mode) { 413 case rotate:414 case scale:425 case ROTATE: 426 case SCALE: 415 427 // if nothing was selected, select primitive under cursor for scaling or rotating 416 428 if (getCurrentDataSet().getSelected().isEmpty()) { … … 423 435 // Mode.scale redraws here 424 436 break; 425 case move:437 case MOVE: 426 438 // also include case when some primitive is under cursor and no shift+ctrl / alt+ctrl is pressed 427 439 // so this is not movement, but selection on primitive under cursor … … 440 452 }, false); 441 453 break; 442 case select:454 case SELECT: 443 455 default: 444 456 if (!(ctrl && Main.isPlatformOsx())) { … … 457 469 @Override 458 470 public void mouseMoved(MouseEvent e) { 459 // Mac OSX simulates with 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)) { 461 473 mouseDragged(e); 462 474 return; … … 484 496 485 497 cancelDrawMode = true; 486 if (mode == Mode. select) {498 if (mode == Mode.SELECT) { 487 499 // Unregisters selectionManager if ctrl has been pressed after mouse click on Mac OS X in order to move the map 488 500 if (ctrl && Main.isPlatformOsx()) { … … 496 508 497 509 // 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)) 499 511 return; 500 512 501 if (mode != Mode. rotate&& mode != Mode.scale) // button is pressed in rotate mode513 if (mode != Mode.ROTATE && mode != Mode.SCALE) // button is pressed in rotate mode 502 514 { 503 515 if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == 0) … … 505 517 } 506 518 507 if (mode == Mode. move) {519 if (mode == Mode.MOVE) { 508 520 // If ctrl is pressed we are in merge mode. Look for a nearby node, 509 521 // highlight it and adjust the cursor accordingly. … … 552 564 553 565 mv.repaint(); 554 if (mode != Mode. scale) {566 if (mode != Mode.SCALE) { 555 567 lastMousePos = e.getPoint(); 556 568 } … … 574 586 mouseReleaseTime = System.currentTimeMillis(); 575 587 576 if (mode == Mode. select) {588 if (mode == Mode.SELECT) { 577 589 selectionManager.unregister(mv); 578 590 … … 585 597 } 586 598 587 if (mode == Mode. move&& e.getButton() == MouseEvent.BUTTON1) {599 if (mode == Mode.MOVE && e.getButton() == MouseEvent.BUTTON1) { 588 600 if (!didMouseDrag) { 589 601 // only built in move mode … … 658 670 private void determineMapMode(boolean hasSelectionNearby) { 659 671 if (shift && ctrl) { 660 mode = Mode. rotate;672 mode = Mode.ROTATE; 661 673 } else if (alt && ctrl) { 662 mode = Mode. scale;674 mode = Mode.SCALE; 663 675 } else if (hasSelectionNearby || dragInProgress()) { 664 mode = Mode. move;676 mode = Mode.MOVE; 665 677 } else { 666 mode = Mode. select;678 mode = Mode.SELECT; 667 679 } 668 680 } … … 693 705 Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(selection); 694 706 // 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)) { 696 708 return false; 697 709 } 698 710 Command c = getLastCommand(); 699 if (mode == Mode. move) {711 if (mode == Mode.MOVE) { 700 712 if (startEN == null) return false; // fix #8128 701 713 getCurrentDataSet().beginUpdate(); … … 725 737 startEN = currentEN; // drag can continue after scaling/rotation 726 738 727 if (mode != Mode. rotate&& mode != Mode.scale) {739 if (mode != Mode.ROTATE && mode != Mode.SCALE) { 728 740 return false; 729 741 } … … 731 743 getCurrentDataSet().beginUpdate(); 732 744 733 if (mode == Mode. rotate) {745 if (mode == Mode.ROTATE) { 734 746 if (c instanceof RotateCommand && affectedNodes.equals(((RotateCommand) c).getTransformedNodes())) { 735 747 ((RotateCommand) c).handleEvent(currentEN); … … 737 749 Main.main.undoRedo.add(new RotateCommand(selection, currentEN)); 738 750 } 739 } else if (mode == Mode. scale) {751 } else if (mode == Mode.SCALE) { 740 752 if (c instanceof ScaleCommand && affectedNodes.equals(((ScaleCommand) c).getTransformedNodes())) { 741 753 ((ScaleCommand) c).handleEvent(currentEN); … … 897 909 } 898 910 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 899 920 @Override 900 921 public String getModeHelpText() { 901 922 if (mouseDownButton == MouseEvent.BUTTON1 && mouseReleaseTime < mouseDownTime) { 902 if (mode == Mode. select)923 if (mode == Mode.SELECT) 903 924 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)) { 905 926 final boolean canMerge = getCurrentDataSet()!=null && !getCurrentDataSet().getSelectedNodes().isEmpty(); 906 927 final String mergeHelp = canMerge ? (" " + tr("Ctrl to merge with nearest node.")) : ""; 907 928 return tr("Release the mouse button to stop moving.") + mergeHelp; 908 } else if (mode == Mode. rotate)929 } else if (mode == Mode.ROTATE) 909 930 return tr("Release the mouse button to stop rotating."); 910 else if (mode == Mode. scale)931 else if (mode == Mode.SCALE) 911 932 return tr("Release the mouse button to stop scaling."); 912 933 } -
trunk/src/org/openstreetmap/josm/gui/MapMover.java
r7509 r7543 22 22 23 23 import org.openstreetmap.josm.Main; 24 import org.openstreetmap.josm.actions.mapmode.SelectAction; 24 25 import org.openstreetmap.josm.data.coor.EastNorth; 25 26 import org.openstreetmap.josm.tools.Destroyable; … … 83 84 84 85 /** 85 * COnstructs a new {@code MapMover}. 86 * Constructs a new {@code MapMover}. 87 * @param navComp the navigatable component 88 * @param contentPane the content pane 86 89 */ 87 90 public MapMover(NavigatableComponent navComp, JPanel contentPane) { … … 126 129 127 130 /** 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. 129 132 */ 130 133 @Override … … 132 135 int offMask = MouseEvent.BUTTON1_DOWN_MASK | MouseEvent.BUTTON2_DOWN_MASK; 133 136 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)) { 136 142 if (mousePosMove == null) 137 143 startMovement(e);
Note:
See TracChangeset
for help on using the changeset viewer.