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