java.lang.Object
javax.accessibility.AccessibleContext
com.sun.java.accessibility.util.Translator
- All Implemented Interfaces:
Accessible
,AccessibleComponent
public class Translator extends AccessibleContext implements Accessible, 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 implementation is missing many things and is not a recommended way
to implement accessibility features for a toolkit. Instead of relying upon this
code, a toolkit's components should implement interface Accessible
directly.
-
Field Summary
Fields Modifier and Type Field Description protected Object
source
The source object needing translating.Fields declared in class javax.accessibility.AccessibleContext
ACCESSIBLE_ACTION_PROPERTY, ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY, ACCESSIBLE_CARET_PROPERTY, ACCESSIBLE_CHILD_PROPERTY, ACCESSIBLE_COMPONENT_BOUNDS_CHANGED, ACCESSIBLE_DESCRIPTION_PROPERTY, ACCESSIBLE_HYPERTEXT_OFFSET, ACCESSIBLE_INVALIDATE_CHILDREN, ACCESSIBLE_NAME_PROPERTY, ACCESSIBLE_SELECTION_PROPERTY, ACCESSIBLE_STATE_PROPERTY, ACCESSIBLE_TABLE_CAPTION_CHANGED, ACCESSIBLE_TABLE_COLUMN_DESCRIPTION_CHANGED, ACCESSIBLE_TABLE_COLUMN_HEADER_CHANGED, ACCESSIBLE_TABLE_MODEL_CHANGED, ACCESSIBLE_TABLE_ROW_DESCRIPTION_CHANGED, ACCESSIBLE_TABLE_ROW_HEADER_CHANGED, ACCESSIBLE_TABLE_SUMMARY_CHANGED, ACCESSIBLE_TEXT_ATTRIBUTES_CHANGED, ACCESSIBLE_TEXT_PROPERTY, ACCESSIBLE_VALUE_PROPERTY, ACCESSIBLE_VISIBLE_DATA_PROPERTY, accessibleDescription, accessibleName, accessibleParent
-
Constructor Summary
Constructors Constructor Description Translator()
Create a newTranslator
.Translator(Object o)
Create a newTranslator
with the source object o. -
Method Summary
Modifier and Type Method Description void
addFocusListener(FocusListener l)
Adds the specifiedFocusListener
to receive focus events from this component.void
addPropertyChangeListener(PropertyChangeListener l)
Add aPropertyChangeListener
to the listener list.boolean
contains(Point p)
Checks whether the specifiedPoint
is within this object's bounds, where thePoint
is relative to the coordinate system of the object.boolean
equals(Object o)
Returns true if this object is the same as the one passed in.static Accessible
getAccessible(Object o)
Obtain an object that implements interfaceAccessible
.Accessible
getAccessibleAt(Point p)
Returns the accessible child contained at the local coordinate Point, if one exists.Accessible
getAccessibleChild(int i)
Return the nth accessible child of the object.int
getAccessibleChildrenCount()
Returns the number of accessible children in the object.AccessibleContext
getAccessibleContext()
Returns this object.String
getAccessibleDescription()
Get the accessible description of this object.int
getAccessibleIndexInParent()
Get the index of this object in its accessible parent.String
getAccessibleName()
Get the accessible name of this object.Accessible
getAccessibleParent()
Get the accessible parent of this object.AccessibleRole
getAccessibleRole()
Get the role of this object.AccessibleStateSet
getAccessibleStateSet()
Get the state of this object, given an already populated state.Color
getBackground()
Get the backgroundColor
of this object.Rectangle
getBounds()
Returns the current bounds of this object.Cursor
getCursor()
Get theCursor
of this object.Font
getFont()
Get theFont
of this object.FontMetrics
getFontMetrics(Font f)
Get theFontMetrics
of this object.Color
getForeground()
Get the foregroundColor
of this object.Locale
getLocale()
Gets theLocale
of the component.Point
getLocation()
Returns the location of the object relative to parent.Point
getLocationOnScreen()
Returns the location of the object on the screen.Dimension
getSize()
Returns the current size of this object.Object
getSource()
Get the sourceObject
of theTranslator
.protected static Class<?>
getTranslatorClass(Class<?> c)
Find a translator for this class.int
hashCode()
Return hashcode.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(FocusListener l)
Removes the specified focus listener so it no longer receives focus events from this component.void
removePropertyChangeListener(PropertyChangeListener l)
Remove thePropertyChangeListener
from the listener list.void
requestFocus()
Requests focus for this object.void
setAccessibleDescription(String s)
Set the accessible description of this object.void
setAccessibleName(String s)
Set the name of this object.void
setBackground(Color c)
Set the backgroundColor
of this object.void
setBounds(Rectangle r)
Sets the current bounds of this object.void
setCursor(Cursor c)
Set theCursor
of this object.void
setEnabled(boolean b)
Set the enabled state of the object.void
setFont(Font f)
Set theFont
of this object.void
setForeground(Color c)
Set the foregroundColor
of this object.void
setLocation(Point p)
Sets the location of the object relative to parent.void
setSize(Dimension d)
Sets the current size of this object.void
setSource(Object o)
Set the source object of theTranslator
.void
setVisible(boolean b)
Set the visible state of the object.Methods declared in class javax.accessibility.AccessibleContext
firePropertyChange, getAccessibleAction, getAccessibleComponent, getAccessibleEditableText, getAccessibleIcon, getAccessibleRelationSet, getAccessibleSelection, getAccessibleTable, getAccessibleText, getAccessibleValue, setAccessibleParent
-
Field Details
-
source
The source object needing translating.
-
-
Constructor Details
-
Translator
public Translator()Create a newTranslator
. You must call thesetSource
method to set the object to be translated after calling this constructor. -
Translator
Create a newTranslator
with the source object o.- Parameters:
o
- the Component that does not implement interfaceAccessible
-
-
Method Details
-
getTranslatorClass
Find a translator for this class. If one doesn't exist for this class explicitly, try its superclass and so on.- Parameters:
c
- a Class- Returns:
- the
Translator
Class for the Class passed in
-
getAccessible
Obtain an object that implements interfaceAccessible
. If the object passed in already implements interfaceAccessible
,getAccessible
merely returns the object.- Parameters:
o
- an Object; if a null is passed in a null is returned- Returns:
- an
Object
, possibly theObject
passed in, that implements theAccessible
interface for theObject
which was passed in
-
getSource
Get the sourceObject
of theTranslator
.- Returns:
- the source
Object
of theTranslator
-
setSource
Set the source object of theTranslator
.- Parameters:
o
- the Component that does not implement interface Accessible
-
equals
Returns true if this object is the same as the one passed in.- Overrides:
equals
in classObject
- Parameters:
o
- theObject
to check against- Returns:
- true if this is the same object
- See Also:
Object.hashCode()
,HashMap
-
hashCode
public int hashCode()Return hashcode.- Overrides:
hashCode
in classObject
- Returns:
- hashcode
- See Also:
Object.equals(java.lang.Object)
,System.identityHashCode(java.lang.Object)
-
getAccessibleContext
Returns this object.- Specified by:
getAccessibleContext
in interfaceAccessible
- Returns:
- the
AccessibleContext
associated with this object
-
getAccessibleName
Get the accessible name of this object.- Overrides:
getAccessibleName
in classAccessibleContext
- Returns:
- the localized name of the object; can be null if this object does not have a name
- See Also:
AccessibleContext.setAccessibleName(java.lang.String)
-
setAccessibleName
Set the name of this object.- Overrides:
setAccessibleName
in classAccessibleContext
- Parameters:
s
- the new localized name of the object- See Also:
AccessibleContext.getAccessibleName()
,AccessibleContext.addPropertyChangeListener(java.beans.PropertyChangeListener)
-
getAccessibleDescription
Get the accessible description of this object.- Overrides:
getAccessibleDescription
in classAccessibleContext
- Returns:
- the description of the object; can be null if this object does not have a description
- See Also:
AccessibleContext.setAccessibleDescription(java.lang.String)
-
setAccessibleDescription
Set the accessible description of this object.- Overrides:
setAccessibleDescription
in classAccessibleContext
- Parameters:
s
- the new localized description of the object- See Also:
AccessibleContext.setAccessibleName(java.lang.String)
,AccessibleContext.addPropertyChangeListener(java.beans.PropertyChangeListener)
-
getAccessibleRole
Get the role of this object.- Specified by:
getAccessibleRole
in classAccessibleContext
- Returns:
- an instance of AccessibleRole describing the role of the object
- See Also:
AccessibleRole
-
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.- Specified by:
getAccessibleStateSet
in classAccessibleContext
- Returns:
- an instance of
AccessibleStateSet
containing the current state of the object - See Also:
AccessibleStateSet
,AccessibleState
,AccessibleContext.addPropertyChangeListener(java.beans.PropertyChangeListener)
-
getAccessibleParent
Get the accessible parent of this object.- Overrides:
getAccessibleParent
in classAccessibleContext
- Returns:
- the accessible parent of this object; can be null if this object does not have an accessible parent
-
getAccessibleIndexInParent
public int getAccessibleIndexInParent()Get the index of this object in its accessible parent.- Specified by:
getAccessibleIndexInParent
in classAccessibleContext
- Returns:
- -1 of this object does not have an accessible parent; otherwise, the index of the child in its accessible parent
- See Also:
AccessibleContext.getAccessibleParent()
,AccessibleContext.getAccessibleChildrenCount()
,AccessibleContext.getAccessibleChild(int)
-
getAccessibleChildrenCount
public int getAccessibleChildrenCount()Returns the number of accessible children in the object.- Specified by:
getAccessibleChildrenCount
in classAccessibleContext
- Returns:
- the number of accessible children in the object
-
getAccessibleChild
Return the nth accessible child of the object.- Specified by:
getAccessibleChild
in classAccessibleContext
- Parameters:
i
- zero-based index of child- Returns:
- the nth accessible child of the object
- See Also:
AccessibleContext.getAccessibleChildrenCount()
-
getLocale
Gets theLocale
of the component. If the component does not have a locale, the locale of its parent is returned.- Specified by:
getLocale
in classAccessibleContext
- Returns:
- the
Locale
of the object - Throws:
IllegalComponentStateException
- If the component does not have its own locale and has not yet been added to a containment hierarchy such that the locale can be determined from the containing parent
-
addPropertyChangeListener
Add aPropertyChangeListener
to the listener list. The listener is registered for all properties.- Overrides:
addPropertyChangeListener
in classAccessibleContext
- Parameters:
l
- The PropertyChangeListener to be added- See Also:
AccessibleContext.ACCESSIBLE_NAME_PROPERTY
,AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY
,AccessibleContext.ACCESSIBLE_STATE_PROPERTY
,AccessibleContext.ACCESSIBLE_VALUE_PROPERTY
,AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY
,AccessibleContext.ACCESSIBLE_TEXT_PROPERTY
,AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY
-
removePropertyChangeListener
Remove thePropertyChangeListener
from the listener list.- Overrides:
removePropertyChangeListener
in classAccessibleContext
- Parameters:
l
- The PropertyChangeListener to be removed
-
getBackground
Get the backgroundColor
of this object.- Specified by:
getBackground
in interfaceAccessibleComponent
- Returns:
- if supported, the background
Color
of the object; otherwise, null - See Also:
AccessibleComponent.setBackground(java.awt.Color)
-
setBackground
Set the backgroundColor
of this object.- Specified by:
setBackground
in interfaceAccessibleComponent
- Parameters:
c
- the newColor
for the background- See Also:
AccessibleComponent.setBackground(java.awt.Color)
-
getForeground
Get the foregroundColor
of this object.- Specified by:
getForeground
in interfaceAccessibleComponent
- Returns:
- if supported, the foreground
Color
of the object; otherwise, null - See Also:
AccessibleComponent.setForeground(java.awt.Color)
-
setForeground
Set the foregroundColor
of this object.- Specified by:
setForeground
in interfaceAccessibleComponent
- Parameters:
c
- the newColor
for the foreground- See Also:
AccessibleComponent.getForeground()
-
getCursor
Get theCursor
of this object.- Specified by:
getCursor
in interfaceAccessibleComponent
- Returns:
- if supported, the Cursor of the object; otherwise, null
- See Also:
AccessibleComponent.setCursor(java.awt.Cursor)
-
setCursor
Set theCursor
of this object.- Specified by:
setCursor
in interfaceAccessibleComponent
- Parameters:
c
- the newCursor
for the object- See Also:
AccessibleComponent.getCursor()
-
getFont
Get theFont
of this object.- Specified by:
getFont
in interfaceAccessibleComponent
- Returns:
- if supported, the
Font
for the object; otherwise, null - See Also:
AccessibleComponent.setFont(java.awt.Font)
-
setFont
Set theFont
of this object.- Specified by:
setFont
in interfaceAccessibleComponent
- Parameters:
f
- the newFont
for the object- See Also:
AccessibleComponent.getFont()
-
getFontMetrics
Get theFontMetrics
of this object.- Specified by:
getFontMetrics
in interfaceAccessibleComponent
- Parameters:
f
- theFont
- 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 interfaceAccessibleComponent
- Returns:
- true if object is enabled; otherwise, false
- See Also:
AccessibleComponent.setEnabled(boolean)
,AccessibleContext.getAccessibleStateSet()
,AccessibleState.ENABLED
,AccessibleStateSet
-
setEnabled
public void setEnabled(boolean b)Set the enabled state of the object.- Specified by:
setEnabled
in interfaceAccessibleComponent
- Parameters:
b
- if true, enables this object; otherwise, disables it- See Also:
AccessibleComponent.isEnabled()
-
isVisible
public boolean isVisible()Determine if the object is visible.- Specified by:
isVisible
in interfaceAccessibleComponent
- Returns:
- true if object is visible; otherwise, false
- See Also:
AccessibleComponent.setVisible(boolean)
,AccessibleContext.getAccessibleStateSet()
,AccessibleState.VISIBLE
,AccessibleStateSet
-
setVisible
public void setVisible(boolean b)Set the visible state of the object.- Specified by:
setVisible
in interfaceAccessibleComponent
- Parameters:
b
- if true, shows this object; otherwise, hides it- See Also:
AccessibleComponent.isVisible()
-
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 interfaceAccessibleComponent
- Returns:
- true if object is showing; otherwise, false
-
contains
Checks whether the specifiedPoint
is within this object's bounds, where thePoint
is relative to the coordinate system of the object.- Specified by:
contains
in interfaceAccessibleComponent
- Parameters:
p
- thePoint
relative to the coordinate system of the object- Returns:
- true if object contains
Point
; otherwise false - See Also:
AccessibleComponent.getBounds()
-
getLocationOnScreen
Returns the location of the object on the screen.- Specified by:
getLocationOnScreen
in interfaceAccessibleComponent
- Returns:
- location of object on screen; can be null if this object is not on the screen
- See Also:
AccessibleComponent.getBounds()
,AccessibleComponent.getLocation()
-
getLocation
Returns the location of the object relative to parent.- Specified by:
getLocation
in interfaceAccessibleComponent
- Returns:
- location of object relative to parent; can be null if this object or its parent are not on the screen
- See Also:
AccessibleComponent.getBounds()
,AccessibleComponent.getLocationOnScreen()
-
setLocation
Sets the location of the object relative to parent.- Specified by:
setLocation
in interfaceAccessibleComponent
- Parameters:
p
- the new position for the top-left corner- See Also:
AccessibleComponent.getLocation()
-
getBounds
Returns the current bounds of this object.- Specified by:
getBounds
in interfaceAccessibleComponent
- Returns:
- current bounds of object; can be null if this object is not on the screen
- See Also:
AccessibleComponent.contains(java.awt.Point)
-
setBounds
Sets the current bounds of this object.- Specified by:
setBounds
in interfaceAccessibleComponent
- Parameters:
r
- rectangle indicating this component's bounds- See Also:
AccessibleComponent.getBounds()
-
getSize
Returns the current size of this object.- Specified by:
getSize
in interfaceAccessibleComponent
- Returns:
- current size of object; can be null if this object is not on the screen
- See Also:
AccessibleComponent.setSize(java.awt.Dimension)
-
setSize
Sets the current size of this object.- Specified by:
setSize
in interfaceAccessibleComponent
- Parameters:
d
- The dimension specifying the new size of the object- See Also:
AccessibleComponent.getSize()
-
getAccessibleAt
Returns the accessible child contained at the local coordinate Point, if one exists.- Specified by:
getAccessibleAt
in interfaceAccessibleComponent
- Parameters:
p
- The point relative to the coordinate system of this object- 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 interfaceAccessibleComponent
- Returns:
- true if object can accept focus; otherwise false
- See Also:
AccessibleContext.getAccessibleStateSet()
,AccessibleState.FOCUSABLE
,AccessibleState.FOCUSED
,AccessibleStateSet
-
requestFocus
public void requestFocus()Requests focus for this object.- Specified by:
requestFocus
in interfaceAccessibleComponent
- See Also:
AccessibleComponent.isFocusTraversable()
-
addFocusListener
Adds the specifiedFocusListener
to receive focus events from this component.- Specified by:
addFocusListener
in interfaceAccessibleComponent
- Parameters:
l
- the focus listener- See Also:
AccessibleComponent.removeFocusListener(java.awt.event.FocusListener)
-
removeFocusListener
Removes the specified focus listener so it no longer receives focus events from this component.- Specified by:
removeFocusListener
in interfaceAccessibleComponent
- Parameters:
l
- the focus listener; this method performs no function, nor does it throw an exception if the listener specified was not previously added to this component; if listener is null, no exception is thrown and no action is performed.- See Also:
AccessibleComponent.addFocusListener(java.awt.event.FocusListener)
-