javax.swing.text
Class JTextComponent.InputMethodRequestsHandler

java.lang.Object
  extended byjavax.swing.text.JTextComponent.InputMethodRequestsHandler
All Implemented Interfaces:
DocumentListener, EventListener, InputMethodRequests
Enclosing class:
JTextComponent

class JTextComponent.InputMethodRequestsHandler
extends Object
implements InputMethodRequests, DocumentListener


Constructor Summary
(package private) JTextComponent.InputMethodRequestsHandler()
           
 
Method Summary
 AttributedCharacterIterator cancelLatestCommittedText(AttributedCharacterIterator.Attribute[] attributes)
          Gets the latest committed text from the text editing component and removes it from the component's text body.
 void changedUpdate(DocumentEvent e)
          Gives notification that an attribute or set of attributes changed.
 AttributedCharacterIterator getCommittedText(int beginIndex, int endIndex, AttributedCharacterIterator.Attribute[] attributes)
          Gets an iterator providing access to the entire text and attributes contained in the text editing component except for uncommitted text.
 int getCommittedTextLength()
          Gets the length of the entire text contained in the text editing component except for uncommitted (composed) text.
 int getInsertPositionOffset()
          Gets the offset of the insert position in the committed text contained in the text editing component.
 TextHitInfo getLocationOffset(int x, int y)
          Gets the offset within the composed text for the specified absolute x and y coordinates on the screen.
 AttributedCharacterIterator getSelectedText(AttributedCharacterIterator.Attribute[] attributes)
          Gets the currently selected text from the text editing component.
 Rectangle getTextLocation(TextHitInfo offset)
          Gets the location of a specified offset in the current composed text, or of the selection in committed text.
 void insertUpdate(DocumentEvent e)
          Gives notification that there was an insert into the document.
 void removeUpdate(DocumentEvent e)
          Gives notification that a portion of the document has been removed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JTextComponent.InputMethodRequestsHandler

JTextComponent.InputMethodRequestsHandler()
Method Detail

cancelLatestCommittedText

public AttributedCharacterIterator cancelLatestCommittedText(AttributedCharacterIterator.Attribute[] attributes)
Description copied from interface: InputMethodRequests
Gets the latest committed text from the text editing component and removes it from the component's text body. This is used for the "Undo Commit" feature in some input methods, where the committed text reverts to its previous composed state. The composed text will be sent to the component using an InputMethodEvent.

Generally, this feature should only be supported immediately after the text was committed, not after the user performed other operations on the text. When the feature is not supported, return null.

The input method may provide a list of attributes that it is interested in. In that case, information about other attributes that the implementor may have need not be made accessible through the iterator. If the list is null, all available attribute information should be made accessible.

Specified by:
cancelLatestCommittedText in interface InputMethodRequests
Parameters:
attributes - a list of attributes that the input method is interested in
Returns:
the latest committed text, or null when the "Undo Commit" feature is not supported

getCommittedText

public AttributedCharacterIterator getCommittedText(int beginIndex,
                                                    int endIndex,
                                                    AttributedCharacterIterator.Attribute[] attributes)
Description copied from interface: InputMethodRequests
Gets an iterator providing access to the entire text and attributes contained in the text editing component except for uncommitted text. Uncommitted (composed) text should be ignored for index calculations and should not be made accessible through the iterator.

The input method may provide a list of attributes that it is interested in. In that case, information about other attributes that the implementor may have need not be made accessible through the iterator. If the list is null, all available attribute information should be made accessible.

Specified by:
getCommittedText in interface InputMethodRequests
Parameters:
beginIndex - the index of the first character
endIndex - the index of the character following the last character
attributes - a list of attributes that the input method is interested in
Returns:
an iterator providing access to the text and its attributes

getCommittedTextLength

public int getCommittedTextLength()
Description copied from interface: InputMethodRequests
Gets the length of the entire text contained in the text editing component except for uncommitted (composed) text.

