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 |
/** |
99 |
|
* This class provides accessibility support for the |
100 |
|
* checkbox. |
101 |
|
* |
102 |
|
* @author Jerry Quinn (jlquinn@optonline.net) |
103 |
|
* @author Andrew John Hughes (gnu_andrew@member.fsf.org) |
104 |
|
*/ |
105 |
|
protected class AccessibleAWTCheckbox |
106 |
extends AccessibleAWTComponent |
extends AccessibleAWTComponent |
107 |
implements ItemListener, AccessibleAction, AccessibleValue |
implements ItemListener, AccessibleAction, AccessibleValue |
108 |
{ |
{ |
|
|
|
109 |
|
|
110 |
/* (non-Javadoc) |
/** |
111 |
|
* Serialization constant to match JDK 1.5 |
112 |
|
*/ |
113 |
|
private static final long serialVersionUID = 7881579233144754107L; |
114 |
|
|
115 |
|
/** |
116 |
|
* Captures changes to the state of the checkbox and |
117 |
|
* fires appropriate accessible property change events. |
118 |
|
* |
119 |
|
* @param event the event fired. |
120 |
* @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent) |
* @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent) |
121 |
*/ |
*/ |
122 |
public void itemStateChanged(ItemEvent event) |
public void itemStateChanged(ItemEvent event) |
126 |
state ? AccessibleState.CHECKED : null); |
state ? AccessibleState.CHECKED : null); |
127 |
} |
} |
128 |
|
|
129 |
|
/** |
130 |
|
* Returns an implementation of the <code>AccessibleAction</code> |
131 |
|
* interface for this accessible object. In this case, the |
132 |
|
* current instance is simply returned (with a more appropriate |
133 |
|
* type), as it also implements the accessible action as well as |
134 |
|
* the context. |
135 |
|
* |
136 |
|
* @return the accessible action associated with this context. |
137 |
|
* @see javax.accessibility.AccessibleAction |
138 |
|
*/ |
139 |
public AccessibleAction getAccessibleAction() |
public AccessibleAction getAccessibleAction() |
140 |
{ |
{ |
141 |
return this; |
return this; |
142 |
} |
} |
143 |
|
|
144 |
|
/** |
145 |
|
* Returns an implementation of the <code>AccessibleValue</code> |
146 |
|
* interface for this accessible object. In this case, the |
147 |
|
* current instance is simply returned (with a more appropriate |
148 |
|
* type), as it also implements the accessible value as well as |
149 |
|
* the context. |
150 |
|
* |
151 |
|
* @return the accessible value associated with this context. |
152 |
|
* @see javax.accessibility.AccessibleValue |
153 |
|
*/ |
154 |
public AccessibleValue getAccessibleValue() |
public AccessibleValue getAccessibleValue() |
155 |
{ |
{ |
156 |
return this; |
return this; |
157 |
} |
} |
158 |
|
|
159 |
/* (non-Javadoc) |
/* |
160 |
|
* The following methods are implemented in the JDK (up to |
161 |
|
* 1.5) as stubs. We do likewise here. |
162 |
|
*/ |
163 |
|
|
164 |
|
/** |
165 |
|
* Returns the number of actions associated with this accessible |
166 |
|
* object. This default implementation returns 0. |
167 |
|
* |
168 |
|
* @return the number of accessible actions available. |
169 |
* @see javax.accessibility.AccessibleAction#getAccessibleActionCount() |
* @see javax.accessibility.AccessibleAction#getAccessibleActionCount() |
170 |
*/ |
*/ |
171 |
public int getAccessibleActionCount() |
public int getAccessibleActionCount() |
172 |
{ |
{ |
173 |
// 1.4.1 does this |
// 1.4.1 and 1.5 do this |
174 |
return 0; |
return 0; |
175 |
} |
} |
176 |
|
|
177 |
/* (non-Javadoc) |
/** |
178 |
|
* Returns a description of the action with the supplied id. |
179 |
|
* This default implementation always returns null. |
180 |
|
* |
181 |
|
* @param i the id of the action whose description should be |
182 |
|
* retrieved. |
183 |
|
* @return a <code>String</code> describing the action. |
184 |
* @see javax.accessibility.AccessibleAction#getAccessibleActionDescription(int) |
* @see javax.accessibility.AccessibleAction#getAccessibleActionDescription(int) |
185 |
*/ |
*/ |
186 |
public String getAccessibleActionDescription(int i) |
public String getAccessibleActionDescription(int i) |
187 |
{ |
{ |
188 |
|
// 1.5 does this |
189 |
return null; |
return null; |
190 |
} |
} |
191 |
|
|
192 |
/* (non-Javadoc) |
/** |
193 |
|
* Executes the action with the specified id. This |
194 |
|
* default implementation simply returns false. |
195 |
|
* |
196 |
|
* @param i the id of the action to perform. |
197 |
|
* @return true if the action was performed. |
198 |
* @see javax.accessibility.AccessibleAction#doAccessibleAction(int) |
* @see javax.accessibility.AccessibleAction#doAccessibleAction(int) |
199 |
*/ |
*/ |
200 |
public boolean doAccessibleAction(int i) |
public boolean doAccessibleAction(int i) |
201 |
{ |
{ |
202 |
|
// 1.5 does this |
203 |
return false; |
return false; |
204 |
} |
} |
205 |
|
|
206 |
/* (non-Javadoc) |
/** |
207 |
|
* Returns the current value of this accessible object. |
208 |
|
* If no value has been set, null is returned. This |
209 |
|
* default implementation always returns null, regardless. |
210 |
|
* |
211 |
|
* @return the numeric value of this object, or null if |
212 |
|
* no value has been set. |
213 |
* @see javax.accessibility.AccessibleValue#getCurrentAccessibleValue() |
* @see javax.accessibility.AccessibleValue#getCurrentAccessibleValue() |
214 |
*/ |
*/ |
215 |
public Number getCurrentAccessibleValue() |
public Number getCurrentAccessibleValue() |
216 |
{ |
{ |
217 |
|
// 1.5 does this |
218 |
return null; |
return null; |
219 |
} |
} |
220 |
|
|
221 |
/* (non-Javadoc) |
/** |
222 |
|
* Sets the current value of this accessible object |
223 |
|
* to that supplied. In this default implementation, |
224 |
|
* the value is never set and the method always returns |
225 |
|
* false. |
226 |
|
* |
227 |
|
* @param number the new accessible value. |
228 |
|
* @return true if the value was set. |
229 |
* @see javax.accessibility.AccessibleValue#setCurrentAccessibleValue(java.lang.Number) |
* @see javax.accessibility.AccessibleValue#setCurrentAccessibleValue(java.lang.Number) |
230 |
*/ |
*/ |
231 |
public boolean setCurrentAccessibleValue(Number number) |
public boolean setCurrentAccessibleValue(Number number) |
232 |
{ |
{ |
233 |
|
// 1.5 does this |
234 |
return false; |
return false; |
235 |
} |
} |
236 |
|
|
237 |
/* (non-Javadoc) |
/** |
238 |
|
* Returns the minimum acceptable accessible value used |
239 |
|
* by this object, or null if no minimum value exists. |
240 |
|
* This default implementation always returns null. |
241 |
|
* |
242 |
|
* @return the minimum acceptable accessible value, or null |
243 |
|
* if there is no minimum. |
244 |
* @see javax.accessibility.AccessibleValue#getMinimumAccessibleValue() |
* @see javax.accessibility.AccessibleValue#getMinimumAccessibleValue() |
245 |
*/ |
*/ |
246 |
public Number getMinimumAccessibleValue() |
public Number getMinimumAccessibleValue() |
248 |
return null; |
return null; |
249 |
} |
} |
250 |
|
|
251 |
/* (non-Javadoc) |
/** |
252 |
|
* Returns the maximum acceptable accessible value used |
253 |
|
* by this object, or null if no maximum value exists. |
254 |
|
* This default implementation always returns null. |
255 |
|
* |
256 |
|
* @return the maximum acceptable accessible value, or null |
257 |
|
* if there is no maximum. |
258 |
* @see javax.accessibility.AccessibleValue#getMaximumAccessibleValue() |
* @see javax.accessibility.AccessibleValue#getMaximumAccessibleValue() |
259 |
*/ |
*/ |
260 |
public Number getMaximumAccessibleValue() |
public Number getMaximumAccessibleValue() |
262 |
return null; |
return null; |
263 |
} |
} |
264 |
|
|
265 |
|
/** |
266 |
|
* Returns the role of this accessible object. |
267 |
|
* |
268 |
|
* @return the instance of <code>AccessibleRole</code>, |
269 |
|
* which describes this object. |
270 |
|
* @see javax.accessibility.AccessibleRole |
271 |
|
*/ |
272 |
public AccessibleRole getAccessibleRole() |
public AccessibleRole getAccessibleRole() |
273 |
{ |
{ |
274 |
return AccessibleRole.CHECK_BOX; |
return AccessibleRole.CHECK_BOX; |
275 |
} |
} |
276 |
|
|
277 |
|
/** |
278 |
|
* Returns the state set of this accessible object. |
279 |
|
* |
280 |
|
* @return a set of <code>AccessibleState</code>s |
281 |
|
* which represent the current state of the |
282 |
|
* accessible object. |
283 |
|
* @see javax.accessibility.AccessibleState |
284 |
|
* @see javax.accessibility.AccessibleStateSet |
285 |
|
*/ |
286 |
|
public AccessibleStateSet getAccessibleStateSet() |
287 |
|
{ |
288 |
|
AccessibleStateSet set = super.getAccessibleStateSet(); |
289 |
|
if (state) |
290 |
|
set.add(AccessibleState.CHECKED); |
291 |
|
return set; |
292 |
|
} |
293 |
|
|
294 |
} |
} |
295 |
|
|
296 |
/*************************************************************************/ |
/*************************************************************************/ |
600 |
} |
} |
601 |
|
|
602 |
/** |
/** |
603 |
* Gets the AccessibleContext associated with this <code>CheckBox</code>. |
* Gets the AccessibleContext associated with this <code>Checkbox</code>. |
604 |
* The context is created, if necessary. |
* The context is created, if necessary. |
605 |
* |
* |
606 |
* @return the associated context |
* @return the associated context |
610 |
/* Create the context if this is the first request */ |
/* Create the context if this is the first request */ |
611 |
if (accessibleContext == null) |
if (accessibleContext == null) |
612 |
{ |
{ |
613 |
AccessibleAWTCheckBox ac = new AccessibleAWTCheckBox(); |
AccessibleAWTCheckbox ac = new AccessibleAWTCheckbox(); |
614 |
accessibleContext = ac; |
accessibleContext = ac; |
615 |
addItemListener(ac); |
addItemListener(ac); |
616 |
} |
} |