APIdia Launch Partner
Top Description Fields Constructors Methods
java.awt.event

public Class InputMethodEvent

extends AWTEvent
Class Inheritance
Imports
java.awt.AWTEvent, .Component, .EventQueue, java.awt.font.TextHitInfo, java.io.IOException, .ObjectInputStream, .Serial, java.lang.annotation.Native, java.text.AttributedCharacterIterator, .CharacterIterator, sun.awt.AWTAccessor, .SunToolkit

Input method events contain information about text that is being composed using an input method. Whenever the text changes, the input method sends an event. If the text component that's currently using the input method is an active client, the event is dispatched to that component. Otherwise, it is dispatched to a separate composition window.

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.

Author
JavaSoft Asia/Pacific
Since
1.2

Field Summary

Modifier and TypeField and Description
private transient TextHitInfo
public static final int
CARET_POSITION_CHANGED

The event type indicating a changed insertion point in input method text.

private transient int
public static final int
INPUT_METHOD_FIRST

Marks the first integer id for the range of input method event ids.

public static final int
INPUT_METHOD_LAST

Marks the last integer id for the range of input method event ids.

public static final int
INPUT_METHOD_TEXT_CHANGED

The event type indicating changed input method text.

private static final long
serialVersionUID

Hides java.awt.AWTEvent.serialVersionUID.

Use serialVersionUID from JDK 1.4 for interoperability.
private transient AttributedCharacterIterator
private transient TextHitInfo
pack-priv long
when

The time stamp that indicates when the event was created.

Inherited from java.awt.AWTEvent:
ACTION_EVENT_MASKADJUSTMENT_EVENT_MASKCOMPONENT_EVENT_MASKconsumedCONTAINER_EVENT_MASKFOCUS_EVENT_MASKHIERARCHY_BOUNDS_EVENT_MASKHIERARCHY_EVENT_MASKidINPUT_METHOD_EVENT_MASKINVOCATION_EVENT_MASKITEM_EVENT_MASKKEY_EVENT_MASKMOUSE_EVENT_MASKMOUSE_MOTION_EVENT_MASKMOUSE_WHEEL_EVENT_MASKPAINT_EVENT_MASKRESERVED_ID_MAXTEXT_EVENT_MASKWINDOW_EVENT_MASKWINDOW_FOCUS_EVENT_MASKWINDOW_STATE_EVENT_MASK

Constructor Summary

AccessConstructor and Description
public
InputMethodEvent(Component
the object where the event originated
source
,
int
the event type
id
,
long
a long integer that specifies the time the event occurred
when
,
AttributedCharacterIterator
the combined committed and composed text, committed text first; must be null when the event type is CARET_POSITION_CHANGED; may be null for INPUT_METHOD_TEXT_CHANGED if there's no committed or composed text
text
,
int
the number of committed characters in the text
committedCharacterCount
,
TextHitInfo
the caret (a.k.a. insertion point); null if there's no caret within current composed text
caret
,
TextHitInfo
the position that's most important to be visible; null if there's no recommendation for a visible position within current composed text
visiblePosition
)

Constructs an InputMethodEvent with the specified source component, type, time, text, caret, and visiblePosition.

public
InputMethodEvent(Component
the object where the event originated
source
,
int
the event type
id
,
AttributedCharacterIterator
the combined committed and composed text, committed text first; must be null when the event type is CARET_POSITION_CHANGED; may be null for INPUT_METHOD_TEXT_CHANGED if there's no committed or composed text
text
,
int
the number of committed characters in the text
committedCharacterCount
,
TextHitInfo
the caret (a.k.a. insertion point); null if there's no caret within current composed text
caret
,
TextHitInfo
the position that's most important to be visible; null if there's no recommendation for a visible position within current composed text
visiblePosition
)

Constructs an InputMethodEvent with the specified source component, type, text, caret, and visiblePosition.

public
InputMethodEvent(Component
the object where the event originated
source
,
int
the event type
id
,
TextHitInfo
the caret (a.k.a. insertion point); null if there's no caret within current composed text
caret
,
TextHitInfo
the position that's most important to be visible; null if there's no recommendation for a visible position within current composed text
visiblePosition
)

Constructs an InputMethodEvent with the specified source component, type, caret, and visiblePosition.

Method Summary

Modifier and TypeMethod and Description
public void
consume()

Overrides java.awt.AWTEvent.consume.

Consumes this event so that it will not be processed in the default manner by the source which originated it.

public TextHitInfo

Returns:

the caret (a.k.a. insertion point). Null if there's no caret within current composed text.
getCaret
()

