Changeset 19458 in osm for applications/editors/josm/plugins/nearclick/src
- Timestamp:
- 2010-01-13T14:56:15+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/nearclick/src/nearclick/NearClickPlugin.java
r13497 r19458 9 9 import java.awt.event.MouseEvent; 10 10 import org.openstreetmap.josm.Main; 11 import org.openstreetmap.josm.plugins.PluginInformation; 11 12 12 13 public class NearClickPlugin implements AWTEventListener { 13 14 14 15 16 17 18 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; 19 20 20 public NearClickPlugin() { 21 Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK); 22 try { 23 int radius = Integer.parseInt(Main.pref.get("nearclick.radius", "7")); 24 radiussquared = radius * radius; 25 delay = Integer.parseInt(Main.pref.get("nearclick.delay", "250")); 26 } catch (NumberFormatException ex) { 27 delay = 250; 28 radiussquared = 7 * 7; 29 } 30 } 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 } 31 34 32 33 34 35 if (e.getButton() != MouseEvent.BUTTON136 37 38 39 40 41 if (e.getWhen() - mouseDownTime < delay&&42 (e.getPoint().x != mouseDownX ||43 e.getPoint().y != mouseDownY) && 44 xdiff * xdiff + ydiff * ydiff < radiussquared 45 ) { 46 try { 47 Robot r = new Robot(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice());48 49 50 51 52 } 53 54 55 56 57 58 59 60 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 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 } 61 64 }
Note:
See TracChangeset
for help on using the changeset viewer.