Thursday, August 9, 2007

Design your Java applications to be more accessible with JAAPI

Takeaway: Did you know that you can use a rich palette of accessibility tools to make your Java application more accessible to users with disabilities? Learn how to incorporate the Java Accessibility API (JAAPI) in your application development work.

The Java platform is becoming increasingly popular for developing desktop applications. In order to comply with standard Windows applications ergonomics, it is essential that accessibility barriers do not exist during application development.

Early releases of the Java API did not have native support for accessibility and assistive devices, thus potentially rendering Java products unusable to many visually impaired users. In an attempt to resolve the situation, Sun Microsystems released the Java Accessibility API (JAAPI). The JAAPI makes GUI component information available to assistive technologies, giving users alternative presentation and control of Java applications.

Accessibility on the Java platform consists of four basic elements:

  • JAAPI: Provides some kind of a contract between a Java application and the assistive technology (such as a screen reader or Braille display device).
  • Java Accessibility Utilities: Provides the ability to get the information from the application and process it for further displaying with special devices. They help assistive technologies monitor component-related events and get additional information about the GUI, such as the current position of the mouse, or the window that currently has focus.
  • Java Access Bridge (JAB): This is the most important element in providing accessibility to the Java platform under the Windows operating system. It was introduced in J2SE 1.3.
  • Java Foundation Classes (JFC): This is a library of GUI components, which fully implement the JAAPI.

JAAPI

The Accessibility API comprises a set of interfaces and classes. The main interface is the Accessible interface; all components that support accessibility must implement this interface. The Accessible interface defines one method, getAccessibleContext. When called on an accessible component, getAccessibleContext returns an AccessibleContext object. This object contains a basic set of accessibility information about the component, such as the component's accessible name, description, role, parent, and children, as well as the component's state. For example, if the component is a window, AccessibleContext indicates whether the window is active.

Most Swing (JFC) components, such as JButton and JTextArea, implement the Accessible interface. You can use the setAccessibleName and setAccessibleDescription methods of AccessibleContext to set an accessible name and description for the button. Listing A offers an example of a simple application that displays a button and makes it accessible.

In addition to methods for setting and getting basic accessibility information, AccessibleContext has methods for retrieving information about components that have special types of characteristics. For example, a component that displays text can make the text accessible to an assistive technology by implementing the AccessibleText interface; the getAccessibleText method of AccessibleContext returns the accessible text for a component that implements the AccessibleText interface. An assistive technology could then use AccessibleText interface methods to perform actions on the text, such as retrieve selected text.

Java Accessibility Utilities

Java Accessibility Utilities consist of a set of interfaces and classes. EventQueueMonitor provides core functions needed by assistive technologies.

The AccessibleIcon interface, for example, extends accessibility to icons. In particular, it gives you a way to specify an accessible description for an icon. It also allows you to retrieve the description and information about the icon's height and width. Listing B shows how to turn an ordinary icon into accessible one.

A new method in getAcessibleContext, called getAccessibleIcon, returns an array of type AccessibleIcon. Each element of the array represents an accessible icon that is associated with the object of interest. In this case, the button has one accessible icon, the house icon.

The AccessibleTable interface extends accessibility information to tables. For example, it provides methods for setting and retrieving an accessible caption for a table, and for getting the number of rows and columns in a table. The Swing class JTable.AccessibleJTable implements the AccessibleTable interface. The getAccessibleTable method in the AccessibleContext returns an object of type AccessibleTable. This object contains a variety of methods for setting and retrieving accessible information about the table. For example, this includes the getAccessibleColumnCount and getAccessibleRowCount methods.

Make JAB interact with Windows, UNIX, and Linux

There are initiatives for JAAPI interaction at the native level for Windows and for GNOME desktop on UNIX and Linux platforms.

For Windows, the Access Bridge spans both the Windows and Java environments. Part of it is a Java class, and the other part is a set of Windows Dynamic Link Libraries (DLLs). When a Windows-based assistive technology runs, it interacts with the DLL portion of the Access Bridge. The Bridge's class then communicates with the Accessibility API and Java Accessibility Utilities through the Java Virtual Machine. (In order to use the JAB, you need to have the Java Accessibility Utilities installed.)

The GNOME desktop on UNIX and Linux platforms is highly customizable and provides APIs and libraries to allow developers to quickly create accessible applications and assistive technologies. GNOME Accessibility Architecture is contributed by Sun Microsystems to the GNOME open source project.

Java Accessibility Helper

The Java Accessibility Helper examines an Abstract Window Toolkit (AWT) or Swing-based application for accessibility and is capable of running various tests against an application. This important tool helps to identify problems with lack of accessibility support in a Java application.

Further reading

For more information about the JAAPI, check out the following resources:

1 comment:

assistive technology said...

Thank you for the link. Java can be very inaccessible for people who use screen readers and the like.