Gets the caret.

public int

Returns:

the number of committed characters in the text
getCommittedCharacterCount
()

Gets the number of committed characters in the text.

private static long

Returns:

most recent event time in the EventQueue
getMostRecentEventTimeForSource
(Object
the source of the event
source
)

Get the most recent event time in the EventQueue which the source belongs to.

public AttributedCharacterIterator

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.
getText
()

Gets the combined committed and composed text.

public TextHitInfo

Returns:

the position that's most important to be visible. Null if there's no recommendation for a visible position within current composed text.
getVisiblePosition
()

Gets the position that's most important to be visible.

public long

Returns:

this event's timestamp
getWhen
()

Returns the time stamp of when this event occurred.

public boolean
isConsumed()

Overrides java.awt.AWTEvent.isConsumed.

Returns whether or not this event has been consumed.

public String

Returns:

a string identifying the event and its attributes
paramString
()

Overrides java.awt.AWTEvent.paramString.

Returns a parameter string identifying this event.

private void
readObject(ObjectInputStream
the ObjectInputStream to read
s
)

Initializes the when field if it is not present in the object input stream.

Inherited from java.awt.AWTEvent:
getIDsetSourcetoString

Field Detail

caretback to summary
private transient TextHitInfo caret
CARET_POSITION_CHANGEDback to summary
public static final int CARET_POSITION_CHANGED

The 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.

Annotations
@Native
committedCharacterCountback to summary
private transient int committedCharacterCount
INPUT_METHOD_FIRSTback to summary
public static final int INPUT_METHOD_FIRST

Marks the first integer id for the range of input method event ids.

Annotations
@Native
INPUT_METHOD_LASTback to summary
public static final int INPUT_METHOD_LAST

Marks the last integer id for the range of input method event ids.

Annotations
@Native
INPUT_METHOD_TEXT_CHANGEDback to summary
public static final int INPUT_METHOD_TEXT_CHANGED

The event type indicating changed input method text. This event is generated by input methods while processing input.

Annotations
@Native
serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.awt.AWTEvent.serialVersionUID.

Use serialVersionUID from JDK 1.4 for interoperability.

Annotations
@Serial
textback to summary
private transient AttributedCharacterIterator text
visiblePositionback to summary
private transient TextHitInfo visiblePosition
whenback to summary
pack-priv long when

The time stamp that indicates when the event was created.

Since
1.4
See Also
getWhen

Constructor Detail

InputMethodEventback to summary
public InputMethodEvent(Component source, int id, long when, AttributedCharacterIterator text, int committedCharacterCount, TextHitInfo caret, TextHitInfo visiblePosition)

Constructs an InputMethodEvent with 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 text if this is an INPUT_METHOD_TEXT_CHANGED event, the composed text within the text of the preceding INPUT_METHOD_TEXT_CHANGED event otherwise.

Note that passing in an invalid id results in unspecified behavior. This method throws an IllegalArgumentException if source is null.

Parameters
source:Component

the object where the event originated

id:int

the event type

when:long

a long integer that specifies the time the event occurred

text:AttributedCharacterIterator

the combined committed and composed text, committed text first; must be null when the event type is CARET_POSITION_CHANGED; may be null for INPUT_METHOD_TEXT_CHANGED if there's no committed or composed text

committedCharacterCount:int

the number of committed characters in the text

caret:TextHitInfo

the caret (a.k.a. insertion point); null if there's no caret within current composed text

visiblePosition:TextHitInfo

the position that's most important to be visible; null if there's no recommendation for a visible position within current composed text

Exceptions
IllegalArgumentException:
  • if id is not in the range INPUT_METHOD_FIRST..INPUT_METHOD_LAST; or if id is CARET_POSITION_CHANGED and text is not null; or if committedCharacterCount is not in the range 0..(text.getEndIndex() - text.getBeginIndex())
  • if source is null
Since
1.4
InputMethodEventback to summary
public InputMethodEvent(Component source, int id, AttributedCharacterIterator text, int committedCharacterCount, TextHitInfo caret, TextHitInfo visiblePosition)

Constructs an InputMethodEvent with 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 text if this is an INPUT_METHOD_TEXT_CHANGED event, the composed text within the text of the preceding INPUT_METHOD_TEXT_CHANGED event otherwise. The time stamp for this event is initialized by invoking java.awt.EventQueue#getMostRecentEventTime().

Note that passing in an invalid id results in unspecified behavior. This method throws an IllegalArgumentException if source is null.

Parameters
source:Component

the object where the event originated

