Top Description Fields Constructors Methods
sun.awt.im

public Class InputContext

extends InputContext
implements ComponentListener, WindowListener
Class Inheritance
All Implemented Interfaces
java.awt.event.WindowListener, java.util.EventListener, java.awt.event.ComponentListener
Known Direct Subclasses
sun.awt.im.InputMethodContext
Imports
java.awt.AWTEvent, .AWTKeyStroke, .Component, .EventQueue, .Frame, .Rectangle, .Toolkit, .Window, java.awt.event.ComponentEvent, .ComponentListener, .FocusEvent, .InputEvent, .InputMethodEvent, .KeyEvent, .WindowEvent, .WindowListener, java.awt.im.InputMethodRequests, java.awt.im.spi.InputMethod, java.lang.Character.Subset, java.security.AccessController, .PrivilegedAction, java.text.MessageFormat, java.util.Collection, .HashMap, .Locale, java.util.prefs.BackingStoreException, .Preferences, sun.util.logging.PlatformLogger, sun.awt.SunToolkit

This InputContext class contains parts of the implementation of java.text.im.InputContext. These parts have been moved here to avoid exposing protected members that are needed by the subclass InputMethodContext.
Author
JavaSoft Asia/Pacific
See Also
java.awt.im.InputContext

Field Summary

Modifier and TypeField and Description
private Component
private Character.Subset[]
private Window
private Rectangle
private boolean
private boolean
private Component
private InputMethod
private boolean
private InputMethodLocator
private static AWTKeyStroke
private static final String
private static boolean
private static final String
private static final String
private static InputContext
private boolean
private static final PlatformLogger
private HashMap<InputMethod, Boolean>
private static InputMethod
private HashMap<InputMethodLocator, InputMethod>

Constructor Summary

AccessConstructor and Description
protected
InputContext()

Constructs an InputContext.

Method Summary

Modifier and TypeMethod and Description
private void
activateInputMethod(boolean updateCompositionArea)

Activates the current input method of this input context, and grabs the composition area for use by this input context.

private synchronized void
private boolean
addedClientWindowListeners()

Returns true if listeners have been set up for client window change notification.

pack-priv synchronized void
changeInputMethod(InputMethodLocator newLocator)

Switches from the current input method to the one described by newLocator.

private boolean
checkInputMethodSelectionKey(KeyEvent event)

Checks the key event is the input method selection key or not.

public void
componentHidden(ComponentEvent
the event to be processed
e
)

Implements java.awt.event.ComponentListener.componentHidden.

Invoked when the component has been made invisible.

public void
componentMoved(ComponentEvent
the event to be processed
e
)

Implements java.awt.event.ComponentListener.componentMoved.

Invoked when the component's position changes.

public void
componentResized(ComponentEvent
the event to be processed
e
)

Implements java.awt.event.ComponentListener.componentResized.

Invoked when the component's size changes.

public void
componentShown(ComponentEvent
the event to be processed
e
)

Implements java.awt.event.ComponentListener.componentShown.

Invoked when the component has been made visible.

private void
deactivateInputMethod(boolean isTemporary)

public void
disableNativeIM()

Turns off the native IM.

public void
dispatchEvent(AWTEvent
The event
event
)

Overrides java.awt.im.InputContext.dispatchEvent.

Dispatches an event to the active input method.

public synchronized void
dispose()

Overrides java.awt.im.InputContext.dispose.

Releases the resources used by this input context.

pack-priv synchronized void
enableClientWindowNotification(InputMethod requester, boolean enable)

public synchronized void
endComposition()

Overrides java.awt.im.InputContext.endComposition.

Ends any input composition that may currently be going on in this context.

private void
focusGained(Component
the component gaining the focus
source
)

Handles focus gained events for any component that's using this input context.

private void
focusLost(Component
the component losing the focus
source
,
boolean
whether the focus change is temporary
isTemporary
)

Handles focus lost events for any component that's using this input context.

pack-priv Component
getClientComponent()

Returns the client component.

pack-priv static Window
private synchronized InputMethod
public synchronized Object
getInputMethodControlObject()

Overrides java.awt.im.InputContext.getInputMethodControlObject.

Returns a control object from the current input method, or null.

public String

Returns:

a string with information about the current input method.
getInputMethodInfo
()

private InputMethod

Returns:

an InputMethod instance
getInputMethodInstance
()

Returns an instance of the input method described by the current input method locator.

pack-priv InputMethodLocator
private AWTKeyStroke
public Locale
getLocale()

Overrides java.awt.im.InputContext.getLocale.

