InputMethodEventpublic class InputMethodEvent extends AWTEvent 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. |
Fields Summary |
---|
private static final long | serialVersionUIDSerial Version ID. | public static final int | INPUT_METHOD_FIRSTMarks the first integer id for the range of input method event ids. | public static final int | INPUT_METHOD_TEXT_CHANGEDThe event type indicating changed input method text. This event is
generated by input methods while processing input. | public static final int | 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. | public static final int | INPUT_METHOD_LASTMarks the last integer id for the range of input method event ids. | long | whenThe time stamp that indicates when the event was created. | private transient AttributedCharacterIterator | text | private transient int | committedCharacterCount | private transient TextHitInfo | caret | private transient TextHitInfo | visiblePosition |
Constructors 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 .
super(source, id);
if (id < INPUT_METHOD_FIRST || id > INPUT_METHOD_LAST) {
throw new IllegalArgumentException("id outside of valid range");
}
if (id == CARET_POSITION_CHANGED && text != null) {
throw new IllegalArgumentException("text must be null for CARET_POSITION_CHANGED");
}
this.when = when;
this.text = text;
int textLength = 0;
if (text != null) {
textLength = text.getEndIndex() - text.getBeginIndex();
}
if (committedCharacterCount < 0 || committedCharacterCount > textLength) {
throw new IllegalArgumentException("committedCharacterCount outside of valid range");
}
this.committedCharacterCount = committedCharacterCount;
this.caret = caret;
this.visiblePosition = visiblePosition;
| 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
{@link java.awt.EventQueue#getMostRecentEventTime()}.
Note that passing in an invalid id results in
unspecified behavior. This method throws an
IllegalArgumentException if source
is null .
this(source, id, EventQueue.getMostRecentEventTime(), text,
committedCharacterCount, caret, visiblePosition);
| 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
{@link java.awt.EventQueue#getMostRecentEventTime()}.
Note that passing in an invalid id results in
unspecified behavior. This method throws an
IllegalArgumentException if source
is null .
this(source, id, EventQueue.getMostRecentEventTime(), null,
0, caret, visiblePosition);
|
Methods Summary |
---|
public void | consume()Consumes this event so that it will not be processed
in the default manner by the source which originated it.
consumed = true;
| public java.awt.font.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.
return caret;
| public int | getCommittedCharacterCount()Gets the number of committed characters in the text.
return committedCharacterCount;
| public java.text.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.
return text;
| public java.awt.font.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.
return visiblePosition;
| public long | getWhen()Returns the time stamp of when this event occurred.
return when;
| public boolean | isConsumed()Returns whether or not this event has been consumed.
return consumed;
| public java.lang.String | 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.
String typeStr;
switch(id) {
case INPUT_METHOD_TEXT_CHANGED:
typeStr = "INPUT_METHOD_TEXT_CHANGED";
break;
case CARET_POSITION_CHANGED:
typeStr = "CARET_POSITION_CHANGED";
break;
default:
typeStr = "unknown type";
}
String textString;
if (text == null) {
textString = "no text";
} else {
StringBuffer textBuffer = new StringBuffer("\"");
int committedCharacterCount = this.committedCharacterCount;
char c = text.first();
while (committedCharacterCount-- > 0) {
textBuffer.append(c);
c = text.next();
}
textBuffer.append("\" + \"");
while (c != CharacterIterator.DONE) {
textBuffer.append(c);
c = text.next();
}
textBuffer.append("\"");
textString = textBuffer.toString();
}
String countString = committedCharacterCount + " characters committed";
String caretString;
if (caret == null) {
caretString = "no caret";
} else {
caretString = "caret: " + caret.toString();
}
String visiblePositionString;
if (visiblePosition == null) {
visiblePositionString = "no visible position";
} else {
visiblePositionString = "visible position: " + visiblePosition.toString();
}
return typeStr + ", " + textString + ", " + countString + ", " + caretString + ", " + visiblePositionString;
| private void | readObject(java.io.ObjectInputStream s)Initializes the when field if it is not present in the
object input stream. In that case, the field will be initialized by
invoking {@link java.awt.EventQueue#getMostRecentEventTime()}.
s.defaultReadObject();
if (when == 0) {
when = EventQueue.getMostRecentEventTime();
}
|
|