javax.swing.text
Class JTextComponent.AccessibleJTextComponent

java.lang.Object
  extended by javax.accessibility.AccessibleContext
      extended by java.awt.Component.AccessibleAWTComponent
          extended by java.awt.Container.AccessibleAWTContainer
              extended by javax.swing.JComponent.AccessibleJComponent
                  extended by javax.swing.text.JTextComponent.AccessibleJTextComponent
All Implemented Interfaces:
Serializable, EventListener, AccessibleAction, AccessibleComponent, AccessibleEditableText, AccessibleExtendedComponent, AccessibleText, CaretListener, DocumentListener
Direct Known Subclasses:
JEditorPane.AccessibleJEditorPane, JTextArea.AccessibleJTextArea, JTextField.AccessibleJTextField
Enclosing class:
JTextComponent

public class JTextComponent.AccessibleJTextComponent
extends JComponent.AccessibleJComponent
implements AccessibleText, CaretListener, DocumentListener, AccessibleAction, AccessibleEditableText

AccessibleJTextComponent implements accessibility hooks for JTextComponent. It allows an accessibility driver to read and manipulate the text component's contents as well as update UI elements such as the caret.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent.AccessibleJComponent
JComponent.AccessibleJComponent.AccessibleContainerHandler, JComponent.AccessibleJComponent.AccessibleFocusHandler
 
Nested classes/interfaces inherited from class java.awt.Component.AccessibleAWTComponent
Component.AccessibleAWTComponent.AccessibleAWTComponentHandler, Component.AccessibleAWTComponent.AccessibleAWTFocusHandler
 
Field Summary
 
Fields inherited from class javax.swing.JComponent.AccessibleJComponent
accessibleContainerHandler, accessibleFocusHandler
 
Fields inherited from class java.awt.Component.AccessibleAWTComponent
accessibleAWTComponentHandler, accessibleAWTFocusHandler
 
Fields inherited from 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
 
Fields inherited from interface javax.accessibility.AccessibleAction
DECREMENT, INCREMENT, TOGGLE_EXPAND
 
Fields inherited from interface javax.accessibility.AccessibleText
CHARACTER, SENTENCE, WORD
 
Constructor Summary
JTextComponent.AccessibleJTextComponent()
          Construct an AccessibleJTextComponent.
 
Method Summary
 void caretUpdate(CaretEvent e)
          Handle a change in the caret position and fire any applicable property change events.
 void changedUpdate(DocumentEvent e)
          Handle a text change event and fire an AccessibleContext.ACCESSIBLE_TEXT_PROPERTY property change event.
 void cut(int start, int end)
          Cuts the text between two indexes.
 void delete(int start, int end)
          Deletes the text between two indexes.
 boolean doAccessibleAction(int i)
          Performs the i-th action.
 int getAccessibleActionCount()
          Returns the number of actions for this object.
 String getAccessibleActionDescription(int i)
          Returns the description of the i-th action.
 AccessibleEditableText getAccessibleEditableText()
          Retrieve an AccessibleEditableText object that controls this text component.
 AccessibleRole getAccessibleRole()
          Retrieve the accessible role of this component.
 AccessibleStateSet getAccessibleStateSet()
          Retreive the accessible state set of this component.
 AccessibleText getAccessibleText()
          Retrieve an AccessibleText object that controls this text component.
 String getAfterIndex(int part, int index)
          Gets the text located after index. null is returned if the index or part is invalid.
 String getAtIndex(int part, int index)
          Gets the text located at index. null is returned if the index or part is invalid.
 String getBeforeIndex(int part, int index)
          Gets the text located before index. null is returned if the index or part is invalid.
 int getCaretPosition()
          Retrieve the current caret position.
 AttributeSet getCharacterAttribute(int index)
          Gets the character attributes of the character at index.
 Rectangle getCharacterBounds(int index)
          Calculate the bounding box of the character at the given index.
 int getCharCount()
          Return the length of the text in this text component.
 int getIndexAtPoint(Point p)
          Get the index of the character at the given point, in component pixel co-ordinates.
 String getSelectedText()
          Retrieve the current text selection.
 int getSelectionEnd()
          Retrieve the index of the last character in the current text selection.
 int getSelectionStart()
          Retrieve the index of the first character in the current text selection.
 String getTextRange(int start, int end)
          Gets the text between two indexes.
 void insertTextAtIndex(int index, String s)
          Inserts the text at the given index.
 void insertUpdate(DocumentEvent e)
          Handle a text insertion event and fire an AccessibleContext.ACCESSIBLE_TEXT_PROPERTY property change event.
 void paste(int start)
          Pastes the text from the system clipboard to the given index.
 void removeUpdate(DocumentEvent e)
          Handle a text removal event and fire an AccessibleContext.ACCESSIBLE_TEXT_PROPERTY property change event.
 void replaceText(int start, int end, String s)
          Replaces the text between two indexes with the given text.
 void selectText(int start, int end)
          Selects the text between two indexes.
 void setAttributes(int start, int end, AttributeSet s)
          Sets the attributes of all the text between two indexes.
 void setTextContents(String s)
          Sets the text contents.
 
