1. /*
  2. * @(#)ButtonModel.java 1.26 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 javax.swing;
  8. import java.awt.event.*;
  9. import java.awt.*;
  10. import javax.swing.event.*;
  11. /**
  12. * State Model for buttons.
  13. * This model is used for check boxes and radio buttons, which are
  14. * special kinds of buttons, as well as for normal buttons.
  15. * For check boxes and radio buttons, pressing the mouse selects
  16. * the button. For normal buttons, pressing the mouse "arms" the
  17. * button. Releasing the mouse over the button then initiates a
  18. * <i>button</i> press, firing its action event. Releasing the
  19. * mouse elsewhere disarms the button.
  20. * <p>
  21. * In use, a UI will invoke {@link #setSelected} when a mouse
  22. * click occurs over a check box or radio button. It will invoke
  23. * {@link #setArmed} when the mouse is pressed over a regular
  24. * button and invoke {@link #setPressed} when the mouse is released.
  25. * If the mouse travels outside the button in the meantime,
  26. * <code>setArmed(false)</code> will tell the button not to fire
  27. * when it sees <code>setPressed</code>. (If the mouse travels
  28. * back in, the button will be rearmed.)
  29. * <blockquote>
  30. * <b>Note: </b><br>
  31. * A button is triggered when it is both "armed" and "pressed".
  32. * </blockquote>
  33. *
  34. * @version 1.26 12/19/03
  35. * @author Jeff Dinkins
  36. */
  37. public interface ButtonModel extends ItemSelectable {
  38. /**
  39. * Indicates partial commitment towards pressing the
  40. * button.
  41. *
  42. * @return true if the button is armed, and ready to be pressed
  43. * @see #setArmed
  44. */
  45. boolean isArmed();
  46. /**
  47. * Indicates if the button has been selected. Only needed for
  48. * certain types of buttons - such as radio buttons and check boxes.
  49. *
  50. * @return true if the button is selected
  51. */
  52. boolean isSelected();
  53. /**
  54. * Indicates if the button can be selected or pressed by
  55. * an input device (such as a mouse pointer). (Check boxes
  56. * are selected, regular buttons are "pressed".)
  57. *
  58. * @return true if the button is enabled, and therefore
  59. * selectable (or pressable)
  60. */
  61. boolean isEnabled();
  62. /**
  63. * Indicates if button has been pressed.
  64. *
  65. * @return true if the button has been pressed
  66. */
  67. boolean isPressed();
  68. /**
  69. * Indicates that the mouse is over the button.
  70. *
  71. * @return true if the mouse is over the button
  72. */
  73. boolean isRollover();
  74. /**
  75. * Marks the button as "armed". If the mouse button is
  76. * released while it is over this item, the button's action event
  77. * fires. If the mouse button is released elsewhere, the
  78. * event does not fire and the button is disarmed.
  79. *
  80. * @param b true to arm the button so it can be selected
  81. */
  82. public void setArmed(boolean b);
  83. /**
  84. * Selects or deselects the button.
  85. *
  86. * @param b true selects the button,
  87. * false deselects the button.
  88. */
  89. public void setSelected(boolean b);
  90. /**
  91. * Enables or disables the button.
  92. *
  93. * @param b true to enable the button
  94. * @see #isEnabled
  95. */
  96. public void setEnabled(boolean b);
  97. /**
  98. * Sets the button to pressed or unpressed.
  99. *
  100. * @param b true to set the button to "pressed"
  101. * @see #isPressed
  102. */
  103. public void setPressed(boolean b);
  104. /**
  105. * Sets or clears the button's rollover state
  106. *
  107. * @param b true to turn on rollover
  108. * @see #isRollover
  109. */
  110. public void setRollover(boolean b);
  111. /**
  112. * Sets the keyboard mnemonic (shortcut key or
  113. * accelerator key) for this button.
  114. *
  115. * @param key an int specifying the accelerator key
  116. */
  117. public void setMnemonic(int key);
  118. /**
  119. * Gets the keyboard mnemonic for this model
  120. *
  121. * @return an int specifying the accelerator key
  122. * @see #setMnemonic
  123. */
  124. public int getMnemonic();
  125. /**
  126. * Sets the actionCommand string that gets sent as part of the
  127. * event when the button is pressed.
  128. *
  129. * @param s the String that identifies the generated event
  130. */
  131. public void setActionCommand(String s);
  132. /**
  133. * Returns the action command for this button.
  134. *
  135. * @return the String that identifies the generated event
  136. * @see #setActionCommand
  137. */
  138. public String getActionCommand();
  139. /**
  140. * Identifies the group this button belongs to --
  141. * needed for radio buttons, which are mutually
  142. * exclusive within their group.
  143. *
  144. * @param group the ButtonGroup this button belongs to
  145. */
  146. public void setGroup(ButtonGroup group);
  147. /**
  148. * Adds an ActionListener to the button.
  149. *
  150. * @param l the listener to add
  151. */
  152. void addActionListener(ActionListener l);
  153. /**
  154. * Removes an ActionListener from the button.
  155. *
  156. * @param l the listener to remove
  157. */
  158. void removeActionListener(ActionListener l);
  159. /**
  160. * Adds an ItemListener to the button.
  161. *
  162. * @param l the listener to add
  163. */
  164. void addItemListener(ItemListener l);
  165. /**
  166. * Removes an ItemListener from the button.
  167. *
  168. * @param l the listener to remove
  169. */
  170. void removeItemListener(ItemListener l);
  171. /**
  172. * Adds a ChangeListener to the button.
  173. *
  174. * @param l the listener to add
  175. */
  176. void addChangeListener(ChangeListener l);
  177. /**
  178. * Removes a ChangeListener from the button.
  179. *
  180. * @param l the listener to remove
  181. */
  182. void removeChangeListener(ChangeListener l);
  183. }