KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > Event


1 /*
2  * @(#)Event.java 1.75 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package java.awt;
8
9 import java.awt.event.*;
10 import java.io.*;
11
12 /**
13  * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
14  * available only for backwards compatilibility. It has been replaced
15  * by the <code>AWTEvent</code> class and its subclasses.
16  * <p>
17  * <code>Event</code> is a platform-independent class that
18  * encapsulates events from the platform's Graphical User
19  * Interface in the Java&nbsp;1.0 event model. In Java&nbsp;1.1
20  * and later versions, the <code>Event</code> class is maintained
21  * only for backwards compatibilty. The information in this
22  * class description is provided to assist programmers in
23  * converting Java&nbsp;1.0 programs to the new event model.
24  * <p>
25  * In the Java&nbsp;1.0 event model, an event contains an
26  * {@link Event#id} field
27  * that indicates what type of event it is and which other
28  * <code>Event</code> variables are relevant for the event.
29  * <p>
30  * For keyboard events, {@link Event#key}
31  * contains a value indicating which key was activated, and
32  * {@link Event#modifiers} contains the
33  * modifiers for that event. For the KEY_PRESS and KEY_RELEASE
34  * event ids, the value of <code>key</code> is the unicode
35  * character code for the key. For KEY_ACTION and
36  * KEY_ACTION_RELEASE, the value of <code>key</code> is
37  * one of the defined action-key identifiers in the
38  * <code>Event</code> class (<code>PGUP</code>,
39  * <code>PGDN</code>, <code>F1</code>, <code>F2</code>, etc).
40  *
41  * @version 1.75 12/19/03
42  * @author Sami Shaio
43  * @since JDK1.0
44  */

