Interface InputMethod
public interface InputMethod
Subclasses of InputMethod can be loaded by the input method framework; they can then be selected either through the API (InputContext.selectInputMethod
) or the user interface (the input method selection menu).
- Since:
- 1.3
Method Summary
Modifier and Type | Method | Description |
---|---|---|
void |
activate() |
Activates the input method for immediate input processing. |
void |
deactivate |
Deactivates the input method. |
void |
dispatchEvent |
Dispatches the event to the input method. |
void |
dispose() |
Releases the resources used by this input method. |
void |
endComposition() |
Ends any input composition that may currently be going on in this context. |
Object |
getControlObject() |
Returns a control object from this input method, or null. |
Locale |
getLocale() |
Returns the current input locale. |
void |
hideWindows() |
Closes or hides all windows opened by this input method instance or its class. |
boolean |
isCompositionEnabled() |
Determines whether this input method is enabled. |
void |
notifyClientWindowChange |
Notifies this input method of changes in the client window location or state. |
void |
reconvert() |
Starts the reconversion operation. |
void |
removeNotify() |
Notifies the input method that a client component has been removed from its containment hierarchy, or that input method support has been disabled for the component. |
void |
setCharacterSubsets |
Sets the subsets of the Unicode character set that this input method is allowed to input. |
void |
setCompositionEnabled |
Enables or disables this input method for composition, depending on the value of the parameter enable . |
void |
setInputMethodContext |
Sets the input method context, which is used to dispatch input method events to the client component and to request information from the client component. |
boolean |
setLocale |
Attempts to set the input locale. |
Method Details
setInputMethodContext
void setInputMethodContext(InputMethodContext context)
This method is called once immediately after instantiating this input method.
- Parameters:
-
context
- the input method context for this input method - Throws:
-
NullPointerException
- ifcontext
is null
setLocale
boolean setLocale(Locale locale)
This method is called
- by
InputContext.selectInputMethod
, - when switching to this input method through the user interface if the user specified a locale or if the previously selected input method's
getLocale
method returns a non-null value.
- Parameters:
-
locale
- locale to input - Returns:
- whether the specified locale is supported
- Throws:
-
NullPointerException
- iflocale
is null
getLocale
Locale getLocale()
This method is called
- by
InputContext.getLocale
and - when switching from this input method to a different one through the user interface.
- Returns:
- the current input locale, or null
setCharacterSubsets
void setCharacterSubsets(Character.Subset[] subsets)
This method is called
- immediately after instantiating this input method,
- when switching to this input method from a different one, and
- by
InputContext.setCharacterSubsets
.
- Parameters:
-
subsets
- the subsets of the Unicode character set from which characters may be input
setCompositionEnabled
void setCompositionEnabled(boolean enable)
enable
. An input method that is enabled for composition interprets incoming events for both composition and control purposes, while a disabled input method does not interpret events for composition. Note however that events are passed on to the input method regardless whether it is enabled or not, and that an input method that is disabled for composition may still interpret events for control purposes, including to enable or disable itself for composition.
For input methods provided by host operating systems, it is not always possible to determine whether this operation is supported. For example, an input method may enable composition only for some locales, and do nothing for other locales. For such input methods, it is possible that this method does not throw UnsupportedOperationException
, but also does not affect whether composition is enabled.
This method is called
- by
InputContext.setCompositionEnabled
, - when switching to this input method from a different one using the user interface or
InputContext.selectInputMethod
, if the previously selected input method'sisCompositionEnabled
method returns without throwing an exception.
- Parameters:
-
enable
- whether to enable the input method for composition - Throws:
-
UnsupportedOperationException
- if this input method does not support the enabling/disabling operation - See Also:
isCompositionEnabled
boolean isCompositionEnabled()
This method is called
- by
InputContext.isCompositionEnabled
and - when switching from this input method to a different one using the user interface or
InputContext.selectInputMethod
.
- Returns:
-
true
if this input method is enabled for composition;false
otherwise. - Throws:
-
UnsupportedOperationException
- if this input method does not support checking whether it is enabled for composition - See Also:
reconvert
void reconvert()
InputMethodRequests.getSelectedText
method. It can use other InputMethodRequests
methods to request additional information required for the reconversion operation. The composed and committed text produced by the operation is sent to the client component as a sequence of InputMethodEvent
s. If the given text cannot be reconverted, the same text should be sent to the client component as committed text. This method is called by InputContext.reconvert
.
- Throws:
-
UnsupportedOperationException
- if the input method does not support the reconversion operation.
dispatchEvent
void dispatchEvent(AWTEvent event)
consume
method; this causes the event to not get dispatched to the component's event processing methods or event listeners. Events are dispatched if they are instances of InputEvent or its subclasses. This includes instances of the AWT classes KeyEvent and MouseEvent.
This method is called by InputContext.dispatchEvent
.
- Parameters:
-
event
- the event being dispatched to the input method - Throws:
-
NullPointerException
- ifevent
is null
notifyClientWindowChange
void notifyClientWindowChange(Rectangle bounds)
InputMethodContext.enableClientWindowNotification
). Calls to this method are temporarily suspended if the input context's removeNotify
method is called, and resume when the input method is activated for a new client component. It is called in the following situations: - when the window containing the current client component changes in location, size, visibility, iconification state, or when the window is closed.
- from
enableClientWindowNotification(inputMethod, true)
if the current client component exists, - when activating the input method for the first time after it called
enableClientWindowNotification(inputMethod, true)
if during the call no current client component was available, - when activating the input method for a new client component after the input context's removeNotify method has been called.
- Parameters:
-
bounds
- client window'sbounds
on the screen; or null if the client window is iconified or invisible
activate
void activate()
If an input method provides its own windows, it should make sure at this point that all necessary windows are open and visible.
This method is called
- by
InputContext.dispatchEvent
when a client component receives a FOCUS_GAINED event, - when switching to this input method from a different one using the user interface or
InputContext.selectInputMethod
.
deactivate
void deactivate(boolean isTemporary)
FocusEvent.isTemporary
. If an input method provides its own windows, only windows that relate to the current composition (such as a lookup choice window) should be closed at this point. It is possible that the input method will be immediately activated again for a different client component, and closing and reopening more persistent windows (such as a control panel) would create unnecessary screen flicker. Before an instance of a different input method class is activated, hideWindows()
is called on the current input method.
This method is called
- by
InputContext.dispatchEvent
when a client component receives a FOCUS_LOST event, - when switching from this input method to a different one using the user interface or
InputContext.selectInputMethod
, - before
removeNotify
if the current client component is removed.
- Parameters:
-
isTemporary
- whether the focus change is temporary
hideWindows
void hideWindows()
removeNotify
void removeNotify()
This method is called by InputContext.removeNotify
.
The method is only called when the input method is inactive.
endComposition
void endComposition()
A text editing component may call this in a variety of situations, for example, when the user moves the insertion point within the text (but outside the composed text), or when the component's text is saved to a file or copied to the clipboard.
This method is called
- by
InputContext.endComposition
, - by
InputContext.dispatchEvent
when switching to a different client component - when switching from this input method to a different one using the user interface or
InputContext.selectInputMethod
.
dispose
void dispose()
This method is called by InputContext.dispose
.
The method is only called when the input method is inactive. No method of this interface is called on this instance after dispose.
getControlObject
Object getControlObject()
This method is called by InputContext.getInputMethodControlObject
.
- Returns:
- a control object from this input method, or null
© 1993, 2021, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/java/awt/im/spi/InputMethod.html