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