- java.lang.Object
-
- java.util.EventObject
-
- java.awt.AWTEvent
-
- java.awt.event.InputMethodEvent
-
- All Implemented Interfaces:
- Serializable
public 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.
- Since:
- 1.2
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static int
CARET_POSITION_CHANGED
The event type indicating a changed insertion point in input method text.static int
INPUT_METHOD_FIRST
Marks the first integer id for the range of input method event ids.static int
INPUT_METHOD_LAST
Marks the last integer id for the range of input method event ids.static int
INPUT_METHOD_TEXT_CHANGED
The event type indicating changed input method text.-
Fields inherited from class java.awt.AWTEvent
ACTION_EVENT_MASK, ADJUSTMENT_EVENT_MASK, COMPONENT_EVENT_MASK, consumed, CONTAINER_EVENT_MASK, FOCUS_EVENT_MASK, HIERARCHY_BOUNDS_EVENT_MASK, HIERARCHY_EVENT_MASK, id, INPUT_METHOD_EVENT_MASK, INVOCATION_EVENT_MASK, ITEM_EVENT_MASK, KEY_EVENT_MASK, MOUSE_EVENT_MASK, MOUSE_MOTION_EVENT_MASK, MOUSE_WHEEL_EVENT_MASK, PAINT_EVENT_MASK, RESERVED_ID_MAX, TEXT_EVENT_MASK, WINDOW_EVENT_MASK, WINDOW_FOCUS_EVENT_MASK, WINDOW_STATE_EVENT_MASK
-
Fields inherited from class java.util.EventObject
source
-
-
Constructor Summary
Constructors Constructor and Description InputMethodEvent(Component source, int id, AttributedCharacterIterator text, int committedCharacterCount, TextHitInfo caret, TextHitInfo visiblePosition)
Constructs anInputMethodEvent
with the specified source component, type, text, caret, and visiblePosition.InputMethodEvent(Component source, int id, long when, AttributedCharacterIterator text, int committedCharacterCount, TextHitInfo caret, TextHitInfo visiblePosition)
Constructs anInputMethodEvent
with the specified source component, type, time, text, caret, and visiblePosition.InputMethodEvent(Component source, int id, TextHitInfo caret, TextHitInfo visiblePosition)
Constructs anInputMethodEvent
with the specified source component, type, caret, and visiblePosition.
-
Method Summary
Methods Modifier and Type Method and Description void
consume()
Consumes this event so that it will not be processed in the default manner by the source which originated it.TextHitInfo
getCaret()
Gets the caret.int
getCommittedCharacterCount()
Gets the number of committed characters in the text.AttributedCharacterIterator
getText()
Gets the combined committed and composed text.TextHitInfo
getVisiblePosition()
Gets the position that's most important to be visible.long
getWhen()
Returns the time stamp of when this event occurred.boolean
isConsumed()
Returns whether or not this event has been consumed.String
paramString()
Returns a parameter string identifying this event.-
Methods inherited from class java.util.EventObject
getSource
-
-
-
-
Field Detail
-
INPUT_METHOD_FIRST
public static final int INPUT_METHOD_FIRST
Marks the first integer id for the range of input method event ids.- See Also:
- Constant Field Values
-
INPUT_METHOD_TEXT_CHANGED
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.- See Also:
- Constant Field Values
-
CARET_POSITION_CHANGED
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.- See Also:
- Constant Field Values
-
INPUT_METHOD_LAST
public static final int INPUT_METHOD_LAST
Marks the last integer id for the range of input method event ids.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
InputMethodEvent
public InputMethodEvent(Component source, int id, long when, AttributedCharacterIterator text, int committedCharacterCount, TextHitInfo caret, TextHitInfo visiblePosition)
Constructs anInputMethodEvent
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 anINPUT_METHOD_TEXT_CHANGED
event, the composed text within thetext
of the precedingINPUT_METHOD_TEXT_CHANGED
event otherwise.Note that passing in an invalid
id
results in unspecified behavior. This method throws anIllegalArgumentException
ifsource
isnull
.- Parameters:
source
- the object where the event originatedid
- the event typewhen
- a long integer that specifies the time the event occurredtext
- the combined committed and composed text, committed text first; must benull
when the event type isCARET_POSITION_CHANGED
; may benull
forINPUT_METHOD_TEXT_CHANGED
if there's no committed or composed textcommittedCharacterCount
- the number of committed characters in the textcaret
- the caret (a.k.a. insertion point);null
if there's no caret within current composed textvisiblePosition
- 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
- ifid
is not in the rangeINPUT_METHOD_FIRST
..INPUT_METHOD_LAST
; or if id isCARET_POSITION_CHANGED
andtext
is notnull
; or ifcommittedCharacterCount
is not in the range0
..(text.getEndIndex() - text.getBeginIndex())
IllegalArgumentException
- ifsource
is null- Since:
- 1.4
-
InputMethodEvent
public InputMethodEvent(Component source, int id, AttributedCharacterIterator text, int committedCharacterCount, TextHitInfo caret, TextHitInfo visiblePosition)
Constructs anInputMethodEvent
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 anINPUT_METHOD_TEXT_CHANGED
event, the composed text within thetext
of the precedingINPUT_METHOD_TEXT_CHANGED
event otherwise. The time stamp for this event is initialized by invokingEventQueue.getMostRecentEventTime()
.Note that passing in an invalid
id
results in unspecified behavior. This method throws anIllegalArgumentException
ifsource
isnull
.- Parameters:
source
- the object where the event originatedid
- the event typetext
- the combined committed and composed text, committed text first; must benull
when the event type isCARET_POSITION_CHANGED
; may benull
forINPUT_METHOD_TEXT_CHANGED
if there's no committed or composed textcommittedCharacterCount
- the number of committed characters in the textcaret
- the caret (a.k.a. insertion point);null
if there's no caret within current composed textvisiblePosition
- 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
- ifid
is not in the rangeINPUT_METHOD_FIRST
..INPUT_METHOD_LAST
; or if id isCARET_POSITION_CHANGED
andtext
is notnull
; or ifcommittedCharacterCount
is not in the range0
..(text.getEndIndex() - text.getBeginIndex())
IllegalArgumentException
- ifsource
is null
-
InputMethodEvent
public InputMethodEvent(Component source, int id, TextHitInfo caret, TextHitInfo visiblePosition)
Constructs anInputMethodEvent
with the specified source component, type, caret, and visiblePosition. The text is set tonull
,committedCharacterCount
to 0.The offsets of
caret
andvisiblePosition
are relative to the current composed text; that is, the composed text within thetext
of the precedingINPUT_METHOD_TEXT_CHANGED
event if the event being constructed as aCARET_POSITION_CHANGED
event. For anINPUT_METHOD_TEXT_CHANGED
event without text,caret
andvisiblePosition
must benull
. The time stamp for this event is initialized by invokingEventQueue.getMostRecentEventTime()
.Note that passing in an invalid
id
results in unspecified behavior. This method throws anIllegalArgumentException
ifsource
isnull
.- Parameters:
source
- the object where the event originatedid
- the event typecaret
- the caret (a.k.a. insertion point);null
if there's no caret within current composed textvisiblePosition
- 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
- ifid
is not in the rangeINPUT_METHOD_FIRST
..INPUT_METHOD_LAST
IllegalArgumentException
- ifsource
is null
-
-
Method Detail
-
getText
public AttributedCharacterIterator getText()
Gets the combined committed and composed text. Characters from index 0 to indexgetCommittedCharacterCount() - 1
are committed text, the remaining characters are composed text.- 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.
-
getCommittedCharacterCount
public int getCommittedCharacterCount()
Gets the number of committed characters in the text.
-
getCaret
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 precedingINPUT_METHOD_TEXT_CHANGED
event otherwise.- Returns:
- the caret (a.k.a. insertion point). Null if there's no caret within current composed text.
-
getVisiblePosition
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 precedingINPUT_METHOD_TEXT_CHANGED
event otherwise.- Returns:
- the position that's most important to be visible. Null if there's no recommendation for a visible position within current composed text.
-
consume
public void consume()
Consumes this event so that it will not be processed in the default manner by the source which originated it.
-
isConsumed
public boolean isConsumed()
Returns whether or not this event has been consumed.- Overrides:
isConsumed
in classAWTEvent
- See Also:
consume()
-
getWhen
public long getWhen()
Returns the time stamp of when this event occurred.- Returns:
- this event's timestamp
- Since:
- 1.4
-
paramString
public 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.- Overrides:
paramString
in classAWTEvent
- Returns:
- a string identifying the event and its attributes
-
-
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 11/06/2005 gemaakt, de laatste keer de 04/03/2020 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-rf-java/awt/event/inputmethodevent.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.