1. /*
  2. * @(#)InputEvent.java 1.22 00/02/02
  3. *
  4. * Copyright 1996-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package java.awt.event;
  11. import java.awt.Event;
  12. import java.awt.Component;
  13. /**
  14. * The root event class for all component-level input events.
  15. *
  16. * Input events are delivered to listeners before they are
  17. * processed normally by the source where they originated.
  18. * This allows listeners and component subclasses to "consume"
  19. * the event so that the source will not process them in their
  20. * default manner. For example, consuming mousePressed events
  21. * on a Button component will prevent the Button from being
  22. * activated.
  23. *
  24. * @author Carl Quinn
  25. * @version 1.22 02/02/00
  26. *
  27. * @see KeyEvent
  28. * @see KeyAdapter
  29. * @see MouseEvent
  30. * @see MouseAdapter
  31. * @see MouseMotionAdapter
  32. *
  33. * @since 1.1
  34. */
  35. public abstract class InputEvent extends ComponentEvent {
  36. /**
  37. * The shift key modifier constant.
  38. */
  39. public static final int SHIFT_MASK = Event.SHIFT_MASK;
  40. /**
  41. * The control key modifier constant.
  42. */
  43. public static final int CTRL_MASK = Event.CTRL_MASK;
  44. /**
  45. * The meta key modifier constant.
  46. */
  47. public static final int META_MASK = Event.META_MASK;
  48. /**
  49. * The alt key modifier constant.
  50. */
  51. public static final int ALT_MASK = Event.ALT_MASK;
  52. /**
  53. * The alt-graph key modifier constant.
  54. */
  55. public static final int ALT_GRAPH_MASK = 1 << 5;
  56. /**
  57. * The mouse button1 modifier constant.
  58. */
  59. public static final int BUTTON1_MASK = 1 << 4;
  60. /**
  61. * The mouse button2 modifier constant.
  62. */
  63. public static final int BUTTON2_MASK = Event.ALT_MASK;
  64. /**
  65. * The mouse button3 modifier constant.
  66. */
  67. public static final int BUTTON3_MASK = Event.META_MASK;
  68. /**
  69. * The input events Time stamp. The time stamp is in
  70. * UTC format that indicates when the input event was
  71. * created.
  72. *
  73. * @serial
  74. * @see getWhen()
  75. */
  76. long when;
  77. /**
  78. * The state of the modifier key at the time the input
  79. * event was fired.
  80. *
  81. * @serial
  82. * @see getModifiers()
  83. * @see java.awt.event.MouseEvent
  84. */
  85. int modifiers;
  86. static {
  87. /* ensure that the necessary native libraries are loaded */
  88. NativeLibLoader.loadLibraries();
  89. initIDs();
  90. }
  91. /**
  92. * Initialize JNI field and method IDs for fields that may be
  93. accessed from C.
  94. */
  95. private static native void initIDs();
  96. /**
  97. * Constructs an InputEvent object with the specified source component,
  98. * modifiers, and type.
  99. * @param source the object where the event originated
  100. * @id the event type
  101. * @when the time the event occurred
  102. * @modifiers the modifier keys down while event occurred
  103. */
  104. InputEvent(Component source, int id, long when, int modifiers) {
  105. super(source, id);
  106. this.when = when;
  107. this.modifiers = modifiers;
  108. }
  109. /**
  110. * Returns whether or not the Shift modifier is down on this event.
  111. */
  112. public boolean isShiftDown() {
  113. return (modifiers & Event.SHIFT_MASK) != 0;
  114. }
  115. /**
  116. * Returns whether or not the Control modifier is down on this event.
  117. */
  118. public boolean isControlDown() {
  119. return (modifiers & Event.CTRL_MASK) != 0;
  120. }
  121. /**
  122. * Returns whether or not the Meta modifier is down on this event.
  123. */
  124. public boolean isMetaDown() {
  125. return (modifiers & Event.META_MASK) != 0;
  126. }
  127. /**
  128. * Returns whether or not the Alt modifier is down on this event.
  129. */
  130. public boolean isAltDown() {
  131. return (modifiers & Event.ALT_MASK) != 0;
  132. }
  133. /**
  134. * Returns whether or not the Alt-Graph modifier is down on this event.
  135. */
  136. public boolean isAltGraphDown() {
  137. return (modifiers & InputEvent.ALT_GRAPH_MASK) != 0;
  138. }
  139. /**
  140. * Returns the timestamp of when this event occurred.
  141. */
  142. public long getWhen() {
  143. return when;
  144. }
  145. /**
  146. * Returns the modifiers flag for this event.
  147. */
  148. public int getModifiers() {
  149. return modifiers;
  150. }
  151. /**
  152. * Consumes this event so that it will not be processed
  153. * in the default manner by the source which originated it.
  154. */
  155. public void consume() {
  156. consumed = true;
  157. }
  158. /**
  159. * Returns whether or not this event has been consumed.
  160. * @see #consume
  161. */
  162. public boolean isConsumed() {
  163. return consumed;
  164. }
  165. // state serialization compatibility with JDK 1.1
  166. static final long serialVersionUID = -2482525981698309786L;
  167. }