com.sun.java.accessibility.util
Class Translator

java.lang.Object
  |
  +--javax.accessibility.AccessibleContext
        |
        +--com.sun.java.accessibility.util.Translator

public class Translator
extends javax.accessibility.AccessibleContext
implements javax.accessibility.Accessible, javax.accessibility.AccessibleComponent

The Translator class provides a translation to interface Accessible for objects that do not implement interface Accessible. Assistive technologies can use the 'getAccessible' class method of Translator to obtain an object that implements interface Accessible. If the object passed in already implements interface Accessible, getAccessible merely returns the object.

An example of how an assistive technology might use the Translator class is as follows:

    Accessible accessible = Translator.getAccessible(someObj);
    // obtain information from the 'accessible' object.
 

NOTE: This is proof-of-concept code and is missing many things. It is also an undesirable way to implement accessibility features for a Toolkit. Instead of relying upon this code, the Toolkit's Components should implement interface Accessible directly. This is also a preliminary draft. The methods and name may change in future beta releases.


Field Summary
protected  java.lang.Object source
          The source object needing translating.
 
Fields inherited from class javax.accessibility.AccessibleContext
ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY, ACCESSIBLE_CARET_PROPERTY, ACCESSIBLE_CHILD_PROPERTY, ACCESSIBLE_DESCRIPTION_PROPERTY, ACCESSIBLE_NAME_PROPERTY, ACCESSIBLE_SELECTION_PROPERTY, ACCESSIBLE_STATE_PROPERTY, ACCESSIBLE_TEXT_PROPERTY, ACCESSIBLE_VALUE_PROPERTY, ACCESSIBLE_VISIBLE_DATA_PROPERTY, accessibleDescription, accessibleName, accessibleParent
 
Constructor Summary
Translator()
          Create a new Translator.
Translator(java.lang.Object o)
          Create a new Translator with the source object o.
 
Method Summary
 void addFocusListener(java.awt.event.FocusListener l)
          Adds the specified focus listener to receive focus events from this component.
 void addPropertyChangeListener(java.beans.PropertyChangeListener l)
          Add a PropertyChangeListener to the listener list.
 boolean contains(java.awt.Point p)
          Checks whether the specified Point is within this object's bounds, where the Point is relative to the coordinate system of the object.
 boolean equals(java.lang.Object o)
          Returns true if this object is the same as the one passed in.
static javax.accessibility.Accessible getAccessible(java.lang.Object o)
          Obtain an object that implements interface Accessible.
 javax.accessibility.Accessible getAccessibleAt(java.awt.Point p)
          Returns the Accessible child contained at the local coordinate Point, if one exists.
 javax.accessibility.Accessible getAccessibleChild(int i)
          Return the nth Accessible child of the object.
 int getAccessibleChildrenCount()
          Returns the number of accessible children in the object.
 javax.accessibility.AccessibleContext getAccessibleContext()
          Returns this object.
 java.lang.String getAccessibleDescription()
          Get the accessible description of this object.
 int getAccessibleIndexInParent()
          Get the index of this object in its accessible parent.
 java.lang.String getAccessibleName()
          Get the accessible name of this object.
 javax.accessibility.Accessible getAccessibleParent()
          Get the Accessible parent of this object.
 javax.accessibility.AccessibleRole getAccessibleRole()
          Get the role of this object.
 javax.accessibility.AccessibleStateSet getAccessibleStateSet()
          Get the state of this object, given an already populated state.
 java.awt.Color getBackground()
          Get the background color of this object.
 java.awt.Rectangle getBounds()
          Returns the current bounds of this object
 java.awt.Cursor getCursor()
          Get the Cursor of this object.
 java.awt.Font getFont()
          Get the Font of this object.
 java.awt.FontMetrics getFontMetrics(java.awt.Font f)
          Get the FontMetrics of this object.
 java.awt.Color getForeground()
          Get the foreground color of this object.
 java.util.Locale getLocale()
          Gets the locale of the component.
 java.awt.Point getLocation()
          Returns the location of the object relative to parent.
 java.awt.Point getLocationOnScreen()
          Returns the location of the object on the screen.
 java.awt.Dimension getSize()
          Returns the current size of this object
 java.lang.Object getSource()
          Get the source object of the Translator.
