Ignore:
Timestamp:
2010-01-13T14:56:15+01:00 (15 years ago)
Author:
guggis
Message:

'Changed the constructor signature of the plugin main class'

File:
1 edited

Legend:

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

    r13497 r19458  
    99import java.awt.event.MouseEvent;
    1010import org.openstreetmap.josm.Main;
     11import org.openstreetmap.josm.plugins.PluginInformation;
    1112
    1213public class NearClickPlugin implements AWTEventListener {
    1314
    14     private int mouseDownX = -1;
    15     private int mouseDownY = -1;
    16     private long mouseDownTime = -1;
    17     private int radiussquared = 49;
    18     private int delay = 250;
     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;
    1920
    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        }
    3134
    32     public void eventDispatched(AWTEvent event) {
    33         if (event instanceof MouseEvent) {
    34             MouseEvent e = (MouseEvent)event;
    35             if ( e.getButton() != MouseEvent.BUTTON1 )
    36                 return;
    37         int xdiff = e.getPoint().x - mouseDownX;
    38         int ydiff = e.getPoint().y - mouseDownY;
    39        
    40             if (e.getID() == MouseEvent.MOUSE_RELEASED) {
    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                         r.mousePress(MouseEvent.BUTTON1_MASK);
    49                         r.mouseRelease(MouseEvent.BUTTON1_MASK);
    50                     } catch (AWTException e1) {
    51                     }
    52                 }               
    53             }
    54             if (e.getID() == MouseEvent.MOUSE_PRESSED) {
    55                 mouseDownX = e.getPoint().x;
    56                 mouseDownY = e.getPoint().y;
    57                 mouseDownTime = e.getWhen();           
    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        }
    6164}
Note: See TracChangeset for help on using the changeset viewer.