java.awt.im

Class InputContext

public class InputContext extends Object

Provides a context for controlling input methods and keyboard layouts. This class provides the communication layer between the client component, and the various locale-dependent text entry input methods that can be used for the client. By default, there is one instance per Window, shared among all components, but this limits text entry to one component at a time. Thus, text components can create their own instance to allow text entry in multiple components at a time.

By using the interfaces of {@link 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.

Since: 1.2

See Also: getInputContext Component

UNKNOWN: updated to 1.4, but unverified

Constructor Summary
protected InputContext()
Construct an InputContext.
Method Summary
voiddispatchEvent(AWTEvent event)
Dispatches an event to the current input method.
voiddispose()
Disposes of the input context and release the resources used by it.
voidendComposition()
Ends any input composition that may currently be going on in this context.
ObjectgetInputMethodControlObject()
Returns a control object from the current input method, or null.
static InputContextgetInstance()
Returns a new InputContext.
LocalegetLocale()
Returns the current locale of the current input method or keyboard layout.
booleanisCompositionEnabled()
Find out if the current input method is enabled.
voidreconvert()
Starts a reconversion operation in the current input method.
voidremoveNotify(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.
booleanselectInputMethod(Locale locale)
Attempts to select an input method or keyboard layout which supports the given locale.
voidsetCharacterSubsets(Character.Subset[] subsets)
Sets the subsets of Unicode characters allowed to be input by the current input method, as well as subsequent input methods.
voidsetCompositionEnabled(boolean enable)
Changes the enabled status of the current input method.

Constructor Detail

InputContext

protected InputContext()
Construct an InputContext. This is protected, so clients must use {@link #getInstance()} instead.

Method Detail

dispatchEvent

public void dispatchEvent(AWTEvent event)
Dispatches an event to the current input method. This is called automatically by AWT. If no input method is available, then the event will never be consumed.

Parameters: event the event to dispatch

Throws: NullPointerException if event is null

dispose

public void dispose()
Disposes of the input context and release the resources used by it. Called automatically by AWT for the default input context of each Window. If no input methods are available, then this method has no effect.

endComposition

public void endComposition()
Ends any input composition that may currently be going on in this context. Depending on the platform and possibly user preferences, this may commit or delete uncommitted text. Any changes to the text are communicated to the active component using an input method event. If no input methods are available, then this method has no effect. This may be called for a variety of reasons, such as when the user moves the insertion point in the client text outside the range of the composed text, or when text is saved to file.

getInputMethodControlObject

public Object getInputMethodControlObject()
Returns a control object from the current input method, or null. A control object provides implementation-dependent methods that control the behavior of the input method or obtain information from the input method. Clients have to compare the result against known input method control object types. If no input methods are available or the current input method does not provide an input method control object, then null is returned.

Returns: the control object, or null

getInstance

public static InputContext getInstance()
Returns a new InputContext.

Returns: a new instance, initialized to the default locale if available

getLocale

public Locale getLocale()
Returns the current locale of the current input method or keyboard layout. Returns null if the input context does not have a current input method or keyboard layout or if the current input method's {@link 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.

Returns: the locale of the current input method, or null

Since: 1.3

isCompositionEnabled

public boolean isCompositionEnabled()
Find out if the current input method is enabled.

Returns: true if the current input method is enabled

Throws: UnsupportedOperationException if there is no current input method, or the input method does not support enabling

Since: 1.3

See Also: InputContext

reconvert

public void reconvert()
Starts a reconversion operation in the current input method. The input method gets the text to reconvert from the client component, using {@link InputMethodRequests#getSelectedText(Attribute[])}. Then the composed and committed text produced by the operation is sent back to the client using a sequence of InputMethodRequests.

Throws: UnsupportedOperationException if there is no current input method, or the input method does not support reconversion

Since: 1.3

removeNotify

public 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. This method is usually called from the client component's {@link 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.

Parameters: client the client component

Throws: NullPointerException if client is null

selectInputMethod

public boolean selectInputMethod(Locale locale)
Attempts to select an input method or keyboard layout which supports the given locale. This returns true if a locale is available and was selected. The following steps are taken in choosing an input method:

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.

Parameters: locale the desired new locale

Returns: true if the new locale is active

Throws: NullPointerException if locale is null

setCharacterSubsets

public 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. The value of null implies all characters are legal. Applications should not rely on this behavior, since native host input methods may not allow restrictions. If no current input method is available, this has no immediate effect.

Parameters: subsets the set of Unicode subsets to accept, or null

setCompositionEnabled

public void setCompositionEnabled(boolean enable)
Changes the enabled status of the current input method. An input method that is enabled for composition interprets incoming events for both composition and control purposes, while a disabled input method only interprets control commands (including commands to enable itself).

Parameters: enable whether to enable the input method

Throws: UnsupportedOperationException if there is no current input method, or the input method does not support enabling

Since: 1.3

See Also: isCompositionEnabled