protected static java.lang.Class getTranslatorClass(java.lang.Class c)
          Find a translator for this class.
 boolean isEnabled()
          Determine if the object is enabled.
 boolean isFocusTraversable()
          Returns whether this object can accept focus or not.
 boolean isShowing()
          Determine if the object is showing.
 boolean isVisible()
          Determine if the object is visible.
 void removeFocusListener(java.awt.event.FocusListener l)
          Removes the specified focus listener so it no longer receives focus events from this component.
 void removePropertyChangeListener(java.beans.PropertyChangeListener l)
          Remove the PropertyChangeListener from the listener list.
 void requestFocus()
          Requests focus for this object.
 void setAccessibleDescription(java.lang.String s)
          Set the accessible description of this object.
 void setAccessibleName(java.lang.String s)
          Set the name of this object.
 void setBackground(java.awt.Color c)
          Set the background color of this object.
 void setBounds(java.awt.Rectangle r)
          Sets the current bounds of this object
 void setCursor(java.awt.Cursor c)
          Set the Cursor of this object.
 void setEnabled(boolean b)
          Set the enabled state of the object.
 void setFont(java.awt.Font f)
          Set the Font of this object.
 void setForeground(java.awt.Color c)
          Set the foreground color of this object.
 void setLocation(java.awt.Point p)
          Sets the location of the object relative to parent.
 void setSize(java.awt.Dimension d)
          Sets the current size of this object
 void setSource(java.lang.Object o)
          Set the source object of the Translator.
 void setVisible(boolean b)
          Set the visible state of the object.
 
Methods inherited from class javax.accessibility.AccessibleContext
firePropertyChange, getAccessibleAction, getAccessibleComponent, getAccessibleSelection, getAccessibleText, getAccessibleValue, setAccessibleParent
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

source

protected java.lang.Object source
The source object needing translating.
Constructor Detail

Translator

public Translator()
Create a new Translator. You must call the setSource method to set the object to be translated after calling this constructor.

Translator

public Translator(java.lang.Object o)
Create a new Translator with the source object o.
Parameters:
o - the Component that does not implement interface Accessible
Method Detail

getTranslatorClass

protected static java.lang.Class getTranslatorClass(java.lang.Class c)
Find a translator for this class. If one doesn't exist for this class explicitly, try its superclass and so on.

getAccessible

public static javax.accessibility.Accessible getAccessible(java.lang.Object o)
Obtain an object that implements interface Accessible. If the object passed in already implements interface Accessible, getAccessible merely returns the object.

getSource

public java.lang.Object getSource()
Get the source object of the Translator.
Returns:
the source object of the Translator

setSource

public void setSource(java.lang.Object o)
Set the source object of the Translator.
Parameters:
o - the Component that does not implement interface Accessible

equals

public boolean equals(java.lang.Object o)
Returns true if this object is the same as the one passed in.
Parameters:
c - the Component to check against.
Returns:
true if this is the same object.
Overrides:
equals in class java.lang.Object

getAccessibleContext

public javax.accessibility.AccessibleContext getAccessibleContext()
Returns this object.
Specified by:
getAccessibleContext in interface javax.accessibility.Accessible

getAccessibleName

public java.lang.String getAccessibleName()
Get the accessible name of this object.
Returns:
the localized name of the object -- can be null if this object does not have a name
Overrides:
getAccessibleName in class javax.accessibility.AccessibleContext

setAccessibleName

public void setAccessibleName(java.lang.String s)
Set the name of this object.
Overrides:
setAccessibleName in class javax.accessibility.AccessibleContext

getAccessibleDescription

public java.lang.String getAccessibleDescription()
Get the accessible description of this object.
Returns:
the description of the object -- can be null if this object does not have a description
Overrides:
getAccessibleDescription in class javax.accessibility.AccessibleContext

setAccessibleDescription

public void setAccessibleDescription(java.lang.String s)
Set the accessible description of this object.
Parameters:
s - the new localized description of the object
Overrides:
setAccessibleDescription in class javax.accessibility.AccessibleContext

getAccessibleRole

