--- old/src/java.desktop/share/classes/java/awt/event/InputMethodEvent.java 2015-04-01 18:37:51.706496300 +0300
+++ new/src/java.desktop/share/classes/java/awt/event/InputMethodEvent.java 2015-04-01 18:37:51.240937200 +0300
@@ -104,6 +104,9 @@
private transient int committedCharacterCount;
private transient TextHitInfo caret;
private transient TextHitInfo visiblePosition;
+ private transient int replaceStart;
+ private transient int replaceEnd;
+
/**
* Constructs an InputMethodEvent
with the specified
@@ -151,6 +154,16 @@
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");
@@ -174,7 +187,9 @@
this.caret = caret;
this.visiblePosition = visiblePosition;
- }
+ this.replaceStart = replaceStart;
+ this.replaceEnd = replaceEnd;
+ }
/**
* Constructs an InputMethodEvent
with the specified
@@ -270,6 +285,57 @@
}
/**
+ * 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
.
+ *
+ * @param source the object where the event originated
+ * @param id the event type
+ * @param caret the caret (a.k.a. insertion point);
+ * null
if there's no caret within current
+ * composed text
+ * @param visiblePosition the position that's most important
+ * to be visible; null
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 id
is not
+ * in the range
+ * INPUT_METHOD_FIRST
..INPUT_METHOD_LAST
+ * @throws IllegalArgumentException if source
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 getCommittedCharacterCount() - 1
are committed
* text, the remaining characters are composed text.
@@ -349,6 +415,24 @@
}
/**
+ * 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
@@ -407,7 +491,14 @@
visiblePositionString = "visible position: " + visiblePosition.toString();
}
- return typeStr + ", " + textString + ", " + countString + ", " + caretString + ", " + visiblePositionString;
+ String replacementRangeString = "";
+ if (replaceStart >= 0) {
+ replacementRangeString = ", replacement range (" + replaceStart +
+ ", " + replaceEnd + ")";
+ }
+
+ return typeStr + ", " + textString + ", " + countString + ", "
+ + caretString + ", " + visiblePositionString + replacementRangeString;
}
/**