Developing Accessible JFC ApplicationsJeff Dunn, June 2000These short guidelines aggregate many of the main points in IBM's Guidelines for Writing Accessible Applications. IBM's guidelines are useful when developing complex custom components. Good human interface and software design can make nearly any software usable by persons with disabilities. Such software is termed accessible, and the Java Foundation Classes (JFC) make implementing accessibility very easy by providing built-in support for the assistive software and technologies used by those with disabilities. It is important to understand how these assistive technologies interact with mainstream applications and what JFC/Swing! developers must do in order to provide the maximum benefit for those with disabilities. If you already have knowledge of assistive technologies and want specifics regarding your Java application, you may want to skip the next few paragraphs. Beginning in the section titled Nuts and Bolts you'll find lots of concrete information and code samples. There are many reasons why software should be made accessible. Of course, it's the "right thing to do" because over 40 million Americans have disabilities, and they have as much (and possibly more) need to use software as the population as a whole. Business factors must also be considered, and the strongest issues involve the Americans with Disabilities Act of 1990 and Section 508 of the Federal Rehabilitation Act. The Americans with Disabilities Act of 1990 (ADA) requires employers to make reasonable accommodations for employees with disabilities. As the world has computerized, "reasonable accommodations" has been interpreted to include providing accessible software. This means that a company's internal applications should work well with assistive technologies and that commercial applications used by the employee must work properly with his or her assistive technology (or technologies). Section 508 of the Federal Rehabilitation Act requires that Federal agencies' electronic and information technology be accessible to people with disabilities, including employees and members of the public. This is a new Act that will be in full force by August of 2000, and its expected interpretation is that federal agencies cannot purchase nor develop software or computer equipment that is not usable by individuals with disabilities. If your software is not accessible, you probably will not be eligible for government contracts. Contents:
Disability - An OverviewDefining what constitutes a disability is a very complex issue, so the term will be greatly simplified here. When developing software to aid the greatest number of people, disabilities can be broadly categorized into sensory impairments and motor skill impairments. At a minimum, developers should be aware of these disabilities:
If an application is sufficient for these populations, it will work very well for most disabilities. However, it is important to realize that a significant number of people have multiple disabilities, and a solution should not be developed that aids one disability group while precluding alternatives for any other group. Cognitive disabilities also deserve consideration, but they will not be addressed directly here. This is because these types of disabilities impair a person's senses in very complex ways, making the impairments difficult to quantify. However, achieving accessibility for the list of disabilities provided above will often allow a person with cognitive disabilities to make effective use of an application. An Assistive Technology PrimerMany users cannot use standard input or output devices, so one or more assistive technologies must be installed in their computing environments to enable their use. There are many types of assistive technologies, some of which affect application design, and some of which do not. For instance, sticky keys make it possible for a person with mobility impairments to type by pressing the Shift key (which "sticks" on) and subsequently pressing the letter to be capitalized with the same finger. This type of technology does not significantly affect application design and is handled by the computing platform. On the other hand, many technologies need help from each application in order to perform their functions properly. When the input focus is on a component that requires input, sighted users can look at the screen near the text field and understand what information is appropriate. Non-sighted users rely on screen readers to explain the context to them, and the screen readers depend upon the applications to provide necessary semantic information. For instance, say that a blind user has used the tab key to move to an address entry field. If the application provides no accessibility information, the screen reader may only say "Editable Text," which does not provide enough information for the user to utilize the application. When the developer takes advantage of the component properties supported by the Java platform, the computer can say something more meaningful, such as "Address, Line 1" (more on these properties in Nuts and Bolts). Clearly, this additional information is indispensable to the user. For other users, the operating system itself provides features that allow them to make effective use of well-behaved applications. For instance, manipulating an application's font can make the difference between a usable and an unusable application for a person with a visual disability. The issue of size is obvious: a person with limited vision benefits greatly from a font that is larger than the default. What may not be so obvious is the effect of the actual typeface. For instance, a block font may be much easier to read than a serif font, and custom fonts could be developed that aid an even broader population. Similarly, the ability to customize colors is a necessity for some people. In the most common case, a selection of colors with high contrast is a great benefit. A less-obvious problem is that some users can see only certain colors and may require what seem strange color combinations to make an application usable. Nuts and BoltsThe Java Accessibility API (JAAPI) is a standard extension in all releases of the Java 2 platform, and this means that the javax.accessibility package exists on any machine where Java 2 is installed. A component can utilize this extension simply by implementing the An The good news is that all of the standard JFC/Swing! components implement the 1. Provide Accessible Names and DescriptionsThe accessible name of an object is often the key to making that object usable by a person with disabilities. The name is a succinct explanation of the object's purpose, and an assistive technology will often present (e.g., speak) the name of each object encountered by a user. A user navigating a graphical interface will encounter many components, so the name of each component is preferably no more than one or two words, in order to avoid information overload. For instance, the fields of an address entry form could be named "Street," "City," and "Zip." The accessible description of an object is a more verbose explanation and should be provided in cases where additional information may be useful. Normally, an assistive technology will retrieve the description when the user makes a request for more information about an object. Once the description has been retrieved, the technology can present the information to the user in a fashion that works well for him or her. Using the address example again, let's imagine a user with poor eyesight generating a billing statement. Via a screen magnifier, the user can see that s/he is entering a Zip Code, but does not know if the current field is part of the sender's or recipient's address. The user will request more information (perhaps by pressing a hotkey), and the assistive technology will read the description. If the developer set the accessible description, the computer could speak "Recipient's Zip Code." When using the standard JFC/Swing! components, objects containing non-editable text will have their accessible names set automatically. Examples of these types of objects are menu items, buttons, radio boxes, and items in a list. However, some objects contain no static text and must have their names set by the developer. If the object on the screen has a label associated with it, the programmer's job is easy. Simply label the object with an instance of JLabel and use JTextField text = new JTextField(20);
JLabel label = new Label("Address Line 1");
label.setLabelFor(text);
// ... Add the text and label to a Container
Other objects do not have labels and require that the programmer set the name explicitly. For ImageIcon(URL url, String name); Accessible descriptions are set automatically by setting a tooltip on an object, via As indicated by the above examples, the great majority of the JFC/Swing! components in an application can have their names and descriptions set automatically. This is by far the preferred method for setting these names, since any changes to the mainstream text via ongoing development or regional localization will automatically be reflected by all assistive technologies. In cases where a component has no label and no tooltip, the accessible strings can be placed directly in the object's AccessibleContext context = component.getAccessibleContext();
context.setAccessibleName("Zip");
context.setAccessibleDescription("Recipient's Zip Code");
It is reasonable to assume that an assistive technology will look for a description and finding none will fall back to using the accessible name of the object. For this and many other reasons, all objects must have accessible names. 2. Do Not Customize Fonts or Colors UnnecessarilyJFC/Swing! applications automatically inherit their font and color properties from the desktop and user preferences. In most cases, interface and application designers can achieve excellent visual results by simply accepting the user's preferences. 3. Implement Necessary Custom Colors and Fonts Via PropertiesAccepting the user's preferences is best when possible, but some applications benefit from using specialized colors or fonts for specific objects. In these cases, the values should be stored in a properties file, which can be shipped with the application's class files. For instance, it would be sensible for a flight simulator to have a red "stop" button in Western regions, so we could define an appropriate property and store it in a file called flightsim.properties: flightsim.stop.color=#ff0000 The program can then load the properties file as a ResourceBundle resources = null;
Color stopColor = Color.red;
try {
resources = ResourceBundle.getBundle("flightsim");
String colorString = resources.getString("flightsim.stop.color");
stopColor = Color.decode(colorString);
} catch (MissingResourceException missingException) {
// Report the error, according to severity
}
// stopColor has now been customized
For most users, the existence of a properties file is transparent, but it provides the important ability to override the default values. In order to customize the properties, the user need only edit the properties file. 4. Use Dynamic GUI LayoutOne of the most common mistakes made by developers using the Java platform is calling the // Invoke on each JFrame, JDialog, and JWindow at creation // and whenever its contents change window.setSize(window.getPreferredSize()); This allows all nested layout managers to affect the size and position of each object at runtime. In those rare instances where an object's preferred size is not acceptable, A dynamic setLayout(null); // NEVER do this! Defeating the Implementing some user interfaces may require custom layout managers, and this should be done by implementing the 5. All Interface Components Must Be Keyboard TraversableMany people cannot use a pointing device effectively, so this is far more important than it may appear at first glance. Pressing the tab key should move the input focus from component to component, and shift-tab should move the focus in the opposite direction. The default
6. Use Mnemonics and AcceleratorsMnemonics are underlined characters that appear in menu items and on the buttons in some dialog boxes. A mnemonic can only be activated when the item is visible and does not require a modifier key (e.g., the user does not need to press the Alt key). All menu items must have mnemonics, so that keyboard-only use is practical. Accelerators are displayed on menu items or buttons in parentheses after the item's text [e.g., "Save (Ctrl+S)"]. The accelerator requires the use of a modifier key, and can be activated any time the application's window has the input focus. Commonly used functionality should always be available via an accelerator. Using accelerators greatly improves the productivity of both power users and persons with mobility impairments. 7. Custom Components Must Implement AccessibleAn application can work with an assistive technology only if all its GUI components implement the As an example, say that an application requires round buttons. If possible, the new button class should extend It makes sense for some custom components to derived directly from Custom components will sometimes need to extend the accessibility behavior of their superclasses. For example, any component that derives directly from Each JFC/Swing! class contains a protected inner class that actually does the accessibility work, and the root class is public class WarningLight extends JComponent implements Accessible {
public AccessibleContext getAccessibleContext() {
// variable accessibleContext is protected in superclass
if (accessibleContext == null) {
accessibleContext = new AccessibleWarningLight();
}
return accessibleContext;
}
protected class AccessibleWarningLight extends AccessibleJComponent {
public AccessibleRole getAccessibleRole() {
return AccessibleRole.ALERT;
}
}
// Implementation of WarningLight omitted...
This is all the code necessary to inherit the accessibility support available in Test CasesOnce you've followed these guidelines, you'll want to test your application to determine how accessible it is to persons with disabilities. There is no substitute for good Human Interface design, but passing these tests will make the difference between a frustrating experience and productivity for many people. 1. Don't touch your mouseBring up each window and popup in your application and attempt to visit every component using only the Tab key on the keyboard. Once you are successful in that regard, you should actually use your application without touching the mouse, verifying that the application's features are all available. This test is important because some users simply cannot use a pointing device. For instance, a blind person can find the mouse and physically move it but has no idea where the pointer is positioned on the screen. While doing this, you should also verify that:
2. Change the default font and colorChoose a font of 24 points or larger, and colors other than the default. Bring up each window of the application and verify that screen objects do not overlap and that the colors are correct. If overlapping does occur, you will need to check the code that interacts with the LayoutManager in that window. A relatively simple way to change the visual properties of a JFC/Swing! application is to create a new user interface theme for the metal look and feel. A sample look and feel has been included as Appendix A and includes a low-vision theme that uses large fonts and high-contrast colors. After compiling this file (LowVisionMetalLookAndFeel.java), add this code to your application so that it will be run before any UI elements have been created: import LowVisionLookAndFeel;
// ... code omitted
try {
UIManager.setLookAndFeel("LowVisionMetalLookAndFeel");
} catch (Exception ex) {
System.out.println("Failed loading Low Vision Metal Look and Feel");
ex.printStackTrace(System.out);
}
This provides an excellent test of the application's response to user preferences. 3. Use a screen readerDownload and install a trial version of a screen reader that works with Java applications, such as IBM's Self-Voicing Kit software. Bring up each window in your application and tab to every component, verifying that you hear a reasonable description of each component as it receives the input focus. For instance, the label of a text field should be read when the text field receives the focus, and icons should cause their names to be read. If some Components do not announce themselves properly, you need to set their accessible names. To get an even better idea of the accessibility of the application, turn your display off. Once you do that, there can be no cheating. Actually use your application in this mode, accessing both core functionality and more lightly-used features. Bon Voyage!Hopefully, you have an understanding of what it means for an application to be accessible. Utilizing that understanding and following these guidelines, you have the ability to leverage the JFC and provide a positive impact in the lives of many people with disabilities. The good news is that the JFC provides a great deal of this functionality automatically, and only a few of the principles described here are specific to accessible applications. These principles provide for better-behaved applications that make everyone more productive. Appendix A: LowVisionMetalLookAndFeelThis look and feel and its associated theme do not include any standard icons, such as those that would be seen in error or warning dialogs. Normally, this is not a real problem and generates minor warning messages to the console. If the user chooses, s/he can copy the standard icons from the metal look and feel to avoid the warnings.
| ||||