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

This class implements accessibility support for the JTextComponent class. It provides an implementation of the Java Accessibility API appropriate to menu user-interface elements.
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()
Constructs an AccessibleJTextComponent.

Method Summary

void
caretUpdate(CaretEvent e)
Handles caret updates (fire appropriate property change event, which are AccessibleContext.ACCESSIBLE_CARET_PROPERTY and AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY).
void
changedUpdate(DocumentEvent e)
Changed update.
void
cut(int start, int end)
Cut the text between two points to the system clipboard.
void
delete(int start, int end)
Delete the text between two points.
boolean
doAccessibleAction(int i)
Perform the specified action.
int
getAccessibleActionCount()
Get the number possible actions for this object, with the zeroth representing the default action.
String
getAccessibleActionDescription(int i)
Get a description for the specified action.
AccessibleEditableText
getAccessibleEditableText()
Returns the AccessibleEditableText interface for this text component.
AccessibleRole
getAccessibleRole()
Returns the accessible role of this component.
AccessibleStateSet
getAccessibleStateSet()
Returns the accessible state set of this component.
AccessibleText
getAccessibleText()
Get the AccessibleText associated with this object.
String
getAfterIndex(int part, int index)
Returns the section of text after the index, or null if the index or part is invalid.
String
getAtIndex(int part, int index)
Returns the section of text at the index, or null if the index or part is invalid.
String
getBeforeIndex(int part, int index)
Returns the section of text before the index, or null if the index or part is invalid.
int
getCaretPosition()
Returns the zero-based offset of the caret.
int
getCharCount()
Return the number of characters.
AttributeSet
getCharacterAttribute(int index)
Returns the attributes of a character at an index, or null if the index is out of bounds.
Rectangle
getCharacterBounds(int index)
Determines the bounding box of the indexed character.
int
getIndexAtPoint(Point p)
Given a point in the coordinate system of this object, return the 0-based index of the character at that point, or -1 if there is none.
String
getSelectedText()
Returns the portion of the text that is selected.
int
getSelectionEnd()
Returns the end offset within the selected text.
int
getSelectionStart()
Returns the start offset within the selected text.
String
getTextRange(int start, int end)
Return the text between two points.
void
insertTextAtIndex(int index, String s)
Inserts the given string at the specified location.
void
insertUpdate(DocumentEvent e)
Insert update.
void
paste(int start)
Paste the text from the system clipboard at the given index.
void
removeUpdate(DocumentEvent e)
Remove update.
void
replaceText(int start, int end, String s)
Replace the text between two points with the given string.
void
selectText(int start, int end)
Select the text between two points.
void
setAttributes(int start, int end, AttributeSet s)
Set the attributes of text between two points.
void
setTextContents(String s)
Set the text contents to the given string.

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, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

AccessibleJTextComponent

public AccessibleJTextComponent()
Constructs an AccessibleJTextComponent. Adds a listener to track caret change.

Method Details

caretUpdate

public void caretUpdate(CaretEvent e)
            throws NotImplementedException
Handles caret updates (fire appropriate property change event, which are AccessibleContext.ACCESSIBLE_CARET_PROPERTY and AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY). This keeps track of the dot position internally. When the caret moves, the internal position is updated after firing the event.
Specified by:
caretUpdate in interface CaretListener
Parameters:
e - - caret event

changedUpdate

public void changedUpdate(DocumentEvent e)
            throws NotImplementedException
Changed update. Fire appropriate property change event which is AccessibleContext.ACCESSIBLE_TEXT_PROPERTY.
Specified by:
changedUpdate in interface DocumentListener
Parameters:
e - - document event

cut

public void cut(int start,
                int end)
Cut the text between two points to the system clipboard.
Specified by:
cut in interface AccessibleEditableText
Parameters:
start - the start position, inclusive
end - the end position, exclusive

delete

public void delete(int start,
                   int end)
Delete the text between two points.
Specified by:
delete in interface AccessibleEditableText
Parameters:
start - the start position, inclusive
end - the end position, exclusive

doAccessibleAction

public boolean doAccessibleAction(int i)
            throws NotImplementedException
Perform the specified action. Does nothing if out of bounds.
Specified by:
doAccessibleAction in interface AccessibleAction
Parameters:
i - the action to perform, 0-based
Returns:
true if the action was performed

getAccessibleActionCount

public int getAccessibleActionCount()
            throws NotImplementedException
Get the number possible actions for this object, with the zeroth representing the default action.
Specified by:
getAccessibleActionCount in interface AccessibleAction
Returns:
the 0-based number of actions

getAccessibleActionDescription

public String getAccessibleActionDescription(int i)
            throws NotImplementedException
Get a description for the specified action. Returns null if out of bounds.
Specified by:
getAccessibleActionDescription in interface AccessibleAction
Parameters:
i - the action to describe, 0-based
Returns:
description of the action

getAccessibleEditableText

public AccessibleEditableText getAccessibleEditableText()
Returns the AccessibleEditableText interface for this text component.
Overrides:
getAccessibleEditableText in interface AccessibleContext
Returns:
this

getAccessibleRole

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

getAccessibleStateSet

public AccessibleStateSet getAccessibleStateSet()
            throws NotImplementedException
Returns 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()
Get the AccessibleText associated with this object. In the implementation of the Java Accessibility API for this class, return this object, which is responsible for implementing the AccessibleText interface on behalf of itself.
Overrides:
getAccessibleText in interface AccessibleContext
Returns:
this

getAfterIndex

public String getAfterIndex(int part,
                            int index)
            throws NotImplementedException