Methods inherited from class javax.swing.JComponent.AccessibleJComponent
addPropertyChangeListener, getAccessibleChild, getAccessibleChildrenCount, getAccessibleDescription, getAccessibleKeyBinding, getAccessibleName, getBorderTitle, getTitledBorderText, getToolTipText, removePropertyChangeListener
 
Methods inherited from class java.awt.Container.AccessibleAWTContainer
getAccessibleAt
 
Methods inherited from class java.awt.Component.AccessibleAWTComponent
addFocusListener, contains, getAccessibleComponent, getAccessibleIndexInParent, getAccessibleParent, getBackground, getBounds, getCursor, getFont, getFontMetrics, getForeground, getLocale, getLocation, getLocationOnScreen, getSize, isEnabled, isFocusTraversable, isShowing, isVisible, removeFocusListener, requestFocus, setBackground, setBounds, setCursor, setEnabled, setFont, setForeground, setLocation, setSize, setVisible
 
Methods inherited from class javax.accessibility.AccessibleContext
firePropertyChange, getAccessibleAction, getAccessibleIcon, getAccessibleRelationSet, getAccessibleSelection, getAccessibleTable, getAccessibleValue, setAccessibleDescription, setAccessibleName, setAccessibleParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.accessibility.AccessibleComponent
addFocusListener, contains, getAccessibleAt, getBackground, getBounds, getCursor, getFont, getFontMetrics, getForeground, getLocation, getLocationOnScreen, getSize, isEnabled, isFocusTraversable, isShowing, isVisible, removeFocusListener, requestFocus, setBackground, setBounds, setCursor, setEnabled, setFont, setForeground, setLocation, setSize, setVisible
 

Constructor Detail

JTextComponent.AccessibleJTextComponent

public JTextComponent.AccessibleJTextComponent()
Construct an AccessibleJTextComponent.

Method Detail

getCaretPosition

public int getCaretPosition()
Retrieve the current caret position. The index of the first caret position is 0.

Specified by:
getCaretPosition in interface AccessibleText
Returns:
caret position

getSelectedText

public String getSelectedText()
Retrieve the current text selection. If no text is selected this method returns null.

Specified by:
getSelectedText in interface AccessibleText
Returns:
the currently selected text or null

getSelectionStart

public int getSelectionStart()
Retrieve the index of the first character in the current text selection. If there is no text in the text component, this method returns 0. If there is text in the text component, but there is no selection, this method returns the current caret position.

Specified by:
getSelectionStart in interface AccessibleText
Returns:
the index of the first character in the selection, the current caret position or 0

getSelectionEnd

public int getSelectionEnd()
Retrieve the index of the last character in the current text selection. If there is no text in the text component, this method returns 0. If there is text in the text component, but there is no selection, this method returns the current caret position.

Specified by:
getSelectionEnd in interface AccessibleText
Returns:
the index of the last character in the selection, the current caret position or 0

caretUpdate

public void caretUpdate(CaretEvent e)
Handle a change in the caret position and fire any applicable property change events.

Specified by:
caretUpdate in interface CaretListener
Parameters:
e - - the caret update event

getAccessibleStateSet

public AccessibleStateSet getAccessibleStateSet()
Retreive the accessible state set of this component.

Overrides:
getAccessibleStateSet in class JComponent.AccessibleJComponent
Returns:
the accessible state set of this component
See Also:
AccessibleState

getAccessibleRole

public AccessibleRole getAccessibleRole()
Retrieve the accessible role of this component.

Overrides:
getAccessibleRole in class JComponent.AccessibleJComponent
Returns:
the accessible role of this component
See Also:
AccessibleRole

getAccessibleEditableText

public AccessibleEditableText getAccessibleEditableText()
Retrieve an AccessibleEditableText object that controls this text component.

Overrides:
getAccessibleEditableText in class AccessibleContext
Returns:
this
See Also:
AccessibleEditableText

getAccessibleText

public AccessibleText getAccessibleText()
Retrieve an AccessibleText object that controls this text component.

Overrides:
getAccessibleText in class AccessibleContext
Returns:
this
See Also:
AccessibleText

insertUpdate

public void insertUpdate(DocumentEvent e)
Handle a text insertion event and fire an AccessibleContext.ACCESSIBLE_TEXT_PROPERTY property change event.

Specified by:
insertUpdate in interface DocumentListener
Parameters:
e - - the insertion event

removeUpdate

public void removeUpdate(DocumentEvent e)
Handle a text removal event and fire an AccessibleContext.ACCESSIBLE_TEXT_PROPERTY property change event.

Specified by:
removeUpdate in interface DocumentListener
Parameters:
e - - the removal event

changedUpdate

public void changedUpdate(DocumentEvent e)
Handle a text change event and fire an AccessibleContext.ACCESSIBLE_TEXT_PROPERTY property change event.

Specified by:
changedUpdate in interface DocumentListener
Parameters:
e - - text change event

getIndexAtPoint