Returns the current locale of the current input method or keyboard layout.

private void
initializeInputMethodSelectionKey()

Initializes the input method selection key definition in preference trees

public boolean
isCompositionEnabled()

Overrides java.awt.im.InputContext.isCompositionEnabled.

Determines whether the current input method is enabled for composition.

private void
private synchronized void
public synchronized void
reconvert()

Overrides java.awt.im.InputContext.reconvert.

Asks the current input method to reconvert text from the current client component.

private synchronized void
public synchronized void
removeNotify(Component
Client component
component
)

Overrides java.awt.im.InputContext.removeNotify.

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.

public synchronized boolean
selectInputMethod(Locale
The desired new locale.
locale
)

Overrides java.awt.im.InputContext.selectInputMethod.

Attempts to select an input method or keyboard layout that supports the given locale, and returns a value indicating whether such an input method or keyboard layout has been successfully selected.

public void
setCharacterSubsets(Character.Subset[]
The subsets of the Unicode character set from which characters may be input
subsets
)

Overrides java.awt.im.InputContext.setCharacterSubsets.

Sets the subsets of the Unicode character set that input methods of this input context should be allowed to input.

public void
setCompositionEnabled(boolean
whether to enable the current input method for composition
enable
)

Overrides java.awt.im.InputContext.setCompositionEnabled.

Enables or disables the current input method for composition, depending on the value of the parameter enable.

public void
windowActivated(WindowEvent
the event to be processed
e
)

Implements java.awt.event.WindowListener.windowActivated.

Invoked when the Window is set to be the active Window.

public void
windowClosed(WindowEvent
the event to be processed
e
)

Implements java.awt.event.WindowListener.windowClosed.

Invoked when a window has been closed as the result of calling dispose on the window.

public void
windowClosing(WindowEvent
the event to be processed
e
)

Implements java.awt.event.WindowListener.windowClosing.

Invoked when the user attempts to close the window from the window's system menu.

public void
windowDeactivated(WindowEvent
the event to be processed
e
)

Implements java.awt.event.WindowListener.windowDeactivated.

Invoked when a Window is no longer the active Window.

public void
windowDeiconified(WindowEvent
the event to be processed
e
)

Implements java.awt.event.WindowListener.windowDeiconified.

Invoked when a window is changed from a minimized to a normal state.

public void
windowIconified(WindowEvent
the event to be processed
e
)

Implements java.awt.event.WindowListener.windowIconified.

Invoked when a window is changed from a normal to a minimized state.

public void
windowOpened(WindowEvent
the event to be processed
e
)

Implements java.awt.event.WindowListener.windowOpened.

Invoked the first time a window is made visible.

Inherited from java.awt.im.InputContext:
getInstance

Field Detail

awtFocussedComponentback to summary
private Component awtFocussedComponent
characterSubsetsback to summary
private Character.Subset[] characterSubsets
clientWindowListenedback to summary
private Window clientWindowListened
clientWindowLocationback to summary
private Rectangle clientWindowLocation
clientWindowNotificationEnabledback to summary
private boolean clientWindowNotificationEnabled
compositionAreaHiddenback to summary
private boolean compositionAreaHidden
currentClientComponentback to summary
private Component currentClientComponent
inputMethodback to summary
private InputMethod inputMethod
inputMethodCreationFailedback to summary
private boolean inputMethodCreationFailed
inputMethodLocatorback to summary
private InputMethodLocator inputMethodLocator
inputMethodSelectionKeyback to summary
private static AWTKeyStroke inputMethodSelectionKey
inputMethodSelectionKeyCodeNameback to summary
private static final String inputMethodSelectionKeyCodeName
inputMethodSelectionKeyInitializedback to summary
private static boolean inputMethodSelectionKeyInitialized
inputMethodSelectionKeyModifiersNameback to summary
private static final String inputMethodSelectionKeyModifiersName
inputMethodSelectionKeyPathback to summary
private static final String inputMethodSelectionKeyPath
inputMethodWindowContextback to summary
private static InputContext inputMethodWindowContext
isInputMethodActiveback to summary
private boolean isInputMethodActive
logback to summary
private static final PlatformLogger log
perInputMethodStateback to summary
private HashMap<InputMethod, Boolean> perInputMethodState
previousInputMethodback to summary
private static InputMethod previousInputMethod
usedInputMethodsback to summary
private HashMap<InputMethodLocator, InputMethod> usedInputMethods

Constructor Detail

InputContextback to summary
protected InputContext()

Constructs an InputContext.

Method Detail