public javax.accessibility.AccessibleRole getAccessibleRole()
Get the role of this object.
Returns:
an instance of AccessibleRole describing the role of the object
Overrides:
getAccessibleRole in class javax.accessibility.AccessibleContext

getAccessibleStateSet

public javax.accessibility.AccessibleStateSet getAccessibleStateSet()
Get the state of this object, given an already populated state. This method is intended for use by subclasses so they don't have to check for everything.
Returns:
an instance of AccessibleStateSet containing the current state of the object
Overrides:
getAccessibleStateSet in class javax.accessibility.AccessibleContext

getAccessibleParent

public javax.accessibility.Accessible getAccessibleParent()
Get the Accessible parent of this object.
Returns:
the Accessible parent of this object -- can be null if this object does not have an Accessible parent
Overrides:
getAccessibleParent in class javax.accessibility.AccessibleContext

getAccessibleIndexInParent

public int getAccessibleIndexInParent()
Get the index of this object in its accessible parent.
Returns:
-1 of this object does not have an accessible parent. Otherwise, the index of the child in its accessible parent.
Overrides:
getAccessibleIndexInParent in class javax.accessibility.AccessibleContext

getAccessibleChildrenCount

public int getAccessibleChildrenCount()
Returns the number of accessible children in the object.
Returns:
the number of accessible children in the object.
Overrides:
getAccessibleChildrenCount in class javax.accessibility.AccessibleContext

getAccessibleChild

public javax.accessibility.Accessible getAccessibleChild(int i)
Return the nth Accessible child of the object.
Parameters:
i - zero-based index of child
Returns:
the nth Accessible child of the object
Overrides:
getAccessibleChild in class javax.accessibility.AccessibleContext

getLocale

public java.util.Locale getLocale()
                           throws java.awt.IllegalComponentStateException
Gets the locale of the component. If the component does not have a locale, the locale of its parent is returned.
Returns:
the Locale of the object.
Overrides:
getLocale in class javax.accessibility.AccessibleContext

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener l)
Add a PropertyChangeListener to the listener list. The listener is registered for all properties.
Overrides:
addPropertyChangeListener in class javax.accessibility.AccessibleContext

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener l)
Remove the PropertyChangeListener from the listener list.
Overrides:
removePropertyChangeListener in class javax.accessibility.AccessibleContext

getBackground

public java.awt.Color getBackground()
Get the background color of this object.
Specified by:
getBackground in interface javax.accessibility.AccessibleComponent
Returns:
if supported, the background color of the object; otherwise, null

setBackground

public void setBackground(java.awt.Color c)
Set the background color of this object.
Specified by:
setBackground in interface javax.accessibility.AccessibleComponent
Parameters:
c - the new Color for the background

getForeground

public java.awt.Color getForeground()
Get the foreground color of this object.
Specified by:
getForeground in interface javax.accessibility.AccessibleComponent
Returns:
if supported, the foreground color of the object; otherwise, null

setForeground

public void setForeground(java.awt.Color c)
Set the foreground color of this object.
Specified by:
setForeground in interface javax.accessibility.AccessibleComponent
Parameters:
c - the new Color for the foreground

getCursor

public java.awt.Cursor getCursor()
Get the Cursor of this object.
Specified by:
getCursor in interface javax.accessibility.AccessibleComponent
Returns:
if supported, the Cursor of the object; otherwise, null

setCursor

public void setCursor(java.awt.Cursor c)
Set the Cursor of this object.
Specified by:
setCursor in interface javax.accessibility.AccessibleComponent
Parameters:
c - the new Cursor for the object

getFont

public java.awt.Font getFont()
Get the Font of this object.
Specified by:
getFont in interface javax.accessibility.AccessibleComponent
Returns:
if supported, the Font for the object; otherwise, null

setFont

public void setFont(java.awt.Font f)
Set the Font of this object.
Specified by:
setFont in interface javax.accessibility.AccessibleComponent
Parameters:
f - the new Font for the object

getFontMetrics

public java.awt.FontMetrics getFontMetrics(java.awt.Font f)
Get the FontMetrics of this object.
Specified by:
getFontMetrics in interface javax.accessibility.AccessibleComponent
Parameters:
f - the Font
Returns:
if supported, the FontMetrics the object; otherwise, null
See Also:
getFont()

