Changeset 7217 in josm
- Timestamp:
- 2014-06-06T10:10:31+02:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java
r7005 r7217 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.AWTEvent;7 6 import java.awt.Cursor; 8 import java.awt.Toolkit;9 import java.awt.event.AWTEventListener;10 7 import java.awt.event.ActionEvent; 11 8 import java.awt.event.InputEvent; … … 29 26 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 30 27 import org.openstreetmap.josm.gui.util.HighlightHelper; 28 import org.openstreetmap.josm.gui.util.ModifierListener; 31 29 import org.openstreetmap.josm.tools.CheckParameterUtil; 32 30 import org.openstreetmap.josm.tools.ImageProvider; … … 48 46 * @author imi 49 47 */ 50 public class DeleteAction extends MapMode implements AWTEventListener {48 public class DeleteAction extends MapMode implements ModifierListener { 51 49 // Cache previous mouse event (needed when only the modifier keys are 52 50 // pressed but the mouse isn't moved) … … 113 111 Main.map.mapView.addMouseMotionListener(this); 114 112 // This is required to update the cursors when ctrl/shift/alt is pressed 115 try { 116 Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK); 117 } catch (SecurityException ex) { 118 Main.warn(ex); 119 } 113 Main.map.keyDetector.addModifierListener(this); 120 114 } 121 115 … … 125 119 Main.map.mapView.removeMouseListener(this); 126 120 Main.map.mapView.removeMouseMotionListener(this); 127 try { 128 Toolkit.getDefaultToolkit().removeAWTEventListener(this); 129 } catch (SecurityException ex) { 130 Main.warn(ex); 131 } 121 Main.map.keyDetector.removeModifierListener(this); 132 122 removeHighlighting(); 133 123 } … … 400 390 */ 401 391 @Override 402 public void eventDispatched(AWTEvent e) {392 public void modifiersChanged(int modifiers) { 403 393 if(oldEvent == null) 404 394 return; 405 395 // We don't have a mouse event, so we pass the old mouse event but the 406 396 // new modifiers. 407 giveUserFeedback(oldEvent, ((InputEvent) e).getModifiers());397 giveUserFeedback(oldEvent, modifiers); 408 398 } 409 399 } -
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r7005 r7217 7 7 import static org.openstreetmap.josm.tools.I18n.trn; 8 8 9 import java.awt.AWTEvent;10 9 import java.awt.BasicStroke; 11 10 import java.awt.Color; 12 import java.awt.Component;13 11 import java.awt.Cursor; 14 12 import java.awt.Graphics2D; 15 import java.awt.KeyboardFocusManager;16 13 import java.awt.Point; 17 14 import java.awt.Stroke; 18 import java.awt.Toolkit;19 import java.awt.event.AWTEventListener;20 15 import java.awt.event.ActionEvent; 21 import java.awt.event.ActionListener;22 import java.awt.event.InputEvent;23 16 import java.awt.event.KeyEvent; 24 17 import java.awt.event.MouseEvent; … … 36 29 import java.util.Map; 37 30 import java.util.Set; 38 import java.util.TreeSet;39 31 40 32 import javax.swing.AbstractAction; 41 33 import javax.swing.JCheckBoxMenuItem; 42 import javax.swing.JFrame;43 34 import javax.swing.JMenuItem; 44 35 import javax.swing.JOptionPane; 45 36 import javax.swing.JPopupMenu; 46 import javax.swing.SwingUtilities;47 import javax.swing.Timer;48 37 49 38 import org.openstreetmap.josm.Main; … … 71 60 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 72 61 import org.openstreetmap.josm.gui.util.GuiHelper; 62 import org.openstreetmap.josm.gui.util.KeyPressReleaseListener; 63 import org.openstreetmap.josm.gui.util.ModifierListener; 73 64 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 74 65 import org.openstreetmap.josm.tools.Geometry; … … 81 72 * Mapmode to add nodes, create and extend ways. 82 73 */ 83 public class DrawAction extends MapMode implements MapViewPaintable, SelectionChangedListener, AWTEventListener {74 public class DrawAction extends MapMode implements MapViewPaintable, SelectionChangedListener, KeyPressReleaseListener, ModifierListener { 84 75 private final Cursor cursorJoinNode; 85 76 private final Cursor cursorJoinWay; … … 112 103 private final SnapHelper snapHelper = new SnapHelper(); 113 104 114 private Shortcut backspaceShortcut;115 private BackSpaceAction backspaceAction;105 private final Shortcut backspaceShortcut; 106 private final BackSpaceAction backspaceAction; 116 107 private final Shortcut snappingShortcut; 108 private boolean ignoreNextKeyRelease; 117 109 118 110 private final SnapChangeAction snapChangeAction; … … 227 219 snapCheckboxMenuItem.getAction().setEnabled(true); 228 220 229 timer = new Timer(0, new ActionListener() {230 @Override231 public void actionPerformed(ActionEvent ae) {232 timer.stop();233 if (set.remove(releaseEvent.getKeyCode())) {234 doKeyReleaseEvent(releaseEvent);235 }236 }237 238 });239 221 Main.map.statusLine.getAnglePanel().addMouseListener(snapHelper.anglePopupListener); 240 222 Main.registerActionShortcut(backspaceAction, backspaceShortcut); … … 245 227 DataSet.addSelectionListener(this); 246 228 247 try { 248 Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK); 249 } catch (SecurityException ex) { 250 Main.warn(ex); 251 } 229 Main.map.keyDetector.addKeyListener(this); 230 Main.map.keyDetector.addModifierListener(this); 231 ignoreNextKeyRelease = true; 252 232 // would like to but haven't got mouse position yet: 253 233 // computeHelperLine(false, false, false); … … 269 249 270 250 removeHighlighting(); 271 try { 272 Toolkit.getDefaultToolkit().removeAWTEventListener(this); 273 } catch (SecurityException ex) { 274 Main.warn(ex); 275 } 251 Main.map.keyDetector.removeKeyListener(this); 252 Main.map.keyDetector.removeModifierListener(this); 276 253 277 254 // when exiting we let everybody know about the currently selected … … 288 265 */ 289 266 @Override 290 public void eventDispatched(AWTEvent event) {267 public void modifiersChanged(int modifiers) { 291 268 if (!Main.isDisplayingMapView() || !Main.map.mapView.isActiveLayerDrawable()) 292 269 return; 293 if (event instanceof KeyEvent) { 294 KeyEvent e = (KeyEvent) event; 295 if (snappingShortcut.isEvent(e) || (useRepeatedShortcut && getShortcut().isEvent(e))) { 296 Component focused = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); 297 if (SwingUtilities.getWindowAncestor(focused) instanceof JFrame) { 298 processKeyEvent(e); 299 } 300 } 301 } // toggle angle snapping 302 updateKeyModifiers((InputEvent) event); 270 updateKeyModifiers(modifiers); 303 271 computeHelperLine(); 304 272 addHighlighting(); 305 273 } 306 274 307 // events for crossplatform key holding processing 308 private final Set<Integer> set = new TreeSet<>(); 309 private KeyEvent releaseEvent; 310 private Timer timer; 311 void processKeyEvent(KeyEvent e) { 275 @Override 276 public void doKeyPressed(KeyEvent e) { 312 277 if (!snappingShortcut.isEvent(e) && !(useRepeatedShortcut && getShortcut().isEvent(e))) 313 278 return; 314 315 if (e.getID() == KeyEvent.KEY_PRESSED) {316 if (timer.isRunning()) {317 timer.stop();318 } else if (set.add((e.getKeyCode()))) {319 doKeyPressEvent(e);320 }321 } else if (e.getID() == KeyEvent.KEY_RELEASED) {322 if (timer.isRunning()) {323 timer.stop();324 if (set.remove(e.getKeyCode())) {325 doKeyReleaseEvent(e);326 }327 } else {328 releaseEvent = e;329 timer.restart();330 }331 }332 }333 334 private void doKeyPressEvent(KeyEvent e) {335 279 snapHelper.setFixedMode(); 336 280 computeHelperLine(); 337 281 redrawIfRequired(); 338 282 } 339 private void doKeyReleaseEvent(KeyEvent e) { 283 284 @Override 285 public void doKeyReleased(KeyEvent e) { 286 if (!snappingShortcut.isEvent(e) && !(useRepeatedShortcut && getShortcut().isEvent(e))) 287 return; 288 if (ignoreNextKeyRelease) { 289 ignoreNextKeyRelease = false; 290 return; 291 } 340 292 snapHelper.unFixOrTurnOff(); 341 293 computeHelperLine(); … … 393 345 * If in nodeway mode, insert the node into the way. 394 346 */ 395 @Override public void mouseReleased(MouseEvent e) { 347 @Override 348 public void mouseReleased(MouseEvent e) { 396 349 if (e.getButton() == MouseEvent.BUTTON3) { 397 350 Point curMousePos = e.getPoint(); … … 419 372 420 373 // we copy ctrl/alt/shift from the event just in case our global 421 // AWTEventdidn't make it through the security manager. Unclear374 // keyDetector didn't make it through the security manager. Unclear 422 375 // if that can ever happen but better be safe. 423 376 updateKeyModifiers(e); … … 775 728 776 729 // we copy ctrl/alt/shift from the event just in case our global 777 // AWTEventdidn't make it through the security manager. Unclear730 // keyDetector didn't make it through the security manager. Unclear 778 731 // if that can ever happen but better be safe. 779 732 updateKeyModifiers(e); … … 941 894 * Repaint on mouse exit so that the helper line goes away. 942 895 */ 943 @Override public void mouseExited(MouseEvent e) { 896 @Override 897 public void mouseExited(MouseEvent e) { 944 898 if(!Main.map.mapView.isActiveLayerDrawable()) 945 899 return; -
trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java
r7216 r7217 6 6 import static org.openstreetmap.josm.tools.I18n.tr; 7 7 8 import java.awt.AWTEvent;9 8 import java.awt.BasicStroke; 10 9 import java.awt.Color; 11 import java.awt.Component;12 10 import java.awt.Cursor; 13 11 import java.awt.Graphics2D; 14 import java.awt.KeyboardFocusManager;15 12 import java.awt.Point; 16 13 import java.awt.Rectangle; 17 14 import java.awt.Stroke; 18 import java.awt.Toolkit;19 import java.awt.event.AWTEventListener;20 15 import java.awt.event.ActionEvent; 21 import java.awt.event.ActionListener;22 import java.awt.event.InputEvent;23 16 import java.awt.event.KeyEvent; 24 17 import java.awt.event.MouseEvent; … … 32 25 import java.util.LinkedList; 33 26 import java.util.List; 34 import java.util.Set;35 import java.util.TreeSet;36 27 import javax.swing.JCheckBoxMenuItem; 37 import javax.swing.JFrame;38 28 import javax.swing.JMenuItem; 39 import javax.swing.SwingUtilities;40 import javax.swing.Timer;41 29 42 30 import org.openstreetmap.josm.Main; … … 60 48 import org.openstreetmap.josm.gui.layer.MapViewPaintable; 61 49 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 50 import org.openstreetmap.josm.gui.util.KeyPressReleaseListener; 62 51 import org.openstreetmap.josm.gui.util.GuiHelper; 52 import org.openstreetmap.josm.gui.util.ModifierListener; 63 53 import org.openstreetmap.josm.tools.Geometry; 64 54 import org.openstreetmap.josm.tools.ImageProvider; … … 68 58 * Makes a rectangle from a line, or modifies a rectangle. 69 59 */ 70 public class ExtrudeAction extends MapMode implements MapViewPaintable {60 public class ExtrudeAction extends MapMode implements MapViewPaintable, KeyPressReleaseListener, ModifierListener { 71 61 72 62 enum Mode { extrude, translate, select, create_new, translate_node } … … 157 147 /** The cursor for the 'alwaysCreateNodes' submode. */ 158 148 private final Cursor cursorCreateNodes; 149 150 private boolean ignoreNextKeyRelease; 159 151 160 152 private static class ReferenceSegment { … … 225 217 tr("Mode: {0}", tr("Extrude Dual alignment")), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE); 226 218 useRepeatedShortcut = Main.pref.getBoolean("extrude.dualalign.toggleOnRepeatedX", true); 227 timer = new Timer(0, new ActionListener() {228 @Override229 public void actionPerformed(ActionEvent ae) {230 timer.stop();231 if (set.remove(releaseEvent.getKeyCode())) {232 doKeyReleaseEvent(releaseEvent);233 }234 }235 });236 219 } 237 220 … … 294 277 Main.map.mapView.addMouseListener(this); 295 278 Main.map.mapView.addMouseMotionListener(this); 296 try {297 Toolkit.getDefaultToolkit().addAWTEventListener(altKeyListener, AWTEvent.KEY_EVENT_MASK);298 } catch (SecurityException ex) {299 Main.warn(ex);300 }301 279 initialMoveDelay = Main.pref.getInteger("edit.initial-move-delay",200); 302 280 initialMoveThreshold = Main.pref.getInteger("extrude.initial-move-threshold", 1); … … 313 291 ignoreSharedNodes = Main.pref.getBoolean("extrude.ignore-shared-nodes", true); 314 292 dualAlignCheckboxMenuItem.getAction().setEnabled(true); 293 ignoreNextKeyRelease = true; 294 Main.map.keyDetector.addKeyListener(this); 295 Main.map.keyDetector.addModifierListener(this); 315 296 } 316 297 … … 321 302 Main.map.mapView.removeTemporaryLayer(this); 322 303 dualAlignCheckboxMenuItem.getAction().setEnabled(false); 323 try { 324 Toolkit.getDefaultToolkit().removeAWTEventListener(altKeyListener); 325 } catch (SecurityException ex) { 326 Main.warn(ex); 327 } 304 Main.map.keyDetector.removeKeyListener(this); 305 Main.map.keyDetector.removeModifierListener(this); 328 306 super.exitMode(); 329 307 } … … 334 312 335 313 /** 336 * This listener is used to indicate different modes via cursor when the Alt/Ctrl/Shift modifier is pressed, 337 * and for listening to dual alignment shortcuts. 338 */ 339 private final AWTEventListener altKeyListener = new AWTEventListener() { 340 @Override 341 public void eventDispatched(AWTEvent e) { 342 if (!Main.isDisplayingMapView() || !Main.map.mapView.isActiveLayerDrawable()) 343 return; 344 InputEvent ie = (InputEvent) e; 345 boolean alt = (ie.getModifiers() & (ActionEvent.ALT_MASK|InputEvent.ALT_GRAPH_MASK)) != 0; 346 boolean ctrl = (ie.getModifiers() & (ActionEvent.CTRL_MASK)) != 0; 347 boolean shift = (ie.getModifiers() & (ActionEvent.SHIFT_MASK)) != 0; 348 if (mode == Mode.select) { 349 Main.map.mapView.setNewCursor(ctrl ? cursorTranslate : alt ? cursorCreateNew : shift ? cursorCreateNodes : cursor, this); 350 } 351 if (e instanceof KeyEvent) { 352 KeyEvent ke = (KeyEvent) e; 353 if (dualAlignShortcut.isEvent(ke) || (useRepeatedShortcut && getShortcut().isEvent(ke))) { 354 Component focused = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); 355 if (SwingUtilities.getWindowAncestor(focused) instanceof JFrame) { 356 processKeyEvent(ke); 357 } 358 } 359 } 314 * This method is called to indicate different modes via cursor when the Alt/Ctrl/Shift modifier is pressed, 315 */ 316 @Override 317 public void modifiersChanged(int modifiers) { 318 if (!Main.isDisplayingMapView() || !Main.map.mapView.isActiveLayerDrawable()) 319 return; 320 updateKeyModifiers(modifiers); 321 if (mode == Mode.select) { 322 Main.map.mapView.setNewCursor(ctrl ? cursorTranslate : alt ? cursorCreateNew : shift ? cursorCreateNodes : cursor, this); 360 323 } 361 324 }; 362 325 363 // events for crossplatform key holding processing364 // thanks to http://www.arco.in-berlin.de/keyevent.html365 private final Set<Integer> set = new TreeSet<Integer>();366 private KeyEvent releaseEvent; 367 private Timer timer;368 p rivate void processKeyEvent(KeyEvent e) {326 @Override 327 public void doKeyPressed(KeyEvent e) { 328 } 329 330 @Override 331 public void doKeyReleased(KeyEvent e) { 369 332 if (!dualAlignShortcut.isEvent(e) && !(useRepeatedShortcut && getShortcut().isEvent(e))) 370 return; 371 372 if (e.getID() == KeyEvent.KEY_PRESSED) { 373 if (timer.isRunning()) { 374 timer.stop(); 375 } else if (set.add((e.getKeyCode()))) { 376 doKeyPressEvent(e); 377 } 378 } else if (e.getID() == KeyEvent.KEY_RELEASED) { 379 if (timer.isRunning()) { 380 timer.stop(); 381 if (set.remove(e.getKeyCode())) { 382 doKeyReleaseEvent(e); 383 } 384 } else { 385 releaseEvent = e; 386 timer.restart(); 387 } 388 } 389 } 390 391 private void doKeyPressEvent(KeyEvent e) { 392 } 393 394 private void doKeyReleaseEvent(KeyEvent e) { 395 toggleDualAlign(); 396 } 397 333 return; 334 if (ignoreNextKeyRelease) { 335 ignoreNextKeyRelease = false; 336 } else { 337 toggleDualAlign(); 338 } 339 } 398 340 /** 399 341 * Toggles dual alignment mode. -
trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java
r7005 r7217 6 6 import static org.openstreetmap.josm.tools.I18n.trn; 7 7 8 import java.awt.AWTEvent;9 8 import java.awt.Color; 10 9 import java.awt.Cursor; … … 12 11 import java.awt.Point; 13 12 import java.awt.Stroke; 14 import java.awt.Toolkit;15 import java.awt.event.AWTEventListener;16 import java.awt.event.InputEvent;17 13 import java.awt.event.KeyEvent; 18 14 import java.awt.event.MouseEvent; … … 47 43 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 48 44 import org.openstreetmap.josm.gui.util.GuiHelper; 45 import org.openstreetmap.josm.gui.util.ModifierListener; 49 46 import org.openstreetmap.josm.tools.ImageProvider; 50 47 import org.openstreetmap.josm.tools.Pair; … … 55 52 */ 56 53 public class ImproveWayAccuracyAction extends MapMode implements MapViewPaintable, 57 SelectionChangedListener, AWTEventListener {54 SelectionChangedListener, ModifierListener { 58 55 59 56 enum State { … … 145 142 DataSet.addSelectionListener(this); 146 143 147 try { 148 Toolkit.getDefaultToolkit().addAWTEventListener(this, 149 AWTEvent.KEY_EVENT_MASK); 150 } catch (SecurityException ex) { 151 Main.warn(ex); 152 } 144 Main.map.keyDetector.addModifierListener(this); 153 145 } 154 146 … … 162 154 DataSet.removeSelectionListener(this); 163 155 164 try { 165 Toolkit.getDefaultToolkit().removeAWTEventListener(this); 166 } catch (SecurityException ex) { 167 Main.warn(ex); 168 } 169 156 Main.map.keyDetector.addModifierListener(this); 170 157 Main.map.mapView.repaint(); 171 158 } … … 321 308 // ------------------------------------------------------------------------- 322 309 @Override 323 public void eventDispatched(AWTEvent event) {310 public void modifiersChanged(int modifiers) { 324 311 if (!Main.isDisplayingMapView() || !Main.map.mapView.isActiveLayerDrawable()) { 325 312 return; 326 313 } 327 updateKeyModifiers( (InputEvent) event);314 updateKeyModifiers(modifiers); 328 315 updateCursorDependentObjectsIfNeeded(); 329 316 updateCursor(); -
trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java
r7005 r7217 6 6 import static org.openstreetmap.josm.tools.I18n.tr; 7 7 8 import java.awt.AWTEvent;9 8 import java.awt.Color; 10 9 import java.awt.Cursor; … … 12 11 import java.awt.Point; 13 12 import java.awt.Stroke; 14 import java.awt.Toolkit;15 import java.awt.event.AWTEventListener;16 import java.awt.event.InputEvent;17 13 import java.awt.event.KeyEvent; 18 14 import java.awt.event.MouseEvent; … … 41 37 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 42 38 import org.openstreetmap.josm.gui.util.GuiHelper; 39 import org.openstreetmap.josm.gui.util.ModifierListener; 43 40 import org.openstreetmap.josm.tools.Geometry; 44 41 import org.openstreetmap.josm.tools.ImageProvider; … … 84 81 * @author Ole Jørgen Brønner (olejorgenb) 85 82 */ 86 public class ParallelWayAction extends MapMode implements AWTEventListener, MapViewPaintable, PreferenceChangedListener {83 public class ParallelWayAction extends MapMode implements ModifierListener, MapViewPaintable, PreferenceChangedListener { 87 84 88 85 private enum Mode { … … 161 158 162 159 //// Needed to update the mouse cursor if modifiers are changed when the mouse is motionless 163 try { 164 Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK); 165 } catch (SecurityException ex) { 166 Main.warn(ex); 167 } 160 Main.map.keyDetector.addModifierListener(this); 168 161 sourceWays = new LinkedHashSet<>(getCurrentDataSet().getSelectedWays()); 169 162 for (Way w : sourceWays) { … … 181 174 Main.map.statusLine.setDist(-1); 182 175 Main.map.statusLine.repaint(); 183 try { 184 Toolkit.getDefaultToolkit().removeAWTEventListener(this); 185 } catch (SecurityException ex) { 186 Main.warn(ex); 187 } 176 Main.map.keyDetector.removeModifierListener(this); 188 177 removeWayHighlighting(sourceWays); 189 178 pWays = null; … … 238 227 239 228 @Override 240 public void eventDispatched(AWTEvent e) {229 public void modifiersChanged(int modifiers) { 241 230 if (Main.map == null || mv == null || !mv.isActiveLayerDrawable()) 242 231 return; 243 232 244 233 // Should only get InputEvents due to the mask in enterMode 245 if (updateModifiersState( (InputEvent) e)) {234 if (updateModifiersState(modifiers)) { 246 235 updateStatusLine(); 247 236 updateCursor(); … … 249 238 } 250 239 251 private boolean updateModifiersState( InputEvent e) {240 private boolean updateModifiersState(int modifiers) { 252 241 boolean oldAlt = alt, oldShift = shift, oldCtrl = ctrl; 253 updateKeyModifiers( e);242 updateKeyModifiers(modifiers); 254 243 return (oldAlt != alt || oldShift != shift || oldCtrl != ctrl); 255 244 } … … 302 291 public void mousePressed(MouseEvent e) { 303 292 requestFocusInMapView(); 304 updateModifiersState(e );293 updateModifiersState(e.getModifiers()); 305 294 // Other buttons are off limit, but we still get events. 306 295 if (e.getButton() != MouseEvent.BUTTON1) … … 327 316 @Override 328 317 public void mouseReleased(MouseEvent e) { 329 updateModifiersState(e );318 updateModifiersState(e.getModifiers()); 330 319 // Other buttons are off limit, but we still get events. 331 320 if (e.getButton() != MouseEvent.BUTTON1) … … 382 371 return; 383 372 384 boolean modifiersChanged = updateModifiersState(e );373 boolean modifiersChanged = updateModifiersState(e.getModifiers()); 385 374 updateFlagsChangeableAlways(); 386 375 -
trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
r7009 r7217 6 6 import static org.openstreetmap.josm.tools.I18n.trn; 7 7 8 import java.awt.AWTEvent;9 8 import java.awt.Cursor; 10 9 import java.awt.Point; 11 10 import java.awt.Rectangle; 12 import java.awt.Toolkit;13 import java.awt.event.AWTEventListener;14 11 import java.awt.event.ActionEvent; 15 12 import java.awt.event.ActionListener; 16 import java.awt.event.InputEvent;17 13 import java.awt.event.KeyEvent; 18 14 import java.awt.event.MouseEvent; … … 53 49 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 54 50 import org.openstreetmap.josm.gui.util.GuiHelper; 51 import org.openstreetmap.josm.gui.util.ModifierListener; 55 52 import org.openstreetmap.josm.tools.ImageProvider; 56 53 import org.openstreetmap.josm.tools.Pair; … … 68 65 * feature "selection remove" is disabled on this platform. 69 66 */ 70 public class SelectAction extends MapMode implements AWTEventListener, SelectionEnded {67 public class SelectAction extends MapMode implements ModifierListener, SelectionEnded { 71 68 // "select" means the selection rectangle and "move" means either dragging 72 69 // or select if no mouse movement occurs (i.e. just clicking) … … 188 185 virtualManager.init(); 189 186 // This is required to update the cursors when ctrl/shift/alt is pressed 190 try { 191 Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK); 192 } catch (SecurityException ex) { 193 Main.warn(ex); 194 } 187 Main.map.keyDetector.addModifierListener(this); 195 188 } 196 189 … … 202 195 mv.removeMouseMotionListener(this); 203 196 mv.setVirtualNodesEnabled(false); 204 try { 205 Toolkit.getDefaultToolkit().removeAWTEventListener(this); 206 } catch (SecurityException ex) { 207 Main.warn(ex); 208 } 197 Main.map.keyDetector.removeModifierListener(this); 209 198 removeHighlighting(); 210 199 } … … 212 201 int previousModifiers; 213 202 214 /**215 * This is called whenever the keyboard modifier status changes216 */217 203 @Override 218 public void eventDispatched(AWTEvent e) { 219 if(oldEvent == null) 220 return; 221 // We don't have a mouse event, so we pass the old mouse event but the 222 // new modifiers. 223 int modif = ((InputEvent) e).getModifiers(); 224 if (previousModifiers == modif) 225 return; 226 previousModifiers = modif; 227 if(giveUserFeedback(oldEvent, ((InputEvent) e).getModifiers())) { 204 public void modifiersChanged(int modifiers) { 205 if (!Main.isDisplayingMapView() || oldEvent==null) return; 206 if(giveUserFeedback(oldEvent, modifiers)) { 228 207 mv.repaint(); 229 208 } -
trunk/src/org/openstreetmap/josm/gui/MapFrame.java
r7075 r7217 73 73 import org.openstreetmap.josm.gui.dialogs.properties.PropertiesDialog; 74 74 import org.openstreetmap.josm.gui.layer.Layer; 75 import org.openstreetmap.josm.gui.util.AdvancedKeyPressDetector; 75 76 import org.openstreetmap.josm.tools.Destroyable; 76 77 import org.openstreetmap.josm.tools.GBC; … … 95 96 */ 96 97 public final MapView mapView; 98 99 /** 100 * This object allows to detect key press and release events 101 */ 102 public final AdvancedKeyPressDetector keyDetector = new AdvancedKeyPressDetector(); 97 103 98 104 /** … … 245 251 for (JComponent c: allMapModeButtons) c.setFocusTraversalKeysEnabled(false); 246 252 } 253 254 keyDetector.register(); 247 255 } 248 256 … … 290 298 statusLine.destroy(); 291 299 mapView.destroy(); 300 keyDetector.unregister(); 292 301 } 293 302
Note:
See TracChangeset
for help on using the changeset viewer.