activateInputMethodback to summary
private void activateInputMethod(boolean updateCompositionArea)

Activates the current input method of this input context, and grabs the composition area for use by this input context. If updateCompositionArea is true, the text in the composition area is updated (set to false if the text is going to change immediately to avoid screen flicker).

addClientWindowListenersback to summary
private synchronized void addClientWindowListeners()
addedClientWindowListenersback to summary
private boolean addedClientWindowListeners()

Returns true if listeners have been set up for client window change notification.

changeInputMethodback to summary
pack-priv synchronized void changeInputMethod(InputMethodLocator newLocator)

Switches from the current input method to the one described by newLocator. The current input method, if any, is asked to end composition, deactivated, and saved for future use. The newLocator is made the current locator. If the input context is active, an input method instance for the new locator is obtained; otherwise this is deferred until required.

checkInputMethodSelectionKeyback to summary
private boolean checkInputMethodSelectionKey(KeyEvent event)

Checks the key event is the input method selection key or not.

componentHiddenback to summary
public void componentHidden(ComponentEvent e)

Implements java.awt.event.ComponentListener.componentHidden.

Doc from java.awt.event.ComponentListener.componentHidden.

Invoked when the component has been made invisible.

Parameters
e:ComponentEvent

the event to be processed

componentMovedback to summary
public void componentMoved(ComponentEvent e)

Implements java.awt.event.ComponentListener.componentMoved.

Doc from java.awt.event.ComponentListener.componentMoved.

Invoked when the component's position changes.

Parameters
e:ComponentEvent

the event to be processed

componentResizedback to summary
public void componentResized(ComponentEvent e)

Implements java.awt.event.ComponentListener.componentResized.

Doc from java.awt.event.ComponentListener.componentResized.

Invoked when the component's size changes.

Parameters
e:ComponentEvent

the event to be processed

componentShownback to summary
public void componentShown(ComponentEvent e)

Implements java.awt.event.ComponentListener.componentShown.

Doc from java.awt.event.ComponentListener.componentShown.

Invoked when the component has been made visible.

Parameters
e:ComponentEvent

the event to be processed

deactivateInputMethodback to summary
private void deactivateInputMethod(boolean isTemporary)
disableNativeIMback to summary
public void disableNativeIM()

Turns off the native IM. The native IM is disabled when the deactivate method of InputMethod is called. It is delayed until the active method is called on a different peer component. This method is provided to explicitly disable the native IM.

dispatchEventback to summary
public void dispatchEvent(AWTEvent event)

Overrides java.awt.im.InputContext.dispatchEvent.

Doc from java.awt.im.InputContext.dispatchEvent.

Dispatches an event to the active input method. Called by AWT. If no input method is available, then the event will never be consumed.

Parameters
event:AWTEvent

The event

Annotations
@SuppressWarnings:fallthrough
See Also
java.awt.im.InputContext#dispatchEvent
disposeback to summary
public synchronized void dispose()

Overrides java.awt.im.InputContext.dispose.

Doc from java.awt.im.InputContext.dispose.

Releases the resources used by this input context. Called by AWT for the default input context of each Window. If no input methods are available, then this method has no effect.

Exceptions
IllegalStateException:
when the currentClientComponent is not null
See Also
java.awt.im.InputContext#dispose
enableClientWindowNotificationback to summary
pack-priv synchronized void enableClientWindowNotification(InputMethod requester, boolean enable)
See Also
java.awt.im.spi.InputMethodContext#enableClientWindowNotification
endCompositionback to summary
public synchronized void endComposition()

Overrides java.awt.im.InputContext.endComposition.

Doc from java.awt.im.InputContext.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.

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.

See Also
java.awt.im.InputContext#endComposition
focusGainedback to summary
private void focusGained(Component source)

Handles focus gained events for any component that's using this input context. These events are generated by AWT when the keyboard focus moves to a component. Besides actual client components, the source components may also be the composition area or any component in an input method window.

When handling the focus event for a client component, this method checks whether the input context was previously active for a different client component, and if so, calls endComposition for the previous client component.

Parameters
source:Component

the component gaining the focus

focusLostback to summary
private void focusLost(Component source, boolean isTemporary)

Handles focus lost events for any component that's using this input context. These events are generated by AWT when the keyboard focus moves away from a component. Besides actual client components, the source components may also be the composition area or any component in an input method window.

Parameters
source:Component

the component losing the focus

isTemporary:boolean

whether the focus change is temporary

getClientComponentback to summary
pack-priv Component getClientComponent()

Returns the client component.