isEnabled

public boolean isEnabled()
Determine if the object is enabled.
Specified by:
isEnabled in interface javax.accessibility.AccessibleComponent
Returns:
true if object is enabled; otherwise, false

setEnabled

public void setEnabled(boolean b)
Set the enabled state of the object.
Specified by:
setEnabled in interface javax.accessibility.AccessibleComponent
Parameters:
b - if true, enables this object; otherwise, disables it

isVisible

public boolean isVisible()
Determine if the object is visible.
Specified by:
isVisible in interface javax.accessibility.AccessibleComponent
Returns:
true if object is visible; otherwise, false

setVisible

public void setVisible(boolean b)
Set the visible state of the object.
Specified by:
setVisible in interface javax.accessibility.AccessibleComponent
Parameters:
b - if true, shows this object; otherwise, hides it

isShowing

public boolean isShowing()
Determine if the object is showing. This is determined by checking the visibility of the object and ancestors of the object.
Specified by:
isShowing in interface javax.accessibility.AccessibleComponent
Returns:
true if object is showing; otherwise, false

contains

public boolean contains(java.awt.Point p)
Checks whether the specified Point is within this object's bounds, where the Point is relative to the coordinate system of the object.
Specified by:
contains in interface javax.accessibility.AccessibleComponent
Parameters:
p - the Point relative to the coordinate system of the object
Returns:
true if object contains Point; otherwise false

getLocationOnScreen

public java.awt.Point getLocationOnScreen()
Returns the location of the object on the screen.
Specified by:
getLocationOnScreen in interface javax.accessibility.AccessibleComponent
Returns:
location of object on screen -- can be null if this object is not on the screen

getLocation

public java.awt.Point getLocation()
Returns the location of the object relative to parent.
Specified by:
getLocation in interface javax.accessibility.AccessibleComponent
Returns:
location of object relative to parent -- can be null if this object or its parent are not on the screen

setLocation

public void setLocation(java.awt.Point p)
Sets the location of the object relative to parent.
Specified by:
setLocation in interface javax.accessibility.AccessibleComponent

getBounds

public java.awt.Rectangle getBounds()
Returns the current bounds of this object
Specified by:
getBounds in interface javax.accessibility.AccessibleComponent
Returns:
current bounds of object -- can be null if this object is not on the screen

setBounds

public void setBounds(java.awt.Rectangle r)
Sets the current bounds of this object
Specified by:
setBounds in interface javax.accessibility.AccessibleComponent

getSize

public java.awt.Dimension getSize()
Returns the current size of this object
Specified by:
getSize in interface javax.accessibility.AccessibleComponent
Returns:
current size of object -- can be null if this object is not on the screen

setSize

public void setSize(java.awt.Dimension d)
Sets the current size of this object
Specified by:
setSize in interface javax.accessibility.AccessibleComponent

getAccessibleAt

public javax.accessibility.Accessible getAccessibleAt(java.awt.Point p)
Returns the Accessible child contained at the local coordinate Point, if one exists.
Specified by:
getAccessibleAt in interface javax.accessibility.AccessibleComponent
Returns:
the Accessible at the specified location, if it exists

isFocusTraversable

public boolean isFocusTraversable()
Returns whether this object can accept focus or not.
Specified by:
isFocusTraversable in interface javax.accessibility.AccessibleComponent
Returns:
true if object can accept focus; otherwise false

requestFocus

public void requestFocus()
Requests focus for this object.
Specified by:
requestFocus in interface javax.accessibility.AccessibleComponent

addFocusListener

public void addFocusListener(java.awt.event.FocusListener l)
Adds the specified focus listener to receive focus events from this component.
Specified by:
addFocusListener in interface javax.accessibility.AccessibleComponent
Parameters:
l - the focus listener

removeFocusListener

public void removeFocusListener(java.awt.event.FocusListener l)
Removes the specified focus listener so it no longer receives focus events from this component.
Specified by:
removeFocusListener in interface javax.accessibility.AccessibleComponent
Parameters:
l - the focus listener