Ignore:
Timestamp:
2007-08-12T13:08:46+02:00 (17 years ago)
Author:
david
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/nearclick/src/nearclick/NearClickPlugin.java

    r2397 r4088  
    88import java.awt.event.AWTEventListener;
    99import java.awt.event.MouseEvent;
     10import org.openstreetmap.josm.Main;
    1011
    1112public class NearClickPlugin implements AWTEventListener {
     
    1415    private int mouseDownY = -1;
    1516    private long mouseDownTime = -1;
     17    private int radiussquared = 49;
     18    private int delay = 250;
    1619
    1720    public NearClickPlugin() {
    1821        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        }
    1930    }
    2031
     
    2435            if ( e.getButton() != MouseEvent.BUTTON1 )
    2536                return;
     37            int xdiff = e.getPoint().x - mouseDownX;
     38            int ydiff = e.getPoint().y - mouseDownY;
     39           
    2640            if (e.getID() == MouseEvent.MOUSE_RELEASED) {
    27                 if ( e.getWhen() - mouseDownTime < 250 &&
    28                         e.getPoint().x - mouseDownX < 7 &&
    29                         e.getPoint().y - mouseDownY < 7 &&
    30                         e.getPoint().x != mouseDownX &&
    31                         e.getPoint().y != mouseDownY ) {
     41                if ( e.getWhen() - mouseDownTime < delay &&
     42                     ( e.getPoint().x != mouseDownX ||
     43                       e.getPoint().y != mouseDownY) &&
     44                     xdiff * xdiff + ydiff * ydiff < radiussquared
     45                  ) {
    3246                    try {
    3347                        Robot r = new Robot(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice());
Note: See TracChangeset for help on using the changeset viewer.