getComponentWindowback to summary
pack-priv static Window getComponentWindow(Component component)
getInputMethodback to summary
private synchronized InputMethod getInputMethod()
getInputMethodControlObjectback to summary
public synchronized Object getInputMethodControlObject()

Overrides java.awt.im.InputContext.getInputMethodControlObject.

Doc from java.awt.im.InputContext.getInputMethodControlObject.

Returns a control object from the current input method, or null. A control object provides methods that control the behavior of the input method or obtain information from the input method. The type of the object is an input method specific class. Clients have to compare the result against known input method control object classes and cast to the appropriate class to invoke the methods provided.

If no input methods are available or the current input method does not provide an input method control object, then null is returned.

Returns:Object

A control object from the current input method, or null.

See Also
java.awt.im.InputContext#getInputMethodControlObject
getInputMethodInfoback to summary
public String getInputMethodInfo()
Returns:String

a string with information about the current input method.

Exceptions
UnsupportedOperationException:
when input method is null
getInputMethodInstanceback to summary
private InputMethod getInputMethodInstance()

Returns an instance of the input method described by the current input method locator. This may be an input method that was previously used and switched out of, or a new instance. The locale, character subsets, and input method context of the input method are set. The inputMethodCreationFailed field is set to true if the instantiation failed.

Returns:InputMethod

an InputMethod instance

See Also
java.awt.im.spi.InputMethod#setInputMethodContext, java.awt.im.spi.InputMethod#setLocale, java.awt.im.spi.InputMethod#setCharacterSubsets
getInputMethodLocatorback to summary
pack-priv InputMethodLocator getInputMethodLocator()
getInputMethodSelectionKeyStrokeback to summary
private AWTKeyStroke getInputMethodSelectionKeyStroke(Preferences root)
getLocaleback to summary
public Locale getLocale()

Overrides java.awt.im.InputContext.getLocale.

Doc from java.awt.im.InputContext.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 java.awt.im.spi.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:Locale

the current locale of the current input method or keyboard layout

See Also
java.awt.im.InputContext#getLocale
initializeInputMethodSelectionKeyback to summary
private void initializeInputMethodSelectionKey()

Initializes the input method selection key definition in preference trees

Annotations
@SuppressWarnings:removal
isCompositionEnabledback to summary
public boolean isCompositionEnabled()

Overrides java.awt.im.InputContext.isCompositionEnabled.

Doc from java.awt.im.InputContext.isCompositionEnabled.

Determines whether the current input method is enabled for composition. 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.

Returns:boolean

true if the current input method is enabled for composition; false otherwise

Exceptions
UnsupportedOperationException:
when input method is null
See Also
java.awt.im.InputContext#isCompositionEnabled
logCreationFailedback to summary
private void logCreationFailed(Throwable throwable)
notifyClientWindowChangeback to summary
private synchronized void notifyClientWindowChange(Window window)
reconvertback to summary
public synchronized void reconvert()

Overrides java.awt.im.InputContext.reconvert.

Doc from java.awt.im.InputContext.reconvert.

Asks the current input method to reconvert text from the current client component. The input method obtains the text to be reconverted from the client component using the InputMethodRequests.getSelectedText method. The other InputMethodRequests methods must be prepared to deal with further information requests by the input method. The composed and/or committed text will be sent to the client component as a sequence of InputMethodEvents. If the input method cannot reconvert the given text, the text is returned as committed text in an InputMethodEvent.

Exceptions
UnsupportedOperationException:
when input method is null
Since
1.3
See Also
java.awt.im.InputContext#reconvert
removeClientWindowListenersback to summary
private synchronized void removeClientWindowListeners()
removeNotifyback to summary
public synchronized void removeNotify(Component component)

Overrides java.awt.im.InputContext.removeNotify.

Doc from java.awt.im.InputContext.removeNotify.

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 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
component:Component

Client component

Exceptions
NullPointerException:
when the component is null.
See Also
java.awt.im.InputContext#removeNotify
selectInputMethodback to summary
public synchronized boolean selectInputMethod(Locale locale)

Overrides java.awt.im.InputContext.selectInputMethod.

Doc from java.awt.im.InputContext.selectInputMethod.

Attempts to select an input method or keyboard layout that supports the given locale, and returns a value indicating whether such an input method or keyboard layout has been successfully selected. The following steps are taken until an input method has been selected:

  • If the currently selected input method or keyboard layout supports the requested locale, it remains selected.
  • If there is no input method or keyboard layout available that supports the requested locale, the current input method or keyboard layout remains selected.
  • If the user has previously selected an input method or keyboard layout for the requested locale from the user interface, then the most recently selected such input method or keyboard layout is reselected.
  • Otherwise, an input method or keyboard layout that supports the requested locale is selected in an implementation dependent way.
