author | serb |
Tue, 31 Jan 2017 19:22:35 +0300 | |
changeset 43722 | 25ba19c20260 |
parent 35667 | ed476aba94de |
permissions | -rw-r--r-- |
2 | 1 |
/* |
43722
25ba19c20260
8143077: Deprecate InputEvent._MASK in favor of InputEvent._DOWN_MASK
serb
parents:
35667
diff
changeset
|
2 |
* Copyright (c) 1995, 2016, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
package java.awt; |
|
26 |
||
43722
25ba19c20260
8143077: Deprecate InputEvent._MASK in favor of InputEvent._DOWN_MASK
serb
parents:
35667
diff
changeset
|
27 |
import java.awt.event.KeyEvent; |
2 | 28 |
|
29 |
/** |
|
35667 | 30 |
* <b>NOTE:</b> The {@code Event} class is obsolete and is |
21278 | 31 |
* available only for backwards compatibility. It has been replaced |
35667 | 32 |
* by the {@code AWTEvent} class and its subclasses. |
2 | 33 |
* <p> |
35667 | 34 |
* {@code Event} is a platform-independent class that |
2 | 35 |
* encapsulates events from the platform's Graphical User |
36 |
* Interface in the Java 1.0 event model. In Java 1.1 |
|
35667 | 37 |
* and later versions, the {@code Event} class is maintained |
21278 | 38 |
* only for backwards compatibility. The information in this |
2 | 39 |
* class description is provided to assist programmers in |
40 |
* converting Java 1.0 programs to the new event model. |
|
41 |
* <p> |
|
42 |
* In the Java 1.0 event model, an event contains an |
|
43 |
* {@link Event#id} field |
|
44 |
* that indicates what type of event it is and which other |
|
35667 | 45 |
* {@code Event} variables are relevant for the event. |
2 | 46 |
* <p> |
47 |
* For keyboard events, {@link Event#key} |
|
48 |
* contains a value indicating which key was activated, and |
|
49 |
* {@link Event#modifiers} contains the |
|
50 |
* modifiers for that event. For the KEY_PRESS and KEY_RELEASE |
|
35667 | 51 |
* event ids, the value of {@code key} is the unicode |
2 | 52 |
* character code for the key. For KEY_ACTION and |
35667 | 53 |
* KEY_ACTION_RELEASE, the value of {@code key} is |
2 | 54 |
* one of the defined action-key identifiers in the |
35667 | 55 |
* {@code Event} class ({@code PGUP}, |
56 |
* {@code PGDN}, {@code F1}, {@code F2}, etc). |
|
2 | 57 |
* |
43722
25ba19c20260
8143077: Deprecate InputEvent._MASK in favor of InputEvent._DOWN_MASK
serb
parents:
35667
diff
changeset
|
58 |
* @deprecated It is recommended that {@code AWTEvent} and its subclasses be |
25ba19c20260
8143077: Deprecate InputEvent._MASK in favor of InputEvent._DOWN_MASK
serb
parents:
35667
diff
changeset
|
59 |
* used instead |
2 | 60 |
* @author Sami Shaio |
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
23010
diff
changeset
|
61 |
* @since 1.0 |
2 | 62 |
*/ |
43722
25ba19c20260
8143077: Deprecate InputEvent._MASK in favor of InputEvent._DOWN_MASK
serb
parents:
35667
diff
changeset
|
63 |
@Deprecated(since = "9") |
2 | 64 |
public class Event implements java.io.Serializable { |
65 |
private transient long data; |
|
66 |
||
67 |
/* Modifier constants */ |
|
68 |
||
69 |
/** |
|
70 |
* This flag indicates that the Shift key was down when the event |
|
71 |
* occurred. |
|
72 |
*/ |
|
73 |
public static final int SHIFT_MASK = 1 << 0; |
|
74 |
||
75 |
/** |
|
76 |
* This flag indicates that the Control key was down when the event |
|
77 |
* occurred. |
|
78 |
*/ |
|
79 |
public static final int CTRL_MASK = 1 << 1; |
|
80 |
||
81 |
/** |
|
82 |
* This flag indicates that the Meta key was down when the event |
|
83 |
* occurred. For mouse events, this flag indicates that the right |
|
84 |
* button was pressed or released. |
|
85 |
*/ |
|
86 |
public static final int META_MASK = 1 << 2; |
|
87 |
||
88 |
/** |
|
89 |
* This flag indicates that the Alt key was down when |
|
90 |
* the event occurred. For mouse events, this flag indicates that the |
|
91 |
* middle mouse button was pressed or released. |
|
92 |
*/ |
|
93 |
public static final int ALT_MASK = 1 << 3; |
|
94 |
||
95 |
/* Action keys */ |
|
96 |
||
97 |
/** |
|
98 |
* The Home key, a non-ASCII action key. |
|
99 |
*/ |
|
100 |
public static final int HOME = 1000; |
|
101 |
||
102 |
/** |
|
103 |
* The End key, a non-ASCII action key. |
|
104 |
*/ |
|
105 |
public static final int END = 1001; |
|
106 |
||
107 |
/** |
|
108 |
* The Page Up key, a non-ASCII action key. |
|
109 |
*/ |
|
110 |
public static final int PGUP = 1002; |
|
111 |
||
112 |
/** |
|
113 |
* The Page Down key, a non-ASCII action key. |
|
114 |
*/ |
|
115 |
public static final int PGDN = 1003; |
|
116 |
||
117 |
/** |
|
118 |
* The Up Arrow key, a non-ASCII action key. |
|
119 |
*/ |
|
120 |
public static final int UP = 1004; |
|
121 |
||
122 |
/** |
|
123 |
* The Down Arrow key, a non-ASCII action key. |
|
124 |
*/ |
|
125 |
public static final int DOWN = 1005; |
|
126 |
||
127 |
/** |
|
128 |
* The Left Arrow key, a non-ASCII action key. |
|
129 |
*/ |
|
130 |
public static final int LEFT = 1006; |
|
131 |
||
132 |
/** |
|
133 |
* The Right Arrow key, a non-ASCII action key. |
|
134 |
*/ |
|
135 |
public static final int RIGHT = 1007; |
|
136 |
||
137 |
/** |
|
138 |
* The F1 function key, a non-ASCII action key. |
|
139 |
*/ |
|
140 |
public static final int F1 = 1008; |
|
141 |
||
142 |
/** |
|
143 |
* The F2 function key, a non-ASCII action key. |
|
144 |
*/ |
|
145 |
public static final int F2 = 1009; |
|
146 |
||
147 |
/** |
|
148 |
* The F3 function key, a non-ASCII action key. |
|
149 |
*/ |
|
150 |
public static final int F3 = 1010; |
|
151 |
||
152 |
/** |
|
153 |
* The F4 function key, a non-ASCII action key. |
|
154 |
*/ |
|
155 |
public static final int F4 = 1011; |
|
156 |
||
157 |
/** |
|
158 |
* The F5 function key, a non-ASCII action key. |
|
159 |
*/ |
|
160 |
public static final int F5 = 1012; |
|
161 |
||
162 |
/** |
|
163 |
* The F6 function key, a non-ASCII action key. |
|
164 |
*/ |
|
165 |
public static final int F6 = 1013; |
|
166 |
||
167 |
/** |
|
168 |
* The F7 function key, a non-ASCII action key. |
|
169 |
*/ |
|
170 |
public static final int F7 = 1014; |
|
171 |
||
172 |
/** |
|
173 |
* The F8 function key, a non-ASCII action key. |
|
174 |
*/ |
|
175 |
public static final int F8 = 1015; |
|
176 |
||
177 |
/** |
|
178 |
* The F9 function key, a non-ASCII action key. |
|
179 |
*/ |
|
180 |
public static final int F9 = 1016; |
|
181 |
||
182 |
/** |
|
183 |
* The F10 function key, a non-ASCII action key. |
|
184 |
*/ |
|
185 |
public static final int F10 = 1017; |
|
186 |
||
187 |
/** |
|
188 |
* The F11 function key, a non-ASCII action key. |
|
189 |
*/ |
|
190 |
public static final int F11 = 1018; |
|
191 |
||
192 |
/** |
|
193 |
* The F12 function key, a non-ASCII action key. |
|
194 |
*/ |
|
195 |
public static final int F12 = 1019; |
|
196 |
||
197 |
/** |
|
198 |
* The Print Screen key, a non-ASCII action key. |
|
199 |
*/ |
|
200 |
public static final int PRINT_SCREEN = 1020; |
|
201 |
||
202 |
/** |
|
203 |
* The Scroll Lock key, a non-ASCII action key. |
|
204 |
*/ |
|
205 |
public static final int SCROLL_LOCK = 1021; |
|
206 |
||
207 |
/** |
|
208 |
* The Caps Lock key, a non-ASCII action key. |
|
209 |
*/ |
|
210 |
public static final int CAPS_LOCK = 1022; |
|
211 |
||
212 |
/** |
|
213 |
* The Num Lock key, a non-ASCII action key. |
|
214 |
*/ |
|
215 |
public static final int NUM_LOCK = 1023; |
|
216 |
||
217 |
/** |
|
218 |
* The Pause key, a non-ASCII action key. |
|
219 |
*/ |
|
220 |
public static final int PAUSE = 1024; |
|
221 |
||
222 |
/** |
|
223 |
* The Insert key, a non-ASCII action key. |
|
224 |
*/ |
|
225 |
public static final int INSERT = 1025; |
|
226 |
||
227 |
/* Non-action keys */ |
|
228 |
||
229 |
/** |
|
230 |
* The Enter key. |
|
231 |
*/ |
|
232 |
public static final int ENTER = '\n'; |
|
233 |
||
234 |
/** |
|
235 |
* The BackSpace key. |
|
236 |
*/ |
|
237 |
public static final int BACK_SPACE = '\b'; |
|
238 |
||
239 |
/** |
|
240 |
* The Tab key. |
|
241 |
*/ |
|
242 |
public static final int TAB = '\t'; |
|
243 |
||
244 |
/** |
|
245 |
* The Escape key. |
|
246 |
*/ |
|
247 |
public static final int ESCAPE = 27; |
|
248 |
||
249 |
/** |
|
250 |
* The Delete key. |
|
251 |
*/ |
|
252 |
public static final int DELETE = 127; |
|
253 |
||
254 |
||
255 |
/* Base for all window events. */ |
|
256 |
private static final int WINDOW_EVENT = 200; |
|
257 |
||
258 |
/** |
|
259 |
* The user has asked the window manager to kill the window. |
|
260 |
*/ |
|
261 |
public static final int WINDOW_DESTROY = 1 + WINDOW_EVENT; |
|
262 |
||
263 |
/** |
|
264 |
* The user has asked the window manager to expose the window. |
|
265 |
*/ |
|
266 |
public static final int WINDOW_EXPOSE = 2 + WINDOW_EVENT; |
|
267 |
||
268 |
/** |
|
269 |
* The user has asked the window manager to iconify the window. |
|
270 |
*/ |
|
271 |
public static final int WINDOW_ICONIFY = 3 + WINDOW_EVENT; |
|
272 |
||
273 |
/** |
|
274 |
* The user has asked the window manager to de-iconify the window. |
|
275 |
*/ |
|
276 |
public static final int WINDOW_DEICONIFY = 4 + WINDOW_EVENT; |
|
277 |
||
278 |
/** |
|
279 |
* The user has asked the window manager to move the window. |
|
280 |
*/ |
|
281 |
public static final int WINDOW_MOVED = 5 + WINDOW_EVENT; |
|
282 |
||
283 |
/* Base for all keyboard events. */ |
|
284 |
private static final int KEY_EVENT = 400; |
|
285 |
||
286 |
/** |
|
287 |
* The user has pressed a normal key. |
|
288 |
*/ |
|
289 |
public static final int KEY_PRESS = 1 + KEY_EVENT; |
|
290 |
||
291 |
/** |
|
292 |
* The user has released a normal key. |
|
293 |
*/ |
|
294 |
public static final int KEY_RELEASE = 2 + KEY_EVENT; |
|
295 |
||
296 |
/** |
|
297 |
* The user has pressed a non-ASCII <em>action</em> key. |
|
35667 | 298 |
* The {@code key} field contains a value that indicates |
2 | 299 |
* that the event occurred on one of the action keys, which |
300 |
* comprise the 12 function keys, the arrow (cursor) keys, |
|
301 |
* Page Up, Page Down, Home, End, Print Screen, Scroll Lock, |
|
302 |
* Caps Lock, Num Lock, Pause, and Insert. |
|
303 |
*/ |
|
304 |
public static final int KEY_ACTION = 3 + KEY_EVENT; |
|
305 |
||
306 |
/** |
|
307 |
* The user has released a non-ASCII <em>action</em> key. |
|
35667 | 308 |
* The {@code key} field contains a value that indicates |
2 | 309 |
* that the event occurred on one of the action keys, which |
310 |
* comprise the 12 function keys, the arrow (cursor) keys, |
|
311 |
* Page Up, Page Down, Home, End, Print Screen, Scroll Lock, |
|
312 |
* Caps Lock, Num Lock, Pause, and Insert. |
|
313 |
*/ |
|
314 |
public static final int KEY_ACTION_RELEASE = 4 + KEY_EVENT; |
|
315 |
||
316 |
/* Base for all mouse events. */ |
|
317 |
private static final int MOUSE_EVENT = 500; |
|
318 |
||
319 |
/** |
|
35667 | 320 |
* The user has pressed the mouse button. The {@code ALT_MASK} |
2 | 321 |
* flag indicates that the middle button has been pressed. |
35667 | 322 |
* The {@code META_MASK} flag indicates that the |
2 | 323 |
* right button has been pressed. |
324 |
* @see java.awt.Event#ALT_MASK |
|
325 |
* @see java.awt.Event#META_MASK |
|
326 |
*/ |
|
327 |
public static final int MOUSE_DOWN = 1 + MOUSE_EVENT; |
|
328 |
||
329 |
/** |
|
35667 | 330 |
* The user has released the mouse button. The {@code ALT_MASK} |
2 | 331 |
* flag indicates that the middle button has been released. |
35667 | 332 |
* The {@code META_MASK} flag indicates that the |
2 | 333 |
* right button has been released. |
334 |
* @see java.awt.Event#ALT_MASK |
|
335 |
* @see java.awt.Event#META_MASK |
|
336 |
*/ |
|
337 |
public static final int MOUSE_UP = 2 + MOUSE_EVENT; |
|
338 |
||
339 |
/** |
|
340 |
* The mouse has moved with no button pressed. |
|
341 |
*/ |
|
342 |
public static final int MOUSE_MOVE = 3 + MOUSE_EVENT; |
|
343 |
||
344 |
/** |
|
345 |
* The mouse has entered a component. |
|
346 |
*/ |
|
347 |
public static final int MOUSE_ENTER = 4 + MOUSE_EVENT; |
|
348 |
||
349 |
/** |
|
350 |
* The mouse has exited a component. |
|
351 |
*/ |
|
352 |
public static final int MOUSE_EXIT = 5 + MOUSE_EVENT; |
|
353 |
||
354 |
/** |
|
355 |
* The user has moved the mouse with a button pressed. The |
|
35667 | 356 |
* {@code ALT_MASK} flag indicates that the middle |
357 |
* button is being pressed. The {@code META_MASK} flag indicates |
|
2 | 358 |
* that the right button is being pressed. |
359 |
* @see java.awt.Event#ALT_MASK |
|
360 |
* @see java.awt.Event#META_MASK |
|
361 |
*/ |
|
362 |
public static final int MOUSE_DRAG = 6 + MOUSE_EVENT; |
|
363 |
||
364 |
||
365 |
/* Scrolling events */ |
|
366 |
private static final int SCROLL_EVENT = 600; |
|
367 |
||
368 |
/** |
|
369 |
* The user has activated the <em>line up</em> |
|
370 |
* area of a scroll bar. |
|
371 |
*/ |
|
372 |
public static final int SCROLL_LINE_UP = 1 + SCROLL_EVENT; |
|
373 |
||
374 |
/** |
|
375 |
* The user has activated the <em>line down</em> |
|
376 |
* area of a scroll bar. |
|
377 |
*/ |
|
378 |
public static final int SCROLL_LINE_DOWN = 2 + SCROLL_EVENT; |
|
379 |
||
380 |
/** |
|
381 |
* The user has activated the <em>page up</em> |
|
382 |
* area of a scroll bar. |
|
383 |
*/ |
|
384 |
public static final int SCROLL_PAGE_UP = 3 + SCROLL_EVENT; |
|
385 |
||
386 |
/** |
|
387 |
* The user has activated the <em>page down</em> |
|
388 |
* area of a scroll bar. |
|
389 |
*/ |
|
390 |
public static final int SCROLL_PAGE_DOWN = 4 + SCROLL_EVENT; |
|
391 |
||
392 |
/** |
|
393 |
* The user has moved the bubble (thumb) in a scroll bar, |
|
394 |
* moving to an "absolute" position, rather than to |
|
21278 | 395 |
* an offset from the last position. |
2 | 396 |
*/ |
397 |
public static final int SCROLL_ABSOLUTE = 5 + SCROLL_EVENT; |
|
398 |
||
399 |
/** |
|
400 |
* The scroll begin event. |
|
401 |
*/ |
|
402 |
public static final int SCROLL_BEGIN = 6 + SCROLL_EVENT; |
|
403 |
||
404 |
/** |
|
405 |
* The scroll end event. |
|
406 |
*/ |
|
407 |
public static final int SCROLL_END = 7 + SCROLL_EVENT; |
|
408 |
||
409 |
/* List Events */ |
|
410 |
private static final int LIST_EVENT = 700; |
|
411 |
||
412 |
/** |
|
413 |
* An item in a list has been selected. |
|
414 |
*/ |
|
415 |
public static final int LIST_SELECT = 1 + LIST_EVENT; |
|
416 |
||
417 |
/** |
|
418 |
* An item in a list has been deselected. |
|
419 |
*/ |
|
420 |
public static final int LIST_DESELECT = 2 + LIST_EVENT; |
|
421 |
||
422 |
/* Misc Event */ |
|
423 |
private static final int MISC_EVENT = 1000; |
|
424 |
||
425 |
/** |
|
426 |
* This event indicates that the user wants some action to occur. |
|
427 |
*/ |
|
428 |
public static final int ACTION_EVENT = 1 + MISC_EVENT; |
|
429 |
||
430 |
/** |
|
431 |
* A file loading event. |
|
432 |
*/ |
|
433 |
public static final int LOAD_FILE = 2 + MISC_EVENT; |
|
434 |
||
435 |
/** |
|
436 |
* A file saving event. |
|
437 |
*/ |
|
438 |
public static final int SAVE_FILE = 3 + MISC_EVENT; |
|
439 |
||
440 |
/** |
|
441 |
* A component gained the focus. |
|
442 |
*/ |
|
443 |
public static final int GOT_FOCUS = 4 + MISC_EVENT; |
|
444 |
||
445 |
/** |
|
446 |
* A component lost the focus. |
|
447 |
*/ |
|
448 |
public static final int LOST_FOCUS = 5 + MISC_EVENT; |
|
449 |
||
450 |
/** |
|
451 |
* The target component. This indicates the component over which the |
|
452 |
* event occurred or with which the event is associated. |
|
453 |
* This object has been replaced by AWTEvent.getSource() |
|
454 |
* |
|
455 |
* @serial |
|
456 |
* @see java.awt.AWTEvent#getSource() |
|
457 |
*/ |
|
458 |
public Object target; |
|
459 |
||
460 |
/** |
|
461 |
* The time stamp. |
|
462 |
* Replaced by InputEvent.getWhen(). |
|
463 |
* |
|
464 |
* @serial |
|
465 |
* @see java.awt.event.InputEvent#getWhen() |
|
466 |
*/ |
|
467 |
public long when; |
|
468 |
||
469 |
/** |
|
470 |
* Indicates which type of event the event is, and which |
|
35667 | 471 |
* other {@code Event} variables are relevant for the event. |
2 | 472 |
* This has been replaced by AWTEvent.getID() |
473 |
* |
|
474 |
* @serial |
|
475 |
* @see java.awt.AWTEvent#getID() |
|
476 |
*/ |
|
477 |
public int id; |
|
478 |
||
479 |
/** |
|
480 |
* The <i>x</i> coordinate of the event. |
|
481 |
* Replaced by MouseEvent.getX() |
|
482 |
* |
|
483 |
* @serial |
|
484 |
* @see java.awt.event.MouseEvent#getX() |
|
485 |
*/ |
|
486 |
public int x; |
|
487 |
||
488 |
/** |
|
489 |
* The <i>y</i> coordinate of the event. |
|
490 |
* Replaced by MouseEvent.getY() |
|
491 |
* |
|
492 |
* @serial |
|
493 |
* @see java.awt.event.MouseEvent#getY() |
|
494 |
*/ |
|
495 |
public int y; |
|
496 |
||
497 |
/** |
|
498 |
* The key code of the key that was pressed in a keyboard event. |
|
499 |
* This has been replaced by KeyEvent.getKeyCode() |
|
500 |
* |
|
501 |
* @serial |
|
502 |
* @see java.awt.event.KeyEvent#getKeyCode() |
|
503 |
*/ |
|
504 |
public int key; |
|
505 |
||
506 |
/** |
|
507 |
* The key character that was pressed in a keyboard event. |
|
508 |
*/ |
|
509 |
// public char keyChar; |
|
510 |
||
511 |
/** |
|
512 |
* The state of the modifier keys. |
|
513 |
* This is replaced with InputEvent.getModifiers() |
|
514 |
* In java 1.1 MouseEvent and KeyEvent are subclasses |
|
515 |
* of InputEvent. |
|
516 |
* |
|
517 |
* @serial |
|
518 |
* @see java.awt.event.InputEvent#getModifiers() |
|
519 |
*/ |
|
520 |
public int modifiers; |
|
521 |
||
522 |
/** |
|
35667 | 523 |
* For {@code MOUSE_DOWN} events, this field indicates the |
2 | 524 |
* number of consecutive clicks. For other events, its value is |
35667 | 525 |
* {@code 0}. |
2 | 526 |
* This field has been replaced by MouseEvent.getClickCount(). |
527 |
* |
|
528 |
* @serial |
|
20172 | 529 |
* @see java.awt.event.MouseEvent#getClickCount() |
2 | 530 |
*/ |
531 |
public int clickCount; |
|
532 |
||
533 |
/** |
|
534 |
* An arbitrary argument of the event. The value of this field |
|
535 |
* depends on the type of event. |
|
35667 | 536 |
* {@code arg} has been replaced by event specific property. |
2 | 537 |
* |
538 |
* @serial |
|
539 |
*/ |
|
540 |
public Object arg; |
|
541 |
||
542 |
/** |
|
543 |
* The next event. This field is set when putting events into a |
|
544 |
* linked list. |
|
545 |
* This has been replaced by EventQueue. |
|
546 |
* |
|
547 |
* @serial |
|
548 |
* @see java.awt.EventQueue |
|
549 |
*/ |
|
550 |
public Event evt; |
|
551 |
||
552 |
/* table for mapping old Event action keys to KeyEvent virtual keys. */ |
|
553 |
private static final int actionKeyCodes[][] = { |
|
554 |
/* virtual key action key */ |
|
555 |
{ KeyEvent.VK_HOME, Event.HOME }, |
|
556 |
{ KeyEvent.VK_END, Event.END }, |
|
557 |
{ KeyEvent.VK_PAGE_UP, Event.PGUP }, |
|
558 |
{ KeyEvent.VK_PAGE_DOWN, Event.PGDN }, |
|
559 |
{ KeyEvent.VK_UP, Event.UP }, |
|
560 |
{ KeyEvent.VK_DOWN, Event.DOWN }, |
|
561 |
{ KeyEvent.VK_LEFT, Event.LEFT }, |
|
562 |
{ KeyEvent.VK_RIGHT, Event.RIGHT }, |
|
563 |
{ KeyEvent.VK_F1, Event.F1 }, |
|
564 |
{ KeyEvent.VK_F2, Event.F2 }, |
|
565 |
{ KeyEvent.VK_F3, Event.F3 }, |
|
566 |
{ KeyEvent.VK_F4, Event.F4 }, |
|
567 |
{ KeyEvent.VK_F5, Event.F5 }, |
|
568 |
{ KeyEvent.VK_F6, Event.F6 }, |
|
569 |
{ KeyEvent.VK_F7, Event.F7 }, |
|
570 |
{ KeyEvent.VK_F8, Event.F8 }, |
|
571 |
{ KeyEvent.VK_F9, Event.F9 }, |
|
572 |
{ KeyEvent.VK_F10, Event.F10 }, |
|
573 |
{ KeyEvent.VK_F11, Event.F11 }, |
|
574 |
{ KeyEvent.VK_F12, Event.F12 }, |
|
575 |
{ KeyEvent.VK_PRINTSCREEN, Event.PRINT_SCREEN }, |
|
576 |
{ KeyEvent.VK_SCROLL_LOCK, Event.SCROLL_LOCK }, |
|
577 |
{ KeyEvent.VK_CAPS_LOCK, Event.CAPS_LOCK }, |
|
578 |
{ KeyEvent.VK_NUM_LOCK, Event.NUM_LOCK }, |
|
579 |
{ KeyEvent.VK_PAUSE, Event.PAUSE }, |
|
580 |
{ KeyEvent.VK_INSERT, Event.INSERT } |
|
581 |
}; |
|
582 |
||
583 |
/** |
|
584 |
* This field controls whether or not the event is sent back |
|
585 |
* down to the peer once the target has processed it - |
|
586 |
* false means it's sent to the peer, true means it's not. |
|
587 |
* |
|
588 |
* @serial |
|
589 |
* @see #isConsumed() |
|
590 |
*/ |
|
591 |
private boolean consumed = false; |
|
592 |
||
593 |
/* |
|
594 |
* JDK 1.1 serialVersionUID |
|
595 |
*/ |
|
596 |
private static final long serialVersionUID = 5488922509400504703L; |
|
597 |
||
598 |
static { |
|
599 |
/* ensure that the necessary native libraries are loaded */ |
|
600 |
Toolkit.loadLibraries(); |
|
601 |
if (!GraphicsEnvironment.isHeadless()) { |
|
602 |
initIDs(); |
|
603 |
} |
|
604 |
} |
|
605 |
||
606 |
/** |
|
607 |
* Initialize JNI field and method IDs for fields that may be |
|
608 |
accessed from C. |
|
609 |
*/ |
|
610 |
private static native void initIDs(); |
|
611 |
||
612 |
/** |
|
35667 | 613 |
* <b>NOTE:</b> The {@code Event} class is obsolete and is |
21278 | 614 |
* available only for backwards compatibility. It has been replaced |
35667 | 615 |
* by the {@code AWTEvent} class and its subclasses. |
2 | 616 |
* <p> |
35667 | 617 |
* Creates an instance of {@code Event} with the specified target |
2 | 618 |
* component, time stamp, event type, <i>x</i> and <i>y</i> |
619 |
* coordinates, keyboard key, state of the modifier keys, and |
|
620 |
* argument. |
|
621 |
* @param target the target component. |
|
622 |
* @param when the time stamp. |
|
623 |
* @param id the event type. |
|
624 |
* @param x the <i>x</i> coordinate. |
|
625 |
* @param y the <i>y</i> coordinate. |
|
626 |
* @param key the key pressed in a keyboard event. |
|
627 |
* @param modifiers the state of the modifier keys. |
|
628 |
* @param arg the specified argument. |
|
629 |
*/ |
|
630 |
public Event(Object target, long when, int id, int x, int y, int key, |
|
631 |
int modifiers, Object arg) { |
|
632 |
this.target = target; |
|
633 |
this.when = when; |
|
634 |
this.id = id; |
|
635 |
this.x = x; |
|
636 |
this.y = y; |
|
637 |
this.key = key; |
|
638 |
this.modifiers = modifiers; |
|
639 |
this.arg = arg; |
|
640 |
this.data = 0; |
|
641 |
this.clickCount = 0; |
|
642 |
switch(id) { |
|
643 |
case ACTION_EVENT: |
|
644 |
case WINDOW_DESTROY: |
|
645 |
case WINDOW_ICONIFY: |
|
646 |
case WINDOW_DEICONIFY: |
|
647 |
case WINDOW_MOVED: |
|
648 |
case SCROLL_LINE_UP: |
|
649 |
case SCROLL_LINE_DOWN: |
|
650 |
case SCROLL_PAGE_UP: |
|
651 |
case SCROLL_PAGE_DOWN: |
|
652 |
case SCROLL_ABSOLUTE: |
|
653 |
case SCROLL_BEGIN: |
|
654 |
case SCROLL_END: |
|
655 |
case LIST_SELECT: |
|
656 |
case LIST_DESELECT: |
|
657 |
consumed = true; // these types are not passed back to peer |
|
658 |
break; |
|
659 |
default: |
|
660 |
} |
|
661 |
} |
|
662 |
||
663 |
/** |
|
35667 | 664 |
* <b>NOTE:</b> The {@code Event} class is obsolete and is |
21278 | 665 |
* available only for backwards compatibility. It has been replaced |
35667 | 666 |
* by the {@code AWTEvent} class and its subclasses. |
2 | 667 |
* <p> |
35667 | 668 |
* Creates an instance of {@code Event}, with the specified target |
2 | 669 |
* component, time stamp, event type, <i>x</i> and <i>y</i> |
670 |
* coordinates, keyboard key, state of the modifier keys, and an |
|
35667 | 671 |
* argument set to {@code null}. |
2 | 672 |
* @param target the target component. |
673 |
* @param when the time stamp. |
|
674 |
* @param id the event type. |
|
675 |
* @param x the <i>x</i> coordinate. |
|
676 |
* @param y the <i>y</i> coordinate. |
|
677 |
* @param key the key pressed in a keyboard event. |
|
678 |
* @param modifiers the state of the modifier keys. |
|
679 |
*/ |
|
680 |
public Event(Object target, long when, int id, int x, int y, int key, int modifiers) { |
|
681 |
this(target, when, id, x, y, key, modifiers, null); |
|
682 |
} |
|
683 |
||
684 |
/** |
|
35667 | 685 |
* <b>NOTE:</b> The {@code Event} class is obsolete and is |
21278 | 686 |
* available only for backwards compatibility. It has been replaced |
35667 | 687 |
* by the {@code AWTEvent} class and its subclasses. |
2 | 688 |
* <p> |
35667 | 689 |
* Creates an instance of {@code Event} with the specified |
2 | 690 |
* target component, event type, and argument. |
691 |
* @param target the target component. |
|
692 |
* @param id the event type. |
|
693 |
* @param arg the specified argument. |
|
694 |
*/ |
|
695 |
public Event(Object target, int id, Object arg) { |
|
696 |
this(target, 0, id, 0, 0, 0, 0, arg); |
|
697 |
} |
|
698 |
||
699 |
/** |
|
35667 | 700 |
* <b>NOTE:</b> The {@code Event} class is obsolete and is |
21278 | 701 |
* available only for backwards compatibility. It has been replaced |
35667 | 702 |
* by the {@code AWTEvent} class and its subclasses. |
2 | 703 |
* <p> |
704 |
* Translates this event so that its <i>x</i> and <i>y</i> |
|
705 |
* coordinates are increased by <i>dx</i> and <i>dy</i>, |
|
706 |
* respectively. |
|
707 |
* <p> |
|
708 |
* This method translates an event relative to the given component. |
|
709 |
* This involves, at a minimum, translating the coordinates into the |
|
710 |
* local coordinate system of the given component. It may also involve |
|
711 |
* translating a region in the case of an expose event. |
|
712 |
* @param dx the distance to translate the <i>x</i> coordinate. |
|
713 |
* @param dy the distance to translate the <i>y</i> coordinate. |
|
714 |
*/ |
|
715 |
public void translate(int dx, int dy) { |
|
716 |
this.x += dx; |
|
717 |
this.y += dy; |
|
718 |
} |
|
719 |
||
720 |
/** |
|
35667 | 721 |
* <b>NOTE:</b> The {@code Event} class is obsolete and is |
21278 | 722 |
* available only for backwards compatibility. It has been replaced |
35667 | 723 |
* by the {@code AWTEvent} class and its subclasses. |
2 | 724 |
* <p> |
725 |
* Checks if the Shift key is down. |
|
35667 | 726 |
* @return {@code true} if the key is down; |
727 |
* {@code false} otherwise. |
|
2 | 728 |
* @see java.awt.Event#modifiers |
729 |
* @see java.awt.Event#controlDown |
|
730 |
* @see java.awt.Event#metaDown |
|
731 |
*/ |
|
732 |
public boolean shiftDown() { |
|
733 |
return (modifiers & SHIFT_MASK) != 0; |
|
734 |
} |
|
735 |
||
736 |
/** |
|
35667 | 737 |
* <b>NOTE:</b> The {@code Event} class is obsolete and is |
21278 | 738 |
* available only for backwards compatibility. It has been replaced |
35667 | 739 |
* by the {@code AWTEvent} class and its subclasses. |
2 | 740 |
* <p> |
741 |
* Checks if the Control key is down. |
|
35667 | 742 |
* @return {@code true} if the key is down; |
743 |
* {@code false} otherwise. |
|
2 | 744 |
* @see java.awt.Event#modifiers |
745 |
* @see java.awt.Event#shiftDown |
|
746 |
* @see java.awt.Event#metaDown |
|
747 |
*/ |
|
748 |
public boolean controlDown() { |
|
749 |
return (modifiers & CTRL_MASK) != 0; |
|
750 |
} |
|
751 |
||
752 |
/** |
|
35667 | 753 |
* <b>NOTE:</b> The {@code Event} class is obsolete and is |
21278 | 754 |
* available only for backwards compatibility. It has been replaced |
35667 | 755 |
* by the {@code AWTEvent} class and its subclasses. |
2 | 756 |
* <p> |
757 |
* Checks if the Meta key is down. |
|
758 |
* |
|
35667 | 759 |
* @return {@code true} if the key is down; |
760 |
* {@code false} otherwise. |
|
2 | 761 |
* @see java.awt.Event#modifiers |
762 |
* @see java.awt.Event#shiftDown |
|
763 |
* @see java.awt.Event#controlDown |
|
764 |
*/ |
|
765 |
public boolean metaDown() { |
|
766 |
return (modifiers & META_MASK) != 0; |
|
767 |
} |
|
768 |
||
769 |
/** |
|
35667 | 770 |
* <b>NOTE:</b> The {@code Event} class is obsolete and is |
21278 | 771 |
* available only for backwards compatibility. It has been replaced |
35667 | 772 |
* by the {@code AWTEvent} class and its subclasses. |
2 | 773 |
*/ |
774 |
void consume() { |
|
775 |
switch(id) { |
|
776 |
case KEY_PRESS: |
|
777 |
case KEY_RELEASE: |
|
778 |
case KEY_ACTION: |
|
779 |
case KEY_ACTION_RELEASE: |
|
780 |
consumed = true; |
|
781 |
break; |
|
782 |
default: |
|
783 |
// event type cannot be consumed |
|
784 |
} |
|
785 |
} |
|
786 |
||
787 |
/** |
|
35667 | 788 |
* <b>NOTE:</b> The {@code Event} class is obsolete and is |
21278 | 789 |
* available only for backwards compatibility. It has been replaced |
35667 | 790 |
* by the {@code AWTEvent} class and its subclasses. |
2 | 791 |
*/ |
792 |
boolean isConsumed() { |
|
793 |
return consumed; |
|
794 |
} |
|
795 |
||
796 |
/* |
|
35667 | 797 |
* <b>NOTE:</b> The {@code Event} class is obsolete and is |
21278 | 798 |
* available only for backwards compatibility. It has been replaced |
35667 | 799 |
* by the {@code AWTEvent} class and its subclasses. |
2 | 800 |
* <p> |
801 |
* Returns the integer key-code associated with the key in this event, |
|
802 |
* as described in java.awt.Event. |
|
803 |
*/ |
|
804 |
static int getOldEventKey(KeyEvent e) { |
|
805 |
int keyCode = e.getKeyCode(); |
|
806 |
for (int i = 0; i < actionKeyCodes.length; i++) { |
|
807 |
if (actionKeyCodes[i][0] == keyCode) { |
|
808 |
return actionKeyCodes[i][1]; |
|
809 |
} |
|
810 |
} |
|
811 |
return (int)e.getKeyChar(); |
|
812 |
} |
|
813 |
||
814 |
/* |
|
35667 | 815 |
* <b>NOTE:</b> The {@code Event} class is obsolete and is |
21278 | 816 |
* available only for backwards compatibility. It has been replaced |
35667 | 817 |
* by the {@code AWTEvent} class and its subclasses. |
2 | 818 |
* <p> |
819 |
* Returns a new KeyEvent char which corresponds to the int key |
|
820 |
* of this old event. |
|
821 |
*/ |
|
822 |
char getKeyEventChar() { |
|
823 |
for (int i = 0; i < actionKeyCodes.length; i++) { |
|
824 |
if (actionKeyCodes[i][1] == key) { |
|
825 |
return KeyEvent.CHAR_UNDEFINED; |
|
826 |
} |
|
827 |
} |
|
828 |
return (char)key; |
|
829 |
} |
|
830 |
||
831 |
/** |
|
35667 | 832 |
* <b>NOTE:</b> The {@code Event} class is obsolete and is |
21278 | 833 |
* available only for backwards compatibility. It has been replaced |
35667 | 834 |
* by the {@code AWTEvent} class and its subclasses. |
2 | 835 |
* <p> |
35667 | 836 |
* Returns a string representing the state of this {@code Event}. |
2 | 837 |
* This method is intended to be used only for debugging purposes, and the |
838 |
* content and format of the returned string may vary between |
|
839 |
* implementations. The returned string may be empty but may not be |
|
35667 | 840 |
* {@code null}. |
2 | 841 |
* |
842 |
* @return the parameter string of this event |
|
843 |
*/ |
|
844 |
protected String paramString() { |
|
845 |
String str = "id=" + id + ",x=" + x + ",y=" + y; |
|
846 |
if (key != 0) { |
|
847 |
str += ",key=" + key; |
|
848 |
} |
|
849 |
if (shiftDown()) { |
|
850 |
str += ",shift"; |
|
851 |
} |
|
852 |
if (controlDown()) { |
|
853 |
str += ",control"; |
|
854 |
} |
|
855 |
if (metaDown()) { |
|
856 |
str += ",meta"; |
|
857 |
} |
|
858 |
if (target != null) { |
|
859 |
str += ",target=" + target; |
|
860 |
} |
|
861 |
if (arg != null) { |
|
862 |
str += ",arg=" + arg; |
|
863 |
} |
|
864 |
return str; |
|
865 |
} |
|
866 |
||
867 |
/** |
|
35667 | 868 |
* <b>NOTE:</b> The {@code Event} class is obsolete and is |
21278 | 869 |
* available only for backwards compatibility. It has been replaced |
35667 | 870 |
* by the {@code AWTEvent} class and its subclasses. |
2 | 871 |
* <p> |
872 |
* Returns a representation of this event's values as a string. |
|
873 |
* @return a string that represents the event and the values |
|
874 |
* of its member fields. |
|
875 |
* @see java.awt.Event#paramString |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
23010
diff
changeset
|
876 |
* @since 1.1 |
2 | 877 |
*/ |
878 |
public String toString() { |
|
879 |
return getClass().getName() + "[" + paramString() + "]"; |
|
880 |
} |
|
881 |
} |