Merge from mainline.
[official-gcc.git] / libjava / classpath / javax / accessibility / AccessibleContext.java
blob972f4feae923dab0e68afd1a3bd0e4e3ccd61164
1 /* AccessibleContext.java -- the context of an accessible object
2 Copyright (C) 2002 Free Software Foundation
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package javax.accessibility;
40 import java.beans.PropertyChangeListener;
41 import java.beans.PropertyChangeSupport;
42 import java.util.Locale;
44 /**
45 * The minimum information that all accessible objects return. This includes
46 * name, description, role, and state of the object, parents and children,
47 * and any other useful information. If a component supports further details,
48 * it should implement one of the following:<ul>
49 * <li>{@link AccessibleAction} - the object can perform actions</li>
50 * <li>{@link AccessibleComponent} - the object has a graphical
51 * representation</li>
52 * <li>{@link AccessibleSelection} - the object allows its children to be
53 * selected</li>
54 * <li>{@link AccessibleText} - the object represents editable text</li>
55 * <li>{@link AccessibleValue} - the object represents a numerical value</li>
56 * </ul>
58 * @author Eric Blake (ebb9@email.byu.edu)
59 * @since 1.2
60 * @status updated to 1.4
62 public abstract class AccessibleContext
64 /**
65 * Constant used when the accessible name has changed. Both the old and new
66 * values are listed in the event.
68 * @see #getAccessibleName()
69 * @see #addPropertyChangeListener(PropertyChangeListener)
71 public static final String ACCESSIBLE_NAME_PROPERTY
72 = "AccessibleName";
74 /**
75 * Constant used when the accessible description has changed. Both the old
76 * and new values are listed in the event.
78 * @see #getAccessibleDescription()
79 * @see #addPropertyChangeListener(PropertyChangeListener)
81 public static final String ACCESSIBLE_DESCRIPTION_PROPERTY
82 = "AccessibleDescription";
84 /**
85 * Constant used when the accessibleStateSet has changed. Both the old and
86 * new values are listed in the event, although either may be null if a
87 * state was disabled at that time.
89 * @see #getAccessibleStateSet()
90 * @see AccessibleState
91 * @see AccessibleStateSet
92 * @see #addPropertyChangeListener(PropertyChangeListener)
94 public static final String ACCESSIBLE_STATE_PROPERTY
95 = "AccessibleState";
97 /**
98 * Constant used when the accessibleValue has changed. Both the old and new
99 * values are listed in the event.
101 * @see #getAccessibleValue()
102 * @see #addPropertyChangeListener(PropertyChangeListener)
104 public static final String ACCESSIBLE_VALUE_PROPERTY
105 = "AccessibleValue";
108 * Constant used when the accessibleSelection has changed. Both the old and
109 * new values of the event are reserved for future use.
111 * @see #getAccessibleSelection()
112 * @see #addPropertyChangeListener(PropertyChangeListener)
114 public static final String ACCESSIBLE_SELECTION_PROPERTY
115 = "AccessibleSelection";
118 * Constant used when the accessibleText has changed. Both the old and new
119 * values of the event are reserved for future use.
121 * @see #getAccessibleText()
122 * @see #addPropertyChangeListener(PropertyChangeListener)
124 public static final String ACCESSIBLE_TEXT_PROPERTY
125 = "AccessibleText";
128 * Constant used when the accessibleText caret has changed. Both the old and
129 * new values are listed in the event.
131 * @see #addPropertyChangeListener(PropertyChangeListener)
133 public static final String ACCESSIBLE_CARET_PROPERTY
134 = "AccessibleCaret";
137 * Constant used when the visible data has changed. Both the old and new
138 * values of the event are reserved for future use.
140 * @see #addPropertyChangeListener(PropertyChangeListener)
142 public static final String ACCESSIBLE_VISIBLE_DATA_PROPERTY
143 = "AccessibleVisibleData";
146 * Constant used when children are added or removed. On addition, the new
147 * value of the event holds the new child; on removal, the old value holds
148 * the removed child.
150 * @see #addPropertyChangeListener(PropertyChangeListener)
152 public static final String ACCESSIBLE_CHILD_PROPERTY
153 = "AccessibleChild";
156 * Constant used when active descendent of a component has changed. Both
157 * the old and new values are listed in the event.
159 * @see #addPropertyChangeListener(PropertyChangeListener)
161 public static final String ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY
162 = "AccessibleActiveDescendant";
165 * Constant used when the accessible table caption has changed. Both the
166 * old and new values are listed in the event.
168 * @see Accessible
169 * @see AccessibleTable
171 public static final String ACCESSIBLE_TABLE_CAPTION_CHANGED
172 = "accessibleTableCaptionChanged";
175 * Constant used when the accessible table summary has changed. Both the
176 * old and new values are listed in the event.
178 * @see Accessible
179 * @see AccessibleTable
181 public static final String ACCESSIBLE_TABLE_SUMMARY_CHANGED
182 = "accessibleTableSummaryChanged";
185 * Constant used when the accessible table model has changed. Only the new
186 * value of the event has meaning.
188 * @see AccessibleTable
189 * @see AccessibleTableModelChange
191 public static final String ACCESSIBLE_TABLE_MODEL_CHANGED
192 = "accessibleTableModelChanged";
195 * Constant used when the accessible table row header has changed. Only the
196 * new value of the event has meaning.
198 * @see AccessibleTable
199 * @see AccessibleTableModelChange
201 public static final String ACCESSIBLE_TABLE_ROW_HEADER_CHANGED
202 = "accessibleTableRowHeaderChanged";
205 * Constant used when the accessible table row description has changed. Only
206 * the new value of the event has meaning.
208 * @see AccessibleTable
210 public static final String ACCESSIBLE_TABLE_ROW_DESCRIPTION_CHANGED
211 = "accessibleTableRowDescriptionChanged";
214 * Constant used when the accessible table column header has changed. Only
215 * the new value of the event has meaning.
217 * @see AccessibleTable
218 * @see AccessibleTableModelChange
220 public static final String ACCESSIBLE_TABLE_COLUMN_HEADER_CHANGED
221 = "accessibleTableColumnHeaderChanged";
224 * Constant used when the accessible table column description has changed.
225 * Only the new value of the event has meaning.
227 * @see AccessibleTable
229 public static final String ACCESSIBLE_TABLE_COLUMN_DESCRIPTION_CHANGED
230 = "accessibleTableColumnDescriptionChanged";
233 * Constant used when supported set of actions has changed. Both the old
234 * and new values are listed in the event.
236 * @see AccessibleAction
238 public static final String ACCESSIBLE_ACTION_PROPERTY
239 = "accessibleActionProperty";
242 * Constant used when a hypertext element received focus. Both the old
243 * and new values are listed in the event, with -1 indicating that no link
244 * had focus.
246 * @see AccessibleHyperlink
248 public static final String ACCESSIBLE_HYPERTEXT_OFFSET
249 = "AccessibleHypertextOffset";
252 * Constant used when a component's bounds have changed. The old and
253 * new bounds are given in the event.
254 * @since 1.5
256 public static final String ACCESSIBLE_COMPONENT_BOUNDS_CHANGED
257 = "accessibleComponentBoundsChanged";
260 * Constant used when the state of child objects changes. The old
261 * value in the event is always null, and the new value is the component
262 * whose children have changed.
263 * @since 1.5
265 public static final String ACCESSIBLE_INVALIDATE_CHILDREN
266 = "accessibleInvalidateChildren";
269 * Constant used when the attributes of some text have changed.
270 * On insertion, the old value is null and the new value is an
271 * {@link AccessibleAttributeSequence} describing the insertion.
272 * On deletion, the old value is an {@link AccessibleAttributeSequence}
273 * and the new value is null. For replacement, both the old
274 * and new values are {@link AccessibleAttributeSequence} objects.
275 * @since 1.5
277 public static final String ACCESSIBLE_TEXT_ATTRIBUTES_CHANGED
278 = "accessibleTextAttributesChanged";
281 * The accessible parent of this object.
283 * @see #getAccessibleParent()
284 * @see #setAccessibleParent(Accessible)
286 protected Accessible accessibleParent;
289 * A localized string naming this object.
291 * @see #getAccessibleName()
292 * @see #setAccessibleName(String)
294 protected String accessibleName;
297 * A localized string describing this object.
299 * @see #getAccessibleDescription()
300 * @see #setAccessibleDescription(String)
302 protected String accessibleDescription;
305 * The listener tool.
307 * @see #addPropertyChangeListener(PropertyChangeListener)
308 * @see #removePropertyChangeListener(PropertyChangeListener)
309 * @see #firePropertyChange(String, Object, Object)
311 private final PropertyChangeSupport listeners
312 = new PropertyChangeSupport(this);
315 * Default constructor.
317 public AccessibleContext()
322 * Get the localized name of the object. For example, a label may just
323 * return the text of the label, while an entry field for city may return
324 * "city" in en_US.
326 * @return the accessible object's name, or null if it is unnamed
327 * @see #setAccessibleName(String)
329 public String getAccessibleName()
331 return accessibleName;
335 * Set the localized name of the object. This will fire a
336 * PropertyChangeEvent with ACCESSIBLE_NAME_PROPERTY.
338 * @param s the new name
339 * @see #getAccessibleName()
340 * @see #addPropertyChangeListener(PropertyChangeListener)
342 public void setAccessibleName(String s)
344 listeners.firePropertyChange(ACCESSIBLE_NAME_PROPERTY, accessibleName, s);
345 accessibleName = s;
349 * Get the localized description of the object. For example, a 'Cancel'
350 * button may be described as "Ignore changes and close dialog box" in
351 * en_US.
353 * @return the accessible object's description, or null if there is none
354 * @see #setAccessibleDescription(String)
356 public String getAccessibleDescription()
358 return accessibleDescription;
362 * Set the localized name of the object. This will fire a
363 * PropertyChangeEvent with ACCESSIBLE_DESCRIPTION_PROPERTY.
365 * @param s the new description
366 * @see #getAccessibleDescription()
367 * @see #addPropertyChangeListener(PropertyChangeListener)
369 public void setAccessibleDescription(String s)
371 listeners.firePropertyChange(ACCESSIBLE_DESCRIPTION_PROPERTY,
372 accessibleDescription, s);
373 accessibleDescription = s;
377 * Gets the role of this object. For example, a button serves the role of
378 * AccessibleRole.PUSH_BUTTON. This allows assistive technologies to funnel
379 * similar objects into the same assistance classes. Note that the class
380 * is extensible, to define new roles if necessary.
382 * @return the role of the object
383 * @see AccessibleRole
385 public abstract AccessibleRole getAccessibleRole();
388 * Gets the state set of this object. A change in the state of the object
389 * will fire a PropertyChangeEvent for ACCESSIBLE_STATE_PROPERTY.
391 * @return the current state of the object
392 * @see AccessibleState
393 * @see AccessibleStateSet
394 * @see #addPropertyChangeListener(PropertyChangeListener)
396 public abstract AccessibleStateSet getAccessibleStateSet();
399 * Return the accessible parent of this object.
401 * @return the accessible parent, or null if there is none
403 public Accessible getAccessibleParent()
405 return accessibleParent;
409 * Sets the accessible parent of this object. This should only be used when
410 * the current parent object should not be the accessible parent; only the
411 * parent of the accessible child should call this method.
413 * @param a the new parent
415 public void setAccessibleParent(Accessible a)
417 accessibleParent = a;
421 * Gets the index of this object within its accessible parent.
423 * @return the 0-based index, or -1 if there is no accessible parent
424 * @see #getAccessibleParent()
425 * @see #getAccessibleChildrenCount()
426 * @see #getAccessibleChild(int)
428 public abstract int getAccessibleIndexInParent();
431 * Returns the number of accessible children of this object.
433 * @return the number of accessible children
434 * @see #getAccessibleChild(int)
436 public abstract int getAccessibleChildrenCount();
439 * Returns the specified accessible chile.
441 * @param i the 0-based index to get
442 * @return the child, or null if out of bounds
443 * @see #getAccessibleChildrenCount()
445 public abstract Accessible getAccessibleChild(int i);
448 * Gets the component locale, deferring to the parent if one is not declared.
450 * @return the locale
451 * @throws java.awt.IllegalComponentStateException if there is no locale
452 * or parent
454 public abstract Locale getLocale();
457 * Add a PropertyChangeListener to the listener list. This listener will
458 * be notified of all property changes to the accessible object.
460 * @param l the listener to add
461 * @see #ACCESSIBLE_NAME_PROPERTY
462 * @see #ACCESSIBLE_DESCRIPTION_PROPERTY
463 * @see #ACCESSIBLE_STATE_PROPERTY
464 * @see #ACCESSIBLE_VALUE_PROPERTY
465 * @see #ACCESSIBLE_SELECTION_PROPERTY
466 * @see #ACCESSIBLE_TEXT_PROPERTY
467 * @see #ACCESSIBLE_VISIBLE_DATA_PROPERTY
468 * @see #removePropertyChangeListener(PropertyChangeListener)
470 public void addPropertyChangeListener(PropertyChangeListener l)
472 listeners.addPropertyChangeListener(l);
476 * Remove a PropertyChangeListener from the listener list.
478 * @param l the listener to remove
479 * @see #addPropertyChangeListener(PropertyChangeListener)
481 public void removePropertyChangeListener(PropertyChangeListener l)
483 listeners.removePropertyChangeListener(l);
487 * Get any supported accessible actions. The default implementation returns
488 * null.
490 * @return the supported action, or null
491 * @see AccessibleAction
493 public AccessibleAction getAccessibleAction()
495 return null;
499 * Get any supported accessible compoent. The default implementation returns
500 * null.
502 * @return the supported component, or null
503 * @see AccessibleComponent
505 public AccessibleComponent getAccessibleComponent()
507 return null;
511 * Get any supported accessible selection. The default implementation returns
512 * null.
514 * @return the supported selection, or null
515 * @see AccessibleSelection
517 public AccessibleSelection getAccessibleSelection()
519 return null;
523 * Get any supported accessible text. The default implementation returns
524 * null.
526 * @return the supported text, or null
527 * @see AccessibleText
529 public AccessibleText getAccessibleText()
531 return null;
535 * Get any supported accessible editable text. The default implementation
536 * returns null.
538 * @return the supported editable text, or null
539 * @see AccessibleEditableText
541 public AccessibleEditableText getAccessibleEditableText()
543 return null;
547 * Get any supported accessible value. The default implementation returns
548 * null.
550 * @return the supported value, or null
551 * @see AccessibleValue
553 public AccessibleValue getAccessibleValue()
555 return null;
559 * Get all supported accessible icons. The default implementation returns
560 * null.
562 * @return the supported icons, or null
563 * @see AccessibleIcon
565 public AccessibleIcon[] getAccessibleIcon()
567 return null;
571 * Get any supported accessible relation set. The default implementation
572 * returns an empty AccessibleRelationSet.
574 * @return the supported relation set, or <code>null</code>
576 * @see AccessibleRelationSet
578 public AccessibleRelationSet getAccessibleRelationSet()
580 return new AccessibleRelationSet();
584 * Get any supported accessible table. The default implementation returns
585 * null.
587 * @return the supported table, or null
588 * @see AccessibleTable
590 public AccessibleTable getAccessibleTable()
592 return null;
596 * Fire an event to report property changes. This is intended for use by
597 * the accessible objects, not general application programs. If oldValue and
598 * newValue differ, and the listenter list is not empty, a PropertyChange
599 * event is fired to each listener.
601 * @param name the property name
602 * @param oldValue the prior value
603 * @param newValue the updated value
604 * @see PropertyChangeSupport
605 * @see #addPropertyChangeListener(PropertyChangeListener)
606 * @see #removePropertyChangeListener(PropertyChangeListener)
607 * @see #ACCESSIBLE_NAME_PROPERTY
608 * @see #ACCESSIBLE_DESCRIPTION_PROPERTY
609 * @see #ACCESSIBLE_STATE_PROPERTY
610 * @see #ACCESSIBLE_VALUE_PROPERTY
611 * @see #ACCESSIBLE_SELECTION_PROPERTY
612 * @see #ACCESSIBLE_TEXT_PROPERTY
613 * @see #ACCESSIBLE_VISIBLE_DATA_PROPERTY
615 public void firePropertyChange(String name, Object oldValue, Object newValue)
617 listeners.firePropertyChange(name, oldValue, newValue);
619 } // class AccessibleContext