Before switching away from an input method, any currently uncommitted text is committed. If no input method or keyboard layout supporting the requested locale is available, then false is returned.

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.

A text editing component may call this method, for example, when the user changes the insertion point, so that the user can immediately continue typing in the language of the surrounding text.

Parameters
locale:Locale

The desired new locale.

Returns:boolean

true if the input method or keyboard layout that's active after this call supports the desired locale.

Exceptions
NullPointerException:
when the locale is null.
See Also
java.awt.im.InputContext#selectInputMethod
setCharacterSubsetsback to summary
public void setCharacterSubsets(Character.Subset[] subsets)

Overrides java.awt.im.InputContext.setCharacterSubsets.

Doc from java.awt.im.InputContext.setCharacterSubsets.

Sets the subsets of the Unicode character set that input methods of this input context should be allowed to input. Null may be passed in to indicate that all characters are allowed. The initial value is null. The setting applies to the current input method as well as input methods selected after this call is made. However, applications cannot rely on this call having the desired effect, since this setting cannot be passed on to all host input methods - applications still need to apply their own character validation. If no input methods are available, then this method has no effect.

Parameters
subsets:Character.Subset[]

The subsets of the Unicode character set from which characters may be input

See Also
java.awt.im.InputContext#setCharacterSubsets
setCompositionEnabledback to summary
public void setCompositionEnabled(boolean enable)

Overrides java.awt.im.InputContext.setCompositionEnabled.

Doc from java.awt.im.InputContext.setCompositionEnabled.

Enables or disables the current input method for composition, depending on the value of the parameter 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.

Parameters
enable:boolean

whether to enable the current input method for composition

Exceptions
UnsupportedOperationException:
when input method is null
See Also
java.awt.im.InputContext#setCompositionEnabled(boolean)
windowActivatedback to summary
public void windowActivated(WindowEvent e)

Implements java.awt.event.WindowListener.windowActivated.

Doc from java.awt.event.WindowListener.windowActivated.

Invoked when the Window is set to be the active Window. Only a Frame or a Dialog can be the active Window. The native windowing system may denote the active Window or its children with special decorations, such as a highlighted title bar. The active Window is always either the focused Window, or the first Frame or Dialog that is an owner of the focused Window.

Parameters
e:WindowEvent

the event to be processed

windowClosedback to summary
public void windowClosed(WindowEvent e)

Implements java.awt.event.WindowListener.windowClosed.

Doc from java.awt.event.WindowListener.windowClosed.

Invoked when a window has been closed as the result of calling dispose on the window.

Parameters
e:WindowEvent

the event to be processed

windowClosingback to summary
public void windowClosing(WindowEvent e)

Implements java.awt.event.WindowListener.windowClosing.

Doc from java.awt.event.WindowListener.windowClosing.

Invoked when the user attempts to close the window from the window's system menu.

Parameters
e:WindowEvent

the event to be processed

windowDeactivatedback to summary
public void windowDeactivated(WindowEvent e)

Implements java.awt.event.WindowListener.windowDeactivated.

Doc from java.awt.event.WindowListener.windowDeactivated.

Invoked when a Window is no longer the active Window. Only a Frame or a Dialog can be the active Window. The native windowing system may denote the active Window or its children with special decorations, such as a highlighted title bar. The active Window is always either the focused Window, or the first Frame or Dialog that is an owner of the focused Window.

Parameters
e:WindowEvent

the event to be processed

windowDeiconifiedback to summary
public void windowDeiconified(WindowEvent e)

Implements java.awt.event.WindowListener.windowDeiconified.

Doc from java.awt.event.WindowListener.windowDeiconified.

Invoked when a window is changed from a minimized to a normal state.

Parameters
e:WindowEvent

the event to be processed

windowIconifiedback to summary
public void windowIconified(WindowEvent e)

Implements java.awt.event.WindowListener.windowIconified.

Doc from java.awt.event.WindowListener.windowIconified.

Invoked when a window is changed from a normal to a minimized state. For many platforms, a minimized window is displayed as the icon specified in the window's iconImage property.

Parameters
e:WindowEvent

the event to be processed

windowOpenedback to summary
public void windowOpened(WindowEvent e)

Implements java.awt.event.WindowListener.windowOpened.

Doc from java.awt.event.WindowListener.windowOpened.

Invoked the first time a window is made visible.

Parameters
e:WindowEvent

the event to be processed