AWTEvent.java 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /* AWTEvent.java -- the root event in AWT
  2. Copyright (C) 1999, 2000, 2002 Free Software Foundation
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package java.awt;
  32. import java.util.EventObject;
  33. /**
  34. * AWTEvent is the root event class for all AWT events in the JDK 1.1 event
  35. * model. It supersedes the Event class from JDK 1.0. Subclasses outside of
  36. * the java.awt package should have IDs greater than RESERVED_ID_MAX.
  37. *
  38. * <p>Event masks defined here are used by components in
  39. * <code>enableEvents</code> to select event types not selected by registered
  40. * listeners. Event masks are appropriately set when registering on
  41. * components.
  42. *
  43. * @author Warren Levy <warrenl@cygnus.com>
  44. * @author Aaron M. Renn <arenn@urbanophile.com>
  45. * @since 1.1
  46. * @status updated to 1.4
  47. */
  48. public abstract class AWTEvent extends EventObject
  49. {
  50. /**
  51. * Compatible with JDK 1.1+.
  52. */
  53. private static final long serialVersionUID = -1825314779160409405L;
  54. /**
  55. * The ID of the event.
  56. *
  57. * @see #getID()
  58. * @see #AWTEvent(Object, int)
  59. * @serial the identifier number of this event
  60. */
  61. protected int id;
  62. /**
  63. * Indicates if the event has been consumed. False mean it is passed to
  64. * the peer, true means it has already been processed. Semantic events
  65. * generated by low-level events always have the value true.
  66. *
  67. * @see #consume()
  68. * @see #isConsumed()
  69. * @serial whether the event has been consumed
  70. */
  71. protected boolean consumed;
  72. /**
  73. * Who knows? It's in the serial version.
  74. *
  75. * @serial No idea what this is for.
  76. */
  77. byte[] bdata;
  78. /** Mask for selecting component events. */
  79. public static final long COMPONENT_EVENT_MASK = 0x00001;
  80. /** Mask for selecting container events. */
  81. public static final long CONTAINER_EVENT_MASK = 0x00002;
  82. /** Mask for selecting component focus events. */
  83. public static final long FOCUS_EVENT_MASK = 0x00004;
  84. /** Mask for selecting keyboard events. */
  85. public static final long KEY_EVENT_MASK = 0x00008;
  86. /** Mask for mouse button events. */
  87. public static final long MOUSE_EVENT_MASK = 0x00010;
  88. /** Mask for mouse motion events. */
  89. public static final long MOUSE_MOTION_EVENT_MASK = 0x00020;
  90. /** Mask for window events. */
  91. public static final long WINDOW_EVENT_MASK = 0x00040;
  92. /** Mask for action events. */
  93. public static final long ACTION_EVENT_MASK = 0x00080;
  94. /** Mask for adjustment events. */
  95. public static final long ADJUSTMENT_EVENT_MASK = 0x00100;
  96. /** Mask for item events. */
  97. public static final long ITEM_EVENT_MASK = 0x00200;
  98. /** Mask for text events. */
  99. public static final long TEXT_EVENT_MASK = 0x00400;
  100. /**
  101. * Mask for input method events.
  102. * @since 1.3
  103. */
  104. public static final long INPUT_METHOD_EVENT_MASK = 0x00800;
  105. /**
  106. * Mask if input methods are enabled. Package visible only.
  107. */
  108. static final long INPUT_ENABLED_EVENT_MASK = 0x01000;
  109. /**
  110. * Mask for paint events.
  111. * @since 1.3
  112. */
  113. public static final long PAINT_EVENT_MASK = 0x02000;
  114. /**
  115. * Mask for invocation events.
  116. * @since 1.3
  117. */
  118. public static final long INVOCATION_EVENT_MASK = 0x04000;
  119. /**
  120. * Mask for hierarchy events.
  121. * @since 1.3
  122. */
  123. public static final long HIERARCHY_EVENT_MASK = 0x08000;
  124. /**
  125. * Mask for hierarchy bounds events.
  126. * @since 1.3
  127. */
  128. public static final long HIERARCHY_BOUNDS_EVENT_MASK = 0x10000;
  129. /**
  130. * Mask for mouse wheel events.
  131. * @since 1.4
  132. */
  133. public static final long MOUSE_WHEEL_EVENT_MASK = 0x20000;
  134. /**
  135. * Mask for window state events.
  136. * @since 1.4
  137. */
  138. public static final long WINDOW_STATE_EVENT_MASK = 0x40000;
  139. /**
  140. * Mask for window focus events.
  141. * @since 1.4
  142. */
  143. public static final long WINDOW_FOCUS_EVENT_MASK = 0x80000;
  144. /**
  145. * This is the highest number for event ids that are reserved for use by
  146. * the AWT system itself. Subclasses outside of java.awt should use higher
  147. * ids.
  148. */
  149. public static final int RESERVED_ID_MAX = 1999;
  150. /**
  151. * Initializes a new AWTEvent from the old Java 1.0 event object.
  152. *
  153. * @param event the old-style event
  154. * @throws NullPointerException if event is null
  155. */
  156. public AWTEvent(Event event)
  157. {
  158. this(event.target, event.id);
  159. consumed = event.consumed;
  160. }
  161. /**
  162. * Create an event on the specified source object and id.
  163. *
  164. * @param source the object that caused the event
  165. * @param id the event id
  166. * @throws IllegalArgumentException if source is null
  167. */
  168. public AWTEvent(Object source, int id)
  169. {
  170. super(source);
  171. this.id = id;
  172. }
  173. /**
  174. * Retarget the event, such as converting a heavyweight component to a
  175. * lightweight child of the original. This is not for general use, but
  176. * is for event targeting systems like KeyboardFocusManager.
  177. *
  178. * @param source the new source
  179. */
  180. public void setSource(Object source)
  181. {
  182. this.source = source;
  183. }
  184. /**
  185. * Returns the event type id.
  186. *
  187. * @return the id number of this event
  188. */
  189. public int getID()
  190. {
  191. return id;
  192. }
  193. /**
  194. * Returns a string representation of this event. This is in the format
  195. * <code>getClass().getName() + '[' + paramString() + "] on "
  196. * + source</code>.
  197. *
  198. * @return a string representation of this event
  199. */
  200. public String toString()
  201. {
  202. return getClass().getName() + "[" + paramString() + "] on " + source;
  203. }
  204. /**
  205. * Returns a string representation of the state of this event. It may be
  206. * empty, but must not be null; it is implementation defined.
  207. *
  208. * @return a string representation of this event
  209. */
  210. public String paramString()
  211. {
  212. return "";
  213. }
  214. /**
  215. * Consumes this event so that it will not be processed in the default
  216. * manner.
  217. */
  218. protected void consume()
  219. {
  220. consumed = true;
  221. }
  222. /**
  223. * Tests whether not not this event has been consumed. A consumed event
  224. * is not processed in the default manner.
  225. *
  226. * @return true if this event has been consumed
  227. */
  228. protected boolean isConsumed()
  229. {
  230. return consumed;
  231. }
  232. } // class AWTEvent