JavaTM 2 Platform
Std. Ed. v1.3.1

java.awt.im
Class InputContext

java.lang.Object
  |
  +--java.awt.im.InputContext

public class InputContext
extends Object

An InputContext object manages the communication between text editing components and input methods. It dispatches events between them, and forwards requests for information from the input method to the text editing component. It also lets text editing components select input methods by locale.

By default, one InputContext instance is created per Window instance, and this input context is shared by all components within the window's container hierarchy. However, this means that only one text input operation is possible at any one time within a window, and that the text needs to be committed when moving the focus from one text component to another. If this is not desired, text components can create their own input context instances.

The Java 2 platform supports input methods that have been developed in the Java programming language, using the interfaces in the java.awt.im.spi package, and installed into a Java 2 runtime environment as extensions. Implementations may also support using the native input methods of the platforms they run on; however, not all platforms and locales provide input methods.

Input methods are unavailable if (a) no input method written in the Java programming language has been installed and (b) the Java 2 implementation or the underlying platform does not support native input methods. In this case, input contexts can still be created and used; their behavior is specified with the individual methods below.

Since:
1.2
See Also:
Component.getInputContext(), Component.enableInputMethods(boolean)

Constructor Summary
protected InputContext()
          Constructs an InputContext.
 
Method Summary
 void dispatchEvent(AWTEvent event)
          Dispatches an event to the active 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 instance.
 Locale getLocale()
          Returns the current locale of the current input method.
 boolean isCompositionEnabled()
          Determines whether the current input method is enabled for composition.
 void reconvert()
          Asks the current input method to reconvert text from the current client component.
 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)
          Selects an input method that supports the given locale.
 void setCharacterSubsets(Character.Subset[] subsets)
          Sets the subsets of the Unicode character set that input methods of this input context should be allowed to input.
 void setCompositionEnabled(boolean enable)
          Enables or disables the current input method for composition, depending on the value of the parameter enable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InputContext

protected InputContext()
Constructs an InputContext. This method is protected so clients cannot instantiate InputContext directly. Input contexts are obtained by calling getInstance().
Method Detail

getInstance

public static InputContext getInstance()
Returns a new InputContext instance.

selectInputMethod

public boolean selectInputMethod(Locale locale)
Selects an input method that supports the given locale. If the currently selected input method supports the desired locale or if there's no input method available that supports the desired locale, the current input method remains active. Otherwise, an input method is selected that supports text input for the desired locale. Before switching to a different input method, any currently uncommitted text is committed. If no input method supporting the desired locale is available, then false is returned.

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 - The desired new locale.
Returns:
Whether the input method that's active after this call supports the desired locale.
Throws:
NullPointerException - if locale is null

getLocale

public Locale getLocale()
Returns the current locale of the current input method. Returns null if the input context does not have a current input method or the input method's InputMethod.getLocale() returns null.
Returns:
the current locale of the current input method
Since:
1.3

setCharacterSubsets

public void setCharacterSubsets(Character.Subset[] subsets)
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 - The subsets of the Unicode character set from which characters may be input

setCompositionEnabled

public void setCompositionEnabled(boolean enable)
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.

Parameters:
enable - whether to enable the current input method for composition
Throws:
UnsupportedOperationException - if there is no current input method available or the current input method does not support the enabling/disabling operation
Since:
1.3
See Also:
isCompositionEnabled()

isCompositionEnabled

public boolean 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:
true if the current input method is enabled for composition; false otherwise
Throws:
UnsupportedOperationException - if there is no current input method available or the current input method does not support checking whether it is enabled for composition
Since:
1.3
See Also:
setCompositionEnabled(boolean)

reconvert

public void 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.
Throws:
UnsupportedOperationException - if there is no current input method available or the current input method does not support the reconversion operation.
Since:
1.3

dispatchEvent

public void dispatchEvent(AWTEvent event)
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 - The event
Throws:
NullPointerException - if event is null

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 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 - Client component
Throws:
NullPointerException - if client is null

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.

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.


dispose

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

getInputMethodControlObject

public Object 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:
A control object from the current input method, or null.

JavaTM 2 Platform
Std. Ed. v1.3.1

Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Java, Java 2D, and JDBC are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-2001 Sun Microsystems, Inc. 901 San Antonio Road
Palo Alto, California, 94303, U.S.A. All Rights Reserved.



Spec-Zone.ru - all specs in one place



free hit counter