public int getIndexAtPoint(Point p)
Get the index of the character at the given point, in component pixel co-ordinates. If the point argument is invalid this method returns -1.

Specified by:
getIndexAtPoint in interface AccessibleText
Parameters:
p - - a point in component pixel co-ordinates
Returns:
a character index, or -1

getCharacterBounds

public Rectangle getCharacterBounds(int index)
Calculate the bounding box of the character at the given index. The returned x and y co-ordinates are relative to this text component's top-left corner. If the index is invalid this method returns null.

Specified by:
getCharacterBounds in interface AccessibleText
Parameters:
index - - the character index
Returns:
a character's bounding box, or null

getCharCount

public int getCharCount()
Return the length of the text in this text component.

Specified by:
getCharCount in interface AccessibleText
Returns:
a character length

getCharacterAttribute

public AttributeSet getCharacterAttribute(int index)
Gets the character attributes of the character at index. If the index is out of bounds, null is returned.

Specified by:
getCharacterAttribute in interface AccessibleText
Parameters:
index - - index of the character
Returns:
the character's attributes

getAtIndex

public String getAtIndex(int part,
                         int index)
Gets the text located at index. null is returned if the index or part is invalid.

Specified by:
getAtIndex in interface AccessibleText
Parameters:
part - - AccessibleText.CHARACTER, AccessibleText.WORD, or AccessibleText.SENTENCE
index - - index of the part
Returns:
the part of text at that index, or null

getAfterIndex

public String getAfterIndex(int part,
                            int index)
Gets the text located after index. null is returned if the index or part is invalid.

Specified by:
getAfterIndex in interface AccessibleText
Parameters:
part - - AccessibleText.CHARACTER, AccessibleText.WORD, or AccessibleText.SENTENCE
index - - index after the part
Returns:
the part of text after that index, or null

getBeforeIndex

public String getBeforeIndex(int part,
                             int index)
Gets the text located before index. null is returned if the index or part is invalid.

Specified by:
getBeforeIndex in interface AccessibleText
Parameters:
part - - AccessibleText.CHARACTER, AccessibleText.WORD, or AccessibleText.SENTENCE
index - - index before the part
Returns:
the part of text before that index, or null

getAccessibleActionCount

public int getAccessibleActionCount()
Returns the number of actions for this object. The zero-th object represents the default action.

Specified by:
getAccessibleActionCount in interface AccessibleAction
Returns:
the number of actions (0-based).

getAccessibleActionDescription

public String getAccessibleActionDescription(int i)
Returns the description of the i-th action. Null is returned if i is out of bounds.

Specified by:
getAccessibleActionDescription in interface AccessibleAction
Parameters:
i - - the action to get the description for
Returns:
description of the i-th action

doAccessibleAction

public boolean doAccessibleAction(int i)
Performs the i-th action. Nothing happens if i is out of bounds.

Specified by:
doAccessibleAction in interface AccessibleAction
Parameters:
i - - the action to perform
Returns:
true if the action was performed successfully

setTextContents

public void setTextContents(String s)
Sets the text contents.

Specified by:
setTextContents in interface AccessibleEditableText
Parameters:
s - - the new text contents.

insertTextAtIndex

public void insertTextAtIndex(int index,
                              String s)
Inserts the text at the given index.

Specified by:
insertTextAtIndex in interface AccessibleEditableText
Parameters:
index - - the index to insert the new text at.
s - - the new text

getTextRange

public String getTextRange(int start,
                           int end)
Gets the text between two indexes.

Specified by:
getTextRange in interface AccessibleEditableText
Parameters:
start - - the starting index (inclusive)
end - - the ending index (exclusive)

delete

public void delete(int start,
                   int end)
Deletes the text between two indexes.

Specified by:
delete in interface AccessibleEditableText
Parameters:
start - - the starting index (inclusive)
end - - the ending index (exclusive)

cut

public void cut(int start,
                int end)
Cuts the text between two indexes. The text is put into the system clipboard.

Specified by:
cut in interface AccessibleEditableText
Parameters:
start - - the starting index (inclusive)
end - - the ending index (exclusive)

paste

public void paste(int start)
Pastes the text from the system clipboard to the given index.

Specified by:
paste in interface AccessibleEditableText
Parameters:
start - - the starting index

replaceText

public void replaceText(int start,
                        int end,
                        String s)
Replaces the text between two indexes with the given text.

Specified by:
replaceText in interface AccessibleEditableText
Parameters:
start - - the starting index (inclusive)
end - - the ending index (exclusive)
s - - the text to paste

selectText

public void selectText(int start,
                       int end)
Selects the text between two indexes.

Specified by:
selectText in interface AccessibleEditableText
Parameters:
start - - the starting index (inclusive)
end - - the ending index (exclusive)

setAttributes

public void setAttributes(int start,
                          int end,
                          AttributeSet s)
Sets the attributes of all the text between two indexes.

Specified by:
setAttributes in interface AccessibleEditableText
Parameters:
start - - the starting index (inclusive)
end - - the ending index (exclusive)
s - - the new attribute set for the text in the range