Specified by:
getCommittedTextLength in interface InputMethodRequests
Returns:
the length of the text except for uncommitted text

getInsertPositionOffset

public int getInsertPositionOffset()
Description copied from interface: InputMethodRequests
Gets the offset of the insert position in the committed text contained in the text editing component. This is the offset at which characters entered through an input method are inserted. This information is used by an input method, for example, to examine the text surrounding the insert position.

Specified by:
getInsertPositionOffset in interface InputMethodRequests
Returns:
the offset of the insert position

getLocationOffset

public TextHitInfo getLocationOffset(int x,
                                     int y)
Description copied from interface: InputMethodRequests
Gets the offset within the composed text for the specified absolute x and y coordinates on the screen. This information is used, for example to handle mouse clicks and the mouse cursor. The offset is relative to the composed text, so offset 0 indicates the beginning of the composed text.

Return null if the location is outside the area occupied by the composed text.

Specified by:
getLocationOffset in interface InputMethodRequests
Parameters:
x - the absolute x coordinate on screen
y - the absolute y coordinate on screen
Returns:
a text hit info describing the offset in the composed text.

getTextLocation

public Rectangle getTextLocation(TextHitInfo offset)
Description copied from interface: InputMethodRequests
Gets the location of a specified offset in the current composed text, or of the selection in committed text. This information is, for example, used to position the candidate window near the composed text, or a composition window near the location where committed text will be inserted.

If the component has composed text (because the most recent InputMethodEvent sent to it contained composed text), then the offset is relative to the composed text - offset 0 indicates the first character in the composed text. The location returned should be for this character.

If the component doesn't have composed text, the offset should be ignored, and the location returned should reflect the beginning (in line direction) of the highlight in the last line containing selected text. For example, for horizontal left-to-right text (such as English), the location to the left of the left-most character on the last line containing selected text is returned. For vertical top-to-bottom text, with lines proceding from right to left, the location to the top of the left-most line containing selected text is returned.

The location is represented as a 0-thickness caret, that is, it has 0 width if the text is drawn horizontally, and 0 height if the text is drawn vertically. Other text orientations need to be mapped to horizontal or vertical orientation. The rectangle uses absolute screen coordinates.

Specified by:
getTextLocation in interface InputMethodRequests
Parameters:
offset - the offset within the composed text, if there is composed text; null otherwise
Returns:
a rectangle representing the screen location of the offset

getSelectedText

public AttributedCharacterIterator getSelectedText(AttributedCharacterIterator.Attribute[] attributes)
Description copied from interface: InputMethodRequests
Gets the currently selected text from the text editing component. This may be used for a variety of purposes. One of them is the "Reconvert" feature in some input methods. In this case, the input method will typically send an input method event to replace the selected text with composed text. Depending on the input method's capabilities, this may be the original composed text for the selected text, the latest composed text entered anywhere in the text, or a version of the text that's converted back from the selected text.

The input method may provide a list of attributes that it is interested in. In that case, information about other attributes that the implementor may have need not be made accessible through the iterator. If the list is null, all available attribute information should be made accessible.

Specified by:
getSelectedText in interface InputMethodRequests
Parameters:
attributes - a list of attributes that the input method is interested in
Returns:
the currently selected text

changedUpdate

public void changedUpdate(DocumentEvent e)
Description copied from interface: DocumentListener
Gives notification that an attribute or set of attributes changed.

Specified by:
changedUpdate in interface DocumentListener
Parameters:
e - the document event

insertUpdate

public void insertUpdate(DocumentEvent e)
Description copied from interface: DocumentListener
Gives notification that there was an insert into the document. The range given by the DocumentEvent bounds the freshly inserted region.

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

removeUpdate

public void removeUpdate(DocumentEvent e)
Description copied from interface: DocumentListener
Gives notification that a portion of the document has been removed. The range is given in terms of what the view last saw (that is, before updating sticky positions).

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