Before going further, there are several simple objects in the accessibility package used by AccessibleContext that we should discuss in more detail. 25.3.1 The AccessibleState Class Each accessible component can have one or more states associated with it. An assistive technology can query these states at any time to determine how best to deal with the component. The accessible states can only be retrieved, however, and not set. There are two classes that the Accessible package uses to handle states: AccessibleState and AccessibleStateSet. The AccessibleState class contains an enumeration of static objects that define states that any accessible component can have. Note that a component can be in more than one state at any time. A list of the possible states that an accessible object can be in, along with a brief description of each, is shown in Table 25-3. Table 25-3. AccessibleState constants State | Meaning | ACTIVE | The window, dialog, or frame is the active one. | ARMED | The object, such as a button, has been pressed but not released, and the mouse cursor is still over the button. | BUSY | The object is busy processing and should not be interrupted. | CHECKED | The object is checked. | COLLAPSED | The object, such as a node in a tree, is collapsed. | EDITABLE | The object supports any form of editing. | ENABLED | The object is enabled. | EXPANDABLE | The object, such as a node in a tree, can report its children. | EXPANDED | The object, such as a node in a tree, is expanded. | FOCUSABLE | The object can accept the focus. | FOCUSED | The object has the focus. | HORIZONTAL | The object's orientation is horizontal. | ICONFIED | The object is iconified. | MODAL | The object is modal and must be closed before the user can switch to another window. | MULTI_LINE | The object is capable of using many lines of text. | MULTISELECTABLE | The object allows multiple children to be selected at the same time. | OPAQUE | The object is completely filled (i.e., paints every pixel) and thus does not allow transparency. | PRESSED | The object, such as a button, is being pressed but has not been released. | RESIZABLE | The object is resizable. | SELECTABLE | The object is capable of being selected from its parent. | SELECTED | The object is selected. | SHOWING | The object and each of its ancestors are visible. | SINGLE_LINE | The object is capable of using only a single line of text. | TRANSIENT | The object is transient. In the context of accessibility, transient objects serve only to help other components perform some underlying duty, such as rendering to the screen. These objects do not generate change events that an assistive technology would be interested in, but are necessary to allow assistive technologies to query through the component hierarchy. | VERTICAL | The object's orientation is vertical. | VISIBLE | The object is visible. | Some of these states are specific to various objects. For example, a JButton cannot be COLLAPSED, and a JLabel cannot be EDITABLE. An assistive technology, however, should know which objects can have which states and how to act accordingly. Note that the individual states of AccessibleState are immutable objects. In order to work with a group (or set) of them, you will need the services of the AccessibleStateSet object. 25.3.1.1 Constructor - protected AccessibleState(String key)
-
This protected constructor is called using any of the states listed above to instantiate an AccessibleState object. It is protected to allow each of the above constants to remain as a strongly typed, static enumeration of states. Follow this procedure if you subclass AccessibleState with your own states. 25.3.2 The AccessibleStateSet Class Because an accessible component can have more than one accessible state at the same time, you must access each of the states through the use of an AccessibleStateSet object. This object is simply a repository (or set) of accessible states, as well as various methods that search and identify particular states. You can retrieve an AccessibleStateSet for each accessible component with the getAccessibleStateSet( ) accessor of the AccessibleContext object. 25.3.2.1 Constructors - AccessibleStateSet( )
-
Create an empty state set. - AccessibleStateSet(AccessibleState[] states)
-
Create a state set using the array of AccessibleState objects passed in to initialize itself. 25.3.2.2 Methods The methods of AccessibleStateSet give you everything you need to manipulate the set: - public boolean add(AccessibleState state)
-
Add a new AccessibleState to the set, returning true if successful. If the state is already present, it is not added, and the method returns false. - public void addAll(AccessibleState[] states)
-
Add all the states specified in the array to the set, ignoring any that are already present. - public void clear( )
-
Clear all states from the state set. - public boolean contains(AccessibleState state)
-
Return a boolean indicating whether the given state is included in the set. - public boolean remove(AccessibleState state)
-
Remove a specific AccessibleState from the set, returning true if successful. If the state is not present in the set, the method returns false. - public AccessibleState[] toArray( )
-
Return all the states in the set as an array of AccessibleState objects. 25.3.3 The AccessibleRole Class A common way to determine the purpose or function of an accessible component is to check its accessibility role. All accessibility roles are bundled inside the AccessibleRole class, which, like the AccessibleState class, consists only of static constants. An assistive technology can query these read-only roles from AccessibleContext to better determine which type of component it is dealing with. If a desired role does not exist in this class, you can always extend the AccessibleRole class into a subclass of your own and include the newly defined role there. Because they are all of type AccessibleRole, the static constants within this class can be used in conjunction with the getAccessibleRole( ) method of an AccessibleContext object. Table 25-4 outlines each of the accessibility roles. Table 25-4. AccessibleRole constants Constant | Meaning | ALERT | Provides an alert to the user | AWT_COMPONENT | A generic AWT component | CANVAS1.3 | An object that you can paint on and receive events from | CHECK_BOX | A dual-state button or checkbox | COLOR_CHOOSER | An object for selecting a color | COLUMN_HEADER | A header for a column of data | COMBO_BOX | A combo box component | DATE_EDITOR1.4 | An editor that can manipulate Date and Time objects | DESKTOP_ICON | An internal frame that has been iconified | DESKTOP_PANE | A desktop pane that supports internal frames | DIALOG | A top-level dialog box | DIRECTORY_PANE | A specialty pane used to locate directories on a filesystem | FILE_CHOOSER | A specialty dialog box for choosing a file | FILLER | Any object that takes up space in a user interface | FONT_CHOOSER1.4 | A component for picking fonts | FRAME | A top-level frame | GLASS_PANE | The glass pane of a frame or applet | GROUP_BOX1.4 | Any bordered container | HYPERLINK1.4 | A link in a hypertext document | ICON1.3 | An icon (small graphic image) | INTERNAL_FRAME | An internal frame inside a desktop frame | LABEL | A string-based label | LAYERED_PANE | A layered-pane object | LIST | A list object | LIST_ITEM1.3 | An element in a list | MENU | A standard menu that descends from a menu bar | MENU_BAR | A menu bar object | MENU_ITEM | A menu item inside a menu | OPTION_PANE | An object that displays a pop-up message | PAGE_TAB | An page tab object, typically a descendant of a page tab list | PAGE_TAB_LIST | A grouping of page tabs | PANEL | A panel object | PASSWORD_TEXT | A password text field that masks its entry text | POPUP_MENU | A pop-up menu | PROGRESS_BAR | A progress bar object | PUSH_BUTTON | A standard button | RADIO_BUTTON | A radio button | ROOT_PANE | The root pane of a frame | ROW_HEADER | A header for a row of data | SCROLL_BAR | A scrollbar | SCROLL_PANE | A scrollpane object | SEPARATOR | A lined separator used in conjunction with a layout manager | SLIDER | A slider object | SPIN_BOX1.4 | A spinner component | SPLIT_PANE | A pane that is split into two adjustable halves | STATUS_BAR1.4 | A label (or labels) used to show application status information | SWING_COMPONENT | A generic Swing component | TABLE | A table object | TEXT | A generic object that displays text | TOGGLE_BUTTON | A dual-state button that does not provide a separate state | TOOL_BAR | A toolbar object | TOOL_TIP | A tooltip object | TREE | A tree object | UNKNOWN | An unknown object | VIEWPORT | A viewport used in a scrollpane | WINDOW | A top-level window without a border or title | 1.3since 1.3, 1.4since 1.4 | 25.3.3.1 Constructor - protected AccessibleRole(String key)
-
This is the only constructor for the AccessibleRole class. Note that the constructor is protected; there is no public constructor for this class. The constructor takes a single String that corresponds to the locale for each of the accessible roles. This locale determines how to translate each of the states and roles into a human-readable form. |