- All Implemented Interfaces:
- Serializable
public class InputMethodEvent extends AWTEvent
The text included with the input method event consists of two parts: committed text and composed text. Either part may be empty. The two parts together replace any uncommitted composed text sent in previous events, or the currently selected committed text. Committed text should be integrated into the text component's persistent data, it will not be sent again. Composed text may be sent repeatedly, with changes to reflect the user's editing operations. Committed text always precedes composed text.
- Since:
- 1.2
- See Also:
- Serialized Form
- 
Field SummaryFields Modifier and Type Field Description static intCARET_POSITION_CHANGEDThe event type indicating a changed insertion point in input method text.static intINPUT_METHOD_FIRSTMarks the first integer id for the range of input method event ids.static intINPUT_METHOD_LASTMarks the last integer id for the range of input method event ids.static intINPUT_METHOD_TEXT_CHANGEDThe event type indicating changed input method text.Fields declared in class java.awt.AWTEventACTION_EVENT_MASK, ADJUSTMENT_EVENT_MASK, COMPONENT_EVENT_MASK, consumed, CONTAINER_EVENT_MASK, FOCUS_EVENT_MASK, HIERARCHY_BOUNDS_EVENT_MASK, HIERARCHY_EVENT_MASK, id, INPUT_METHOD_EVENT_MASK, INVOCATION_EVENT_MASK, ITEM_EVENT_MASK, KEY_EVENT_MASK, MOUSE_EVENT_MASK, MOUSE_MOTION_EVENT_MASK, MOUSE_WHEEL_EVENT_MASK, PAINT_EVENT_MASK, RESERVED_ID_MAX, TEXT_EVENT_MASK, WINDOW_EVENT_MASK, WINDOW_FOCUS_EVENT_MASK, WINDOW_STATE_EVENT_MASK
- 
Constructor SummaryConstructors Constructor Description InputMethodEvent(Component source, int id, long when, AttributedCharacterIterator text, int committedCharacterCount, TextHitInfo caret, TextHitInfo visiblePosition)Constructs anInputMethodEventwith the specified source component, type, time, text, caret, and visiblePosition.InputMethodEvent(Component source, int id, TextHitInfo caret, TextHitInfo visiblePosition)Constructs anInputMethodEventwith the specified source component, type, caret, and visiblePosition.InputMethodEvent(Component source, int id, AttributedCharacterIterator text, int committedCharacterCount, TextHitInfo caret, TextHitInfo visiblePosition)Constructs anInputMethodEventwith the specified source component, type, text, caret, and visiblePosition.
- 
Method SummaryModifier and Type Method Description voidconsume()Consumes this event so that it will not be processed in the default manner by the source which originated it.TextHitInfogetCaret()Gets the caret.intgetCommittedCharacterCount()Gets the number of committed characters in the text.AttributedCharacterIteratorgetText()Gets the combined committed and composed text.TextHitInfogetVisiblePosition()Gets the position that's most important to be visible.longgetWhen()Returns the time stamp of when this event occurred.booleanisConsumed()Returns whether or not this event has been consumed.StringparamString()Returns a parameter string identifying this event.
- 
Field Details- 
INPUT_METHOD_FIRSTMarks the first integer id for the range of input method event ids.- See Also:
- Constant Field Values
 
- 
INPUT_METHOD_TEXT_CHANGEDThe event type indicating changed input method text. This event is generated by input methods while processing input.- See Also:
- Constant Field Values
 
- 
CARET_POSITION_CHANGEDThe event type indicating a changed insertion point in input method text. This event is generated by input methods while processing input if only the caret changed.- See Also:
- Constant Field Values
 
- 
INPUT_METHOD_LASTMarks the last integer id for the range of input method event ids.- See Also:
- Constant Field Values
 
 
- 
- 
Constructor Details- 
InputMethodEventpublic InputMethodEvent(Component source, int id, long when, AttributedCharacterIterator text, int committedCharacterCount, TextHitInfo caret, TextHitInfo visiblePosition)Constructs anInputMethodEventwith the specified source component, type, time, text, caret, and visiblePosition.The offsets of caret and visiblePosition are relative to the current composed text; that is, the composed text within textif this is anINPUT_METHOD_TEXT_CHANGEDevent, the composed text within thetextof the precedingINPUT_METHOD_TEXT_CHANGEDevent otherwise.Note that passing in an invalid idresults in unspecified behavior. This method throws anIllegalArgumentExceptionifsourceisnull.- Parameters:
- source- the object where the event originated
- id- the event type
- when- a long integer that specifies the time the event occurred
- text- the combined committed and composed text, committed text first; must be- nullwhen the event type is- CARET_POSITION_CHANGED; may be- nullfor- INPUT_METHOD_TEXT_CHANGEDif there's no committed or composed text
- committedCharacterCount- the number of committed characters in the text
- caret- the caret (a.k.a. insertion point);- nullif there's no caret within current composed text
- visiblePosition- the position that's most important to be visible;- nullif there's no recommendation for a visible position within current composed text
- Throws:
- IllegalArgumentException- if- idis not in the range- INPUT_METHOD_FIRST..- INPUT_METHOD_LAST; or if id is- CARET_POSITION_CHANGEDand- textis not- null; or if- committedCharacterCountis not in the range- 0..- (text.getEndIndex() - text.getBeginIndex())
- IllegalArgumentException- if- sourceis null
- Since:
- 1.4
 
