1 |
771 |
jeremybenn |
|
2 |
|
|
/* AWTEvent.java -- the root event in AWT
|
3 |
|
|
Copyright (C) 1999, 2000, 2002, 2005 Free Software Foundation
|
4 |
|
|
|
5 |
|
|
This file is part of GNU Classpath.
|
6 |
|
|
|
7 |
|
|
GNU Classpath is free software; you can redistribute it and/or modify
|
8 |
|
|
it under the terms of the GNU General Public License as published by
|
9 |
|
|
the Free Software Foundation; either version 2, or (at your option)
|
10 |
|
|
any later version.
|
11 |
|
|
|
12 |
|
|
GNU Classpath is distributed in the hope that it will be useful, but
|
13 |
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15 |
|
|
General Public License for more details.
|
16 |
|
|
|
17 |
|
|
You should have received a copy of the GNU General Public License
|
18 |
|
|
along with GNU Classpath; see the file COPYING. If not, write to the
|
19 |
|
|
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
20 |
|
|
02110-1301 USA.
|
21 |
|
|
|
22 |
|
|
Linking this library statically or dynamically with other modules is
|
23 |
|
|
making a combined work based on this library. Thus, the terms and
|
24 |
|
|
conditions of the GNU General Public License cover the whole
|
25 |
|
|
combination.
|
26 |
|
|
|
27 |
|
|
As a special exception, the copyright holders of this library give you
|
28 |
|
|
permission to link this library with independent modules to produce an
|
29 |
|
|
executable, regardless of the license terms of these independent
|
30 |
|
|
modules, and to copy and distribute the resulting executable under
|
31 |
|
|
terms of your choice, provided that you also meet, for each linked
|
32 |
|
|
independent module, the terms and conditions of the license of that
|
33 |
|
|
module. An independent module is a module which is not derived from
|
34 |
|
|
or based on this library. If you modify this library, you may extend
|
35 |
|
|
this exception to your version of the library, but you are not
|
36 |
|
|
obligated to do so. If you do not wish to do so, delete this
|
37 |
|
|
exception statement from your version. */
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
package java.awt;
|
41 |
|
|
|
42 |
|
|
import java.awt.event.ActionEvent;
|
43 |
|
|
import java.awt.event.AdjustmentEvent;
|
44 |
|
|
import java.awt.event.ComponentEvent;
|
45 |
|
|
import java.awt.event.ContainerEvent;
|
46 |
|
|
import java.awt.event.FocusEvent;
|
47 |
|
|
import java.awt.event.InputMethodEvent;
|
48 |
|
|
import java.awt.event.InvocationEvent;
|
49 |
|
|
import java.awt.event.ItemEvent;
|
50 |
|
|
import java.awt.event.KeyEvent;
|
51 |
|
|
import java.awt.event.MouseEvent;
|
52 |
|
|
import java.awt.event.PaintEvent;
|
53 |
|
|
import java.awt.event.TextEvent;
|
54 |
|
|
import java.awt.event.WindowEvent;
|
55 |
|
|
import java.util.EventObject;
|
56 |
|
|
|
57 |
|
|
/**
|
58 |
|
|
* AWTEvent is the root event class for all AWT events in the JDK 1.1 event
|
59 |
|
|
* model. It supersedes the Event class from JDK 1.0. Subclasses outside of
|
60 |
|
|
* the java.awt package should have IDs greater than RESERVED_ID_MAX.
|
61 |
|
|
*
|
62 |
|
|
* <p>Event masks defined here are used by components in
|
63 |
|
|
* <code>enableEvents</code> to select event types not selected by registered
|
64 |
|
|
* listeners. Event masks are appropriately set when registering on
|
65 |
|
|
* components.
|
66 |
|
|
*
|
67 |
|
|
* @author Warren Levy (warrenl@cygnus.com)
|
68 |
|
|
* @author Aaron M. Renn (arenn@urbanophile.com)
|
69 |
|
|
* @since 1.1
|
70 |
|
|
* @status updated to 1.4
|
71 |
|
|
*/
|
72 |
|
|
public abstract class AWTEvent extends EventObject
|
73 |
|
|
{
|
74 |
|
|
/**
|
75 |
|
|
* Compatible with JDK 1.1+.
|
76 |
|
|
*/
|
77 |
|
|
private static final long serialVersionUID = -1825314779160409405L;
|
78 |
|
|
|
79 |
|
|
/**
|
80 |
|
|
* The ID of the event.
|
81 |
|
|
*
|
82 |
|
|
* @see #getID()
|
83 |
|
|
* @see #AWTEvent(Object, int)
|
84 |
|
|
* @serial the identifier number of this event
|
85 |
|
|
*/
|
86 |
|
|
protected int id;
|
87 |
|
|
|
88 |
|
|
/**
|
89 |
|
|
* Indicates if the event has been consumed. False mean it is passed to
|
90 |
|
|
* the peer, true means it has already been processed. Semantic events
|
91 |
|
|
* generated by low-level events always have the value true.
|
92 |
|
|
*
|
93 |
|
|
* @see #consume()
|
94 |
|
|
* @see #isConsumed()
|
95 |
|
|
* @serial whether the event has been consumed
|
96 |
|
|
*/
|
97 |
|
|
protected boolean consumed;
|
98 |
|
|
|
99 |
|
|
/**
|
100 |
|
|
* Used for implementing a simple linked list in EventQueue.
|
101 |
|
|
*/
|
102 |
|
|
transient AWTEvent queueNext;
|
103 |
|
|
|
104 |
|
|
/**
|
105 |
|
|
* Who knows? It's in the serial version.
|
106 |
|
|
*
|
107 |
|
|
* @serial No idea what this is for.
|
108 |
|
|
*/
|
109 |
|
|
byte[] bdata;
|
110 |
|
|
|
111 |
|
|
/**
|
112 |
|
|
* Indicates if this event is dispatched by the KeyboardFocusManager.
|
113 |
|
|
*/
|
114 |
|
|
boolean isFocusManagerEvent = false;
|
115 |
|
|
|
116 |
|
|
/** Mask for selecting component events. */
|
117 |
|
|
public static final long COMPONENT_EVENT_MASK = 0x00001;
|
118 |
|
|
|
119 |
|
|
/** Mask for selecting container events. */
|
120 |
|
|
public static final long CONTAINER_EVENT_MASK = 0x00002;
|
121 |
|
|
|
122 |
|
|
/** Mask for selecting component focus events. */
|
123 |
|
|
public static final long FOCUS_EVENT_MASK = 0x00004;
|
124 |
|
|
|
125 |
|
|
/** Mask for selecting keyboard events. */
|
126 |
|
|
public static final long KEY_EVENT_MASK = 0x00008;
|
127 |
|
|
|
128 |
|
|
/** Mask for mouse button events. */
|
129 |
|
|
public static final long MOUSE_EVENT_MASK = 0x00010;
|
130 |
|
|
|
131 |
|
|
/** Mask for mouse motion events. */
|
132 |
|
|
public static final long MOUSE_MOTION_EVENT_MASK = 0x00020;
|
133 |
|
|
|
134 |
|
|
/** Mask for window events. */
|
135 |
|
|
public static final long WINDOW_EVENT_MASK = 0x00040;
|
136 |
|
|
|
137 |
|
|
/** Mask for action events. */
|
138 |
|
|
public static final long ACTION_EVENT_MASK = 0x00080;
|
139 |
|
|
|
140 |
|
|
/** Mask for adjustment events. */
|
141 |
|
|
public static final long ADJUSTMENT_EVENT_MASK = 0x00100;
|
142 |
|
|
|
143 |
|
|
/** Mask for item events. */
|
144 |
|
|
public static final long ITEM_EVENT_MASK = 0x00200;
|
145 |
|
|
|
146 |
|
|
/** Mask for text events. */
|
147 |
|
|
public static final long TEXT_EVENT_MASK = 0x00400;
|
148 |
|
|
|
149 |
|
|
/**
|
150 |
|
|
* Mask for input method events.
|
151 |
|
|
* @since 1.3
|
152 |
|
|
*/
|
153 |
|
|
public static final long INPUT_METHOD_EVENT_MASK = 0x00800;
|
154 |
|
|
|
155 |
|
|
/**
|
156 |
|
|
* Mask if input methods are enabled. Package visible only.
|
157 |
|
|
*/
|
158 |
|
|
static final long INPUT_ENABLED_EVENT_MASK = 0x01000;
|
159 |
|
|
|
160 |
|
|
/**
|
161 |
|
|
* Mask for paint events.
|
162 |
|
|
* @since 1.3
|
163 |
|
|
*/
|
164 |
|
|
public static final long PAINT_EVENT_MASK = 0x02000;
|
165 |
|
|
|
166 |
|
|
/**
|
167 |
|
|
* Mask for invocation events.
|
168 |
|
|
* @since 1.3
|
169 |
|
|
*/
|
170 |
|
|
public static final long INVOCATION_EVENT_MASK = 0x04000;
|
171 |
|
|
|
172 |
|
|
/**
|
173 |
|
|
* Mask for hierarchy events.
|
174 |
|
|
* @since 1.3
|
175 |
|
|
*/
|
176 |
|
|
public static final long HIERARCHY_EVENT_MASK = 0x08000;
|
177 |
|
|
|
178 |
|
|
/**
|
179 |
|
|
* Mask for hierarchy bounds events.
|
180 |
|
|
* @since 1.3
|
181 |
|
|
*/
|
182 |
|
|
public static final long HIERARCHY_BOUNDS_EVENT_MASK = 0x10000;
|
183 |
|
|
|
184 |
|
|
/**
|
185 |
|
|
* Mask for mouse wheel events.
|
186 |
|
|
* @since 1.4
|
187 |
|
|
*/
|
188 |
|
|
public static final long MOUSE_WHEEL_EVENT_MASK = 0x20000;
|
189 |
|
|
|
190 |
|
|
/**
|
191 |
|
|
* Mask for window state events.
|
192 |
|
|
* @since 1.4
|
193 |
|
|
*/
|
194 |
|
|
public static final long WINDOW_STATE_EVENT_MASK = 0x40000;
|
195 |
|
|
|
196 |
|
|
/**
|
197 |
|
|
* Mask for window focus events.
|
198 |
|
|
* @since 1.4
|
199 |
|
|
*/
|
200 |
|
|
public static final long WINDOW_FOCUS_EVENT_MASK = 0x80000;
|
201 |
|
|
|
202 |
|
|
/**
|
203 |
|
|
* This is the highest number for event ids that are reserved for use by
|
204 |
|
|
* the AWT system itself. Subclasses outside of java.awt should use higher
|
205 |
|
|
* ids.
|
206 |
|
|
*/
|
207 |
|
|
public static final int RESERVED_ID_MAX = 1999;
|
208 |
|
|
|
209 |
|
|
|
210 |
|
|
/**
|
211 |
|
|
* Initializes a new AWTEvent from the old Java 1.0 event object.
|
212 |
|
|
*
|
213 |
|
|
* @param event the old-style event
|
214 |
|
|
* @throws NullPointerException if event is null
|
215 |
|
|
*/
|
216 |
|
|
public AWTEvent(Event event)
|
217 |
|
|
{
|
218 |
|
|
this(event.target, event.id);
|
219 |
|
|
consumed = event.consumed;
|
220 |
|
|
}
|
221 |
|
|
|
222 |
|
|
/**
|
223 |
|
|
* Create an event on the specified source object and id.
|
224 |
|
|
*
|
225 |
|
|
* @param source the object that caused the event
|
226 |
|
|
* @param id the event id
|
227 |
|
|
* @throws IllegalArgumentException if source is null
|
228 |
|
|
*/
|
229 |
|
|
public AWTEvent(Object source, int id)
|
230 |
|
|
{
|
231 |
|
|
super(source);
|
232 |
|
|
this.id = id;
|
233 |
|
|
}
|
234 |
|
|
|
235 |
|
|
/**
|
236 |
|
|
* Retarget the event, such as converting a heavyweight component to a
|
237 |
|
|
* lightweight child of the original. This is not for general use, but
|
238 |
|
|
* is for event targeting systems like KeyboardFocusManager.
|
239 |
|
|
*
|
240 |
|
|
* @param source the new source
|
241 |
|
|
*/
|
242 |
|
|
public void setSource(Object source)
|
243 |
|
|
{
|
244 |
|
|
this.source = source;
|
245 |
|
|
}
|
246 |
|
|
|
247 |
|
|
/**
|
248 |
|
|
* Returns the event type id.
|
249 |
|
|
*
|
250 |
|
|
* @return the id number of this event
|
251 |
|
|
*/
|
252 |
|
|
public int getID()
|
253 |
|
|
{
|
254 |
|
|
return id;
|
255 |
|
|
}
|
256 |
|
|
|
257 |
|
|
/**
|
258 |
|
|
* Create a string that represents this event in the format
|
259 |
|
|
* <code>classname[eventstring] on sourcecomponentname</code>.
|
260 |
|
|
*
|
261 |
|
|
* @return a string representing this event
|
262 |
|
|
*/
|
263 |
|
|
public String toString ()
|
264 |
|
|
{
|
265 |
|
|
String src;
|
266 |
|
|
if (source instanceof Component)
|
267 |
|
|
src = ((Component) source).getName();
|
268 |
|
|
else if (source instanceof MenuComponent)
|
269 |
|
|
src = ((MenuComponent) source).getName();
|
270 |
|
|
else if (source != null)
|
271 |
|
|
src = source.toString();
|
272 |
|
|
else
|
273 |
|
|
src = "null";
|
274 |
|
|
String string = getClass ().getName () + "[" + paramString () + "] on "
|
275 |
|
|
+ src;
|
276 |
|
|
return string;
|
277 |
|
|
}
|
278 |
|
|
|
279 |
|
|
/**
|
280 |
|
|
* Returns a string representation of the state of this event. It may be
|
281 |
|
|
* empty, but must not be null; it is implementation defined.
|
282 |
|
|
*
|
283 |
|
|
* @return a string representation of this event
|
284 |
|
|
*/
|
285 |
|
|
public String paramString()
|
286 |
|
|
{
|
287 |
|
|
return "";
|
288 |
|
|
}
|
289 |
|
|
|
290 |
|
|
/**
|
291 |
|
|
* Consumes this event so that it will not be processed in the default
|
292 |
|
|
* manner.
|
293 |
|
|
*/
|
294 |
|
|
protected void consume()
|
295 |
|
|
{
|
296 |
|
|
consumed = true;
|
297 |
|
|
}
|
298 |
|
|
|
299 |
|
|
/**
|
300 |
|
|
* Tests whether not not this event has been consumed. A consumed event
|
301 |
|
|
* is not processed in the default manner.
|
302 |
|
|
*
|
303 |
|
|
* @return true if this event has been consumed
|
304 |
|
|
*/
|
305 |
|
|
protected boolean isConsumed()
|
306 |
|
|
{
|
307 |
|
|
return consumed;
|
308 |
|
|
}
|
309 |
|
|
|
310 |
|
|
/**
|
311 |
|
|
* Converts an event id to the appropriate event mask.
|
312 |
|
|
*
|
313 |
|
|
* @param id the event id
|
314 |
|
|
*
|
315 |
|
|
* @return the event mask for the specified id
|
316 |
|
|
*/
|
317 |
|
|
static long eventIdToMask(int id)
|
318 |
|
|
{
|
319 |
|
|
long mask = 0;
|
320 |
|
|
switch (id)
|
321 |
|
|
{
|
322 |
|
|
case ActionEvent.ACTION_PERFORMED:
|
323 |
|
|
mask = ACTION_EVENT_MASK;
|
324 |
|
|
break;
|
325 |
|
|
case AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED:
|
326 |
|
|
mask = ADJUSTMENT_EVENT_MASK;
|
327 |
|
|
break;
|
328 |
|
|
case ComponentEvent.COMPONENT_MOVED:
|
329 |
|
|
case ComponentEvent.COMPONENT_RESIZED:
|
330 |
|
|
case ComponentEvent.COMPONENT_SHOWN:
|
331 |
|
|
case ComponentEvent.COMPONENT_HIDDEN:
|
332 |
|
|
mask = COMPONENT_EVENT_MASK;
|
333 |
|
|
break;
|
334 |
|
|
case ContainerEvent.COMPONENT_ADDED:
|
335 |
|
|
case ContainerEvent.COMPONENT_REMOVED:
|
336 |
|
|
mask = CONTAINER_EVENT_MASK;
|
337 |
|
|
break;
|
338 |
|
|
case FocusEvent.FOCUS_GAINED:
|
339 |
|
|
case FocusEvent.FOCUS_LOST:
|
340 |
|
|
mask = FOCUS_EVENT_MASK;
|
341 |
|
|
break;
|
342 |
|
|
case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
|
343 |
|
|
case InputMethodEvent.CARET_POSITION_CHANGED:
|
344 |
|
|
mask = INPUT_METHOD_EVENT_MASK;
|
345 |
|
|
break;
|
346 |
|
|
case InvocationEvent.INVOCATION_DEFAULT:
|
347 |
|
|
mask = INVOCATION_EVENT_MASK;
|
348 |
|
|
break;
|
349 |
|
|
case ItemEvent.ITEM_STATE_CHANGED:
|
350 |
|
|
mask = ITEM_EVENT_MASK;
|
351 |
|
|
break;
|
352 |
|
|
case KeyEvent.KEY_TYPED:
|
353 |
|
|
case KeyEvent.KEY_PRESSED:
|
354 |
|
|
case KeyEvent.KEY_RELEASED:
|
355 |
|
|
mask = KEY_EVENT_MASK;
|
356 |
|
|
break;
|
357 |
|
|
case MouseEvent.MOUSE_CLICKED:
|
358 |
|
|
case MouseEvent.MOUSE_PRESSED:
|
359 |
|
|
case MouseEvent.MOUSE_RELEASED:
|
360 |
|
|
mask = MOUSE_EVENT_MASK;
|
361 |
|
|
break;
|
362 |
|
|
case MouseEvent.MOUSE_MOVED:
|
363 |
|
|
case MouseEvent.MOUSE_ENTERED:
|
364 |
|
|
case MouseEvent.MOUSE_EXITED:
|
365 |
|
|
case MouseEvent.MOUSE_DRAGGED:
|
366 |
|
|
mask = MOUSE_MOTION_EVENT_MASK;
|
367 |
|
|
break;
|
368 |
|
|
case MouseEvent.MOUSE_WHEEL:
|
369 |
|
|
mask = MOUSE_WHEEL_EVENT_MASK;
|
370 |
|
|
break;
|
371 |
|
|
case PaintEvent.PAINT:
|
372 |
|
|
case PaintEvent.UPDATE:
|
373 |
|
|
mask = PAINT_EVENT_MASK;
|
374 |
|
|
break;
|
375 |
|
|
case TextEvent.TEXT_VALUE_CHANGED:
|
376 |
|
|
mask = TEXT_EVENT_MASK;
|
377 |
|
|
break;
|
378 |
|
|
case WindowEvent.WINDOW_OPENED:
|
379 |
|
|
case WindowEvent.WINDOW_CLOSING:
|
380 |
|
|
case WindowEvent.WINDOW_CLOSED:
|
381 |
|
|
case WindowEvent.WINDOW_ICONIFIED:
|
382 |
|
|
case WindowEvent.WINDOW_DEICONIFIED:
|
383 |
|
|
case WindowEvent.WINDOW_ACTIVATED:
|
384 |
|
|
case WindowEvent.WINDOW_DEACTIVATED:
|
385 |
|
|
mask = WINDOW_EVENT_MASK;
|
386 |
|
|
break;
|
387 |
|
|
case WindowEvent.WINDOW_GAINED_FOCUS:
|
388 |
|
|
case WindowEvent.WINDOW_LOST_FOCUS:
|
389 |
|
|
mask = WINDOW_FOCUS_EVENT_MASK;
|
390 |
|
|
break;
|
391 |
|
|
case WindowEvent.WINDOW_STATE_CHANGED:
|
392 |
|
|
mask = WINDOW_STATE_EVENT_MASK;
|
393 |
|
|
break;
|
394 |
|
|
default:
|
395 |
|
|
mask = 0;
|
396 |
|
|
}
|
397 |
|
|
return mask;
|
398 |
|
|
}
|
399 |
|
|
} // class AWTEvent
|