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