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