javax.swing.text

Class JTextComponent.AccessibleJTextComponent

Enclosing Class:
JTextComponent
Implemented Interfaces:
AccessibleAction, AccessibleComponent, AccessibleEditableText, AccessibleExtendedComponent, AccessibleText, CaretListener, DocumentListener, EventListener, Serializable
Known Direct Subclasses:
JEditorPane.AccessibleJEditorPane, JTextArea.AccessibleJTextArea, JTextField.AccessibleJTextField

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.Container.AccessibleAWTContainer

Container.AccessibleAWTContainer.AccessibleContainerHandler

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.Container.AccessibleAWTContainer

accessibleContainerHandler

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

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.
int
getCharCount()
Return the length of the text in this text component.
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
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, getAccessibleRole, getAccessibleStateSet, getBorderTitle, getTitledBorderText, getToolTipText, removePropertyChangeListener

Methods inherited from class java.awt.Container.AccessibleAWTContainer

getAccessibleAt, getAccessibleChild, getAccessibleChildrenCount

Methods inherited from class java.awt.Component.AccessibleAWTComponent

addFocusListener, addPropertyChangeListener, contains, getAccessibleAt, getAccessibleChild, getAccessibleChildrenCount, getAccessibleComponent, getAccessibleDescription, getAccessibleIndexInParent, getAccessibleName, getAccessibleParent, getAccessibleRole, getAccessibleStateSet, getBackground, getBounds, getCursor, getFont, getFontMetrics, getForeground, getLocale, getLocation, getLocationOnScreen, getSize, isEnabled, isFocusTraversable, isShowing, isVisible, removeFocusListener, removePropertyChangeListener, requestFocus, setBackground, setBounds, setCursor, setEnabled, setFont, setForeground, setLocation, setSize, setVisible

Methods inherited from class javax.accessibility.AccessibleContext

addPropertyChangeListener, firePropertyChange, getAccessibleAction, getAccessibleChild, getAccessibleChildrenCount, getAccessibleComponent, getAccessibleDescription, getAccessibleEditableText, getAccessibleIcon, getAccessibleIndexInParent, getAccessibleName, getAccessibleParent, getAccessibleRelationSet, getAccessibleRole, getAccessibleSelection, getAccessibleStateSet, getAccessibleTable, getAccessibleText, getAccessibleValue, getLocale, removePropertyChangeListener, setAccessibleDescription, setAccessibleName, setAccessibleParent

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

AccessibleJTextComponent

public AccessibleJTextComponent()
Construct an AccessibleJTextComponent.

Method Details

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

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

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)

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)

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

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

getAccessibleEditableText

public AccessibleEditableText getAccessibleEditableText()
Retrieve an AccessibleEditableText object that controls this text component.
Overrides:
getAccessibleEditableText in interface AccessibleContext
Returns:
this

getAccessibleRole

public AccessibleRole getAccessibleRole()
Retrieve the accessible role of this component.
Overrides:
getAccessibleRole in interface JComponent.AccessibleJComponent
Returns:
the accessible role of this component

getAccessibleStateSet

public AccessibleStateSet getAccessibleStateSet()
Retreive the accessible state set of this component.
Overrides:
getAccessibleStateSet in interface JComponent.AccessibleJComponent
Returns:
the accessible state set of this component

getAccessibleText

public AccessibleText getAccessibleText()
Retrieve an AccessibleText object that controls this text component.
Overrides:
getAccessibleText in interface AccessibleContext
Returns:
this

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

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

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

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

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

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

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

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

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

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

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)

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

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

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

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

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

setTextContents

public void setTextContents(String s)
Sets the text contents.
Specified by:
setTextContents in interface AccessibleEditableText
Parameters:
s - - the new text contents.

JTextComponent.java -- Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.