public class InputContext extends Object
By using the interfaces of java.awt.im.spi
, you can install
extensions which allow additional input methods. Some of these may use
platform native input methods, or keyboard layouts provided by the platform.
Input methods are unavailable if none have been installed and the platform
has no underlying native input methods. Extensions are installed as jar
files, usually accessed in the default extension location or specified by
the -extdir VM flag. The jar must contain a file named
"META_INF/services/java.awt.im.spi.InputMethodDescriptor" which lists,
one entry per line in UTF-8 encoding, each class in the jar that implements
java.awt.im.spi.InputMethodDescriptor.
Component.getInputContext()
,
Component.enableInputMethods(boolean)
Modifier | Constructor and Description |
---|---|
protected |
InputContext()
Construct an InputContext.
|
Modifier and Type | Method and Description |
---|---|
void |
dispatchEvent(AWTEvent event)
Dispatches an event to the current input method.
|
void |
dispose()
Disposes of the input context and release the resources used by it.
|
void |
endComposition()
Ends any input composition that may currently be going on in this
context.
|
Object |
getInputMethodControlObject()
Returns a control object from the current input method, or null.
|
static InputContext |
getInstance()
Returns a new InputContext.
|
Locale |
getLocale()
Returns the current locale of the current input method or keyboard
layout.
|
boolean |
isCompositionEnabled()
Find out if the current input method is enabled.
|
void |
reconvert()
Starts a reconversion operation in the current input method.
|
void |
removeNotify(Component client)
Notifies the input context that a client component has been removed from
its containment hierarchy, or that input method support has been disabled
for the component.
|
boolean |
selectInputMethod(Locale locale)
Attempts to select an input method or keyboard layout which supports the
given locale.
|
void |
setCharacterSubsets(Character.Subset[] subsets)
Sets the subsets of Unicode characters allowed to be input by the current
input method, as well as subsequent input methods.
|
void |
setCompositionEnabled(boolean enable)
Changes the enabled status of the current input method.
|
protected InputContext()
getInstance()
instead.public static InputContext getInstance()
public boolean selectInputMethod(Locale locale)
Before switching away from an input method, any currently uncommitted text is committed. Not all host operating systems provide API to determine the locale of the currently selected native input method or keyboard layout, and to select a native input method or keyboard layout by locale. For host operating systems that don't provide such API, selectInputMethod assumes that native input methods or keyboard layouts provided by the host operating system support only the system's default locale.
An example of where this may be called is in a multi-language document, when moving the insertion point between sections of different locale, so that the user may use the input method appropriate to that section of the document.
locale
- the desired new localeNullPointerException
- if locale is nullpublic Locale getLocale()
InputMethod.getLocale()
method returns null. Not all host
operating systems provide API to determine the locale of the currently
selected native input method or keyboard layout. For host operating
systems that don't provide such API, getLocale assumes that the current
locale of all native input methods or keyboard layouts provided by the
host operating system is the system's default locale.public void setCharacterSubsets(Character.Subset[] subsets)
subsets
- the set of Unicode subsets to accept, or nullpublic void setCompositionEnabled(boolean enable)
enable
- whether to enable the input methodUnsupportedOperationException
- if there is no current input method,
or the input method does not support enablingisCompositionEnabled()
public boolean isCompositionEnabled()
UnsupportedOperationException
- if there is no current input method,
or the input method does not support enablingsetCompositionEnabled(boolean)
public void reconvert()
InputMethodRequests#getSelectedText(Attribute[])
. Then the
composed and committed text produced by the operation is sent back to
the client using a sequence of InputMethodRequests.UnsupportedOperationException
- if there is no current input method,
or the input method does not support reconversionpublic void dispatchEvent(AWTEvent event)
event
- the event to dispatchNullPointerException
- if event is nullpublic void removeNotify(Component client)
Component.removeNotify()
method. Potentially pending
input from input methods for this component is discarded. If no input
methods are available, then this method has no effect.client
- the client componentNullPointerException
- if client is nullpublic void endComposition()
public void dispose()
public Object getInputMethodControlObject()