45 public class Event implements java.io.Serializable JavaDoc {
46     private transient long data;
47
48     /* Modifier constants */
49
50     /**
51      * This flag indicates that the Shift key was down when the event
52      * occurred.
53      */

54     public static final int SHIFT_MASK = 1 << 0;
55
56     /**
57      * This flag indicates that the Control key was down when the event
58      * occurred.
59      */

60     public static final int CTRL_MASK = 1 << 1;
61
62     /**
63      * This flag indicates that the Meta key was down when the event
64      * occurred. For mouse events, this flag indicates that the right
65      * button was pressed or released.
66      */

67     public static final int META_MASK = 1 << 2;
68
69     /**
70      * This flag indicates that the Alt key was down when
71      * the event occurred. For mouse events, this flag indicates that the
72      * middle mouse button was pressed or released.
73      */

74     public static final int ALT_MASK = 1 << 3;
75
76     /* Action keys */
77
78     /**
79      * The Home key, a non-ASCII action key.
80      */

81     public static final int HOME = 1000;
82
83     /**
84      * The End key, a non-ASCII action key.
85      */

86     public static final int END = 1001;
87
88     /**
89      * The Page Up key, a non-ASCII action key.
90      */

91     public static final int PGUP = 1002;
92
93     /**
94      * The Page Down key, a non-ASCII action key.
95      */

96     public static final int PGDN = 1003;
97
98     /**
99      * The Up Arrow key, a non-ASCII action key.
100      */

101     public static final int UP = 1004;
102
103     /**
104      * The Down Arrow key, a non-ASCII action key.
105      */

106     public static final int DOWN = 1005;
107
108     /**
109      * The Left Arrow key, a non-ASCII action key.
110      */

111     public static final int LEFT = 1006;
112
113     /**
114      * The Right Arrow key, a non-ASCII action key.
115      */

116     public static final int RIGHT = 1007;
117
118     /**
119      * The F1 function key, a non-ASCII action key.
120      */

121     public static final int F1 = 1008;
122
123     /**
124      * The F2 function key, a non-ASCII action key.
125      */

126     public static final int F2 = 1009;
127
128     /**
129      * The F3 function key, a non-ASCII action key.
130      */

131     public static final int F3 = 1010;
132
133     /**
134      * The F4 function key, a non-ASCII action key.
135      */

136     public static final int F4 = 1011;
137
138     /**
139      * The F5 function key, a non-ASCII action key.
140      */

141     public static final int F5 = 1012;
142
143     /**
144      * The F6 function key, a non-ASCII action key.
145      */

146     public static final int F6 = 1013;
147
148     /**
149      * The F7 function key, a non-ASCII action key.
150      */

151     public static final int F7 = 1014;
152
153     /**
154      * The F8 function key, a non-ASCII action key.
155      */

156     public static final int F8 = 1015;
157
158     /**
159      * The F9 function key, a non-ASCII action key.
160      */

161     public static final int F9 = 1016;
162
163     /**
164      * The F10 function key, a non-ASCII action key.
165      */

166     public static final int F10 = 1017;
167
168     /**
169      * The F11 function key, a non-ASCII action key.
170      */

171     public static final int F11 = 1018;
172
173     /**
174      * The F12 function key, a non-ASCII action key.
175      */

176     public static final int F12 = 1019;
177
178     /**
179      * The Print Screen key, a non-ASCII action key.
180      */

181     public static final int PRINT_SCREEN = 1020;
182
183     /**
184      * The Scroll Lock key, a non-ASCII action key.
185      */

186     public static final int SCROLL_LOCK = 1021;
187
188     /**
189      * The Caps Lock key, a non-ASCII action key.
190      */

191     public static final int CAPS_LOCK = 1022;
192
193     /**
194      * The Num Lock key, a non-ASCII action key.
195      */

196     public static final int NUM_LOCK = 1023;
197
198     /**
199      * The Pause key, a non-ASCII action key.
200      */

201     public static final int PAUSE = 1024;
202
203     /**
204      * The Insert key, a non-ASCII action key.
205      */

206     public static final int INSERT = 1025;
207
208     /* Non-action keys */
209
210     /**
211      * The Enter key.
212      */

213     public static final int ENTER = '\n';
214
215     /**
216      * The BackSpace key.
217      */

218     public static final int BACK_SPACE = '\b';
219
220     /**
221      * The Tab key.
222      */

223     public static final int TAB = '\t';
224
225     /**
226      * The Escape key.
227      */

228     public static final int ESCAPE = 27;
229
230     /**
231      * The Delete key.
232      */

233     public static final int DELETE = 127;
234
235
236     /* Base for all window events. */
237     private static final int WINDOW_EVENT = 200;
238
239     /**
240      * The user has asked the window manager to kill the window.
241      */

242     public static final int WINDOW_DESTROY = 1 + WINDOW_EVENT;
243
244     /**
245      * The user has asked the window manager to expose the window.
246      */

247     public static final int WINDOW_EXPOSE = 2 + WINDOW_EVENT;
248
249     /**
250      * The user has asked the window manager to iconify the window.
251      */

252     public static final int WINDOW_ICONIFY = 3 + WINDOW_EVENT;
253
254     /**
255      * The user has asked the window manager to de-iconify the window.
256      */

257     public static final int WINDOW_DEICONIFY = 4 + WINDOW_EVENT;
258
259     /**
260      * The user has asked the window manager to move the window.
261      */

262     public static final int WINDOW_MOVED = 5 + WINDOW_EVENT;
263
264     /* Base for all keyboard events. */
265     private static final int KEY_EVENT = 400;
266
267     /**
268      * The user has pressed a normal key.
269      */

270     public static final int KEY_PRESS = 1 + KEY_EVENT;
271
272     /**
273      * The user has released a normal key.
274      */

275     public static final int KEY_RELEASE = 2 + KEY_EVENT;
276
277     /**
278      * The user has pressed a non-ASCII <em>action</em> key.
279      * The <code>key</code> field contains a value that indicates
280      * that the event occurred on one of the action keys, which
281      * comprise the 12 function keys, the arrow (cursor) keys,
282      * Page Up, Page Down, Home, End, Print Screen, Scroll Lock,
283      * Caps Lock, Num Lock, Pause, and Insert.
284      */

285     public static final int KEY_ACTION = 3 + KEY_EVENT;
286
287     /**
288      * The user has released a non-ASCII <em>action</em> key.
289      * The <code>key</code> field contains a value that indicates
290      * that the event occurred on one of the action keys, which
291      * comprise the 12 function keys, the arrow (cursor) keys,
292      * Page Up, Page Down, Home, End, Print Screen, Scroll Lock,
293      * Caps Lock, Num Lock, Pause, and Insert.
294      */

295     public static final int KEY_ACTION_RELEASE = 4 + KEY_EVENT;
296
297     /* Base for all mouse events. */
298     private static final int MOUSE_EVENT = 500;
299
300     /**
301      * The user has pressed the mouse button. The <code>ALT_MASK</code>
302      * flag indicates that the middle button has been pressed.
303      * The <code>META_MASK</code>flag indicates that the
304      * right button has been pressed.
305      * @see java.awt.Event#ALT_MASK
306      * @see java.awt.Event#META_MASK
307      */

308     public static final int MOUSE_DOWN = 1 + MOUSE_EVENT;
309
310     /**
311      * The user has released the mouse button. The <code>ALT_MASK</code>
312      * flag indicates that the middle button has been released.
313      * The <code>META_MASK</code>flag indicates that the
314      * right button has been released.
315      * @see java.awt.Event#ALT_MASK
316      * @see java.awt.Event#META_MASK
317      */

318     public static final int MOUSE_UP = 2 + MOUSE_EVENT;
319
320     /**
321      * The mouse has moved with no button pressed.
322      */

323     public static final int MOUSE_MOVE = 3 + MOUSE_EVENT;
324
325     /**
326      * The mouse has entered a component.
327      */

328     public static final int MOUSE_ENTER = 4 + MOUSE_EVENT;
329
330     /**
331      * The mouse has exited a component.
332      */

333     public static final int MOUSE_EXIT = 5 + MOUSE_EVENT;
334
335     /**
336      * The user has moved the mouse with a button pressed. The
337      * <code>ALT_MASK</code> flag indicates that the middle
338      * button is being pressed. The <code>META_MASK</code> flag indicates
339      * that the right button is being pressed.
340      * @see java.awt.Event#ALT_MASK
341      * @see java.awt.Event#META_MASK
342      */

343     public static final int MOUSE_DRAG = 6 + MOUSE_EVENT;
344
345
346     /* Scrolling events */
347     private static final int SCROLL_EVENT = 600;
348
349     /**
350      * The user has activated the <em>line up</em>
351      * area of a scroll bar.
352      */

353     public static final int SCROLL_LINE_UP = 1 + SCROLL_EVENT;
354
355     /**
356      * The user has activated the <em>line down</em>
357      * area of a scroll bar.
358      */

359     public static final int SCROLL_LINE_DOWN = 2 + SCROLL_EVENT;
360
361     /**
362      * The user has activated the <em>page up</em>
363      * area of a scroll bar.
364      */

365     public static final int SCROLL_PAGE_UP = 3 + SCROLL_EVENT;
366
367     /**
368      * The user has activated the <em>page down</em>
369      * area of a scroll bar.
370      */

371     public static final int SCROLL_PAGE_DOWN = 4 + SCROLL_EVENT;
372
373     /**
374      * The user has moved the bubble (thumb) in a scroll bar,
375      * moving to an "absolute" position, rather than to
376      * an offset from the last postion.
377      */

378     public static final int SCROLL_ABSOLUTE = 5 + SCROLL_EVENT;
379
380     /**
381      * The scroll begin event.
382      */

383     public static final int SCROLL_BEGIN = 6 + SCROLL_EVENT;
384
385     /**
386      * The scroll end event.
387      */

388     public static final int SCROLL_END = 7 + SCROLL_EVENT;
389
390     /* List Events */
391     private static final int LIST_EVENT = 700;
392
393     /**
394      * An item in a list has been selected.
395      */

396     public static final int LIST_SELECT = 1 + LIST_EVENT;
397
398     /**
399      * An item in a list has been deselected.
400      */

401     public static final int LIST_DESELECT = 2 + LIST_EVENT;
402
403     /* Misc Event */
404     private static final int MISC_EVENT = 1000;
405
406     /**
407      * This event indicates that the user wants some action to occur.
408      */

409     public static final int ACTION_EVENT = 1 + MISC_EVENT;
410
411     /**
412      * A file loading event.
413      */

414     public static final int LOAD_FILE = 2 + MISC_EVENT;
415
416     /**
417      * A file saving event.
418      */

419     public static final int SAVE_FILE = 3 + MISC_EVENT;
420
421     /**
422      * A component gained the focus.
423      */

424     public static final int GOT_FOCUS = 4 + MISC_EVENT;
425
426     /**
427      * A component lost the focus.
428      */

429     public static final int LOST_FOCUS = 5 + MISC_EVENT;
430
431     /**
432      * The target component. This indicates the component over which the
433      * event occurred or with which the event is associated.
434      * This object has been replaced by AWTEvent.getSource()
435      *
436      * @serial
437      * @see java.awt.AWTEvent#getSource()
438      */

439     public Object JavaDoc target;
440
441     /**
442      * The time stamp.
443      * Replaced by InputEvent.getWhen().
444      *
445      * @serial
446      * @see java.awt.event.InputEvent#getWhen()
447      */

448     public long when;
449
450     /**
451      * Indicates which type of event the event is, and which
452      * other <code>Event</code> variables are relevant for the event.
453      * This has been replaced by AWTEvent.getID()
454      *
455      * @serial
456      * @see java.awt.AWTEvent#getID()
457      */

458     public int id;
459
460     /**
461      * The <i>x</i> coordinate of the event.
462      * Replaced by MouseEvent.getX()
463      *
464      * @serial
465      * @see java.awt.event.MouseEvent#getX()
466      */

467     public int x;
468
469     /**
470      * The <i>y</i> coordinate of the event.
471      * Replaced by MouseEvent.getY()
472      *
473      * @serial
474      * @see java.awt.event.MouseEvent#getY()
475      */

476     public int y;
477
478     /**
479      * The key code of the key that was pressed in a keyboard event.
480      * This has been replaced by KeyEvent.getKeyCode()
481      *
482      * @serial
483      * @see java.awt.event.KeyEvent#getKeyCode()
484      */

485     public int key;
486
487     /**
488      * The key character that was pressed in a keyboard event.
489      */

490 // public char keyChar;
491

492     /**
493      * The state of the modifier keys.
494      * This is replaced with InputEvent.getModifiers()
495      * In java 1.1 MouseEvent and KeyEvent are subclasses
496      * of InputEvent.
497      *
498      * @serial
499      * @see java.awt.event.InputEvent#getModifiers()
500      */

501     public int modifiers;
502
503     /**
504      * For <code>MOUSE_DOWN</code> events, this field indicates the
505      * number of consecutive clicks. For other events, its value is
506      * <code>0</code>.
507      * This field has been replaced by MouseEvent.getClickCount().
508      *
509      * @serial
510      * @see java.awt.event.MouseEvent#getClickCount().
511      */

512     public int clickCount;
513
514     /**
515      * An arbitrary argument of the event. The value of this field
516      * depends on the type of event.
517      * <code>arg</code> has been replaced by event specific property.
518      *
519      * @serial
520      */

521     public Object JavaDoc arg;
522
523     /**
524      * The next event. This field is set when putting events into a
525      * linked list.
526      * This has been replaced by EventQueue.
527      *
528      * @serial
529      * @see java.awt.EventQueue
530      */

531     public Event JavaDoc evt;
532
533     /* table for mapping old Event action keys to KeyEvent virtual keys. */
534     private static final int actionKeyCodes[][] = {
535     /* virtual key action key */
536         { KeyEvent.VK_HOME, Event.HOME },
537         { KeyEvent.VK_END, Event.END },
538         { KeyEvent.VK_PAGE_UP, Event.PGUP },
539         { KeyEvent.VK_PAGE_DOWN, Event.PGDN },
540         { KeyEvent.VK_UP, Event.UP },
541         { KeyEvent.VK_DOWN, Event.DOWN },
542         { KeyEvent.VK_LEFT, Event.LEFT },
543         { KeyEvent.VK_RIGHT, Event.RIGHT },
544         { KeyEvent.VK_F1, Event.F1 },
545         { KeyEvent.VK_F2, Event.F2 },
546         { KeyEvent.VK_F3, Event.F3 },
547         { KeyEvent.VK_F4, Event.F4 },
548         { KeyEvent.VK_F5, Event.F5 },
549         { KeyEvent.VK_F6, Event.F6 },
550         { KeyEvent.VK_F7, Event.F7 },
551         { KeyEvent.VK_F8, Event.F8 },
552         { KeyEvent.VK_F9, Event.F9 },
553         { KeyEvent.VK_F10, Event.F10 },
554         { KeyEvent.VK_F11, Event.F11 },
555         { KeyEvent.VK_F12, Event.F12 },
556         { KeyEvent.VK_PRINTSCREEN, Event.PRINT_SCREEN },
557         { KeyEvent.VK_SCROLL_LOCK, Event.SCROLL_LOCK },
558         { KeyEvent.VK_CAPS_LOCK, Event.CAPS_LOCK },
559         { KeyEvent.VK_NUM_LOCK, Event.NUM_LOCK },
560         { KeyEvent.VK_PAUSE, Event.PAUSE },
561         { KeyEvent.VK_INSERT, Event.INSERT }
562     };
563
564     /**
565      * This field controls whether or not the event is sent back
566      * down to the peer once the target has processed it -
567      * false means it's sent to the peer, true means it's not.
568      *
569      * @serial
570      * @see #isConsumed()
571      */

572     private boolean consumed = false;
573
574     /*
575      * JDK 1.1 serialVersionUID
576      */

577     private static final long serialVersionUID = 5488922509400504703L;
578
579     static {
580         /* ensure that the necessary native libraries are loaded */
581     Toolkit.loadLibraries();
582         if (!GraphicsEnvironment.isHeadless()) {
583             initIDs();
584         }
585     }
586
587     /**
588      * Initialize JNI field and method IDs for fields that may be
589        accessed from C.
590      */

591     private static native void initIDs();
592
593     /**
594      * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
595      * available only for backwards compatilibility. It has been replaced
596      * by the <code>AWTEvent</code> class and its subclasses.
597      * <p>
598      * Creates an instance of <code>Event</code> with the specified target
599      * component, time stamp, event type, <i>x</i> and <i>y</i>
600      * coordinates, keyboard key, state of the modifier keys, and
601      * argument.
602      * @param target the target component.
603      * @param when the time stamp.
604      * @param id the event type.
605      * @param x the <i>x</i> coordinate.
606      * @param y the <i>y</i> coordinate.
607      * @param key the key pressed in a keyboard event.
608      * @param modifiers the state of the modifier keys.
609      * @param arg the specified argument.
610      */

611     public Event(Object JavaDoc target, long when, int id, int x, int y, int key,
612          int modifiers, Object JavaDoc arg) {
613     this.target = target;
614     this.when = when;
615     this.id = id;
616     this.x = x;
617     this.y = y;
618     this.key = key;
619     this.modifiers = modifiers;
620     this.arg = arg;
621     this.data = 0;
622     this.clickCount = 0;
623         switch(id) {
624           case ACTION_EVENT:
625           case WINDOW_DESTROY:
626           case WINDOW_ICONIFY:
627           case WINDOW_DEICONIFY:
628           case WINDOW_MOVED:
629           case SCROLL_LINE_UP:
630           case SCROLL_LINE_DOWN:
631           case SCROLL_PAGE_UP:
632           case SCROLL_PAGE_DOWN:
633           case SCROLL_ABSOLUTE:
634           case SCROLL_BEGIN:
635           case SCROLL_END:
636           case LIST_SELECT:
637           case LIST_DESELECT:
638             consumed = true; // these types are not passed back to peer
639
break;
640           default:
641         }
642     }
643
644     /**
645      * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
646      * available only for backwards compatilibility. It has been replaced
647      * by the <code>AWTEvent</code> class and its subclasses.
648      * <p>
649      * Creates an instance of <code>Event</code>, with the specified target
650      * component, time stamp, event type, <i>x</i> and <i>y</i>
651      * coordinates, keyboard key, state of the modifier keys, and an
652      * argument set to <code>null</code>.
653      * @param target the target component.
654      * @param when the time stamp.
655      * @param id the event type.
656      * @param x the <i>x</i> coordinate.
657      * @param y the <i>y</i> coordinate.
658      * @param key the key pressed in a keyboard event.
659      * @param modifiers the state of the modifier keys.
660      */

661     public Event(Object JavaDoc target, long when, int id, int x, int y, int key, int modifiers) {
662     this(target, when, id, x, y, key, modifiers, null);
663     }
664
665     /**
666      * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
667      * available only for backwards compatilibility. It has been replaced
668      * by the <code>AWTEvent</code> class and its subclasses.
669      * <p>
670      * Creates an instance of <code>Event</code> with the specified
671      * target component, event type, and argument.
672      * @param target the target component.
673      * @param id the event type.
674      * @param arg the specified argument.
675      */

676     public Event(Object JavaDoc target, int id, Object JavaDoc arg) {
677     this(target, 0, id, 0, 0, 0, 0, arg);
678     }
679
680     /**
681      * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
682      * available only for backwards compatilibility. It has been replaced
683      * by the <code>AWTEvent</code> class and its subclasses.
684      * <p>
685      * Translates this event so that its <i>x</i> and <i>y</i>
686      * coordinates are increased by <i>dx</i> and <i>dy</i>,
687      * respectively.
688      * <p>
689      * This method translates an event relative to the given component.
690      * This involves, at a minimum, translating the coordinates into the
691      * local coordinate system of the given component. It may also involve
692      * translating a region in the case of an expose event.
693      * @param dx the distance to translate the <i>x</i> coordinate.
694      * @param dy the distance to translate the <i>y</i> coordinate.
695      */

696     public void translate(int dx, int dy) {
697     this.x += dx;
698     this.y += dy;
699     }
700
701     /**
702      * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
703      * available only for backwards compatilibility. It has been replaced
704      * by the <code>AWTEvent</code> class and its subclasses.
705      * <p>
706      * Checks if the Shift key is down.
707      * @return <code>true</code> if the key is down;
708      * <code>false</code> otherwise.
709      * @see java.awt.Event#modifiers
710      * @see java.awt.Event#controlDown
711      * @see java.awt.Event#metaDown
712      */

713     public boolean shiftDown() {
714     return (modifiers & SHIFT_MASK) != 0;
715     }
716
717     /**
718      * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
719      * available only for backwards compatilibility. It has been replaced
720      * by the <code>AWTEvent</code> class and its subclasses.
721      * <p>
722      * Checks if the Control key is down.
723      * @return <code>true</code> if the key is down;
724      * <code>false</code> otherwise.
725      * @see java.awt.Event#modifiers
726      * @see java.awt.Event#shiftDown
727      * @see java.awt.Event#metaDown
728      */

729     public boolean controlDown() {
730     return (modifiers & CTRL_MASK) != 0;
731     }
732
733     /**
734      * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
735      * available only for backwards compatilibility. It has been replaced
736      * by the <code>AWTEvent</code> class and its subclasses.
737      * <p>
738      * Checks if the Meta key is down.
739      *
740      * @return <code>true</code> if the key is down;
741      * <code>false</code> otherwise.
742      * @see java.awt.Event#modifiers
743      * @see java.awt.Event#shiftDown
744      * @see java.awt.Event#controlDown
745      */

746     public boolean metaDown() {
747     return (modifiers & META_MASK) != 0;
748     }
749
750     /**
751      * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
752      * available only for backwards compatilibility. It has been replaced
753      * by the <code>AWTEvent</code> class and its subclasses.
754      */

755     void consume() {
756         switch(id) {
757           case KEY_PRESS:
758           case KEY_RELEASE:
759           case KEY_ACTION:
760           case KEY_ACTION_RELEASE:
761               consumed = true;
762               break;
763           default:
764               // event type cannot be consumed
765
}
766     }
767
768     /**
769      * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
770      * available only for backwards compatilibility. It has been replaced
771      * by the <code>AWTEvent</code> class and its subclasses.
772      */

773     boolean isConsumed() {
774         return consumed;
775     }
776
777     /*
778      * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
779      * available only for backwards compatilibility. It has been replaced
780      * by the <code>AWTEvent</code> class and its subclasses.
781      * <p>
782      * Returns the integer key-code associated with the key in this event,
783      * as described in java.awt.Event.
784      */

785     static int getOldEventKey(KeyEvent e) {
786         int keyCode = e.getKeyCode();
787         for (int i = 0; i < actionKeyCodes.length; i++) {
788             if (actionKeyCodes[i][0] == keyCode) {
789                 return actionKeyCodes[i][1];
790             }
791         }
792         return (int)e.getKeyChar();
793     }
794
795     /*
796      * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
797      * available only for backwards compatilibility. It has been replaced
798      * by the <code>AWTEvent</code> class and its subclasses.
799      * <p>
800      * Returns a new KeyEvent char which corresponds to the int key
801      * of this old event.
802      */

803     char getKeyEventChar() {
804        for (int i = 0; i < actionKeyCodes.length; i++) {
805             if (actionKeyCodes[i][1] == key) {
806                 return KeyEvent.CHAR_UNDEFINED;
807             }
808        }
809        return (char)key;
810     }
811
812     /**
813      * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
814      * available only for backwards compatilibility. It has been replaced
815      * by the <code>AWTEvent</code> class and its subclasses.
816      * <p>
817      * Returns a string representing the state of this <code>Event</code>.
818      * This method is intended to be used only for debugging purposes, and the
819      * content and format of the returned string may vary between
820      * implementations. The returned string may be empty but may not be
821      * <code>null</code>.
822      *
823      * @return the parameter string of this event
824      */

825     protected String JavaDoc paramString() {
826     String JavaDoc str = "id=" + id + ",x=" + x + ",y=" + y;
827     if (key != 0) {
828         str += ",key=" + key;
829     }
830     if (shiftDown()) {
831         str += ",shift";
832     }
833     if (controlDown()) {
834         str += ",control";
835     }
836     if (metaDown()) {
837         str += ",meta";
838     }
839     if (target != null) {
840         str += ",target=" + target;
841     }
842     if (arg != null) {
843         str += ",arg=" + arg;
844     }
845     return str;
846     }
847
848     /**
849      * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
850      * available only for backwards compatilibility. It has been replaced
851      * by the <code>AWTEvent</code> class and its subclasses.
852      * <p>
853      * Returns a representation of this event's values as a string.
854      * @return a string that represents the event and the values
855      * of its member fields.
856      * @see java.awt.Event#paramString
857      * @since JDK1.1
858      */

859     public String JavaDoc toString() {
860     return getClass().getName() + "[" + paramString() + "]";
861     }
862 }
863
Popular Tags