If you are a typical software engineer and take a glance at this text, you'll find it is easier to use the JFC than to implement the Accessibility API. Make it easy on yourself and use the JFC!
This section discusses how you use the JFC to build your accessible Java application. It is broken down as follows:
The JFC is an extremely rich class library that has implemented both keyboard accessibility as well as the accessibility API. If you use JFC "as is", there are only a few simple things you need to do:
- Provide Descriptive Component Text: Set the accessible description on all
components; see section 2.9 Describe Icons and
Hint: Some JFC components use the tool tip for this information in the absence of you setting an accessible description. So, if you already set the tool tip text, this task might be complete.
- Describe Icons and Graphics:
In short, these simple programming functions let you meet essential accessibility programming requirements. JFC takes care of the rest!
JTextComponent is a class with an extendable document model. Each element within the document model needs only to support a common element interface. The element could be anything from another JFC component to simple text. Furthermore, the document model itself has a pre-defined interface. This design allows you to embed documents within documents, insert other complex components, and so on.
What enables assistive technologies, such as a screen reader program, to decipher this is:
Unless you modify the JTextComponent, AccessibleText or AccessibleHyperlink implementations, these interfaces still allow an assistive technology to read your "basic" document. JTextComponent implements AccessibleHypertext on Swing editor kits that supports hypertext, allowing assistive technology to enumerate and activate the links in your document. Developers can also break the accessibility of documents by improperly implementing the AttributeSet and its attribute elements.
are JFC classes that define an interface to an attribute set.StyleConstants
defines a common set of attributes for the attribute set. Without a known set of attributes, assistive technologies will not know what to do with your document, much the same way that component technology fails without a set of standards.
In implementing your AttributeSet for document elements, it is important that you define attributes using those pre-defined in the StyleConstants class. Use the following list of Key/Value pairs:
|StyleConstant Attribute Keys||Class Definition for the Value|
|Alignment||ALIGN_CENTER, ALIGN_JUSTIFIED, or ALIGN_RIGHT|
|BidiLevel||Integer Bidirectional level as assigned by the Unicode bidi algorithm|
|ComponentAttribute||Component or JComponent that must implement Accessible|
|ComposedTextAttribute||AttributedString that represents the composed text.|
|Model Attribute||Object defining the model for embedded objects that have a model view separation.|
|Orientation||String representation of orientation|
Table 3.0 AttributeSet Key/Value Pairs Defined in StyleConstants.java
If you are converting an existing program to JFC, the AttributeSet and MutableAttribute interfaces should allow you to convert your existing document structure to a JFC implementation. These interfaces provide for text runs, and embedded components. StyleConstants.java has a provision for embedded components that allows you to embed components in your document elements; you can add things like spreadsheets, and tables. Furthermore, you can define your own user interface using JFC to give whatever look you want to your document. Also, JFC comes with source to show you different implementations other than plain text areas.
It is essential that when you add components to your document model, the components implement the Accessible Interface. If you use standard JFC components, they already do.
For example, if you are building a web browser, theNameAttribute
for <H1> should be the string "<H1>." This can help an assistive technologies tailor themselves for your application. For example, a screen reader program could be designed to navigate the HTML tags of a web document.
The root component class is calledJComponent
and is a descendant of the AWT container class.JComponent
is the root class of almost all JFC classes.
The design of each component is based on the Model-View-Controller (MVC) architecture. Each component is broken into three parts:
Implementation of the Accessibility API is triggered from the "data portion" of each JFC component. This lets you implement an accessible application without affecting its "look and feel."
When developing your application using the JFC, it is important that you avoid modifying or replacing the "data model portion" of each component with your own. You run the risk of improperly implementing methods that are required to support the interfaces and this could break the accessibility features of the component.
Another JFC concept is a cell renderer. A cell renderer is an interface that a JFC component uses to define a component drawing object within a list of elements. For example, the JFC uses ListCellRenderers for JList elements and TableCellRenderers for JTable elements. For a given cell renderer, a method is provided to return a component configured for a given element, like getListCellRendererComponent in the JList component.
If you change the cell renderer for a JFC component, make sure it implements Accessible. If you implement your cell renderer on an existing JFC component, you can configure your cell renderer for the given element and reuse an already accessible component. An example of this is how JList uses JLabel to render its children.
If you need to build completely new components follow section 5.0 Building Custom Accessible Components by starting with aJComponent
as your base component.