| Constructor: |
public InputMethodEvent(Component source,
int id,
TextHitInfo caret,
TextHitInfo visiblePosition) {
this(source, id, EventQueue.getMostRecentEventTime(), null,
0, caret, 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 - the object where the event originated
id - the event type
caret - the caret (a.k.a. insertion point);
null if there's no caret within current
composed text
visiblePosition - the position that's most important
to be visible; null if there's no
recommendation for a visible position within current
composed text
Throws:
IllegalArgumentException - if id is not
in the range
INPUT_METHOD_FIRST..INPUT_METHOD_LAST
IllegalArgumentException - if source is null
|
public InputMethodEvent(Component source,
int id,
AttributedCharacterIterator text,
int committedCharacterCount,
TextHitInfo caret,
TextHitInfo visiblePosition) {
this(source, id, EventQueue.getMostRecentEventTime(), text,
committedCharacterCount, caret, 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 - the object where the event originated
id - the event type
text - 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 - the number of committed
characters in the text
caret - the caret (a.k.a. insertion point);
null if there's no caret within current
composed text
visiblePosition - the position that's most important
to be visible; null if there's no
recommendation for a visible position within current
composed text
Throws:
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())
IllegalArgumentException - if source is null
|
public InputMethodEvent(Component source,
int id,
long when,
AttributedCharacterIterator text,
int committedCharacterCount,
TextHitInfo caret,
TextHitInfo visiblePosition) {
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;
}
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 - 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 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 - the number of committed
characters in the text
caret - the caret (a.k.a. insertion point);
null if there's no caret within current
composed text
visiblePosition - the position that's most important
to be visible; null if there's no
recommendation for a visible position within current
composed text
Throws:
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())
IllegalArgumentException - if source is null
- since:
1.4 -
|
| Method from java.awt.event.InputMethodEvent Detail: |
public void consume() {
consumed = true;
}
Consumes this event so that it will not be processed
in the default manner by the source which originated it. |
public TextHitInfo getCaret() {
return caret;
}
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. |
public int getCommittedCharacterCount() {
return committedCharacterCount;
}
Gets the number of committed characters in the text. |
public AttributedCharacterIterator getText() {
return text;
}
Gets the combined committed and composed text.
Characters from index 0 to index getCommittedCharacterCount() - 1 are committed
text, the remaining characters are composed text. |
public TextHitInfo getVisiblePosition() {
return visiblePosition;
}
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. |
public long getWhen() {
return when;
}
Returns the time stamp of when this event occurred. |
public boolean isConsumed() {
return consumed;
}
Returns whether or not this event has been consumed. |
public String paramString() {
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 {
StringBuilder textBuffer = new StringBuilder("\"");
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;
}
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. |