KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > ButtonModel


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
9
10 import java.awt.event.*;
11 import java.awt.*;
12 import javax.swing.event.*;
13
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.26 12/19/03
38  * @author Jeff Dinkins
39  */

40 public interface ButtonModel extends ItemSelectable {
41     
42     /**
43      * Indicates partial commitment towards pressing the
44      * button.
45      *
46      * @return true if the button is armed, and ready to be pressed
47      * @see #setArmed
48      */

49     boolean isArmed();
50         
51     /**
52      * Indicates if the button has been selected. Only needed for
53      * certain types of buttons - such as radio buttons and check boxes.
54      *
55      * @return true if the button is selected
56      */

57     boolean isSelected();
58         
59     /**
60      * Indicates if the button can be selected or pressed by
61      * an input device (such as a mouse pointer). (Check boxes
62      * are selected, regular buttons are "pressed".)
63      *
64      * @return true if the button is enabled, and therefore
65      * selectable (or pressable)
66      */

67     boolean isEnabled();
68         
69     /**
70      * Indicates if button has been pressed.
71      *
72      * @return true if the button has been pressed
73      */

74     boolean isPressed();
75
76     /**
77      * Indicates that the mouse is over the button.
78      *
79      * @return true if the mouse is over the button
80      */

81     boolean isRollover();
82
83     /**
84      * Marks the button as "armed". If the mouse button is
85      * released while it is over this item, the button's action event
86      * fires. If the mouse button is released elsewhere, the
87      * event does not fire and the button is disarmed.
88      *
89      * @param b true to arm the button so it can be selected
90      */

91     public void setArmed(boolean b);
92
93     /**
94      * Selects or deselects the button.
95      *
96      * @param b true selects the button,
97      * false deselects the button.
98      */

99     public void setSelected(boolean b);
100
101     /**
102      * Enables or disables the button.
103      *
104      * @param b true to enable the button
105      * @see #isEnabled
106      */

107     public void setEnabled(boolean b);
108
109     /**
110      * Sets the button to pressed or unpressed.
111      *
112      * @param b true to set the button to "pressed"
113      * @see #isPressed
114      */

115     public void setPressed(boolean b);
116
117     /**
118      * Sets or clears the button's rollover state
119      *
120      * @param b true to turn on rollover
121      * @see #isRollover
122      */

123     public void setRollover(boolean b);
124
125     /**
126      * Sets the keyboard mnemonic (shortcut key or
127      * accelerator key) for this button.
128      *
129      * @param key an int specifying the accelerator key
130      */

131     public void setMnemonic(int key);
132
133     /**
134      * Gets the keyboard mnemonic for this model
135      *
136      * @return an int specifying the accelerator key
137      * @see #setMnemonic
138      */

139     public int getMnemonic();
140
141     /**
142      * Sets the actionCommand string that gets sent as part of the
143      * event when the button is pressed.
144      *
145      * @param s the String that identifies the generated event
146      */

147     public void setActionCommand(String JavaDoc s);
148
149     /**
150      * Returns the action command for this button.
151      *
152      * @return the String that identifies the generated event
153      * @see #setActionCommand
154      */

155     public String JavaDoc getActionCommand();
156
157     /**
158      * Identifies the group this button belongs to --
159      * needed for radio buttons, which are mutually
160      * exclusive within their group.
161      *
162      * @param group the ButtonGroup this button belongs to
163      */

164     public void setGroup(ButtonGroup JavaDoc group);
165     
166     /**
167      * Adds an ActionListener to the button.
168      *
169      * @param l the listener to add
170      */

171     void addActionListener(ActionListener l);
172
173     /**
174      * Removes an ActionListener from the button.
175      *
176      * @param l the listener to remove
177      */

178     void removeActionListener(ActionListener l);
179
180     /**
181      * Adds an ItemListener to the button.
182      *
183      * @param l the listener to add
184      */

185     void addItemListener(ItemListener l);
186
187     /**
188      * Removes an ItemListener from the button.
189      *
190      * @param l the listener to remove
191      */

192     void removeItemListener(ItemListener l);
193
194     /**
195      * Adds a ChangeListener to the button.
196      *
197      * @param l the listener to add
198      */

199     void addChangeListener(ChangeListener l);
200
201     /**
202      * Removes a ChangeListener from the button.
203      *
204      * @param l the listener to remove
205      */

206     void removeChangeListener(ChangeListener l);
207
208 }
209
Popular Tags