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