Changeset 23192 in osm for applications/editors/josm/plugins/nearclick
- Timestamp:
- 2010-09-15T18:59:53+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/nearclick/src/nearclick/NearClickPlugin.java
r19458 r23192 13 13 public class NearClickPlugin implements AWTEventListener { 14 14 15 16 17 18 19 15 private int mouseDownX = -1; 16 private int mouseDownY = -1; 17 private long mouseDownTime = -1; 18 private int radiussquared = 49; 19 private int delay = 250; 20 20 21 22 23 24 25 26 27 28 29 30 31 32 33 21 public NearClickPlugin(PluginInformation info) { 22 Toolkit.getDefaultToolkit().addAWTEventListener(this, 23 AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK); 24 try { 25 int radius = Integer.parseInt(Main.pref 26 .get("nearclick.radius", "7")); 27 radiussquared = radius * radius; 28 delay = Integer.parseInt(Main.pref.get("nearclick.delay", "250")); 29 } catch (NumberFormatException ex) { 30 delay = 250; 31 radiussquared = 7 * 7; 32 } 33 } 34 34 35 36 37 38 39 40 41 35 public void eventDispatched(AWTEvent event) { 36 if (event instanceof MouseEvent) { 37 MouseEvent e = (MouseEvent) event; 38 if (e.getButton() != MouseEvent.BUTTON1) 39 return; 40 int xdiff = e.getPoint().x - mouseDownX; 41 int ydiff = e.getPoint().y - mouseDownY; 42 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 43 if (e.getID() == MouseEvent.MOUSE_RELEASED) { 44 if (e.getWhen() - mouseDownTime < delay 45 && (e.getPoint().x != mouseDownX || e.getPoint().y != mouseDownY) 46 && xdiff * xdiff + ydiff * ydiff < radiussquared) { 47 try { 48 Robot r = new Robot(GraphicsEnvironment 49 .getLocalGraphicsEnvironment() 50 .getDefaultScreenDevice()); 51 r.mousePress(MouseEvent.BUTTON1_MASK); 52 r.mouseRelease(MouseEvent.BUTTON1_MASK); 53 } catch (AWTException e1) { 54 } 55 } 56 } 57 if (e.getID() == MouseEvent.MOUSE_PRESSED) { 58 mouseDownX = e.getPoint().x; 59 mouseDownY = e.getPoint().y; 60 mouseDownTime = e.getWhen(); 61 } 62 } 63 } 64 64 }
Note:
See TracChangeset
for help on using the changeset viewer.