48 |
import javax.accessibility.AccessibleContext; |
import javax.accessibility.AccessibleContext; |
49 |
import javax.accessibility.AccessibleRole; |
import javax.accessibility.AccessibleRole; |
50 |
import javax.accessibility.AccessibleState; |
import javax.accessibility.AccessibleState; |
51 |
|
import javax.accessibility.AccessibleStateSet; |
52 |
import javax.accessibility.AccessibleValue; |
import javax.accessibility.AccessibleValue; |
53 |
|
|
54 |
/** |
/** |
56 |
* or more Checkboxes can be grouped by a CheckboxGroup. |
* or more Checkboxes can be grouped by a CheckboxGroup. |
57 |
* |
* |
58 |
* @author Aaron M. Renn (arenn@urbanophile.com) |
* @author Aaron M. Renn (arenn@urbanophile.com) |
59 |
* @author Tom Tromey <tromey@redhat.com> |
* @author Tom Tromey (tromey@redhat.com) |
60 |
*/ |
*/ |
61 |
public class Checkbox extends Component |
public class Checkbox extends Component |
62 |
implements ItemSelectable, Accessible, Serializable |
implements ItemSelectable, Accessible, Serializable |
95 |
// The list of listeners for this object. |
// The list of listeners for this object. |
96 |
private transient ItemListener item_listeners; |
private transient ItemListener item_listeners; |
97 |
|
|
98 |
protected class AccessibleAWTCheckBox |
protected class AccessibleAWTCheckbox |
99 |
extends AccessibleAWTComponent |
extends AccessibleAWTComponent |
100 |
implements ItemListener, AccessibleAction, AccessibleValue |
implements ItemListener, AccessibleAction, AccessibleValue |
101 |
{ |
{ |
|
|
|
102 |
|
|
103 |
/* (non-Javadoc) |
/** |
104 |
|
* Serialization constant to match JDK 1.5 |
105 |
|
*/ |
106 |
|
private static final long serialVersionUID = 7881579233144754107L; |
107 |
|
|
108 |
|
/** |
109 |
|
* Captures changes to the state of the checkbox and |
110 |
|
* fires appropriate accessible property change events. |
111 |
|
* |
112 |
|
* @param event the event fired. |
113 |
* @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent) |
* @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent) |
114 |
*/ |
*/ |
115 |
public void itemStateChanged(ItemEvent event) |
public void itemStateChanged(ItemEvent event) |
119 |
state ? AccessibleState.CHECKED : null); |
state ? AccessibleState.CHECKED : null); |
120 |
} |
} |
121 |
|
|
122 |
|
/** |
123 |
|
* Returns an implementation of the <code>AccessibleAction</code> |
124 |
|
* interface for this accessible object. In this case, the |
125 |
|
* current instance is simply returned (with a more appropriate |
126 |
|
* type), as it also implements the accessible action as well as |
127 |
|
* the context. |
128 |
|
* |
129 |
|
* @return the accessible action associated with this context. |
130 |
|
* @see javax.accessibility.AccessibleAction |
131 |
|
*/ |
132 |
public AccessibleAction getAccessibleAction() |
public AccessibleAction getAccessibleAction() |
133 |
{ |
{ |
134 |
return this; |
return this; |
135 |
} |
} |
136 |
|
|
137 |
|
/** |
138 |
|
* Returns an implementation of the <code>AccessibleValue</code> |
139 |
|
* interface for this accessible object. In this case, the |
140 |
|
* current instance is simply returned (with a more appropriate |
141 |
|
* type), as it also implements the accessible value as well as |
142 |
|
* the context. |
143 |
|
* |
144 |
|
* @return the accessible value associated with this context. |
145 |
|
* @see javax.accessibility.AccessibleValue |
146 |
|
*/ |
147 |
public AccessibleValue getAccessibleValue() |
public AccessibleValue getAccessibleValue() |
148 |
{ |
{ |
149 |
return this; |
return this; |
150 |
} |
} |
151 |
|
|
152 |
/* (non-Javadoc) |
/* |
153 |
|
* The following methods are implemented in the JDK (up to |
154 |
|
* 1.5) as stubs. We do likewise here. |
155 |
|
*/ |
156 |
|
|
157 |
|
/** |
158 |
|
* Returns the number of actions associated with this accessible |
159 |
|
* object. This default implementation returns 0. |
160 |
|
* |
161 |
|
* @return the number of accessible actions available. |
162 |
* @see javax.accessibility.AccessibleAction#getAccessibleActionCount() |
* @see javax.accessibility.AccessibleAction#getAccessibleActionCount() |
163 |
*/ |
*/ |
164 |
public int getAccessibleActionCount() |
public int getAccessibleActionCount() |
165 |
{ |
{ |
166 |
// 1.4.1 does this |
// 1.4.1 and 1.5 do this |
167 |
return 0; |
return 0; |
168 |
} |
} |
169 |
|
|
170 |
/* (non-Javadoc) |
/** |
171 |
|
* Returns a description of the action with the supplied id. |
172 |
|
* This default implementation always returns null. |
173 |
|
* |
174 |
|
* @param i the id of the action whose description should be |
175 |
|
* retrieved. |
176 |
|
* @return a <code>String</code> describing the action. |
177 |
* @see javax.accessibility.AccessibleAction#getAccessibleActionDescription(int) |
* @see javax.accessibility.AccessibleAction#getAccessibleActionDescription(int) |
178 |
*/ |
*/ |
179 |
public String getAccessibleActionDescription(int i) |
public String getAccessibleActionDescription(int i) |
180 |
{ |
{ |
181 |
|
// 1.5 does this |
182 |
return null; |
return null; |
183 |
} |
} |
184 |
|
|
185 |
/* (non-Javadoc) |
/** |
186 |
|
* Executes the action with the specified id. This |
187 |
|
* default implementation simply returns false. |
188 |
|
* |
189 |
|
* @param i the id of the action to perform. |
190 |
|
* @return true if the action was performed. |
191 |
* @see javax.accessibility.AccessibleAction#doAccessibleAction(int) |
* @see javax.accessibility.AccessibleAction#doAccessibleAction(int) |
192 |
*/ |
*/ |
193 |
public boolean doAccessibleAction(int i) |
public boolean doAccessibleAction(int i) |
194 |
{ |
{ |
195 |
|
// 1.5 does this |
196 |
return false; |
return false; |
197 |
} |
} |
198 |
|
|
199 |
/* (non-Javadoc) |
/** |
200 |
|
* Returns the current value of this accessible object. |
201 |
|
* If no value has been set, null is returned. This |
202 |
|
* default implementation always returns null, regardless. |
203 |
|
* |
204 |
|
* @return the numeric value of this object, or null if |
205 |
|
* no value has been set. |
206 |
* @see javax.accessibility.AccessibleValue#getCurrentAccessibleValue() |
* @see javax.accessibility.AccessibleValue#getCurrentAccessibleValue() |
207 |
*/ |
*/ |
208 |
public Number getCurrentAccessibleValue() |
public Number getCurrentAccessibleValue() |
209 |
{ |
{ |
210 |
|
// 1.5 does this |
211 |
return null; |
return null; |
212 |
} |
} |
213 |
|
|
214 |
/* (non-Javadoc) |
/** |
215 |
|
* Sets the current value of this accessible object |
216 |
|
* to that supplied. In this default implementation, |
217 |
|
* the value is never set and the method always returns |
218 |
|
* false. |
219 |
|
* |
220 |
|
* @param number the new accessible value. |
221 |
|
* @return true if the value was set. |
222 |
* @see javax.accessibility.AccessibleValue#setCurrentAccessibleValue(java.lang.Number) |
* @see javax.accessibility.AccessibleValue#setCurrentAccessibleValue(java.lang.Number) |
223 |
*/ |
*/ |
224 |
public boolean setCurrentAccessibleValue(Number number) |
public boolean setCurrentAccessibleValue(Number number) |
225 |
{ |
{ |
226 |
|
// 1.5 does this |
227 |
return false; |
return false; |
228 |
} |
} |
229 |
|
|
230 |
/* (non-Javadoc) |
/** |
231 |
|
* Returns the minimum acceptable accessible value used |
232 |
|
* by this object, or null if no minimum value exists. |
233 |
|
* This default implementation always returns null. |
234 |
|
* |
235 |
|
* @return the minimum acceptable accessible value, or null |
236 |
|
* if there is no minimum. |
237 |
* @see javax.accessibility.AccessibleValue#getMinimumAccessibleValue() |
* @see javax.accessibility.AccessibleValue#getMinimumAccessibleValue() |
238 |
*/ |
*/ |
239 |
public Number getMinimumAccessibleValue() |
public Number getMinimumAccessibleValue() |
241 |
return null; |
return null; |
242 |
} |
} |
243 |
|
|
244 |
/* (non-Javadoc) |
/** |
245 |
|
* Returns the maximum acceptable accessible value used |
246 |
|
* by this object, or null if no maximum value exists. |
247 |
|
* This default implementation always returns null. |
248 |
|
* |
249 |
|
* @return the maximum acceptable accessible value, or null |
250 |
|
* if there is no maximum. |
251 |
* @see javax.accessibility.AccessibleValue#getMaximumAccessibleValue() |
* @see javax.accessibility.AccessibleValue#getMaximumAccessibleValue() |
252 |
*/ |
*/ |
253 |
public Number getMaximumAccessibleValue() |
public Number getMaximumAccessibleValue() |
255 |
return null; |
return null; |
256 |
} |
} |
257 |
|
|
258 |
|
/** |
259 |
|
* Returns the role of this accessible object. |
260 |
|
* |
261 |
|
* @return the instance of <code>AccessibleRole</code>, |
262 |
|
* which describes this object. |
263 |
|
* @see javax.accessibility.AccessibleRole |
264 |
|
*/ |
265 |
public AccessibleRole getAccessibleRole() |
public AccessibleRole getAccessibleRole() |
266 |
{ |
{ |
267 |
return AccessibleRole.CHECK_BOX; |
return AccessibleRole.CHECK_BOX; |
268 |
} |
} |
269 |
|
|
270 |
|
/** |
271 |
|
* Returns the state set of this accessible object. |
272 |
|
* |
273 |
|
* @return a set of <code>AccessibleState</code>s |
274 |
|
* which represent the current state of the |
275 |
|
* accessible object. |
276 |
|
* @see javax.accessibility.AccessibleState |
277 |
|
* @see javax.accessibility.AccessibleStateSet |
278 |
|
*/ |
279 |
|
public AccessibleStateSet getAccessibleStateSet() |
280 |
|
{ |
281 |
|
AccessibleStateSet set = super.getAccessibleStateSet(); |
282 |
|
if (state) |
283 |
|
set.add(AccessibleState.CHECKED); |
284 |
|
return set; |
285 |
|
} |
286 |
|
|
287 |
} |
} |
288 |
|
|
289 |
/*************************************************************************/ |
/*************************************************************************/ |
593 |
} |
} |
594 |
|
|
595 |
/** |
/** |
596 |
* Gets the AccessibleContext associated with this <code>CheckBox</code>. |
* Gets the AccessibleContext associated with this <code>Checkbox</code>. |
597 |
* The context is created, if necessary. |
* The context is created, if necessary. |
598 |
* |
* |
599 |
* @return the associated context |
* @return the associated context |
603 |
/* Create the context if this is the first request */ |
/* Create the context if this is the first request */ |
604 |
if (accessibleContext == null) |
if (accessibleContext == null) |
605 |
{ |
{ |
606 |
AccessibleAWTCheckBox ac = new AccessibleAWTCheckBox(); |
AccessibleAWTCheckbox ac = new AccessibleAWTCheckbox(); |
607 |
accessibleContext = ac; |
accessibleContext = ac; |
608 |
addItemListener(ac); |
addItemListener(ac); |
609 |
} |
} |