KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swingwt > awt > event > MouseEvent


1 /*
2    SwingWT
3    Copyright(c)2003-2004, R. Rawson-Tetley
4
5    For more information on distributing and using this program, please
6    see the accompanying "COPYING" file.
7
8    Contact me by electronic mail: bobintetley@users.sourceforge.net
9
10    $Log: MouseEvent.java,v $
11    Revision 1.11 2004/05/06 12:35:21 bobintetley
12    Parity with Swing constants for Binary Compatibility + fixes to JDesktopPane
13
14    Revision 1.10 2004/04/30 23:18:26 dannaab
15    List selection support, misc bug fixes
16
17    Revision 1.9 2004/04/23 10:02:49 bobintetley
18    MouseEvent BUTTON_MASK constants, JSlider.createStandardLabels(), FontMetrics
19    thread safety, Component/Toolkit.getFontMetrics() and MouseMotionAdapter
20
21    Revision 1.8 2004/04/16 10:19:06 dannaab
22    Misc bug fixes, InputMap implementation, preliminary undo support
23
24    Revision 1.7 2004/01/26 14:05:23 bobintetley
25    Compatibility methods
26
27    Revision 1.6 2003/12/17 10:57:35 bobintetley
28    JTableHeader implementation plus Table event/model fixes
29
30    Revision 1.5 2003/12/14 09:13:38 bobintetley
31    Added CVS log to source headers
32
33 */

34
35
36 package swingwt.awt.event;
37
38 import swingwt.awt.*;
39
40 public class MouseEvent extends InputEvent implements java.io.Serializable JavaDoc {
41     
42     public static final int NOBUTTON = 0;
43     public static final int BUTTON1 = 1;
44     public static final int BUTTON2 = 2;
45     public static final int BUTTON3 = 3;
46     public static final int BUTTON1_MASK = BUTTON1;
47     public static final int BUTTON2_MASK = BUTTON2;
48     public static final int BUTTON3_MASK = BUTTON3;
49     
50     public static final int MOUSE_FIRST = 500;
51     public static final int MOUSE_LAST = 507;
52     public static final int MOUSE_CLICKED = MOUSE_FIRST;
53     public static final int MOUSE_PRESSED = 1 + MOUSE_FIRST;
54     public static final int MOUSE_RELEASED = 2 + MOUSE_FIRST;
55     public static final int MOUSE_MOVED = 3 + MOUSE_FIRST;
56     public static final int MOUSE_ENTERED = 4 + MOUSE_FIRST;
57     public static final int MOUSE_EXITED = 5 + MOUSE_FIRST;
58     public static final int MOUSE_DRAGGED = 6 + MOUSE_FIRST;
59     public static final int MOUSE_WHEEL = 7 + MOUSE_FIRST;
60     
61     public int clickCount = 1;
62     public int eventID = 0;
63     private int button = 0;
64     private int x = 0;
65     private int y = 0;
66     private boolean popupTrigger = false;
67
68     public static final int CLICKED = 0;
69     public static final int ENTERED = 1;
70     public static final int EXITED = 2;
71     public static final int PRESSED = 3;
72     public static final int RELEASED = 4;
73
74     public MouseEvent( Component source, int id, long when, int modifiers,
75                 int x, int y, int clickCount, boolean popupTrigger ) {
76         this(source, id, when, modifiers, x, y, clickCount, popupTrigger, NOBUTTON);
77     }
78
79     public MouseEvent( Component source, int id, long when, int modifiers, int x, int y,
80                 int clickCount, boolean popupTrigger, int button) {
81         super(source, id, when, modifiers);
82
83         this.x = x;
84         this.y = y;
85         this.clickCount = clickCount;
86         this.popupTrigger = popupTrigger;
87         this.button = button;
88     }
89
90     public MouseEvent(Component source) {
91         super(source);
92     }
93
94     /**
95      * If this mouse event should trigger a popup I guess.
96      * I never used this, but I've just set it to respond
97      * to whether it's a right click for convenience
98      */

99     public boolean isPopupTrigger() {
100         return button == 3;
101     }
102
103     public int getModifiers() {
104         // We don't have keyboard modifiers for mice (unlike AWT)
105
return 0;
106     }
107     
108     /** Returns the number of mouse clicks associated with this event */
109     public int getClickCount() {
110         return clickCount;
111     }
112     
113     /** Getter for property button.
114      * @return Value of property button.
115      *
116      */

117     public int getButton() {
118         return button;
119     }
120     
121     /** Setter for property button.
122      * @param button New value of property button.
123      *
124      */

125     public void setButton(int button) {
126         this.button = button;
127     }
128     
129     /** Getter for property x.
130      * @return Value of property x.
131      *
132      */

133     public int getX() {
134         return x;
135     }
136     
137     /** Setter for property x.
138      * @param x New value of property x.
139      *
140      */

141     public void setX(int x) {
142         this.x = x;
143     }
144     
145     /** Getter for property y.
146      * @return Value of property y.
147      *
148      */

149     public int getY() {
150         return y;
151     }
152     
153     /** Setter for property y.
154      * @param y New value of property y.
155      *
156      */

157     public void setY(int y) {
158         this.y = y;
159     }
160
161     public Point getPoint() {
162         return new Point(x, y);
163     }
164     
165     public int translateSWTButton(int swtButton) {
166         int ret = NOBUTTON;
167         switch (swtButton) {
168             case (org.eclipse.swt.SWT.NONE): ret = NOBUTTON; break;
169             case (org.eclipse.swt.SWT.BUTTON1): ret = BUTTON1; break;
170             case (org.eclipse.swt.SWT.BUTTON2): ret = BUTTON2; break;
171             case (org.eclipse.swt.SWT.BUTTON3): ret = BUTTON3; break;
172         }
173         return ret;
174     }
175 }
176
Popular Tags