Returns the section of text after the index, or null if the index or part is invalid.
Specified by:
getAfterIndex in interface AccessibleText
Parameters:
part - AccessibleText.CHARACTER, AccessibleText.WORD, or AccessibleText.SENTENCE
index - the 0-based character index
Returns:
the selection of text after that index, or null

getAtIndex

public String getAtIndex(int part,
                         int index)
            throws NotImplementedException
Returns the section of text at the index, or null if the index or part is invalid.
Specified by:
getAtIndex in interface AccessibleText
Parameters:
part - AccessibleText.CHARACTER, AccessibleText.WORD, or AccessibleText.SENTENCE
index - the 0-based character index
Returns:
the selection of text at that index, or null

getBeforeIndex

public String getBeforeIndex(int part,
                             int index)
            throws NotImplementedException
Returns the section of text before the index, or null if the index or part is invalid.
Specified by:
getBeforeIndex in interface AccessibleText
Parameters:
part - AccessibleText.CHARACTER, AccessibleText.WORD, or AccessibleText.SENTENCE
index - the 0-based character index
Returns:
the selection of text before that index, or null

getCaretPosition

public int getCaretPosition()
Returns the zero-based offset of the caret. Note: The character to the right of the caret will have the same index value as the offset (the caret is between two characters).
Specified by:
getCaretPosition in interface AccessibleText
Returns:
offset of caret

getCharCount

public int getCharCount()
Return the number of characters.
Specified by:
getCharCount in interface AccessibleText
Returns:
the character count

getCharacterAttribute

public AttributeSet getCharacterAttribute(int index)
            throws NotImplementedException
Returns the attributes of a character at an index, or null if the index is out of bounds.
Specified by:
getCharacterAttribute in interface AccessibleText
Parameters:
index - the 0-based character index
Returns:
the character's attributes

getCharacterBounds

public Rectangle getCharacterBounds(int index)
            throws NotImplementedException
Determines the bounding box of the indexed character. Returns an empty rectangle if the index is out of bounds. The bounds are returned in local coordinates. If the index is invalid a null rectangle is returned. The screen coordinates returned are "unscrolled coordinates" if the JTextComponent is contained in a JScrollPane in which case the resulting rectangle should be composed with the parent coordinates. Note: the JTextComponent must have a valid size (e.g. have been added to a parent container whose ancestor container is a valid top-level window) for this method to be able to return a meaningful (non-null) value.
Specified by:
getCharacterBounds in interface AccessibleText
Parameters:
index - the 0-based character index
Returns:
the bounding box, may be empty or null.

getIndexAtPoint

public int getIndexAtPoint(Point p)
            throws NotImplementedException
Given a point in the coordinate system of this object, return the 0-based index of the character at that point, or -1 if there is none.
Specified by:
getIndexAtPoint in interface AccessibleText
Parameters:
p - the point to look at
Returns:
the character index, or -1

getSelectedText

public String getSelectedText()
Returns the portion of the text that is selected.
Specified by:
getSelectedText in interface AccessibleText
Returns:
null if no text is selected.

getSelectionEnd

public int getSelectionEnd()
Returns the end offset within the selected text. If there is no selection, but there is a caret, the start and end offsets will be the same. Return 0 if the text is empty, or the caret position if no selection.
Specified by:
getSelectionEnd in interface AccessibleText
Returns:
index of the end of the text >= 0.

getSelectionStart

public int getSelectionStart()
Returns the start offset within the selected text. If there is no selection, but there is a caret, the start and end offsets will be the same. Return 0 if the text is empty, or the caret position if no selection.
Specified by:
getSelectionStart in interface AccessibleText
Returns:
index of the start of the text >= 0.

getTextRange

public String getTextRange(int start,
                           int end)
Return the text between two points.
Specified by:
getTextRange in interface AccessibleEditableText
Parameters:
start - the start position, inclusive
end - the end position, exclusive

insertTextAtIndex

public void insertTextAtIndex(int index,
                              String s)
            throws NotImplementedException
Inserts the given string at the specified location.
Specified by:
insertTextAtIndex in interface AccessibleEditableText
Parameters:
index - the index for insertion
s - the new text

insertUpdate

public void insertUpdate(DocumentEvent e)
            throws NotImplementedException
Insert update. Fire appropriate property change event which is AccessibleContext.ACCESSIBLE_TEXT_PROPERTY.
Specified by:
insertUpdate in interface DocumentListener
Parameters:
e - - document event

paste

public void paste(int start)
Paste the text from the system clipboard at the given index.
Specified by:
paste in interface AccessibleEditableText
Parameters:
start - the start position

removeUpdate

public void removeUpdate(DocumentEvent e)
            throws NotImplementedException
Remove update. Fire appropriate property change event which is AccessibleContext.ACCESSIBLE_TEXT_PROPERTY.
Specified by:
removeUpdate in interface DocumentListener
Parameters:
e - - document event

replaceText

public void replaceText(int start,
                        int end,
                        String s)
Replace the text between two points with the given string.
Specified by:
replaceText in interface AccessibleEditableText
Parameters:
start - the start position, inclusive
end - the end position, exclusive
s - the string to paste

selectText

public void selectText(int start,
                       int end)
Select the text between two points.
Specified by:
selectText in interface AccessibleEditableText
Parameters:
start - the start position, inclusive
end - the end position, exclusive

setAttributes

public void setAttributes(int start,
                          int end,
                          AttributeSet s)
            throws NotImplementedException
Set the attributes of text between two points.
Specified by:
setAttributes in interface AccessibleEditableText
Parameters:
start - the start position, inclusive
end - the end position, exclusive
s - the new attribute set for the range

setTextContents

public void setTextContents(String s)
            throws NotImplementedException
Set the text contents to the given string.
Specified by:
setTextContents in interface AccessibleEditableText
Parameters:
s - the new text

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.