java.awt.im.spi

Interface InputMethod

public interface InputMethod

This interface supports complex text input, often for situations where the text is more complex than a keyboard will accomodate. For example, this can be used for Chinese, Japanese, and Korean, where multiple keystrokes are necessary to compose text. This could also support things like phonetic English, or reordering Thai.

These contexts can be loaded by the input method framework, using {@link InputContext#selectInputMethod(Locale)}.

Since: 1.3

UNKNOWN: updated to 1.4

Method Summary
voidactivate()
Activate this input method for input processing.
voiddeactivate(boolean isTemporary)
Deactivate this input method, either temporarily or permanently for the given client.
voiddispatchEvent(AWTEvent event)
Dispatch an event to the input method.
voiddispose()
Disposes the input method and release any resources it is using.
voidendComposition()
End any input composition currently taking place.
ObjectgetControlObject()
Returns a control object from this input method, or null.
LocalegetLocale()
Returns the current input locale, or null if none is defined.
voidhideWindows()
Close or hide all windows opened by this input method.
booleanisCompositionEnabled()
Find out if this input method is enabled.
voidnotifyClientWindowChange(Rectangle bounds)
Notify this input method of changes in the client window.
voidreconvert()
Starts a reconversion operation.
voidremoveNotify()
Notify the input method that a client component has been removed from its hierarchy, or that input method support has been disabled.
voidsetCharacterSubsets(Character.Subset[] subsets)
Sets the allowed Unicode subsets that this input method can use.
voidsetCompositionEnabled(boolean enable)
Changes the enabled status of this input method.
voidsetInputMethodContext(InputMethodContext context)
Set the input method context, which ties the input method to a client component.
booleansetLocale(Locale locale)
Sets the input locale.

Method Detail

activate

public void activate()
Activate this input method for input processing. If the input method provides its own windows, it should make them open and visible at this time. This method is called when a client component receives a FOCUS_GAINED event, or when switching to this input method from another one. It is only called when the input method is inactive, assuming that new instances begin in an inactive state.

deactivate

public void deactivate(boolean isTemporary)
Deactivate this input method, either temporarily or permanently for the given client. If the input method provides its own windows, it should only close those related to the current composition (such as a lookup choice panel), while leaving more persistant windows (like a control panel) open to avoid screen flicker. Before control is given to another input method, {@link #hideWindows()} will be called on this instance. This method is called when a client component receives a FOCUS_LOST event, when switching to another input method, or before {@link #removeNotify()} when the client is removed.

Parameters: isTemporary true if the focus change is temporary

dispatchEvent

public void dispatchEvent(AWTEvent event)
Dispatch an event to the input method. If input method support is enabled, certain events are dispatched to the input method before the client component or event listeners. The input method must either consume the event or pass it on to the component. Instances of InputEvent, including KeyEvent and MouseEvent, are given to this input method. This method is called by {@link InputContext#dispatchEvent(AWTEvent)}.

Parameters: event the event to dispatch

Throws: NullPointerException if event is null

dispose

public void dispose()
Disposes the input method and release any resources it is using. In particular, the input method should dispose windows and close files. This is called by {@link InputContext#dispose()}, when the input method is inactive; and nothing will be called on this instance afterwards.

endComposition

public void endComposition()
End any input composition currently taking place. Depending on the platform and user preferences, this may commit or delete uncommitted text, using input method events. 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. This is called by {@link InputContext#endComposition()}, when switching to a new input method, or by {@link InputContext#selectInputMethod(Locale)}.

getControlObject

public Object getControlObject()
Returns a control object from this input method, or null. A control object provides method to control the behavior of this input method, as well as query information about it. The object is implementation dependent, so clients must compare the result against known input method control object types. This is called by {@link InputContext#getInputMethodControlObject()}.

Returns: the control object, or null

getLocale

public Locale getLocale()
Returns the current input locale, or null if none is defined. This is called by {@link InputContext#getLocale()}, or before switching input methods.

Returns: the current input locale, or null

hideWindows

public void hideWindows()
Close or hide all windows opened by this input method. This is called before activating a different input method, and before calling {@link #dispose()} on this instance. It is only called when the input method is inactive.

isCompositionEnabled

public boolean isCompositionEnabled()
Find out if this input method is enabled. This is called by {@link InputContext#isCompositionEnabled()}, or when switching input methods via {@link InputContext#selectInputMethod(Locale)}.

Returns: true if this input method is enabled

Throws: UnsupportedOperationException if enabling/disabling is unsupported

See Also: InputMethod

notifyClientWindowChange

public void notifyClientWindowChange(Rectangle bounds)
Notify this input method of changes in the client window. This is called when notifications are enabled (see {@link InputMethodContext#enableClientWindowNotification(InputMethod, boolean)}, if {@link InputContext#removeNotify(Component)} has not been called. The following situations trigger a notification:

Parameters: bounds the client window's current bounds, or null

reconvert

public void reconvert()
Starts a reconversion operation. The input method gets its text from the client, 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 InputMethodEvents. This is called by {@link InputContext#reconvert()}.

Throws: UnsupportedOperationException if reconversion is unsupported

removeNotify

public void removeNotify()
Notify the input method that a client component has been removed from its hierarchy, or that input method support has been disabled. This is called by {@link InputContext#removeNotify(Component)}, and only when the input method is inactive.

setCharacterSubsets

public void setCharacterSubsets(Character.Subset[] subsets)
Sets the allowed Unicode subsets that this input method can use. Null indicates that all characters are allowed. This is called after creation, or when switching to this input method, by {@link InputContext#setCharacterSubsets(Character.Subset[])}.

Parameters: subsets the accepted subsets for this input method, or null for all

setCompositionEnabled

public void setCompositionEnabled(boolean enable)
Changes the enabled status of this input method. An enabled input method accepts incoming events for composition and control purposes, while a disabled input method ignores events (except for control purposes). This is called by {@link InputContext#setCompositionEnabled(boolean)} or when switching from an input method if the previous input method returned without exception on {@link #isCompositionEnabled()}.

Parameters: enable whether to enable this input method

Throws: UnsupportedOperationException if enabling/disabling is unsupported

See Also: isCompositionEnabled

setInputMethodContext

public void setInputMethodContext(InputMethodContext context)
Set the input method context, which ties the input method to a client component. This is called once automatically when creating the input method.

Parameters: context the context for this input method

Throws: NullPointerException if context is null

setLocale

public boolean setLocale(Locale locale)
Sets the input locale. If the input method supports that locale, it changes its behavior to be consistent with the locale and returns true. Otherwise, it returns false. This is called by {@link InputContext#selectInputMethod(Locale)} when the user specifies a locale, or when the previously selected input method had a locale.

Parameters: locale the locale to use for input

Returns: true if the change is successful

Throws: NullPointerException if locale is null