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