W3cubDocs

/OpenJDK 21

Class Translator

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

Modifier and Type Field Description
protected Object source
The source object needing translating.

Constructor Summary

Constructor Description
Translator()
Create a new Translator.
Translator(Object o)
Create a new Translator with the source object o.

Method Summary

Modifier and Type Method Description
void addFocusListener(FocusListener l)
Adds the specified FocusListener to receive focus events from this component.
void addPropertyChangeListener(PropertyChangeListener l)
Add a PropertyChangeListener to the listener list.
boolean contains(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(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 interface Accessible.
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 background Color of this object.
Rectangle getBounds()
Returns the current bounds of this object.
Cursor getCursor()
Get the Cursor of this object.
Font getFont()
Get the Font of this object.
FontMetrics getFontMetrics(Font f)
Get the FontMetrics of this object.
Color getForeground()
Get the foreground Color of this object.
Locale getLocale()
Gets the Locale 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 source Object of the Translator.
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 the PropertyChangeListener 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 background Color of this object.
void setBounds(Rectangle r)
Sets the current bounds of this object.
void setCursor(Cursor c)
Set the Cursor of this object.
void setEnabled(boolean b)
Set the enabled state of the object.
void setFont(Font f)
Set the Font of this object.
void setForeground(Color c)
Set the foreground Color 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 the Translator.
void setVisible(boolean b)
Set the visible state of the object.

Methods declared in class java.lang.Object

clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait

Field Details

source

protected Object source
The source object needing translating.

Constructor Details

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(Object o)
Create a new Translator with the source object o.
Parameters:
o - the Component that does not implement interface Accessible

Method Details

getTranslatorClass

protected static Class<?> getTranslatorClass(Class<?> c)
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

public static Accessible getAccessible(Object o)
Obtain an object that implements interface Accessible. If the object passed in already implements interface Accessible, getAccessible merely returns the object.
Parameters:
o - an Object; if a null is passed in a null is returned
Returns:
an Object, possibly the Object passed in, that implements the Accessible interface for the Object which was passed in

getSource

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

setSource

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

equals

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

hashCode

public int hashCode()
Return hashcode.
Overrides:
hashCode in class Object
Returns:
hashcode
See Also:

getAccessibleContext

public AccessibleContext getAccessibleContext()
Returns this object.
Specified by:
getAccessibleContext in interface Accessible
Returns:
the AccessibleContext associated with this object

getAccessibleName

public String getAccessibleName()
Get the accessible name of this object.
Overrides:
getAccessibleName in class AccessibleContext
Returns:
the localized name of the object; can be null if this object does not have a name
See Also:

setAccessibleName

public void setAccessibleName(String s)
Set the name of this object.
Overrides:
setAccessibleName in class AccessibleContext
Parameters:
s - the new localized name of the object
See Also:

getAccessibleDescription

public String getAccessibleDescription()
Get the accessible description of this object.
Overrides:
getAccessibleDescription in class AccessibleContext
Returns:
the description of the object; can be null if this object does not have a description
See Also:

setAccessibleDescription

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

getAccessibleRole

public AccessibleRole getAccessibleRole()
Get the role of this object.
Specified by:
getAccessibleRole in class AccessibleContext
Returns:
an instance of AccessibleRole describing the role of the object
See Also:

getAccessibleStateSet

public 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.
Specified by:
getAccessibleStateSet in class AccessibleContext
Returns:
an instance of AccessibleStateSet containing the current state of the object
See Also:

getAccessibleParent

public Accessible getAccessibleParent()
Get the accessible parent of this object.
Overrides:
getAccessibleParent in class AccessibleContext
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 class AccessibleContext
Returns:
-1 of this object does not have an accessible parent; otherwise, the index of the child in its accessible parent
See Also:

getAccessibleChildrenCount

public int getAccessibleChildrenCount()
Returns the number of accessible children in the object.
Specified by:
getAccessibleChildrenCount in class AccessibleContext
Returns:
the number of accessible children in the object

getAccessibleChild

public Accessible getAccessibleChild(int i)
Return the nth accessible child of the object.
Specified by:
getAccessibleChild in class AccessibleContext
Parameters:
i - zero-based index of child
Returns:
the nth accessible child of the object
See Also:

getLocale

public Locale getLocale() throws IllegalComponentStateException
Gets the Locale of the component. If the component does not have a locale, the locale of its parent is returned.
Specified by:
getLocale in class AccessibleContext
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

public void addPropertyChangeListener(PropertyChangeListener l)
Add a PropertyChangeListener to the listener list. The listener is registered for all properties.
Overrides:
addPropertyChangeListener in class AccessibleContext
Parameters:
l - The PropertyChangeListener to be added
See Also:

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener l)
Remove the PropertyChangeListener from the listener list.
Overrides:
removePropertyChangeListener in class AccessibleContext
Parameters:
l - The PropertyChangeListener to be removed

getBackground

public Color getBackground()
Get the background Color of this object.
Specified by:
getBackground in interface AccessibleComponent
Returns:
if supported, the background Color of the object; otherwise, null
See Also:

setBackground

public void setBackground(Color c)
Set the background Color of this object.
Specified by:
setBackground in interface AccessibleComponent
Parameters:
c - the new Color for the background
See Also:

getForeground

public Color getForeground()
Get the foreground Color of this object.
Specified by:
getForeground in interface AccessibleComponent
Returns:
if supported, the foreground Color of the object; otherwise, null
See Also:

setForeground

public void setForeground(Color c)
Set the foreground Color of this object.
Specified by:
setForeground in interface AccessibleComponent
Parameters:
c - the new Color for the foreground
See Also:

getCursor

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

setCursor

public void setCursor(Cursor c)
Set the Cursor of this object.
Specified by:
setCursor in interface AccessibleComponent
Parameters:
c - the new Cursor for the object
See Also:

getFont

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

setFont

public void setFont(Font f)
Set the Font of this object.
Specified by:
setFont in interface AccessibleComponent
Parameters:
f - the new Font for the object
See Also:

getFontMetrics

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

isEnabled

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

setEnabled

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

isVisible

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

setVisible

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

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 AccessibleComponent
Returns:
true if object is showing; otherwise, false

contains

public boolean contains(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 AccessibleComponent
Parameters:
p - the Point relative to the coordinate system of the object
Returns:
true if object contains Point; otherwise false
See Also:

getLocationOnScreen

public Point getLocationOnScreen()
Returns the location of the object on the screen.
Specified by:
getLocationOnScreen in interface AccessibleComponent
Returns:
location of object on screen; can be null if this object is not on the screen
See Also:

getLocation

public Point getLocation()
Returns the location of the object relative to parent.
Specified by:
getLocation in interface AccessibleComponent
Returns:
location of object relative to parent; can be null if this object or its parent are not on the screen
See Also:

setLocation

public void setLocation(Point p)
Sets the location of the object relative to parent.
Specified by:
setLocation in interface AccessibleComponent
Parameters:
p - the new position for the top-left corner
See Also:

getBounds

public Rectangle getBounds()
Returns the current bounds of this object.
Specified by:
getBounds in interface AccessibleComponent
Returns:
current bounds of object; can be null if this object is not on the screen
See Also:

setBounds

public void setBounds(Rectangle r)
Sets the current bounds of this object.
Specified by:
setBounds in interface AccessibleComponent
Parameters:
r - rectangle indicating this component's bounds
See Also:

getSize

public Dimension getSize()
Returns the current size of this object.
Specified by:
getSize in interface AccessibleComponent
Returns:
current size of object; can be null if this object is not on the screen
See Also:

setSize

public void setSize(Dimension d)
Sets the current size of this object.
Specified by:
setSize in interface AccessibleComponent
Parameters:
d - The dimension specifying the new size of the object
See Also:

getAccessibleAt

public Accessible getAccessibleAt(Point p)
Returns the accessible child contained at the local coordinate Point, if one exists.
Specified by:
getAccessibleAt in interface AccessibleComponent
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 interface AccessibleComponent
Returns:
true if object can accept focus; otherwise false
See Also:

requestFocus

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

addFocusListener

public void addFocusListener(FocusListener l)
Adds the specified FocusListener to receive focus events from this component.
Specified by:
addFocusListener in interface AccessibleComponent
Parameters:
l - the focus listener
See Also:

removeFocusListener

public void removeFocusListener(FocusListener l)
Removes the specified focus listener so it no longer receives focus events from this component.
Specified by:
removeFocusListener in interface AccessibleComponent
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:

© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/jdk.accessibility/com/sun/java/accessibility/util/Translator.html