src/java.desktop/share/classes/java/awt/event/InputMethodEvent.java
Print this page
*** 102,111 ****
--- 102,114 ----
// Text object
private transient AttributedCharacterIterator text;
private transient int committedCharacterCount;
private transient TextHitInfo caret;
private transient TextHitInfo visiblePosition;
+ private transient int replaceStart;
+ private transient int replaceEnd;
+
/**
* Constructs an <code>InputMethodEvent</code> with the specified
* source component, type, time, text, caret, and visiblePosition.
* <p>
*** 149,158 ****
--- 152,171 ----
* @since 1.4
*/
public InputMethodEvent(Component source, int id, long when,
AttributedCharacterIterator text, int committedCharacterCount,
TextHitInfo caret, TextHitInfo visiblePosition) {
+
+ this(source, id, when, text, committedCharacterCount,
+ caret, visiblePosition, -1, -1);
+ }
+
+ private InputMethodEvent(Component source, int id, long when,
+ AttributedCharacterIterator text, int committedCharacterCount,
+ TextHitInfo caret, TextHitInfo visiblePosition,
+ int replaceStart, int replaceEnd) {
+
super(source, id);
if (id < INPUT_METHOD_FIRST || id > INPUT_METHOD_LAST) {
throw new IllegalArgumentException("id outside of valid range");
}
*** 172,181 ****
--- 185,196 ----
}
this.committedCharacterCount = committedCharacterCount;
this.caret = caret;
this.visiblePosition = visiblePosition;
+ this.replaceStart = replaceStart;
+ this.replaceEnd = replaceEnd;
}
/**
* Constructs an <code>InputMethodEvent</code> with the specified
* source component, type, text, caret, and visiblePosition.
*** 268,277 ****
--- 283,343 ----
getMostRecentEventTimeForSource(source),
null, 0, caret, visiblePosition);
}
/**
+ * Constructs an <code>InputMethodEvent</code> with the
+ * specified source component, type, caret, and visiblePosition.
+ * The text is set to <code>null</code>,
+ * <code>committedCharacterCount</code> to 0.
+ * <p>
+ * The offsets of <code>caret</code> and <code>visiblePosition</code>
+ * are relative to the current composed text; that is,
+ * the composed text within the <code>text</code> of the
+ * preceding <code>INPUT_METHOD_TEXT_CHANGED</code> event if the
+ * event being constructed as a <code>CARET_POSITION_CHANGED</code> event.
+ * For an <code>INPUT_METHOD_TEXT_CHANGED</code> event without text,
+ * <code>caret</code> and <code>visiblePosition</code> must be
+ * <code>null</code>.
+ * The time stamp for this event is initialized by invoking
+ * {@link java.awt.EventQueue#getMostRecentEventTime()}.
+ * <p>Note that passing in an invalid <code>id</code> results in
+ * unspecified behavior. This method throws an
+ * <code>IllegalArgumentException</code> if <code>source</code>
+ * is <code>null</code>.
+ *
+ * @param source the object where the event originated
+ * @param id the event type
+ * @param caret the caret (a.k.a. insertion point);
+ * <code>null</code> if there's no caret within current
+ * composed text
+ * @param visiblePosition the position that's most important
+ * to be visible; <code>null</code> if there's no
+ * recommendation for a visible position within current
+ * composed text
+ * @param replaceStart start of the text range in the text document
+ * which this IM event content should replace.
+ * -1 if no content should be replaced
+ * @param replaceEnd end of the text range in the text document
+ * which this IM event content should replace.
+ * -1 if no content should be replaced
+ * @throws IllegalArgumentException if <code>id</code> is not
+ * in the range
+ * <code>INPUT_METHOD_FIRST</code>..<code>INPUT_METHOD_LAST</code>
+ * @throws IllegalArgumentException if <code>source</code> is null
+ */
+ public InputMethodEvent(Component source, int id, AttributedCharacterIterator text,
+ int committedCharacterCount, TextHitInfo caret, TextHitInfo visiblePosition,
+ int replaceStart, int replaceEnd) {
+
+ this(source, id, getMostRecentEventTimeForSource(source), text,
+ committedCharacterCount, caret, visiblePosition,
+ replaceStart, replaceEnd);
+ }
+
+
+ /**
* Gets the combined committed and composed text.
* Characters from index 0 to index <code>getCommittedCharacterCount() - 1</code> are committed
* text, the remaining characters are composed text.
*
* @return the text.
*** 347,356 ****
--- 413,440 ----
public long getWhen() {
return when;
}
/**
+ * Returns start of the text range in the text document
+ * which this IM event content should replace.
+ * @return -1 if no content should be replaced
+ */
+ public int getReplaceStart() {
+ return replaceStart;
+ }
+
+ /**
+ * Returns end of the text range in the text document
+ * which this IM event content should replace.
+ * @return -1 if no content should be replaced
+ */
+ public int getReplaceEnd() {
+ return replaceEnd;
+ }
+
+ /**
* 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,
*** 405,415 ****
visiblePositionString = "no visible position";
} else {
visiblePositionString = "visible position: " + visiblePosition.toString();
}
! return typeStr + ", " + textString + ", " + countString + ", " + caretString + ", " + visiblePositionString;
}
/**
* Initializes the <code>when</code> field if it is not present in the
* object input stream. In that case, the field will be initialized by
--- 489,506 ----
visiblePositionString = "no visible position";
} else {
visiblePositionString = "visible position: " + visiblePosition.toString();
}
! String replacementRangeString = "";
! if (replaceStart >= 0) {
! replacementRangeString = ", replacement range (" + replaceStart +
! ", " + replaceEnd + ")";
! }
!
! return typeStr + ", " + textString + ", " + countString + ", "
! + caretString + ", " + visiblePositionString + replacementRangeString;
}
/**
* Initializes the <code>when</code> field if it is not present in the
* object input stream. In that case, the field will be initialized by