Changeset 4327 in josm for trunk/src/org/openstreetmap/josm/actions
- Timestamp:
- 2011-08-21T13:12:53+02:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/actions/mapmode
- Files:
-
- 7 edited
-
DeleteAction.java (modified) (12 diffs)
-
DrawAction.java (modified) (4 diffs)
-
ExtrudeAction.java (modified) (3 diffs)
-
MapMode.java (modified) (3 diffs)
-
ParallelWayAction.java (modified) (6 diffs)
-
PlayHeadDragMode.java (modified) (3 diffs)
-
SelectAction.java (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java
r3919 r4327 6 6 import java.awt.AWTEvent; 7 7 import java.awt.Cursor; 8 import java.awt.EventQueue;9 8 import java.awt.Toolkit; 10 9 import java.awt.event.AWTEventListener; … … 14 13 import java.awt.event.MouseEvent; 15 14 import java.util.Collections; 15 import java.util.HashSet; 16 import java.util.Set; 16 17 17 18 import org.openstreetmap.josm.Main; 18 19 import org.openstreetmap.josm.command.Command; 19 20 import org.openstreetmap.josm.command.DeleteCommand; 21 import org.openstreetmap.josm.data.osm.DataSet; 20 22 import org.openstreetmap.josm.data.osm.Node; 21 23 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 45 47 * @author imi 46 48 */ 47 48 /**49 * This class contains stubs for highlighting affected primitives when affected.50 * However, way segments can be deleted as well, but cannot be highlighted51 * alone. If the highlight feature for this delete action is to be implemented52 * properly, highlighting way segments must be possible first. --xeen, 2009-09-0253 */54 49 public class DeleteAction extends MapMode implements AWTEventListener { 55 50 // Cache previous mouse event (needed when only the modifier keys are 56 51 // pressed but the mouse isn't moved) 57 52 private MouseEvent oldEvent = null; 53 54 /** 55 * elements that have been highlighted in the previous iteration. Used 56 * to remove the highlight from them again as otherwise the whole data 57 * set would have to be checked. 58 */ 59 private Set<OsmPrimitive> oldHighlights = new HashSet<OsmPrimitive>(); 60 61 private boolean drawTargetHighlight; 58 62 59 63 private enum DeleteMode { … … 101 105 return; 102 106 107 drawTargetHighlight = Main.pref.getBoolean("draw.target-highlight", true); 108 103 109 Main.map.mapView.addMouseListener(this); 104 110 Main.map.mapView.addMouseMotionListener(this); … … 120 126 System.out.println(ex); 121 127 } 128 removeHighlighting(); 122 129 } 123 130 … … 157 164 @Override public void mouseMoved(MouseEvent e) { 158 165 oldEvent = e; 159 updateCursor(e, e.getModifiers()); 166 giveUserFeedback(e); 167 } 168 169 /** 170 * removes any highlighting that may have been set beforehand. 171 */ 172 private void removeHighlighting() { 173 for(OsmPrimitive prim : oldHighlights) { 174 prim.setHighlighted(false); 175 } 176 oldHighlights = new HashSet<OsmPrimitive>(); 177 DataSet ds = getCurrentDataSet(); 178 if(ds != null) { 179 ds.clearHighlightedWaySegments(); 180 } 181 } 182 183 /** 184 * handles everything related to highlighting primitives and way 185 * segments for the given pointer position (via MouseEvent) and 186 * modifiers. 187 * @param e 188 * @param modifiers 189 */ 190 private void addHighlighting(MouseEvent e, int modifiers) { 191 if(!drawTargetHighlight) 192 return; 193 removeHighlighting(); 194 195 DeleteParameters parameters = getDeleteParameters(e, modifiers); 196 197 if(parameters.mode == DeleteMode.segment) { 198 // deleting segments is the only action not working on OsmPrimitives 199 // so we have to handle them separately. 200 DataSet ds = getCurrentDataSet(); 201 if(ds != null) { 202 ds.setHighlightedWaySegments(Collections.singleton(parameters.nearestSegment)); 203 } 204 } else { 205 // don't call buildDeleteCommands for DeleteMode.segment because it doesn't support 206 // silent operation and SplitWayAction will show dialogs. A lot. 207 Command delCmd = buildDeleteCommands(e, modifiers, true); 208 if(delCmd == null) { 209 Main.map.mapView.repaint(); 210 return; 211 } 212 213 // all other cases delete OsmPrimitives directly, so we can 214 // safely do the following 215 for(OsmPrimitive osm : delCmd.getParticipatingPrimitives()) { 216 osm.setHighlighted(true); 217 oldHighlights.add(osm); 218 } 219 } 220 Main.map.mapView.repaint(); 160 221 } 161 222 162 223 /** 163 224 * This function handles all work related to updating the cursor and 164 * highlights. For now, only the cursor is enabled because highlighting 165 * requires WaySegment to be highlightable. 225 * highlights 166 226 * 227 * @param MouseEvent 228 * @param int modifiers 229 */ 230 private void updateCursor(MouseEvent e, int modifiers) { 231 if (!Main.isDisplayingMapView()) 232 return; 233 if(!Main.map.mapView.isActiveLayerVisible() || e == null) 234 return; 235 236 DeleteParameters parameters = getDeleteParameters(e, modifiers); 237 Main.map.mapView.setNewCursor(parameters.mode.cursor(), this); 238 } 239 /** 240 * Gives the user feedback for the action he/she is about to do. Currently 241 * calls the cursor and target highlighting routines. Allows for modifiers 242 * not taken from the given mouse event. 243 * 167 244 * Normally the mouse event also contains the modifiers. However, when the 168 245 * mouse is not moved and only modifier keys are pressed, no mouse event … … 170 247 * mouseevent. Instead we copy the previous event and only update the 171 248 * modifiers. 172 * 173 * @param MouseEvent 174 * @param int modifiers 175 */ 176 private void updateCursor(MouseEvent e, int modifiers) { 177 if (!Main.isDisplayingMapView()) 178 return; 179 if(!Main.map.mapView.isActiveLayerVisible() || e == null) 180 return; 181 182 DeleteParameters parameters = getDeleteParameters(e, modifiers); 183 Main.map.mapView.setNewCursor(parameters.mode.cursor(), this); 249 */ 250 private void giveUserFeedback(MouseEvent e, int modifiers) { 251 updateCursor(e, modifiers); 252 addHighlighting(e, modifiers); 253 } 254 255 /** 256 * Gives the user feedback for the action he/she is about to do. Currently 257 * calls the cursor and target highlighting routines. Extracts modifiers 258 * from mouse event. 259 */ 260 private void giveUserFeedback(MouseEvent e) { 261 giveUserFeedback(e, e.getModifiers()); 184 262 } 185 263 … … 204 282 205 283 getCurrentDataSet().setSelected(); 284 giveUserFeedback(e); 206 285 Main.map.mapView.repaint(); 207 286 } … … 242 321 243 322 private DeleteParameters getDeleteParameters(MouseEvent e, int modifiers) { 244 // Note: CTRL is the only modifier that is checked in MouseMove, don't 245 // forget updating it there 246 boolean ctrl = (modifiers & ActionEvent.CTRL_MASK) != 0; 247 boolean shift = (modifiers & ActionEvent.SHIFT_MASK) != 0; 248 boolean alt = (modifiers & (ActionEvent.ALT_MASK|InputEvent.ALT_GRAPH_MASK)) != 0; 323 updateKeyModifiers(modifiers); 249 324 250 325 DeleteParameters result = new DeleteParameters(); … … 288 363 return DeleteCommand.delete(getEditLayer(),Collections.singleton(parameters.nearestNode), false, silent); 289 364 case node_with_references: 290 return DeleteCommand.deleteWithReferences(getEditLayer(),Collections.singleton(parameters.nearestNode)); 365 return DeleteCommand.deleteWithReferences(getEditLayer(),Collections.singleton(parameters.nearestNode), silent); 291 366 case segment: 292 367 return DeleteCommand.deleteWaySegment(getEditLayer(), parameters.nearestSegment); … … 296 371 return DeleteCommand.delete(getEditLayer(), Collections.singleton(parameters.nearestSegment.way), true, silent); 297 372 case way_with_references: 298 return DeleteCommand.deleteWithReferences(getEditLayer(),Collections.singleton(parameters.nearestSegment.way),true); 373 return DeleteCommand.deleteWithReferences(getEditLayer(), Collections.singleton(parameters.nearestSegment.way), true); 299 374 default: 300 375 return null; … … 306 381 */ 307 382 public void eventDispatched(AWTEvent e) { 383 if(e == null) 384 return; 308 385 // We don't have a mouse event, so we pass the old mouse event but the 309 386 // new modifiers. 310 updateCursor(oldEvent, ((InputEvent)e).getModifiers());387 giveUserFeedback(oldEvent, ((InputEvent) e).getModifiers()); 311 388 } 312 389 } -
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r4191 r4327 9 9 import java.awt.Color; 10 10 import java.awt.Cursor; 11 import java.awt.EventQueue;12 11 import java.awt.Graphics2D; 13 12 import java.awt.Point; 14 13 import java.awt.Toolkit; 15 14 import java.awt.event.AWTEventListener; 16 import java.awt.event.ActionEvent;17 15 import java.awt.event.InputEvent; 18 16 import java.awt.event.KeyEvent; … … 66 64 private double PHI=Math.toRadians(90); 67 65 68 private boolean ctrl;69 private boolean alt;70 private boolean shift;71 66 private Node mouseOnExistingNode; 72 67 private Set<Way> mouseOnExistingWays = new HashSet<Way>(); … … 513 508 getCurrentDataSet().setSelected(newSelection); 514 509 515 // "viewport following" mode for tracing long features 516 // from aerial imagery or GPS tracks. 510 // "viewport following" mode for tracing long features 511 // from aerial imagery or GPS tracks. 517 512 if (n != null && Main.map.mapView.viewportFollowing) { 518 513 Main.map.mapView.smoothScrollTo(n.getEastNorth()); … … 602 597 } 603 598 604 private void updateKeyModifiers(InputEvent e) {605 ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0;606 alt = (e.getModifiers() & (ActionEvent.ALT_MASK|InputEvent.ALT_GRAPH_MASK)) != 0;607 shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0;608 }609 610 private void updateKeyModifiers(MouseEvent e) {611 ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0;612 alt = (e.getModifiers() & (ActionEvent.ALT_MASK|InputEvent.ALT_GRAPH_MASK)) != 0;613 shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0;614 }615 616 599 /** 617 600 * This method prepares data required for painting the "helper line" from -
trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java
r4142 r4327 185 185 return; 186 186 187 updateKeyModifiers(e); 188 187 189 selectedSegment = Main.map.mapView.getNearestWaySegment(e.getPoint(), OsmPrimitive.isSelectablePredicate); 188 190 … … 192 194 // Otherwise switch to another mode 193 195 194 if ( (e.getModifiers() & ActionEvent.CTRL_MASK) != 0) {196 if (ctrl) { 195 197 mode = Mode.translate; 196 } else if ( (e.getModifiers() & (ActionEvent.ALT_MASK|InputEvent.ALT_GRAPH_MASK)) != 0) {198 } else if (alt) { 197 199 mode = Mode.create_new; 198 200 // create a new segment and then select and extrude the new segment … … 202 204 mode = Mode.extrude; 203 205 getCurrentDataSet().setSelected(selectedSegment.way); 204 alwaysCreateNodes = ((e.getModifiers() & ActionEvent.SHIFT_MASK) != 0);206 alwaysCreateNodes = shift; 205 207 } 206 208 -
trunk/src/org/openstreetmap/josm/actions/mapmode/MapMode.java
r3919 r4327 4 4 import java.awt.Cursor; 5 5 import java.awt.event.ActionEvent; 6 import java.awt.event.InputEvent; 6 7 import java.awt.event.MouseEvent; 7 8 import java.awt.event.MouseListener; … … 25 26 abstract public class MapMode extends JosmAction implements MouseListener, MouseMotionListener { 26 27 protected final Cursor cursor; 28 protected boolean ctrl; 29 protected boolean alt; 30 protected boolean shift; 27 31 28 32 /** … … 77 81 } 78 82 83 protected void updateKeyModifiers(InputEvent e) { 84 updateKeyModifiers(e.getModifiers()); 85 } 86 87 protected void updateKeyModifiers(MouseEvent e) { 88 updateKeyModifiers(e.getModifiers()); 89 } 90 91 protected void updateKeyModifiers(int modifiers) { 92 ctrl = (modifiers & ActionEvent.CTRL_MASK) != 0; 93 alt = (modifiers & (ActionEvent.ALT_MASK|InputEvent.ALT_GRAPH_MASK)) != 0; 94 shift = (modifiers & ActionEvent.SHIFT_MASK) != 0; 95 } 96 79 97 public void mouseReleased(MouseEvent e) {} 80 98 public void mouseExited(MouseEvent e) {} -
trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java
r4251 r4327 14 14 import java.awt.Toolkit; 15 15 import java.awt.event.AWTEventListener; 16 import java.awt.event.ActionEvent;17 16 import java.awt.event.InputEvent; 18 17 import java.awt.event.KeyEvent; … … 109 108 private final MapView mv; 110 109 111 private boolean ctrl;112 private boolean alt;113 private boolean shift;114 115 110 // Mouse tracking state 116 111 private Point mousePressedPos; … … 233 228 private boolean updateModifiersState(InputEvent e) { 234 229 boolean oldAlt = alt, oldShift = shift, oldCtrl = ctrl; 235 alt = (e.getModifiers() & (ActionEvent.ALT_MASK | InputEvent.ALT_GRAPH_MASK)) != 0; 236 ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 237 shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 230 updateKeyModifiers(e); 238 231 boolean changed = (oldAlt != alt || oldShift != shift || oldCtrl != ctrl); 239 232 return changed; … … 394 387 if (!isModifiersValidForDragMode()) 395 388 return; 396 if (!initParallelWays(mousePressedPos, copyTags)) {389 if (!initParallelWays(mousePressedPos, copyTags)) 397 390 return; 398 }399 391 setMode(Mode.dragging); 400 392 } … … 409 401 double realD = mv.getProjection().eastNorth2latlon(enp).greatCircleDistance(mv.getProjection().eastNorth2latlon(nearestPointOnRefLine)); 410 402 double snappedRealD = realD; 411 403 412 404 // TODO: abuse of isToTheRightSideOfLine function. 413 405 boolean toTheRight = Geometry.isToTheRightSideOfLine(referenceSegment.getFirstNode(), … … 431 423 } 432 424 pWays.changeOffset(d); 433 425 434 426 Main.map.statusLine.setDist(Math.abs(snappedRealD)); 435 427 Main.map.statusLine.repaint(); -
trunk/src/org/openstreetmap/josm/actions/mapmode/PlayHeadDragMode.java
r2808 r4327 6 6 import java.awt.Cursor; 7 7 import java.awt.Point; 8 import java.awt.event.ActionEvent;9 8 import java.awt.event.MouseEvent; 10 9 … … 28 27 public PlayHeadDragMode(PlayHeadMarker m) { 29 28 super(tr("Drag play head"), "playheaddrag", tr("Drag play head"), null, 30 Main.map, Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); 29 Main.map, Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); 31 30 playHeadMarker = m; 32 31 } … … 68 67 if (ev.getButton() != MouseEvent.BUTTON1 || p == null || ! dragging) 69 68 return; 70 boolean shift = (ev.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 69 70 updateKeyModifiers(ev); 71 71 72 EastNorth en = Main.map.mapView.getEastNorth(ev.getX(), ev.getY()); 72 73 if (! shift) { -
trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
r4191 r4327 6 6 import static org.openstreetmap.josm.tools.I18n.trn; 7 7 8 import java.awt.AWTEvent; 8 9 import java.awt.Cursor; 9 10 import java.awt.Point; 10 11 import java.awt.Rectangle; 12 import java.awt.Toolkit; 13 import java.awt.event.AWTEventListener; 11 14 import java.awt.event.ActionEvent; 12 15 import java.awt.event.InputEvent; … … 16 19 import java.util.Collection; 17 20 import java.util.Collections; 21 import java.util.HashSet; 18 22 import java.util.Iterator; 19 23 import java.util.LinkedList; 24 import java.util.Set; 20 25 21 26 import javax.swing.JOptionPane; … … 60 65 * @author imi 61 66 */ 62 public class SelectAction extends MapMode implements SelectionEnded { 67 public class SelectAction extends MapMode implements AWTEventListener, SelectionEnded { 68 // "select" means the selection rectangle and "move" means either dragging 69 // or select if no mouse movement occurs (i.e. just clicking) 63 70 enum Mode { move, rotate, scale, select } 64 71 72 // contains all possible cases the cursor can be in the SelectAction except the 73 // the move pointer (latter is a system one and not an image) 74 private enum SelectActionCursor { 75 rect("normal", "selection"), 76 rect_add("normal", "select_add"), 77 rect_rm("normal", "select_remove"), 78 way("normal", "select_way"), 79 way_add("normal", "select_way_add"), 80 way_rm("normal", "select_way_remove"), 81 node("normal", "select_node"), 82 node_add("normal", "select_node_add"), 83 node_rm("normal", "select_node_remove"), 84 virtual_node("normal", "addnode"), 85 scale("scale", null), 86 rotate("rotate", null); 87 88 private final Cursor c; 89 private SelectActionCursor(String main, String sub) { 90 c = ImageProvider.getCursor(main, sub); 91 } 92 public Cursor cursor() { 93 return c; 94 } 95 } 96 97 // Cache previous mouse event (needed when only the modifier keys are 98 // pressed but the mouse isn't moved) 99 private MouseEvent oldEvent = null; 100 65 101 private Mode mode = null; 66 102 private SelectionManager selectionManager; 67 103 private boolean cancelDrawMode = false; 104 private boolean drawTargetHighlight; 68 105 private boolean didMouseDrag = false; 69 106 /** … … 94 131 private int initialMoveThreshold; 95 132 private boolean initialMoveThresholdExceeded = false; 133 134 /** 135 * elements that have been highlighted in the previous iteration. Used 136 * to remove the highlight from them again as otherwise the whole data 137 * set would have to be checked. 138 */ 139 private Set<OsmPrimitive> oldHighlights = new HashSet<OsmPrimitive>(); 96 140 97 141 /** … … 109 153 initialMoveDelay = Main.pref.getInteger("edit.initial-move-delay", 200); 110 154 initialMoveThreshold = Main.pref.getInteger("edit.initial-move-threshold", 5); 155 drawTargetHighlight = Main.pref.getBoolean("draw.target-highlight", true); 156 // This is required to update the cursors when ctrl/shift/alt is pressed 157 try { 158 Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK); 159 } catch (SecurityException ex) { 160 System.out.println(ex); 161 } 111 162 } 112 163 … … 127 178 mv.removeMouseMotionListener(this); 128 179 mv.setVirtualNodesEnabled(false); 180 removeHighlighting(); 181 } 182 183 /** 184 * works out which cursor should be displayed for most of SelectAction's 185 * features. The only exception is the "move" cursor when actually dragging 186 * primitives. 187 * @param nearbyStuff primitives near the cursor 188 * @return the cursor that should be displayed 189 */ 190 private Cursor getCursor(Collection<OsmPrimitive> nearbyStuff) { 191 String c = "rect"; 192 switch(mode) { 193 case move: 194 if(virtualNode != null) { 195 c = "virtual_node"; 196 break; 197 } 198 199 // nearbyStuff cannot be empty as otherwise we would be in 200 // Move.select and not Move.move 201 OsmPrimitive osm = nearbyStuff.iterator().next(); 202 203 c = (osm instanceof Node) ? "node" : c; 204 c = (osm instanceof Way) ? "way" : c; 205 206 if(shift) { 207 c += "_add"; 208 } else if(ctrl) { 209 c += osm.isSelected() ? "_rm" : "_add"; 210 } 211 break; 212 case rotate: 213 c = "rotate"; 214 break; 215 case scale: 216 c = "scale"; 217 break; 218 case select: 219 c = "rect" + (shift ? "_add" : (ctrl ? "_rm" : "")); 220 break; 221 } 222 return SelectActionCursor.valueOf(c).cursor(); 223 } 224 225 /** 226 * Removes all existing highlights. 227 * @return true if a repaint is required 228 */ 229 private boolean removeHighlighting() { 230 boolean needsRepaint = false; 231 DataSet ds = getCurrentDataSet(); 232 if(ds != null && !ds.getHighlightedVirtualNodes().isEmpty()) { 233 needsRepaint = true; 234 ds.clearHighlightedVirtualNodes(); 235 } 236 if(oldHighlights.isEmpty()) 237 return needsRepaint; 238 239 for(OsmPrimitive prim : oldHighlights) { 240 prim.setHighlighted(false); 241 } 242 oldHighlights = new HashSet<OsmPrimitive>(); 243 return true; 244 } 245 246 /** 247 * handles adding highlights and updating the cursor for the given mouse event. 248 * @param MouseEvent which should be used as base for the feedback 249 * @return true if repaint is required 250 */ 251 private boolean giveUserFeedback(MouseEvent e) { 252 return giveUserFeedback(e, e.getModifiers()); 253 } 254 255 /** 256 * handles adding highlights and updating the cursor for the given mouse event. 257 * @param MouseEvent which should be used as base for the feedback 258 * @param define custom keyboard modifiers if the ones from MouseEvent are outdated or similar 259 * @return true if repaint is required 260 */ 261 private boolean giveUserFeedback(MouseEvent e, int modifiers) { 262 boolean needsRepaint = false; 263 264 Collection<OsmPrimitive> c = MapView.asColl( 265 mv.getNearestNodeOrWay(e.getPoint(), OsmPrimitive.isSelectablePredicate, true)); 266 267 updateKeyModifiers(modifiers); 268 determineMapMode(!c.isEmpty()); 269 270 if(drawTargetHighlight) { 271 needsRepaint = removeHighlighting(); 272 } 273 274 virtualWays.clear(); 275 virtualNode = null; 276 if(mode == Mode.move && setupVirtual(e)) { 277 DataSet ds = getCurrentDataSet(); 278 if (ds != null) { 279 ds.setHighlightedVirtualNodes(virtualWays); 280 } 281 mv.setNewCursor(SelectActionCursor.virtual_node.cursor(), this); 282 // don't highlight anything else if a virtual node will be 283 return true; 284 } 285 286 mv.setNewCursor(getCursor(c), this); 287 288 // return early if there can't be any highlights 289 if(!drawTargetHighlight || mode != Mode.move || c.isEmpty()) 290 return needsRepaint; 291 292 for(OsmPrimitive x : c) { 293 // only highlight primitives that will change the selection 294 // when clicked. I.e. don't highlight selected elements unless 295 // we are in toggle mode. 296 if(ctrl || !x.isSelected()) { 297 x.setHighlighted(true); 298 oldHighlights.add(x); 299 } 300 } 301 return needsRepaint || !oldHighlights.isEmpty(); 302 } 303 304 /** 305 * This is called whenever the keyboard modifier status changes 306 */ 307 public void eventDispatched(AWTEvent e) { 308 if(oldEvent == null) 309 return; 310 // We don't have a mouse event, so we pass the old mouse event but the 311 // new modifiers. 312 giveUserFeedback(oldEvent, ((InputEvent) e).getModifiers()); 129 313 } 130 314 … … 264 448 public void mouseMoved(MouseEvent e) { 265 449 // Mac OSX simulates with ctrl + mouse 1 the second mouse button hence no dragging events get fired. 266 //267 450 if ((Main.platform instanceof PlatformHookOsx) && (mode == Mode.rotate || mode == Mode.scale)) { 268 451 mouseDragged(e); 269 } 270 } 452 return; 453 } 454 oldEvent = e; 455 if(giveUserFeedback(e)) { 456 mv.repaint(); 457 } 458 } 459 460 @Override 461 public void mouseExited(MouseEvent e) { 462 if(removeHighlighting()) { 463 mv.repaint(); 464 } 465 } 466 271 467 private Node virtualNode = null; 272 468 private Collection<WaySegment> virtualWays = new LinkedList<WaySegment>(); … … 339 535 Point p = e.getPoint(); 340 536 boolean waitForMouseUp = Main.pref.getBoolean("mappaint.select.waits-for-mouse-up", false); 341 boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0;342 boolean alt = ((e.getModifiers() & (ActionEvent.ALT_MASK | InputEvent.ALT_GRAPH_MASK)) != 0|| Main.pref.getBoolean("selectaction.cycles.multiple.matches", false));537 updateKeyModifiers(e); 538 alt = alt || Main.pref.getBoolean("selectaction.cycles.multiple.matches", false); 343 539 344 540 if (!alt) { … … 389 585 390 586 /** 587 * sets the mapmode according to key modifiers and if there are any 588 * selectables nearby. Everything has to be pre-determined for this 589 * function; its main purpose is to centralize what the modifiers do. 590 * @param nearSelectables 591 */ 592 private void determineMapMode(boolean hasSelectionNearby) { 593 if (shift && ctrl) { 594 mode = Mode.rotate; 595 } else if (alt && ctrl) { 596 mode = Mode.scale; 597 } else if (hasSelectionNearby) { 598 mode = Mode.move; 599 } else { 600 mode = Mode.select; 601 } 602 } 603 604 /** 391 605 * Look, whether any object is selected. If not, select the nearest node. 392 606 * If there are no nodes in the dataset, do nothing. … … 400 614 public void mousePressed(MouseEvent e) { 401 615 // return early 402 if (!mv.isActiveLayerVisible() || !(Boolean) this.getValue("active") || e.getButton() != MouseEvent.BUTTON1) { 403 return; 404 } 616 if (!mv.isActiveLayerVisible() || !(Boolean) this.getValue("active") || e.getButton() != MouseEvent.BUTTON1) 617 return; 405 618 406 619 // request focus in order to enable the expected keyboard shortcuts 407 620 mv.requestFocus(); 408 621 409 boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 410 boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 411 boolean alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0; 622 // update which modifiers are pressed (shift, alt, ctrl) 623 updateKeyModifiers(e); 412 624 413 625 // We don't want to change to draw tool if the user tries to (de)select … … 422 634 mv.getNearestNodeOrWay(e.getPoint(), OsmPrimitive.isSelectablePredicate, true)); 423 635 424 if (shift && ctrl) { 425 mode = Mode.rotate; 426 636 determineMapMode(!c.isEmpty()); 637 switch(mode) { 638 case rotate: 639 case scale: 427 640 if (getCurrentDataSet().getSelected().isEmpty()) { 428 641 getCurrentDataSet().setSelected(c); … … 432 645 // Mode.move redraws when mouseDragged is called 433 646 // Mode.rotate redraws here 434 mv.setNewCursor(ImageProvider.getCursor("rotate", null), this);435 mv.repaint();436 } else if (alt && ctrl) {437 mode = Mode.scale;438 439 if (getCurrentDataSet().getSelected().isEmpty()) {440 getCurrentDataSet().setSelected(c);441 }442 443 // Mode.select redraws when selectPrims is called444 // Mode.move redraws when mouseDragged is called445 647 // Mode.scale redraws here 446 mv.setNewCursor(ImageProvider.getCursor("scale", null), this); 447 mv.repaint(); 448 } else if (!c.isEmpty()) { 449 mode = Mode.move; 450 648 break; 649 case move: 451 650 if (!cancelDrawMode && c.iterator().next() instanceof Way) { 452 651 setupVirtual(e); … … 454 653 455 654 selectPrims(cycleSetup(c, e), e, false, false); 456 } else {457 mode = Mode.select;458 655 break; 656 case select: 657 default: 459 658 selectionManager.register(mv); 460 659 selectionManager.mousePressed(e); 461 } 462 660 break; 661 } 662 giveUserFeedback(e); 663 mv.repaint(); 463 664 updateStatusLine(); 464 665 } … … 466 667 @Override 467 668 public void mouseReleased(MouseEvent e) { 468 if (!mv.isActiveLayerVisible()) { 469 return; 470 } 669 if (!mv.isActiveLayerVisible()) 670 return; 471 671 472 672 startingDraggingPos = null; 473 673 474 mv.setNewCursor(cursor, this);475 674 if (mode == Mode.select) { 476 675 selectionManager.unregister(mv); … … 489 688 virtualNode = null; 490 689 491 // do nothing if the click was to short to be recognized as a drag, 690 // do nothing if the click was to short too be recognized as a drag, 492 691 // but the release position is farther than 10px away from the press position 493 if (lastMousePos.distanceSq(e.getPoint()) < 100) { 692 if (lastMousePos == null || lastMousePos.distanceSq(e.getPoint()) < 100) { 494 693 selectPrims(cyclePrims(cycleList, e), e, true, false); 495 694 … … 500 699 // click and switch back to SelectMode 501 700 Main.worker.execute(new Runnable() { 502 503 701 public void run() { 504 702 Main.map.selectDrawTool(true); … … 539 737 } 540 738 541 // I don't see why we need this.542 //updateStatusLine();543 739 mode = null; 740 giveUserFeedback(e); 544 741 updateStatusLine(); 545 742 } 546 743 547 744 public void selectionEnded(Rectangle r, MouseEvent e) { 548 boolean alt = (e.getModifiersEx() & (MouseEvent.ALT_DOWN_MASK | MouseEvent.ALT_GRAPH_DOWN_MASK)) != 0;745 updateKeyModifiers(e); 549 746 selectPrims(selectionManager.getObjectsInRectangle(r, alt), e, true, true); 550 747 } … … 554 751 * selection cycle given by <code>prims</code>. 555 752 * @param prims the primitives that form the selection cycle 556 * @param shift whether shift is pressed 557 * @param ctrl whether ctrl is pressed 753 * @param mouse event 558 754 * @return the next element of cycle list <code>prims</code>. 559 755 */ … … 562 758 563 759 if (prims.size() > 1) { 564 boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 565 boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 760 updateKeyModifiers(e); 566 761 567 762 DataSet ds = getCurrentDataSet(); … … 630 825 631 826 private void selectPrims(Collection<OsmPrimitive> prims, MouseEvent e, boolean released, boolean area) { 632 boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 633 boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 827 updateKeyModifiers(e); 634 828 DataSet ds = getCurrentDataSet(); 635 829 636 830 // not allowed together: do not change dataset selection, return early 637 if ((shift && ctrl) || (ctrl && !released) || (!virtualWays.isEmpty())) { 638 return; 639 } 831 if ((shift && ctrl) || (ctrl && !released) || (!virtualWays.isEmpty())) 832 return; 640 833 641 834 if (!released) { … … 666 859 @Override 667 860 public String getModeHelpText() { 668 if (mode == Mode.select) {861 if (mode == Mode.select) 669 862 return tr("Release the mouse button to select the objects in the rectangle."); 670 }else if (mode == Mode.move){863 else if (mode == Mode.move) 671 864 return tr("Release the mouse button to stop moving. Ctrl to merge with nearest node."); 672 }else if (mode == Mode.rotate){865 else if (mode == Mode.rotate) 673 866 return tr("Release the mouse button to stop rotating."); 674 }else if (mode == Mode.scale){867 else if (mode == Mode.scale) 675 868 return tr("Release the mouse button to stop scaling."); 676 } else {869 else 677 870 return tr("Move objects by dragging; Shift to add to selection (Ctrl to toggle); Shift-Ctrl to rotate selected; Alt-Ctrl to scale selected; or change selection"); 678 }679 871 } 680 872
Note:
See TracChangeset
for help on using the changeset viewer.
