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 package java.awt;
26
27 import java.awt.event.*;
28 import java.io.*;
29
30 /**
31 * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
32 * available only for backwards compatibility. It has been replaced
33 * by the <code>AWTEvent</code> class and its subclasses.
34 * <p>
35 * <code>Event</code> is a platform-independent class that
36 * encapsulates events from the platform's Graphical User
37 * Interface in the Java 1.0 event model. In Java 1.1
38 * and later versions, the <code>Event</code> class is maintained
39 * only for backwards compatibility. The information in this
40 * class description is provided to assist programmers in
41 * converting Java 1.0 programs to the new event model.
42 * <p>
43 * In the Java 1.0 event model, an event contains an
44 * {@link Event#id} field
45 * that indicates what type of event it is and which other
46 * <code>Event</code> variables are relevant for the event.
47 * <p>
48 * For keyboard events, {@link Event#key}
49 * contains a value indicating which key was activated, and
50 * {@link Event#modifiers} contains the
51 * modifiers for that event. For the KEY_PRESS and KEY_RELEASE
52 * event ids, the value of <code>key</code> is the unicode
53 * character code for the key. For KEY_ACTION and
54 * KEY_ACTION_RELEASE, the value of <code>key</code> is
55 * one of the defined action-key identifiers in the
56 * <code>Event</code> class (<code>PGUP</code>,
57 * <code>PGDN</code>, <code>F1</code>, <code>F2</code>, etc).
58 *
59 * @author Sami Shaio
60 * @since 1.0
61 */
62 public class Event implements java.io.Serializable {
63 private transient long data;
64
65 /* Modifier constants */
66
67 /**
68 * This flag indicates that the Shift key was down when the event
69 * occurred.
70 */
71 public static final int SHIFT_MASK = 1 << 0;
72
73 /**
74 * This flag indicates that the Control key was down when the event
75 * occurred.
76 */
77 public static final int CTRL_MASK = 1 << 1;
276 /**
277 * The user has asked the window manager to move the window.
278 */
279 public static final int WINDOW_MOVED = 5 + WINDOW_EVENT;
280
281 /* Base for all keyboard events. */
282 private static final int KEY_EVENT = 400;
283
284 /**
285 * The user has pressed a normal key.
286 */
287 public static final int KEY_PRESS = 1 + KEY_EVENT;
288
289 /**
290 * The user has released a normal key.
291 */
292 public static final int KEY_RELEASE = 2 + KEY_EVENT;
293
294 /**
295 * The user has pressed a non-ASCII <em>action</em> key.
296 * The <code>key</code> field contains a value that indicates
297 * that the event occurred on one of the action keys, which
298 * comprise the 12 function keys, the arrow (cursor) keys,
299 * Page Up, Page Down, Home, End, Print Screen, Scroll Lock,
300 * Caps Lock, Num Lock, Pause, and Insert.
301 */
302 public static final int KEY_ACTION = 3 + KEY_EVENT;
303
304 /**
305 * The user has released a non-ASCII <em>action</em> key.
306 * The <code>key</code> field contains a value that indicates
307 * that the event occurred on one of the action keys, which
308 * comprise the 12 function keys, the arrow (cursor) keys,
309 * Page Up, Page Down, Home, End, Print Screen, Scroll Lock,
310 * Caps Lock, Num Lock, Pause, and Insert.
311 */
312 public static final int KEY_ACTION_RELEASE = 4 + KEY_EVENT;
313
314 /* Base for all mouse events. */
315 private static final int MOUSE_EVENT = 500;
316
317 /**
318 * The user has pressed the mouse button. The <code>ALT_MASK</code>
319 * flag indicates that the middle button has been pressed.
320 * The <code>META_MASK</code>flag indicates that the
321 * right button has been pressed.
322 * @see java.awt.Event#ALT_MASK
323 * @see java.awt.Event#META_MASK
324 */
325 public static final int MOUSE_DOWN = 1 + MOUSE_EVENT;
326
327 /**
328 * The user has released the mouse button. The <code>ALT_MASK</code>
329 * flag indicates that the middle button has been released.
330 * The <code>META_MASK</code>flag indicates that the
331 * right button has been released.
332 * @see java.awt.Event#ALT_MASK
333 * @see java.awt.Event#META_MASK
334 */
335 public static final int MOUSE_UP = 2 + MOUSE_EVENT;
336
337 /**
338 * The mouse has moved with no button pressed.
339 */
340 public static final int MOUSE_MOVE = 3 + MOUSE_EVENT;
341
342 /**
343 * The mouse has entered a component.
344 */
345 public static final int MOUSE_ENTER = 4 + MOUSE_EVENT;
346
347 /**
348 * The mouse has exited a component.
349 */
350 public static final int MOUSE_EXIT = 5 + MOUSE_EVENT;
351
352 /**
353 * The user has moved the mouse with a button pressed. The
354 * <code>ALT_MASK</code> flag indicates that the middle
355 * button is being pressed. The <code>META_MASK</code> flag indicates
356 * that the right button is being pressed.
357 * @see java.awt.Event#ALT_MASK
358 * @see java.awt.Event#META_MASK
359 */
360 public static final int MOUSE_DRAG = 6 + MOUSE_EVENT;
361
362
363 /* Scrolling events */
364 private static final int SCROLL_EVENT = 600;
365
366 /**
367 * The user has activated the <em>line up</em>
368 * area of a scroll bar.
369 */
370 public static final int SCROLL_LINE_UP = 1 + SCROLL_EVENT;
371
372 /**
373 * The user has activated the <em>line down</em>
374 * area of a scroll bar.
375 */
449 * The target component. This indicates the component over which the
450 * event occurred or with which the event is associated.
451 * This object has been replaced by AWTEvent.getSource()
452 *
453 * @serial
454 * @see java.awt.AWTEvent#getSource()
455 */
456 public Object target;
457
458 /**
459 * The time stamp.
460 * Replaced by InputEvent.getWhen().
461 *
462 * @serial
463 * @see java.awt.event.InputEvent#getWhen()
464 */
465 public long when;
466
467 /**
468 * Indicates which type of event the event is, and which
469 * other <code>Event</code> variables are relevant for the event.
470 * This has been replaced by AWTEvent.getID()
471 *
472 * @serial
473 * @see java.awt.AWTEvent#getID()
474 */
475 public int id;
476
477 /**
478 * The <i>x</i> coordinate of the event.
479 * Replaced by MouseEvent.getX()
480 *
481 * @serial
482 * @see java.awt.event.MouseEvent#getX()
483 */
484 public int x;
485
486 /**
487 * The <i>y</i> coordinate of the event.
488 * Replaced by MouseEvent.getY()
489 *
501 */
502 public int key;
503
504 /**
505 * The key character that was pressed in a keyboard event.
506 */
507 // public char keyChar;
508
509 /**
510 * The state of the modifier keys.
511 * This is replaced with InputEvent.getModifiers()
512 * In java 1.1 MouseEvent and KeyEvent are subclasses
513 * of InputEvent.
514 *
515 * @serial
516 * @see java.awt.event.InputEvent#getModifiers()
517 */
518 public int modifiers;
519
520 /**
521 * For <code>MOUSE_DOWN</code> events, this field indicates the
522 * number of consecutive clicks. For other events, its value is
523 * <code>0</code>.
524 * This field has been replaced by MouseEvent.getClickCount().
525 *
526 * @serial
527 * @see java.awt.event.MouseEvent#getClickCount()
528 */
529 public int clickCount;
530
531 /**
532 * An arbitrary argument of the event. The value of this field
533 * depends on the type of event.
534 * <code>arg</code> has been replaced by event specific property.
535 *
536 * @serial
537 */
538 public Object arg;
539
540 /**
541 * The next event. This field is set when putting events into a
542 * linked list.
543 * This has been replaced by EventQueue.
544 *
545 * @serial
546 * @see java.awt.EventQueue
547 */
548 public Event evt;
549
550 /* table for mapping old Event action keys to KeyEvent virtual keys. */
551 private static final int actionKeyCodes[][] = {
552 /* virtual key action key */
553 { KeyEvent.VK_HOME, Event.HOME },
554 { KeyEvent.VK_END, Event.END },
591 /*
592 * JDK 1.1 serialVersionUID
593 */
594 private static final long serialVersionUID = 5488922509400504703L;
595
596 static {
597 /* ensure that the necessary native libraries are loaded */
598 Toolkit.loadLibraries();
599 if (!GraphicsEnvironment.isHeadless()) {
600 initIDs();
601 }
602 }
603
604 /**
605 * Initialize JNI field and method IDs for fields that may be
606 accessed from C.
607 */
608 private static native void initIDs();
609
610 /**
611 * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
612 * available only for backwards compatibility. It has been replaced
613 * by the <code>AWTEvent</code> class and its subclasses.
614 * <p>
615 * Creates an instance of <code>Event</code> with the specified target
616 * component, time stamp, event type, <i>x</i> and <i>y</i>
617 * coordinates, keyboard key, state of the modifier keys, and
618 * argument.
619 * @param target the target component.
620 * @param when the time stamp.
621 * @param id the event type.
622 * @param x the <i>x</i> coordinate.
623 * @param y the <i>y</i> coordinate.
624 * @param key the key pressed in a keyboard event.
625 * @param modifiers the state of the modifier keys.
626 * @param arg the specified argument.
627 */
628 public Event(Object target, long when, int id, int x, int y, int key,
629 int modifiers, Object arg) {
630 this.target = target;
631 this.when = when;
632 this.id = id;
633 this.x = x;
634 this.y = y;
635 this.key = key;
642 case WINDOW_DESTROY:
643 case WINDOW_ICONIFY:
644 case WINDOW_DEICONIFY:
645 case WINDOW_MOVED:
646 case SCROLL_LINE_UP:
647 case SCROLL_LINE_DOWN:
648 case SCROLL_PAGE_UP:
649 case SCROLL_PAGE_DOWN:
650 case SCROLL_ABSOLUTE:
651 case SCROLL_BEGIN:
652 case SCROLL_END:
653 case LIST_SELECT:
654 case LIST_DESELECT:
655 consumed = true; // these types are not passed back to peer
656 break;
657 default:
658 }
659 }
660
661 /**
662 * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
663 * available only for backwards compatibility. It has been replaced
664 * by the <code>AWTEvent</code> class and its subclasses.
665 * <p>
666 * Creates an instance of <code>Event</code>, with the specified target
667 * component, time stamp, event type, <i>x</i> and <i>y</i>
668 * coordinates, keyboard key, state of the modifier keys, and an
669 * argument set to <code>null</code>.
670 * @param target the target component.
671 * @param when the time stamp.
672 * @param id the event type.
673 * @param x the <i>x</i> coordinate.
674 * @param y the <i>y</i> coordinate.
675 * @param key the key pressed in a keyboard event.
676 * @param modifiers the state of the modifier keys.
677 */
678 public Event(Object target, long when, int id, int x, int y, int key, int modifiers) {
679 this(target, when, id, x, y, key, modifiers, null);
680 }
681
682 /**
683 * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
684 * available only for backwards compatibility. It has been replaced
685 * by the <code>AWTEvent</code> class and its subclasses.
686 * <p>
687 * Creates an instance of <code>Event</code> with the specified
688 * target component, event type, and argument.
689 * @param target the target component.
690 * @param id the event type.
691 * @param arg the specified argument.
692 */
693 public Event(Object target, int id, Object arg) {
694 this(target, 0, id, 0, 0, 0, 0, arg);
695 }
696
697 /**
698 * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
699 * available only for backwards compatibility. It has been replaced
700 * by the <code>AWTEvent</code> class and its subclasses.
701 * <p>
702 * Translates this event so that its <i>x</i> and <i>y</i>
703 * coordinates are increased by <i>dx</i> and <i>dy</i>,
704 * respectively.
705 * <p>
706 * This method translates an event relative to the given component.
707 * This involves, at a minimum, translating the coordinates into the
708 * local coordinate system of the given component. It may also involve
709 * translating a region in the case of an expose event.
710 * @param dx the distance to translate the <i>x</i> coordinate.
711 * @param dy the distance to translate the <i>y</i> coordinate.
712 */
713 public void translate(int dx, int dy) {
714 this.x += dx;
715 this.y += dy;
716 }
717
718 /**
719 * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
720 * available only for backwards compatibility. It has been replaced
721 * by the <code>AWTEvent</code> class and its subclasses.
722 * <p>
723 * Checks if the Shift key is down.
724 * @return <code>true</code> if the key is down;
725 * <code>false</code> otherwise.
726 * @see java.awt.Event#modifiers
727 * @see java.awt.Event#controlDown
728 * @see java.awt.Event#metaDown
729 */
730 public boolean shiftDown() {
731 return (modifiers & SHIFT_MASK) != 0;
732 }
733
734 /**
735 * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
736 * available only for backwards compatibility. It has been replaced
737 * by the <code>AWTEvent</code> class and its subclasses.
738 * <p>
739 * Checks if the Control key is down.
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#metaDown
745 */
746 public boolean controlDown() {
747 return (modifiers & CTRL_MASK) != 0;
748 }
749
750 /**
751 * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
752 * available only for backwards compatibility. It has been replaced
753 * by the <code>AWTEvent</code> class and its subclasses.
754 * <p>
755 * Checks if the Meta key is down.
756 *
757 * @return <code>true</code> if the key is down;
758 * <code>false</code> otherwise.
759 * @see java.awt.Event#modifiers
760 * @see java.awt.Event#shiftDown
761 * @see java.awt.Event#controlDown
762 */
763 public boolean metaDown() {
764 return (modifiers & META_MASK) != 0;
765 }
766
767 /**
768 * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
769 * available only for backwards compatibility. It has been replaced
770 * by the <code>AWTEvent</code> class and its subclasses.
771 */
772 void consume() {
773 switch(id) {
774 case KEY_PRESS:
775 case KEY_RELEASE:
776 case KEY_ACTION:
777 case KEY_ACTION_RELEASE:
778 consumed = true;
779 break;
780 default:
781 // event type cannot be consumed
782 }
783 }
784
785 /**
786 * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
787 * available only for backwards compatibility. It has been replaced
788 * by the <code>AWTEvent</code> class and its subclasses.
789 */
790 boolean isConsumed() {
791 return consumed;
792 }
793
794 /*
795 * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
796 * available only for backwards compatibility. It has been replaced
797 * by the <code>AWTEvent</code> class and its subclasses.
798 * <p>
799 * Returns the integer key-code associated with the key in this event,
800 * as described in java.awt.Event.
801 */
802 static int getOldEventKey(KeyEvent e) {
803 int keyCode = e.getKeyCode();
804 for (int i = 0; i < actionKeyCodes.length; i++) {
805 if (actionKeyCodes[i][0] == keyCode) {
806 return actionKeyCodes[i][1];
807 }
808 }
809 return (int)e.getKeyChar();
810 }
811
812 /*
813 * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
814 * available only for backwards compatibility. It has been replaced
815 * by the <code>AWTEvent</code> class and its subclasses.
816 * <p>
817 * Returns a new KeyEvent char which corresponds to the int key
818 * of this old event.
819 */
820 char getKeyEventChar() {
821 for (int i = 0; i < actionKeyCodes.length; i++) {
822 if (actionKeyCodes[i][1] == key) {
823 return KeyEvent.CHAR_UNDEFINED;
824 }
825 }
826 return (char)key;
827 }
828
829 /**
830 * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
831 * available only for backwards compatibility. It has been replaced
832 * by the <code>AWTEvent</code> class and its subclasses.
833 * <p>
834 * Returns a string representing the state of this <code>Event</code>.
835 * This method is intended to be used only for debugging purposes, and the
836 * content and format of the returned string may vary between
837 * implementations. The returned string may be empty but may not be
838 * <code>null</code>.
839 *
840 * @return the parameter string of this event
841 */
842 protected String paramString() {
843 String str = "id=" + id + ",x=" + x + ",y=" + y;
844 if (key != 0) {
845 str += ",key=" + key;
846 }
847 if (shiftDown()) {
848 str += ",shift";
849 }
850 if (controlDown()) {
851 str += ",control";
852 }
853 if (metaDown()) {
854 str += ",meta";
855 }
856 if (target != null) {
857 str += ",target=" + target;
858 }
859 if (arg != null) {
860 str += ",arg=" + arg;
861 }
862 return str;
863 }
864
865 /**
866 * <b>NOTE:</b> The <code>Event</code> class is obsolete and is
867 * available only for backwards compatibility. It has been replaced
868 * by the <code>AWTEvent</code> class and its subclasses.
869 * <p>
870 * Returns a representation of this event's values as a string.
871 * @return a string that represents the event and the values
872 * of its member fields.
873 * @see java.awt.Event#paramString
874 * @since 1.1
875 */
876 public String toString() {
877 return getClass().getName() + "[" + paramString() + "]";
878 }
879 }
|
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 package java.awt;
26
27 import java.awt.event.*;
28 import java.io.*;
29
30 /**
31 * <b>NOTE:</b> The {@code Event} class is obsolete and is
32 * available only for backwards compatibility. It has been replaced
33 * by the {@code AWTEvent} class and its subclasses.
34 * <p>
35 * {@code Event} is a platform-independent class that
36 * encapsulates events from the platform's Graphical User
37 * Interface in the Java 1.0 event model. In Java 1.1
38 * and later versions, the {@code Event} class is maintained
39 * only for backwards compatibility. The information in this
40 * class description is provided to assist programmers in
41 * converting Java 1.0 programs to the new event model.
42 * <p>
43 * In the Java 1.0 event model, an event contains an
44 * {@link Event#id} field
45 * that indicates what type of event it is and which other
46 * {@code Event} variables are relevant for the event.
47 * <p>
48 * For keyboard events, {@link Event#key}
49 * contains a value indicating which key was activated, and
50 * {@link Event#modifiers} contains the
51 * modifiers for that event. For the KEY_PRESS and KEY_RELEASE
52 * event ids, the value of {@code key} is the unicode
53 * character code for the key. For KEY_ACTION and
54 * KEY_ACTION_RELEASE, the value of {@code key} is
55 * one of the defined action-key identifiers in the
56 * {@code Event} class ({@code PGUP},
57 * {@code PGDN}, {@code F1}, {@code F2}, etc).
58 *
59 * @author Sami Shaio
60 * @since 1.0
61 */
62 public class Event implements java.io.Serializable {
63 private transient long data;
64
65 /* Modifier constants */
66
67 /**
68 * This flag indicates that the Shift key was down when the event
69 * occurred.
70 */
71 public static final int SHIFT_MASK = 1 << 0;
72
73 /**
74 * This flag indicates that the Control key was down when the event
75 * occurred.
76 */
77 public static final int CTRL_MASK = 1 << 1;
276 /**
277 * The user has asked the window manager to move the window.
278 */
279 public static final int WINDOW_MOVED = 5 + WINDOW_EVENT;
280
281 /* Base for all keyboard events. */
282 private static final int KEY_EVENT = 400;
283
284 /**
285 * The user has pressed a normal key.
286 */
287 public static final int KEY_PRESS = 1 + KEY_EVENT;
288
289 /**
290 * The user has released a normal key.
291 */
292 public static final int KEY_RELEASE = 2 + KEY_EVENT;
293
294 /**
295 * The user has pressed a non-ASCII <em>action</em> key.
296 * The {@code key} field contains a value that indicates
297 * that the event occurred on one of the action keys, which
298 * comprise the 12 function keys, the arrow (cursor) keys,
299 * Page Up, Page Down, Home, End, Print Screen, Scroll Lock,
300 * Caps Lock, Num Lock, Pause, and Insert.
301 */
302 public static final int KEY_ACTION = 3 + KEY_EVENT;
303
304 /**
305 * The user has released a non-ASCII <em>action</em> key.
306 * The {@code key} field contains a value that indicates
307 * that the event occurred on one of the action keys, which
308 * comprise the 12 function keys, the arrow (cursor) keys,
309 * Page Up, Page Down, Home, End, Print Screen, Scroll Lock,
310 * Caps Lock, Num Lock, Pause, and Insert.
311 */
312 public static final int KEY_ACTION_RELEASE = 4 + KEY_EVENT;
313
314 /* Base for all mouse events. */
315 private static final int MOUSE_EVENT = 500;
316
317 /**
318 * The user has pressed the mouse button. The {@code ALT_MASK}
319 * flag indicates that the middle button has been pressed.
320 * The {@code META_MASK} flag indicates that the
321 * right button has been pressed.
322 * @see java.awt.Event#ALT_MASK
323 * @see java.awt.Event#META_MASK
324 */
325 public static final int MOUSE_DOWN = 1 + MOUSE_EVENT;
326
327 /**
328 * The user has released the mouse button. The {@code ALT_MASK}
329 * flag indicates that the middle button has been released.
330 * The {@code META_MASK} flag indicates that the
331 * right button has been released.
332 * @see java.awt.Event#ALT_MASK
333 * @see java.awt.Event#META_MASK
334 */
335 public static final int MOUSE_UP = 2 + MOUSE_EVENT;
336
337 /**
338 * The mouse has moved with no button pressed.
339 */
340 public static final int MOUSE_MOVE = 3 + MOUSE_EVENT;
341
342 /**
343 * The mouse has entered a component.
344 */
345 public static final int MOUSE_ENTER = 4 + MOUSE_EVENT;
346
347 /**
348 * The mouse has exited a component.
349 */
350 public static final int MOUSE_EXIT = 5 + MOUSE_EVENT;
351
352 /**
353 * The user has moved the mouse with a button pressed. The
354 * {@code ALT_MASK} flag indicates that the middle
355 * button is being pressed. The {@code META_MASK} flag indicates
356 * that the right button is being pressed.
357 * @see java.awt.Event#ALT_MASK
358 * @see java.awt.Event#META_MASK
359 */
360 public static final int MOUSE_DRAG = 6 + MOUSE_EVENT;
361
362
363 /* Scrolling events */
364 private static final int SCROLL_EVENT = 600;
365
366 /**
367 * The user has activated the <em>line up</em>
368 * area of a scroll bar.
369 */
370 public static final int SCROLL_LINE_UP = 1 + SCROLL_EVENT;
371
372 /**
373 * The user has activated the <em>line down</em>
374 * area of a scroll bar.
375 */
449 * The target component. This indicates the component over which the
450 * event occurred or with which the event is associated.
451 * This object has been replaced by AWTEvent.getSource()
452 *
453 * @serial
454 * @see java.awt.AWTEvent#getSource()
455 */
456 public Object target;
457
458 /**
459 * The time stamp.
460 * Replaced by InputEvent.getWhen().
461 *
462 * @serial
463 * @see java.awt.event.InputEvent#getWhen()
464 */
465 public long when;
466
467 /**
468 * Indicates which type of event the event is, and which
469 * other {@code Event} variables are relevant for the event.
470 * This has been replaced by AWTEvent.getID()
471 *
472 * @serial
473 * @see java.awt.AWTEvent#getID()
474 */
475 public int id;
476
477 /**
478 * The <i>x</i> coordinate of the event.
479 * Replaced by MouseEvent.getX()
480 *
481 * @serial
482 * @see java.awt.event.MouseEvent#getX()
483 */
484 public int x;
485
486 /**
487 * The <i>y</i> coordinate of the event.
488 * Replaced by MouseEvent.getY()
489 *
501 */
502 public int key;
503
504 /**
505 * The key character that was pressed in a keyboard event.
506 */
507 // public char keyChar;
508
509 /**
510 * The state of the modifier keys.
511 * This is replaced with InputEvent.getModifiers()
512 * In java 1.1 MouseEvent and KeyEvent are subclasses
513 * of InputEvent.
514 *
515 * @serial
516 * @see java.awt.event.InputEvent#getModifiers()
517 */
518 public int modifiers;
519
520 /**
521 * For {@code MOUSE_DOWN} events, this field indicates the
522 * number of consecutive clicks. For other events, its value is
523 * {@code 0}.
524 * This field has been replaced by MouseEvent.getClickCount().
525 *
526 * @serial
527 * @see java.awt.event.MouseEvent#getClickCount()
528 */
529 public int clickCount;
530
531 /**
532 * An arbitrary argument of the event. The value of this field
533 * depends on the type of event.
534 * {@code arg} has been replaced by event specific property.
535 *
536 * @serial
537 */
538 public Object arg;
539
540 /**
541 * The next event. This field is set when putting events into a
542 * linked list.
543 * This has been replaced by EventQueue.
544 *
545 * @serial
546 * @see java.awt.EventQueue
547 */
548 public Event evt;
549
550 /* table for mapping old Event action keys to KeyEvent virtual keys. */
551 private static final int actionKeyCodes[][] = {
552 /* virtual key action key */
553 { KeyEvent.VK_HOME, Event.HOME },
554 { KeyEvent.VK_END, Event.END },
591 /*
592 * JDK 1.1 serialVersionUID
593 */
594 private static final long serialVersionUID = 5488922509400504703L;
595
596 static {
597 /* ensure that the necessary native libraries are loaded */
598 Toolkit.loadLibraries();
599 if (!GraphicsEnvironment.isHeadless()) {
600 initIDs();
601 }
602 }
603
604 /**
605 * Initialize JNI field and method IDs for fields that may be
606 accessed from C.
607 */
608 private static native void initIDs();
609
610 /**
611 * <b>NOTE:</b> The {@code Event} class is obsolete and is
612 * available only for backwards compatibility. It has been replaced
613 * by the {@code AWTEvent} class and its subclasses.
614 * <p>
615 * Creates an instance of {@code Event} with the specified target
616 * component, time stamp, event type, <i>x</i> and <i>y</i>
617 * coordinates, keyboard key, state of the modifier keys, and
618 * argument.
619 * @param target the target component.
620 * @param when the time stamp.
621 * @param id the event type.
622 * @param x the <i>x</i> coordinate.
623 * @param y the <i>y</i> coordinate.
624 * @param key the key pressed in a keyboard event.
625 * @param modifiers the state of the modifier keys.
626 * @param arg the specified argument.
627 */
628 public Event(Object target, long when, int id, int x, int y, int key,
629 int modifiers, Object arg) {
630 this.target = target;
631 this.when = when;
632 this.id = id;
633 this.x = x;
634 this.y = y;
635 this.key = key;
642 case WINDOW_DESTROY:
643 case WINDOW_ICONIFY:
644 case WINDOW_DEICONIFY:
645 case WINDOW_MOVED:
646 case SCROLL_LINE_UP:
647 case SCROLL_LINE_DOWN:
648 case SCROLL_PAGE_UP:
649 case SCROLL_PAGE_DOWN:
650 case SCROLL_ABSOLUTE:
651 case SCROLL_BEGIN:
652 case SCROLL_END:
653 case LIST_SELECT:
654 case LIST_DESELECT:
655 consumed = true; // these types are not passed back to peer
656 break;
657 default:
658 }
659 }
660
661 /**
662 * <b>NOTE:</b> The {@code Event} class is obsolete and is
663 * available only for backwards compatibility. It has been replaced
664 * by the {@code AWTEvent} class and its subclasses.
665 * <p>
666 * Creates an instance of {@code Event}, with the specified target
667 * component, time stamp, event type, <i>x</i> and <i>y</i>
668 * coordinates, keyboard key, state of the modifier keys, and an
669 * argument set to {@code null}.
670 * @param target the target component.
671 * @param when the time stamp.
672 * @param id the event type.
673 * @param x the <i>x</i> coordinate.
674 * @param y the <i>y</i> coordinate.
675 * @param key the key pressed in a keyboard event.
676 * @param modifiers the state of the modifier keys.
677 */
678 public Event(Object target, long when, int id, int x, int y, int key, int modifiers) {
679 this(target, when, id, x, y, key, modifiers, null);
680 }
681
682 /**
683 * <b>NOTE:</b> The {@code Event} class is obsolete and is
684 * available only for backwards compatibility. It has been replaced
685 * by the {@code AWTEvent} class and its subclasses.
686 * <p>
687 * Creates an instance of {@code Event} with the specified
688 * target component, event type, and argument.
689 * @param target the target component.
690 * @param id the event type.
691 * @param arg the specified argument.
692 */
693 public Event(Object target, int id, Object arg) {
694 this(target, 0, id, 0, 0, 0, 0, arg);
695 }
696
697 /**
698 * <b>NOTE:</b> The {@code Event} class is obsolete and is
699 * available only for backwards compatibility. It has been replaced
700 * by the {@code AWTEvent} class and its subclasses.
701 * <p>
702 * Translates this event so that its <i>x</i> and <i>y</i>
703 * coordinates are increased by <i>dx</i> and <i>dy</i>,
704 * respectively.
705 * <p>
706 * This method translates an event relative to the given component.
707 * This involves, at a minimum, translating the coordinates into the
708 * local coordinate system of the given component. It may also involve
709 * translating a region in the case of an expose event.
710 * @param dx the distance to translate the <i>x</i> coordinate.
711 * @param dy the distance to translate the <i>y</i> coordinate.
712 */
713 public void translate(int dx, int dy) {
714 this.x += dx;
715 this.y += dy;
716 }
717
718 /**
719 * <b>NOTE:</b> The {@code Event} class is obsolete and is
720 * available only for backwards compatibility. It has been replaced
721 * by the {@code AWTEvent} class and its subclasses.
722 * <p>
723 * Checks if the Shift key is down.
724 * @return {@code true} if the key is down;
725 * {@code false} otherwise.
726 * @see java.awt.Event#modifiers
727 * @see java.awt.Event#controlDown
728 * @see java.awt.Event#metaDown
729 */
730 public boolean shiftDown() {
731 return (modifiers & SHIFT_MASK) != 0;
732 }
733
734 /**
735 * <b>NOTE:</b> The {@code Event} class is obsolete and is
736 * available only for backwards compatibility. It has been replaced
737 * by the {@code AWTEvent} class and its subclasses.
738 * <p>
739 * Checks if the Control key is down.
740 * @return {@code true} if the key is down;
741 * {@code false} otherwise.
742 * @see java.awt.Event#modifiers
743 * @see java.awt.Event#shiftDown
744 * @see java.awt.Event#metaDown
745 */
746 public boolean controlDown() {
747 return (modifiers & CTRL_MASK) != 0;
748 }
749
750 /**
751 * <b>NOTE:</b> The {@code Event} class is obsolete and is
752 * available only for backwards compatibility. It has been replaced
753 * by the {@code AWTEvent} class and its subclasses.
754 * <p>
755 * Checks if the Meta key is down.
756 *
757 * @return {@code true} if the key is down;
758 * {@code false} otherwise.
759 * @see java.awt.Event#modifiers
760 * @see java.awt.Event#shiftDown
761 * @see java.awt.Event#controlDown
762 */
763 public boolean metaDown() {
764 return (modifiers & META_MASK) != 0;
765 }
766
767 /**
768 * <b>NOTE:</b> The {@code Event} class is obsolete and is
769 * available only for backwards compatibility. It has been replaced
770 * by the {@code AWTEvent} class and its subclasses.
771 */
772 void consume() {
773 switch(id) {
774 case KEY_PRESS:
775 case KEY_RELEASE:
776 case KEY_ACTION:
777 case KEY_ACTION_RELEASE:
778 consumed = true;
779 break;
780 default:
781 // event type cannot be consumed
782 }
783 }
784
785 /**
786 * <b>NOTE:</b> The {@code Event} class is obsolete and is
787 * available only for backwards compatibility. It has been replaced
788 * by the {@code AWTEvent} class and its subclasses.
789 */
790 boolean isConsumed() {
791 return consumed;
792 }
793
794 /*
795 * <b>NOTE:</b> The {@code Event} class is obsolete and is
796 * available only for backwards compatibility. It has been replaced
797 * by the {@code AWTEvent} class and its subclasses.
798 * <p>
799 * Returns the integer key-code associated with the key in this event,
800 * as described in java.awt.Event.
801 */
802 static int getOldEventKey(KeyEvent e) {
803 int keyCode = e.getKeyCode();
804 for (int i = 0; i < actionKeyCodes.length; i++) {
805 if (actionKeyCodes[i][0] == keyCode) {
806 return actionKeyCodes[i][1];
807 }
808 }
809 return (int)e.getKeyChar();
810 }
811
812 /*
813 * <b>NOTE:</b> The {@code Event} class is obsolete and is
814 * available only for backwards compatibility. It has been replaced
815 * by the {@code AWTEvent} class and its subclasses.
816 * <p>
817 * Returns a new KeyEvent char which corresponds to the int key
818 * of this old event.
819 */
820 char getKeyEventChar() {
821 for (int i = 0; i < actionKeyCodes.length; i++) {
822 if (actionKeyCodes[i][1] == key) {
823 return KeyEvent.CHAR_UNDEFINED;
824 }
825 }
826 return (char)key;
827 }
828
829 /**
830 * <b>NOTE:</b> The {@code Event} class is obsolete and is
831 * available only for backwards compatibility. It has been replaced
832 * by the {@code AWTEvent} class and its subclasses.
833 * <p>
834 * Returns a string representing the state of this {@code Event}.
835 * This method is intended to be used only for debugging purposes, and the
836 * content and format of the returned string may vary between
837 * implementations. The returned string may be empty but may not be
838 * {@code null}.
839 *
840 * @return the parameter string of this event
841 */
842 protected String paramString() {
843 String str = "id=" + id + ",x=" + x + ",y=" + y;
844 if (key != 0) {
845 str += ",key=" + key;
846 }
847 if (shiftDown()) {
848 str += ",shift";
849 }
850 if (controlDown()) {
851 str += ",control";
852 }
853 if (metaDown()) {
854 str += ",meta";
855 }
856 if (target != null) {
857 str += ",target=" + target;
858 }
859 if (arg != null) {
860 str += ",arg=" + arg;
861 }
862 return str;
863 }
864
865 /**
866 * <b>NOTE:</b> The {@code Event} class is obsolete and is
867 * available only for backwards compatibility. It has been replaced
868 * by the {@code AWTEvent} class and its subclasses.
869 * <p>
870 * Returns a representation of this event's values as a string.
871 * @return a string that represents the event and the values
872 * of its member fields.
873 * @see java.awt.Event#paramString
874 * @since 1.1
875 */
876 public String toString() {
877 return getClass().getName() + "[" + paramString() + "]";
878 }
879 }
|