javax.swing.text

Class JTextComponent.AccessibleJTextComponent

public class JTextComponent.AccessibleJTextComponent extends 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.
Constructor Summary
AccessibleJTextComponent()
Construct an AccessibleJTextComponent.
Method Summary
voidcaretUpdate(CaretEvent e)
Handle a change in the caret position and fire any applicable property change events.
voidchangedUpdate(DocumentEvent e)
Handle a text change event and fire an AccessibleContext.ACCESSIBLE_TEXT_PROPERTY property change event.
voidcut(int start, int end)
Cuts the text between two indexes.
voiddelete(int start, int end)
Deletes the text between two indexes.
booleandoAccessibleAction(int i)
Performs the i-th action.
intgetAccessibleActionCount()
Returns the number of actions for this object.
StringgetAccessibleActionDescription(int i)
Returns the description of the i-th action.
AccessibleEditableTextgetAccessibleEditableText()
Retrieve an AccessibleEditableText object that controls this text component.
AccessibleRolegetAccessibleRole()
Retrieve the accessible role of this component.
AccessibleStateSetgetAccessibleStateSet()
Retreive the accessible state set of this component.
AccessibleTextgetAccessibleText()
Retrieve an AccessibleText object that controls this text component.
StringgetAfterIndex(int part, int index)
Gets the text located after index. null is returned if the index or part is invalid.
StringgetAtIndex(int part, int index)
Gets the text located at index. null is returned if the index or part is invalid.
StringgetBeforeIndex(int part, int index)
Gets the text located before index. null is returned if the index or part is invalid.
intgetCaretPosition()
Retrieve the current caret position.
AttributeSetgetCharacterAttribute(int index)
Gets the character attributes of the character at index.
RectanglegetCharacterBounds(int index)
Calculate the bounding box of the character at the given index.
intgetCharCount()
Return the length of the text in this text component.
intgetIndexAtPoint(Point p)
Get the index of the character at the given point, in component pixel co-ordinates.
StringgetSelectedText()
Retrieve the current text selection.
intgetSelectionEnd()
Retrieve the index of the last character in the current text selection.
intgetSelectionStart()
Retrieve the index of the first character in the current text selection.
StringgetTextRange(int start, int end)
Gets the text between two indexes.
voidinsertTextAtIndex(int index, String s)
Inserts the text at the given index.
voidinsertUpdate(DocumentEvent e)
Handle a text insertion event and fire an AccessibleContext.ACCESSIBLE_TEXT_PROPERTY property change event.
voidpaste(int start)
Pastes the text from the system clipboard to the given index.
voidremoveUpdate(DocumentEvent e)
Handle a text removal event and fire an AccessibleContext.ACCESSIBLE_TEXT_PROPERTY property change event.
voidreplaceText(int start, int end, String s)
Replaces the text between two indexes with the given text.
voidselectText(int start, int end)
Selects the text between two indexes.
voidsetAttributes(int start, int end, AttributeSet s)
Sets the attributes of all the text between two indexes.
voidsetTextContents(String s)
Sets the text contents.

Constructor Detail

AccessibleJTextComponent

public AccessibleJTextComponent()
Construct an AccessibleJTextComponent.

Method Detail

caretUpdate

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

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.

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.

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.

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.

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.

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.

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.

Returns: this

getAccessibleRole

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

Returns: the accessible role of this component

See Also: AccessibleRole

getAccessibleStateSet

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

Returns: the accessible state set of this component

getAccessibleText

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

Returns: this

See Also: AccessibleText

getAfterIndex

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

Parameters: part - {@link #CHARACTER}, {@link #WORD}, or {@link #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.

Parameters: part - {@link #CHARACTER}, {@link #WORD}, or {@link #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.

Parameters: part - {@link #CHARACTER}, {@link #WORD}, or {@link #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.

Returns: caret position

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.

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.

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.

Returns: a character length

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.

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.

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.

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.

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.

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.

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.

Parameters: e - the insertion event

paste

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

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.

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.

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.

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.

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.

Parameters: s - the new text contents.