1. /*
  2. * @(#)ActionEvent.java 1.19 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.awt.event;
  8. import java.awt.AWTEvent;
  9. import java.awt.Event;
  10. /**
  11. * A semantic event which indicates that a component-defined action occured.
  12. * This high-level event is generated by a component (such as a Button) when
  13. * the component-specific action occurs (such as being pressed).
  14. * The event is passed to every every <code>ActionListener</code> object
  15. * that registered to receive such events using the component's
  16. * <code>addActionListener</code> method.
  17. * <P>
  18. * The object that implements the <code>ActionListener</code> interface
  19. * gets this <code>ActionEvent</code> when the event occurs. The listener
  20. * is therefore spared the details of processing individual mouse movements
  21. * and mouse clicks, and can instead process a "meaningful" (semantic)
  22. * event like "button pressed".
  23. *
  24. * @see ActionListener
  25. * @see <a href="http://java.sun.com/docs/books/tutorial/post1.0/ui/eventmodel.html">Tutorial: Java 1.1 Event Model</a>
  26. * @see <a href="http://www.awl.com/cp/javaseries/jcl1_2.html">Reference: The Java Class Libraries (update file)</a>
  27. *
  28. * @version 1.19 11/29/01
  29. * @author Carl Quinn
  30. */
  31. public class ActionEvent extends AWTEvent {
  32. /**
  33. * The shift modifier. An indicator that the shift key was held
  34. * down during the event.
  35. */
  36. public static final int SHIFT_MASK = Event.SHIFT_MASK;
  37. /**
  38. * The control modifier. An indicator that the control key was held
  39. * down during the event.
  40. */
  41. public static final int CTRL_MASK = Event.CTRL_MASK;
  42. /**
  43. * The meta modifier. An indicator that the meta key was held
  44. * down during the event.
  45. */
  46. public static final int META_MASK = Event.META_MASK;
  47. /**
  48. * The alt modifier. An indicator that the alt key was held
  49. * down during the event.
  50. */
  51. public static final int ALT_MASK = Event.ALT_MASK;
  52. /**
  53. * The first number in the range of ids used for action events.
  54. */
  55. public static final int ACTION_FIRST = 1001;
  56. /**
  57. * The last number in the range of ids used for action events.
  58. */
  59. public static final int ACTION_LAST = 1001;
  60. /**
  61. * This event id indicates that a meaningful action occured.
  62. */
  63. public static final int ACTION_PERFORMED = ACTION_FIRST; //Event.ACTION_EVENT
  64. /**
  65. * The nonlocalized string that gives more details
  66. * of what actually caused the event.
  67. * This information is very specific to the component
  68. * that fired it.
  69. * @serial
  70. * @see getActionCommand()
  71. */
  72. String actionCommand;
  73. /**
  74. * This represents the key modifier that was selected,
  75. * and is used to determine the state of the selected key.
  76. * If no modifier has been selected it will default to
  77. * zero.
  78. *
  79. * @serial
  80. * @see getModifiers()
  81. */
  82. int modifiers;
  83. /*
  84. * JDK 1.1 serialVersionUID
  85. */
  86. private static final long serialVersionUID = -7671078796273832149L;
  87. /**
  88. * Constructs an <code>ActionEvent</code> object.
  89. *
  90. * @param source the object that originated the event
  91. * @param id an integer that identifies the event
  92. * @param command a string that may specify a command (possibly one
  93. * of several) associated with the event
  94. */
  95. public ActionEvent(Object source, int id, String command) {
  96. this(source, id, command, 0);
  97. }
  98. /**
  99. * Constructs an <code>ActionEvent</code> object with modifier keys.
  100. *
  101. * @param source the object that originated the event
  102. * @param id an integer that identifies the event
  103. * @param command a string that may specify a command (possibly one
  104. * of several) associated with the event
  105. * @param modifiers the modifier keys held down during this action
  106. */
  107. public ActionEvent(Object source, int id, String command, int modifiers) {
  108. super(source, id);
  109. this.actionCommand = command;
  110. this.modifiers = modifiers;
  111. }
  112. /**
  113. * Returns the command string associated with this action.
  114. * This string allows a "modal" component to specify one of several
  115. * commands, depending on its state. For example, a single button might
  116. * toggle between "show details" and "hide details". The source object
  117. * and the event would be the same in each case, but the command string
  118. * would identify the intended action.
  119. *
  120. *@return the string identifying the command for this event
  121. */
  122. public String getActionCommand() {
  123. return actionCommand;
  124. }
  125. /**
  126. * Returns the modifier keys held down during this action event.
  127. *
  128. * @return the integer sum of the modifier constants
  129. */
  130. public int getModifiers() {
  131. return modifiers;
  132. }
  133. /**
  134. * Returns a parameter string identifying this action event.
  135. * This method is useful for event-logging and for debugging.
  136. *
  137. * @return a string identifying the event and its associated command
  138. */
  139. public String paramString() {
  140. String typeStr;
  141. switch(id) {
  142. case ACTION_PERFORMED:
  143. typeStr = "ACTION_PERFORMED";
  144. break;
  145. default:
  146. typeStr = "unknown type";
  147. }
  148. return typeStr + ",cmd="+actionCommand;
  149. }
  150. }