1 /*
   2  * Copyright (c) 1995, 2002, 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 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 compatilibility.  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&nbsp;1.0 event model. In Java&nbsp;1.1
  38  * and later versions, the <code>Event</code> class is maintained
  39  * only for backwards compatibilty. The information in this
  40  * class description is provided to assist programmers in
  41  * converting Java&nbsp;1.0 programs to the new event model.
  42  * <p>
  43  * In the Java&nbsp;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      JDK1.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;
  78 
  79     /**
  80      * This flag indicates that the Meta key was down when the event
  81      * occurred. For mouse events, this flag indicates that the right
  82      * button was pressed or released.
  83      */
  84     public static final int META_MASK           = 1 << 2;
  85 
  86     /**
  87      * This flag indicates that the Alt key was down when
  88      * the event occurred. For mouse events, this flag indicates that the
  89      * middle mouse button was pressed or released.
  90      */
  91     public static final int ALT_MASK            = 1 << 3;
  92 
  93     /* Action keys */
  94 
  95     /**
  96      * The Home key, a non-ASCII action key.
  97      */
  98     public static final int HOME                = 1000;
  99 
 100     /**
 101      * The End key, a non-ASCII action key.
 102      */
 103     public static final int END                 = 1001;
 104 
 105     /**
 106      * The Page Up key, a non-ASCII action key.
 107      */
 108     public static final int PGUP                = 1002;
 109 
 110     /**
 111      * The Page Down key, a non-ASCII action key.
 112      */
 113     public static final int PGDN                = 1003;
 114 
 115     /**
 116      * The Up Arrow key, a non-ASCII action key.
 117      */
 118     public static final int UP                  = 1004;
 119 
 120     /**
 121      * The Down Arrow key, a non-ASCII action key.
 122      */
 123     public static final int DOWN                = 1005;
 124 
 125     /**
 126      * The Left Arrow key, a non-ASCII action key.
 127      */
 128     public static final int LEFT                = 1006;
 129 
 130     /**
 131      * The Right Arrow key, a non-ASCII action key.
 132      */
 133     public static final int RIGHT               = 1007;
 134 
 135     /**
 136      * The F1 function key, a non-ASCII action key.
 137      */
 138     public static final int F1                  = 1008;
 139 
 140     /**
 141      * The F2 function key, a non-ASCII action key.
 142      */
 143     public static final int F2                  = 1009;
 144 
 145     /**
 146      * The F3 function key, a non-ASCII action key.
 147      */
 148     public static final int F3                  = 1010;
 149 
 150     /**
 151      * The F4 function key, a non-ASCII action key.
 152      */
 153     public static final int F4                  = 1011;
 154 
 155     /**
 156      * The F5 function key, a non-ASCII action key.
 157      */
 158     public static final int F5                  = 1012;
 159 
 160     /**
 161      * The F6 function key, a non-ASCII action key.
 162      */
 163     public static final int F6                  = 1013;
 164 
 165     /**
 166      * The F7 function key, a non-ASCII action key.
 167      */
 168     public static final int F7                  = 1014;
 169 
 170     /**
 171      * The F8 function key, a non-ASCII action key.
 172      */
 173     public static final int F8                  = 1015;
 174 
 175     /**
 176      * The F9 function key, a non-ASCII action key.
 177      */
 178     public static final int F9                  = 1016;
 179 
 180     /**
 181      * The F10 function key, a non-ASCII action key.
 182      */
 183     public static final int F10                 = 1017;
 184 
 185     /**
 186      * The F11 function key, a non-ASCII action key.
 187      */
 188     public static final int F11                 = 1018;
 189 
 190     /**
 191      * The F12 function key, a non-ASCII action key.
 192      */
 193     public static final int F12                 = 1019;
 194 
 195     /**
 196      * The Print Screen key, a non-ASCII action key.
 197      */
 198     public static final int PRINT_SCREEN        = 1020;
 199 
 200     /**
 201      * The Scroll Lock key, a non-ASCII action key.
 202      */
 203     public static final int SCROLL_LOCK         = 1021;
 204 
 205     /**
 206      * The Caps Lock key, a non-ASCII action key.
 207      */
 208     public static final int CAPS_LOCK           = 1022;
 209 
 210     /**
 211      * The Num Lock key, a non-ASCII action key.
 212      */
 213     public static final int NUM_LOCK            = 1023;
 214 
 215     /**
 216      * The Pause key, a non-ASCII action key.
 217      */
 218     public static final int PAUSE               = 1024;
 219 
 220     /**
 221      * The Insert key, a non-ASCII action key.
 222      */
 223     public static final int INSERT              = 1025;
 224 
 225     /* Non-action keys */
 226 
 227     /**
 228      * The Enter key.
 229      */
 230     public static final int ENTER               = '\n';
 231 
 232     /**
 233      * The BackSpace key.
 234      */
 235     public static final int BACK_SPACE          = '\b';
 236 
 237     /**
 238      * The Tab key.
 239      */
 240     public static final int TAB                 = '\t';
 241 
 242     /**
 243      * The Escape key.
 244      */
 245     public static final int ESCAPE              = 27;
 246 
 247     /**
 248      * The Delete key.
 249      */
 250     public static final int DELETE              = 127;
 251 
 252 
 253     /* Base for all window events. */
 254     private static final int WINDOW_EVENT       = 200;
 255 
 256     /**
 257      * The user has asked the window manager to kill the window.
 258      */
 259     public static final int WINDOW_DESTROY      = 1 + WINDOW_EVENT;
 260 
 261     /**
 262      * The user has asked the window manager to expose the window.
 263      */
 264     public static final int WINDOW_EXPOSE       = 2 + WINDOW_EVENT;
 265 
 266     /**
 267      * The user has asked the window manager to iconify the window.
 268      */
 269     public static final int WINDOW_ICONIFY      = 3 + WINDOW_EVENT;
 270 
 271     /**
 272      * The user has asked the window manager to de-iconify the window.
 273      */
 274     public static final int WINDOW_DEICONIFY    = 4 + WINDOW_EVENT;
 275 
 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      */
 376     public static final int SCROLL_LINE_DOWN    = 2 + SCROLL_EVENT;
 377 
 378     /**
 379      * The user has activated the <em>page up</em>
 380      * area of a scroll bar.
 381      */
 382     public static final int SCROLL_PAGE_UP      = 3 + SCROLL_EVENT;
 383 
 384     /**
 385      * The user has activated the <em>page down</em>
 386      * area of a scroll bar.
 387      */
 388     public static final int SCROLL_PAGE_DOWN    = 4 + SCROLL_EVENT;
 389 
 390     /**
 391      * The user has moved the bubble (thumb) in a scroll bar,
 392      * moving to an "absolute" position, rather than to
 393      * an offset from the last postion.
 394      */
 395     public static final int SCROLL_ABSOLUTE     = 5 + SCROLL_EVENT;
 396 
 397     /**
 398      * The scroll begin event.
 399      */
 400     public static final int SCROLL_BEGIN        = 6 + SCROLL_EVENT;
 401 
 402     /**
 403      * The scroll end event.
 404      */
 405     public static final int SCROLL_END          = 7 + SCROLL_EVENT;
 406 
 407     /* List Events */
 408     private static final int LIST_EVENT         = 700;
 409 
 410     /**
 411      * An item in a list has been selected.
 412      */
 413     public static final int LIST_SELECT         = 1 + LIST_EVENT;
 414 
 415     /**
 416      * An item in a list has been deselected.
 417      */
 418     public static final int LIST_DESELECT       = 2 + LIST_EVENT;
 419 
 420     /* Misc Event */
 421     private static final int MISC_EVENT         = 1000;
 422 
 423     /**
 424      * This event indicates that the user wants some action to occur.
 425      */
 426     public static final int ACTION_EVENT        = 1 + MISC_EVENT;
 427 
 428     /**
 429      * A file loading event.
 430      */
 431     public static final int LOAD_FILE           = 2 + MISC_EVENT;
 432 
 433     /**
 434      * A file saving event.
 435      */
 436     public static final int SAVE_FILE           = 3 + MISC_EVENT;
 437 
 438     /**
 439      * A component gained the focus.
 440      */
 441     public static final int GOT_FOCUS           = 4 + MISC_EVENT;
 442 
 443     /**
 444      * A component lost the focus.
 445      */
 446     public static final int LOST_FOCUS          = 5 + MISC_EVENT;
 447 
 448     /**
 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      *
 490      * @serial
 491      * @see java.awt.event.MouseEvent#getY()
 492      */
 493     public int y;
 494 
 495     /**
 496      * The key code of the key that was pressed in a keyboard event.
 497      * This has been replaced by KeyEvent.getKeyCode()
 498      *
 499      * @serial
 500      * @see java.awt.event.KeyEvent#getKeyCode()
 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          },
 555         { KeyEvent.VK_PAGE_UP,     Event.PGUP         },
 556         { KeyEvent.VK_PAGE_DOWN,   Event.PGDN         },
 557         { KeyEvent.VK_UP,          Event.UP           },
 558         { KeyEvent.VK_DOWN,        Event.DOWN         },
 559         { KeyEvent.VK_LEFT,        Event.LEFT         },
 560         { KeyEvent.VK_RIGHT,       Event.RIGHT        },
 561         { KeyEvent.VK_F1,          Event.F1           },
 562         { KeyEvent.VK_F2,          Event.F2           },
 563         { KeyEvent.VK_F3,          Event.F3           },
 564         { KeyEvent.VK_F4,          Event.F4           },
 565         { KeyEvent.VK_F5,          Event.F5           },
 566         { KeyEvent.VK_F6,          Event.F6           },
 567         { KeyEvent.VK_F7,          Event.F7           },
 568         { KeyEvent.VK_F8,          Event.F8           },
 569         { KeyEvent.VK_F9,          Event.F9           },
 570         { KeyEvent.VK_F10,         Event.F10          },
 571         { KeyEvent.VK_F11,         Event.F11          },
 572         { KeyEvent.VK_F12,         Event.F12          },
 573         { KeyEvent.VK_PRINTSCREEN, Event.PRINT_SCREEN },
 574         { KeyEvent.VK_SCROLL_LOCK, Event.SCROLL_LOCK  },
 575         { KeyEvent.VK_CAPS_LOCK,   Event.CAPS_LOCK    },
 576         { KeyEvent.VK_NUM_LOCK,    Event.NUM_LOCK     },
 577         { KeyEvent.VK_PAUSE,       Event.PAUSE        },
 578         { KeyEvent.VK_INSERT,      Event.INSERT       }
 579     };
 580 
 581     /**
 582      * This field controls whether or not the event is sent back
 583      * down to the peer once the target has processed it -
 584      * false means it's sent to the peer, true means it's not.
 585      *
 586      * @serial
 587      * @see #isConsumed()
 588      */
 589     private boolean consumed = false;
 590 
 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 compatilibility.  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;
 636         this.modifiers = modifiers;
 637         this.arg = arg;
 638         this.data = 0;
 639         this.clickCount = 0;
 640         switch(id) {
 641           case ACTION_EVENT:
 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 compatilibility.  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 compatilibility.  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 compatilibility.  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 compatilibility.  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 compatilibility.  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 compatilibility.  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 compatilibility.  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 compatilibility.  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 compatilibility.  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 compatilibility.  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 compatilibility.  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 compatilibility.  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     JDK1.1
 875      */
 876     public String toString() {
 877         return getClass().getName() + "[" + paramString() + "]";
 878     }
 879 }