- 
InputMethodEventpublic InputMethodEvent(Component source, int id, AttributedCharacterIterator text, int committedCharacterCount, TextHitInfo caret, TextHitInfo visiblePosition)Constructs anInputMethodEventwith the specified source component, type, text, caret, and visiblePosition.The offsets of caret and visiblePosition are relative to the current composed text; that is, the composed text within textif this is anINPUT_METHOD_TEXT_CHANGEDevent, the composed text within thetextof the precedingINPUT_METHOD_TEXT_CHANGEDevent otherwise. The time stamp for this event is initialized by invokingEventQueue.getMostRecentEventTime().Note that passing in an invalid idresults in unspecified behavior. This method throws anIllegalArgumentExceptionifsourceisnull.- Parameters:
- source- the object where the event originated
- id- the event type
- text- the combined committed and composed text, committed text first; must be- nullwhen the event type is- CARET_POSITION_CHANGED; may be- nullfor- INPUT_METHOD_TEXT_CHANGEDif there's no committed or composed text
- committedCharacterCount- the number of committed characters in the text
- caret- the caret (a.k.a. insertion point);- nullif there's no caret within current composed text
- visiblePosition- the position that's most important to be visible;- nullif there's no recommendation for a visible position within current composed text
- Throws:
- IllegalArgumentException- if- idis not in the range- INPUT_METHOD_FIRST..- INPUT_METHOD_LAST; or if id is- CARET_POSITION_CHANGEDand- textis not- null; or if- committedCharacterCountis not in the range- 0..- (text.getEndIndex() - text.getBeginIndex())
- IllegalArgumentException- if- sourceis null
 
- 
InputMethodEventConstructs anInputMethodEventwith the specified source component, type, caret, and visiblePosition. The text is set tonull,committedCharacterCountto 0.The offsets of caretandvisiblePositionare relative to the current composed text; that is, the composed text within thetextof the precedingINPUT_METHOD_TEXT_CHANGEDevent if the event being constructed as aCARET_POSITION_CHANGEDevent. For anINPUT_METHOD_TEXT_CHANGEDevent without text,caretandvisiblePositionmust benull. The time stamp for this event is initialized by invokingEventQueue.getMostRecentEventTime().Note that passing in an invalid idresults in unspecified behavior. This method throws anIllegalArgumentExceptionifsourceisnull.- Parameters:
- source- the object where the event originated
- id- the event type
- caret- the caret (a.k.a. insertion point);- nullif there's no caret within current composed text
- visiblePosition- the position that's most important to be visible;- nullif there's no recommendation for a visible position within current composed text
- Throws:
- IllegalArgumentException- if- idis not in the range- INPUT_METHOD_FIRST..- INPUT_METHOD_LAST
- IllegalArgumentException- if- sourceis null
 
 
- 
- 
Method Details- 
getTextGets the combined committed and composed text. Characters from index 0 to indexgetCommittedCharacterCount() - 1are committed text, the remaining characters are composed text.- Returns:
- the text. Always null for CARET_POSITION_CHANGED; may be null for INPUT_METHOD_TEXT_CHANGED if there's no composed or committed text.
 
- 
getCommittedCharacterCountpublic int getCommittedCharacterCount()Gets the number of committed characters in the text.- Returns:
- the number of committed characters in the text
 
- 
getCaretGets the caret.The offset of the caret is relative to the current composed text; that is, the composed text within getText() if this is an INPUT_METHOD_TEXT_CHANGEDevent, the composed text within getText() of the precedingINPUT_METHOD_TEXT_CHANGEDevent otherwise.- Returns:
- the caret (a.k.a. insertion point). Null if there's no caret within current composed text.
 
- 
getVisiblePositionGets the position that's most important to be visible.The offset of the visible position is relative to the current composed text; that is, the composed text within getText() if this is an INPUT_METHOD_TEXT_CHANGEDevent, the composed text within getText() of the precedingINPUT_METHOD_TEXT_CHANGEDevent otherwise.- Returns:
- the position that's most important to be visible. Null if there's no recommendation for a visible position within current composed text.
 
- 
consumepublic void consume()Consumes this event so that it will not be processed in the default manner by the source which originated it.
- 
isConsumedpublic boolean isConsumed()Returns whether or not this event has been consumed.- Overrides:
- isConsumedin class- AWTEvent
- Returns:
- trueif this event has been consumed; otherwise- false
- See Also:
- consume()
 
- 
getWhenpublic long getWhen()Returns the time stamp of when this event occurred.- Returns:
- this event's timestamp
- Since:
- 1.4
 
- 
paramStringReturns a parameter string identifying this event. This method is useful for event-logging and for debugging. It contains the event ID in text form, the characters of the committed and composed text separated by "+", the number of committed characters, the caret, and the visible position.- Overrides:
- paramStringin class- AWTEvent
- Returns:
- a string identifying the event and its attributes
 
 
-