2
|
1 |
/*
|
|
2 |
* Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
package javax.swing;
|
|
26 |
|
|
27 |
|
|
28 |
import java.awt.event.*;
|
|
29 |
import java.awt.*;
|
|
30 |
import javax.swing.event.*;
|
|
31 |
|
|
32 |
/**
|
|
33 |
* State model for buttons.
|
|
34 |
* <p>
|
|
35 |
* This model is used for regular buttons, as well as check boxes
|
|
36 |
* and radio buttons, which are special kinds of buttons. In practice,
|
|
37 |
* a button's UI takes the responsibility of calling methods on its
|
|
38 |
* model to manage the state, as detailed below:
|
|
39 |
* <p>
|
|
40 |
* In simple terms, pressing and releasing the mouse over a regular
|
|
41 |
* button triggers the button and causes and <code>ActionEvent</code>
|
|
42 |
* to be fired. The same behavior can be produced via a keyboard key
|
|
43 |
* defined by the look and feel of the button (typically the SPACE BAR).
|
|
44 |
* Pressing and releasing this key while the button has
|
|
45 |
* focus will give the same results. For check boxes and radio buttons, the
|
|
46 |
* mouse or keyboard equivalent sequence just described causes the button
|
|
47 |
* to become selected.
|
|
48 |
* <p>
|
|
49 |
* In details, the state model for buttons works as follows
|
|
50 |
* when used with the mouse:
|
|
51 |
* <br>
|
|
52 |
* Pressing the mouse on top of a button makes the model both
|
|
53 |
* armed and pressed. As long as the mouse remains down,
|
|
54 |
* the model remains pressed, even if the mouse moves
|
|
55 |
* outside the button. On the contrary, the model is only
|
|
56 |
* armed while the mouse remains pressed within the bounds of
|
|
57 |
* the button (it can move in or out of the button, but the model
|
|
58 |
* is only armed during the portion of time spent within the button).
|
|
59 |
* A button is triggered, and an <code>ActionEvent</code> is fired,
|
|
60 |
* when the mouse is released while the model is armed
|
|
61 |
* - meaning when it is released over top of the button after the mouse
|
|
62 |
* has previously been pressed on that button (and not already released).
|
|
63 |
* Upon mouse release, the model becomes unarmed and unpressed.
|
|
64 |
* <p>
|
|
65 |
* In details, the state model for buttons works as follows
|
|
66 |
* when used with the keyboard:
|
|
67 |
* <br>
|
|
68 |
* Pressing the look and feel defined keyboard key while the button
|
|
69 |
* has focus makes the model both armed and pressed. As long as this key
|
|
70 |
* remains down, the model remains in this state. Releasing the key sets
|
|
71 |
* the model to unarmed and unpressed, triggers the button, and causes an
|
|
72 |
* <code>ActionEvent</code> to be fired.
|
|
73 |
*
|
|
74 |
* @author Jeff Dinkins
|
|
75 |
*/
|
|
76 |
public interface ButtonModel extends ItemSelectable {
|
|
77 |
|
|
78 |
/**
|
|
79 |
* Indicates partial commitment towards triggering the
|
|
80 |
* button.
|
|
81 |
*
|
|
82 |
* @return <code>true</code> if the button is armed,
|
|
83 |
* and ready to be triggered
|
|
84 |
* @see #setArmed
|
|
85 |
*/
|
|
86 |
boolean isArmed();
|
|
87 |
|
|
88 |
/**
|
|
89 |
* Indicates if the button has been selected. Only needed for
|
|
90 |
* certain types of buttons - such as radio buttons and check boxes.
|
|
91 |
*
|
|
92 |
* @return <code>true</code> if the button is selected
|
|
93 |
*/
|
|
94 |
boolean isSelected();
|
|
95 |
|
|
96 |
/**
|
|
97 |
* Indicates if the button can be selected or triggered by
|
|
98 |
* an input device, such as a mouse pointer.
|
|
99 |
*
|
|
100 |
* @return <code>true</code> if the button is enabled
|
|
101 |
*/
|
|
102 |
boolean isEnabled();
|
|
103 |
|
|
104 |
/**
|
|
105 |
* Indicates if the button is pressed.
|
|
106 |
*
|
|
107 |
* @return <code>true</code> if the button is pressed
|
|
108 |
*/
|
|
109 |
boolean isPressed();
|
|
110 |
|
|
111 |
/**
|
|
112 |
* Indicates that the mouse is over the button.
|
|
113 |
*
|
|
114 |
* @return <code>true</code> if the mouse is over the button
|
|
115 |
*/
|
|
116 |
boolean isRollover();
|
|
117 |
|
|
118 |
/**
|
|
119 |
* Marks the button as armed or unarmed.
|
|
120 |
*
|
|
121 |
* @param b whether or not the button should be armed
|
|
122 |
*/
|
|
123 |
public void setArmed(boolean b);
|
|
124 |
|
|
125 |
/**
|
|
126 |
* Selects or deselects the button.
|
|
127 |
*
|
|
128 |
* @param b <code>true</code> selects the button,
|
|
129 |
* <code>false</code> deselects the button
|
|
130 |
*/
|
|
131 |
public void setSelected(boolean b);
|
|
132 |
|
|
133 |
/**
|
|
134 |
* Enables or disables the button.
|
|
135 |
*
|
|
136 |
* @param b whether or not the button should be enabled
|
|
137 |
* @see #isEnabled
|
|
138 |
*/
|
|
139 |
public void setEnabled(boolean b);
|
|
140 |
|
|
141 |
/**
|
|
142 |
* Sets the button to pressed or unpressed.
|
|
143 |
*
|
|
144 |
* @param b whether or not the button should be pressed
|
|
145 |
* @see #isPressed
|
|
146 |
*/
|
|
147 |
public void setPressed(boolean b);
|
|
148 |
|
|
149 |
/**
|
|
150 |
* Sets or clears the button's rollover state
|
|
151 |
*
|
|
152 |
* @param b whether or not the button is in the rollover state
|
|
153 |
* @see #isRollover
|
|
154 |
*/
|
|
155 |
public void setRollover(boolean b);
|
|
156 |
|
|
157 |
/**
|
|
158 |
* Sets the keyboard mnemonic (shortcut key or
|
|
159 |
* accelerator key) for the button.
|
|
160 |
*
|
|
161 |
* @param key an int specifying the accelerator key
|
|
162 |
*/
|
|
163 |
public void setMnemonic(int key);
|
|
164 |
|
|
165 |
/**
|
|
166 |
* Gets the keyboard mnemonic for the button.
|
|
167 |
*
|
|
168 |
* @return an int specifying the accelerator key
|
|
169 |
* @see #setMnemonic
|
|
170 |
*/
|
|
171 |
public int getMnemonic();
|
|
172 |
|
|
173 |
/**
|
|
174 |
* Sets the action command string that gets sent as part of the
|
|
175 |
* <code>ActionEvent</code> when the button is triggered.
|
|
176 |
*
|
|
177 |
* @param s the <code>String</code> that identifies the generated event
|
|
178 |
* @see #getActionCommand
|
|
179 |
* @see java.awt.event.ActionEvent#getActionCommand
|
|
180 |
*/
|
|
181 |
public void setActionCommand(String s);
|
|
182 |
|
|
183 |
/**
|
|
184 |
* Returns the action command string for the button.
|
|
185 |
*
|
|
186 |
* @return the <code>String</code> that identifies the generated event
|
|
187 |
* @see #setActionCommand
|
|
188 |
*/
|
|
189 |
public String getActionCommand();
|
|
190 |
|
|
191 |
/**
|
|
192 |
* Identifies the group the button belongs to --
|
|
193 |
* needed for radio buttons, which are mutually
|
|
194 |
* exclusive within their group.
|
|
195 |
*
|
|
196 |
* @param group the <code>ButtonGroup</code> the button belongs to
|
|
197 |
*/
|
|
198 |
public void setGroup(ButtonGroup group);
|
|
199 |
|
|
200 |
/**
|
|
201 |
* Adds an <code>ActionListener</code> to the model.
|
|
202 |
*
|
|
203 |
* @param l the listener to add
|
|
204 |
*/
|
|
205 |
void addActionListener(ActionListener l);
|
|
206 |
|
|
207 |
/**
|
|
208 |
* Removes an <code>ActionListener</code> from the model.
|
|
209 |
*
|
|
210 |
* @param l the listener to remove
|
|
211 |
*/
|
|
212 |
void removeActionListener(ActionListener l);
|
|
213 |
|
|
214 |
/**
|
|
215 |
* Adds an <code>ItemListener</code> to the model.
|
|
216 |
*
|
|
217 |
* @param l the listener to add
|
|
218 |
*/
|
|
219 |
void addItemListener(ItemListener l);
|
|
220 |
|
|
221 |
/**
|
|
222 |
* Removes an <code>ItemListener</code> from the model.
|
|
223 |
*
|
|
224 |
* @param l the listener to remove
|
|
225 |
*/
|
|
226 |
void removeItemListener(ItemListener l);
|
|
227 |
|
|
228 |
/**
|
|
229 |
* Adds a <code>ChangeListener</code> to the model.
|
|
230 |
*
|
|
231 |
* @param l the listener to add
|
|
232 |
*/
|
|
233 |
void addChangeListener(ChangeListener l);
|
|
234 |
|
|
235 |
/**
|
|
236 |
* Removes a <code>ChangeListener</code> from the model.
|
|
237 |
*
|
|
238 |
* @param l the listener to remove
|
|
239 |
*/
|
|
240 |
void removeChangeListener(ChangeListener l);
|
|
241 |
|
|
242 |
}
|