I l@ve RuBoard |
![]() ![]() |
25.5 Classes Added in SDK 1.3 and 1.4The 1.3 and 1.4 SDKs both augmented the Accessibility package. Three interfaces in particular stand out: AccessibleIcon, AccessibleEditableText, and AccessibleTable. 25.5.1 The AccessibleIcon InterfaceAdded in the 1.3 release, the AccessibleIcon interface allows assistive technologies to get information about any icons on a component (such as a button or a label). Notice that the getAccessibleIcon( ) method from the AccessibleContext class returns an array of icons. While Swing labels and buttons do not support multiple icons, custom components can freely do so and still provide useful information to assistive technologies. 25.5.1.1 PropertiesTable 25-12 lists the three descriptive properties for AccessibleIcon. accessibleIcon-Description is the most useful property and can be set through the accessible context as it is on other components.
25.5.2 The AccessibleEditableText InterfaceWhile the AccessibleText interface has always been part of Swing, an editable representation for text did not exist. With the release of the 1.4 SDK, AccessibleEditableText fills that gap. 25.5.2.1 PropertyAs an extension of the AccessibleText interface, most of the properties for AccessibleEditableText are inherited. One writable property to alter the contents of the text component, textContents, was added. It is shown in Table 25-13.
25.5.2.2 Text manipulation methodsThe remaining AccessibleEditableText methods allow assistive technologies to manipulate text in the editable component:
25.5.3 The AccessibleTable InterfaceThe 1.3 SDK also introduced an accessible interface for tables. This interface allows assistive technologies access to descriptive information on the table and its various parts (rows, columns, and cells). 25.5.3.1 PropertiesThe properties in Table 25-14 describe just about every part of a table you would expect to have access to. Some of the less obvious properties include accessibleAt , which returns the Accessible object at a given row and column. The accessibleCaption property is the table caption—which is not necessarily the same as the summary. The extent properties (accessibleColumnExtentAt and accessibleRowExtentAt) provide information on how many columns or rows, respectively, the Accessible object occupies. For example, an accessible spreadsheet might have an entry that occupies two or more "straddled" cells.
25.5.4 Relations and Extended InformationAmong the other accessibility pieces added in the 1.3 and 1.4 releases are the AccessibleRelation and AccessibleRelationSet classes. A new method in the AccessibleContext class gives you access to the relation set for an accessible component. A relation set is the collection of all relationships between this component and other components in the system. The AccessibleRelation class encodes these relationships. An AccessibleRelation can describe several relationships, including control (controller/controlled by), labeling (label for/labeled by), and membership. Perhaps not surprisingly, the extended accessibility interfaces (AccessibleExtendedTable and AccessibleExtendedComponent) provide information above and beyond what's available through their parent interfaces, AccessibleTable and AccessibleComponent, respectively. The extended component interface describes information for onscreen components, including tooltip text, border text, and key bindings. The extended table information allows you to translate between row and column indices and a linear index of Accessible objects. For example, given a pair of row and column values, you can look up the Accessible object associated with that cell. Alternatively, you can take the index of a particular Accessible object and find out which row or column it is associated with. The last big addition to the accessibility package is the AccessibleKeyBindings interface. This interface simply describes the key bindings (i.e., shortcuts and mnemonics) associated with a component. Again, this type of information is available in other formats from other places, but this interface gives assistive technologies a consistent view of the bindings as well as a consistent way of extracting the relevant parts. 25.5.5 Implementing AccessibleActionHere is a short example that implements an AccessibleContext and the AccessibleAction interface for a simple AWT button: // ActionExampleButton.java // import java.util.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.accessibility.*; public class ActionExampleButton extends Button implements ActionListener, Accessible { public ActionExampleButton( ) { super("Press this Button"); addActionListener(this); } public AccessibleContext getAccessibleContext( ) { return (new ActionAccessibleContext( )); } public void actionPerformed(ActionEvent e) { System.out.println("The button was pressed!"); } public void processActionEvent(ActionEvent e) { super.processActionEvent(e); } // This class contains the accessible context for the component. Many of the // abstract methods simply call the SwingUtilities class to get the job done; // this is advised if you can get away with it. Otherwise, see the source code // for SwingUtilities. class ActionAccessibleContext extends AccessibleContext { public ActionAccessibleContext( ) { super( ); setAccessibleName("Button"); setAccessibleDescription("Press the Button"); } public AccessibleRole getAccessibleRole( ) { // Fill in whatever role you want here. return (AccessibleRole.AWT_COMPONENT); } public AccessibleStateSet getAccessibleStateSet( ) { return SwingUtilities.getAccessibleStateSet(ActionExample.this); } public int getAccessibleIndexInParent( ) { return SwingUtilities.getAccessibleIndexInParent(ActionExample.this); } public int getAccessibleChildrenCount( ) { return SwingUtilities.getAccessibleChildrenCount(ActionExample.this); } public Accessible getAccessibleChild(int i) { return SwingUtilities.getAccessibleChild(ActionExample.this, i); } public Locale getLocale( ) { // Ask the component what its locale is. return ActionExample.this.getLocale( ); } public AccessibleAction getAccessibleAction( ) { return new AccessAction( ); } } // This class implements the AccessibleAction interface. Essentially, there // is only one action, which is the equivalent of clicking on the button. class AccessAction implements AccessibleAction { final int NUMBER_OF_ACTIONS = 1; final String DESCRIPTION = "Presses the button"; public int getAccessibleActionCount( ) { return NUMBER_OF_ACTIONS; } public String getAccessibleActionDescription(int i) { if (i == 0) return (DESCRIPTION); else return null; } public boolean doAccessibleAction(int i) { if (i == 0) { // Simulate clicking on a button. ActionExample.this.processActionEvent(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, ActionExample.this.getActionCommand( ))); return true; } else return false; } } public static void main(String s[]) { ActionExampleButton example = new ActionExampleButton( ); JFrame frame = new JFrame("AccessibleAction Example"); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); frame.getContentPane( ).add(example, BorderLayout.CENTER); frame.setSize(100, 100); frame.setVisible(true); } } The result is somewhat anticlimactic: the example creates a simple button on the screen, and nothing else. If you click on the button, the following output is displayed: The button was pressed! However, it is important to know that an assistive technology could incorporate itself into the virtual machine and find out the button's state and description and even cause the button to be clicked. In order to understand more about how this can occur, we need to talk about the accessibility utility classes. |
I l@ve RuBoard |
![]() ![]() |