id:int

the event type

text:AttributedCharacterIterator

the combined committed and composed text, committed text first; must be null when the event type is CARET_POSITION_CHANGED; may be null for INPUT_METHOD_TEXT_CHANGED if there's no committed or composed text

committedCharacterCount:int

the number of committed characters in the text

caret:TextHitInfo

the caret (a.k.a. insertion point); null if there's no caret within current composed text

visiblePosition:TextHitInfo

the position that's most important to be visible; null if there's no recommendation for a visible position within current composed text

Exceptions
IllegalArgumentException:
  • if id is not in the range INPUT_METHOD_FIRST..INPUT_METHOD_LAST; or if id is CARET_POSITION_CHANGED and text is not null; or if committedCharacterCount is not in the range 0..(text.getEndIndex() - text.getBeginIndex())
  • if source is null
InputMethodEventback to summary
public InputMethodEvent(Component source, int id, TextHitInfo caret, TextHitInfo visiblePosition)

Constructs an InputMethodEvent with the specified source component, type, caret, and visiblePosition. The text is set to null, committedCharacterCount to 0.

The offsets of caret and visiblePosition are relative to the current composed text; that is, the composed text within the text of the preceding INPUT_METHOD_TEXT_CHANGED event if the event being constructed as a CARET_POSITION_CHANGED event. For an INPUT_METHOD_TEXT_CHANGED event without text, caret and visiblePosition must be null. The time stamp for this event is initialized by invoking java.awt.EventQueue#getMostRecentEventTime().

Note that passing in an invalid id results in unspecified behavior. This method throws an IllegalArgumentException if source is null.

Parameters
source:Component

the object where the event originated

id:int

the event type

caret:TextHitInfo

the caret (a.k.a. insertion point); null if there's no caret within current composed text

visiblePosition:TextHitInfo

the position that's most important to be visible; null if there's no recommendation for a visible position within current composed text

Exceptions
IllegalArgumentException:
  • if id is not in the range INPUT_METHOD_FIRST..INPUT_METHOD_LAST
  • if source is null

Method Detail

consumeback to summary
public void consume()

Overrides java.awt.AWTEvent.consume.

Consumes this event so that it will not be processed in the default manner by the source which originated it.

getCaretback to summary
public TextHitInfo getCaret()

Gets 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_CHANGED event, the composed text within getText() of the preceding INPUT_METHOD_TEXT_CHANGED event otherwise.

Returns:TextHitInfo

the caret (a.k.a. insertion point). Null if there's no caret within current composed text.

getCommittedCharacterCountback to summary
public int getCommittedCharacterCount()

Gets the number of committed characters in the text.

Returns:int

the number of committed characters in the text

getMostRecentEventTimeForSourceback to summary
private static long getMostRecentEventTimeForSource(Object source)

Get the most recent event time in the EventQueue which the source belongs to.

Parameters
source:Object

the source of the event

Returns:long

most recent event time in the EventQueue

Exceptions
IllegalArgumentException:
if source is null.
getTextback to summary
public AttributedCharacterIterator getText()

Gets the combined committed and composed text. Characters from index 0 to index getCommittedCharacterCount() - 1 are committed text, the remaining characters are composed text.

Returns:AttributedCharacterIterator

the text. Always null for CARET_POSITION_CHANGED; may be null for INPUT_METHOD_TEXT_CHANGED if there's no composed or committed text.

getVisiblePositionback to summary
public TextHitInfo getVisiblePosition()

Gets 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_CHANGED event, the composed text within getText() of the preceding INPUT_METHOD_TEXT_CHANGED event otherwise.

Returns:TextHitInfo

the position that's most important to be visible. Null if there's no recommendation for a visible position within current composed text.

getWhenback to summary
public long getWhen()

Returns the time stamp of when this event occurred.

Returns:long

this event's timestamp

Since
1.4
isConsumedback to summary
public boolean isConsumed()

Overrides java.awt.AWTEvent.isConsumed.

Returns whether or not this event has been consumed.

See Also
consume
paramStringback to summary
public String paramString()

Overrides java.awt.AWTEvent.paramString.

Returns 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.

Returns:String

a string identifying the event and its attributes

readObjectback to summary
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException

Initializes the when field if it is not present in the object input stream. In that case, the field will be initialized by invoking java.awt.EventQueue#getMostRecentEventTime().

Parameters
s:ObjectInputStream

the ObjectInputStream to read

Annotations
@Serial
Exceptions
ClassNotFoundException:
if the class of a serialized object could not be found
IOException:
if an I/O error occurs