1. /*
  2. * @(#)InputContext.java 1.28 00/04/06
  3. *
  4. * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package java.awt.im;
  11. import java.awt.Component;
  12. import java.util.Locale;
  13. import java.awt.AWTEvent;
  14. import java.lang.Character.Subset;
  15. import sun.awt.im.InputMethodContext;
  16. /**
  17. * An InputContext object manages the communication between text editing
  18. * components and input methods. It dispatches events between them, and
  19. * forwards requests for information from the input method to the text
  20. * editing component. It also lets text editing components select input
  21. * methods by locale.
  22. *
  23. * <p>
  24. * By default, one InputContext instance is created per Window instance,
  25. * and this input context is shared by all components within the window's
  26. * container hierarchy. However, this means that only one text input
  27. * operation is possible at any one time within a window, and that the
  28. * text needs to be committed when moving the focus from one text component
  29. * to another. If this is not desired, text components can create their
  30. * own input context instances.
  31. *
  32. * <p>
  33. * The Java 2 platform supports input methods that have been developed in the Java
  34. * programming language, using the interfaces in the {@link java.awt.im.spi} package,
  35. * and installed into a Java 2 runtime environment as extensions. Implementations
  36. * may also support using the native input methods of the platforms they run on;
  37. * however, not all platforms and locales provide input methods.
  38. *
  39. * <p>
  40. * Input methods are <em>unavailable</em> if (a) no input method written
  41. * in the Java programming language has been installed and (b) the Java 2 implementation
  42. * or the underlying platform does not support native input methods. In this case,
  43. * input contexts can still be created and used; their behavior is specified with
  44. * the individual methods below.
  45. *
  46. * @see java.awt.Component#getInputContext
  47. * @see java.awt.Component#enableInputMethods
  48. * @version 1.28, 04/06/00
  49. * @author JavaSoft Asia/Pacific
  50. * @since 1.2
  51. */
  52. public class InputContext {
  53. /**
  54. * Constructs an InputContext.
  55. * This method is protected so clients cannot instantiate
  56. * InputContext directly. Input contexts are obtained by
  57. * calling {@link #getInstance}.
  58. */
  59. protected InputContext() {
  60. // real implementation is in sun.awt.im.InputContext
  61. }
  62. /**
  63. * Returns a new InputContext instance.
  64. */
  65. public static InputContext getInstance() {
  66. return new sun.awt.im.InputMethodContext();
  67. }
  68. /**
  69. * Selects an input method that supports the given locale.
  70. * If the currently selected input method supports the desired locale
  71. * or if there's no input method available that supports the desired
  72. * locale, the current input method remains active. Otherwise, an input
  73. * method is selected that supports text input for the desired locale.
  74. * Before switching to a different input method, any currently uncommitted
  75. * text is committed.
  76. * If no input method supporting the desired locale is available,
  77. * then false is returned.
  78. *
  79. * <p>
  80. * A text editing component may call this method, for example, when
  81. * the user changes the insertion point, so that the user can
  82. * immediately continue typing in the language of the surrounding text.
  83. *
  84. * @param locale The desired new locale.
  85. * @return Whether the input method that's active after this call
  86. * supports the desired locale.
  87. * @exception NullPointerException if <code>locale</code> is null
  88. */
  89. public boolean selectInputMethod(Locale locale) {
  90. // real implementation is in sun.awt.im.InputContext
  91. return false;
  92. }
  93. /**
  94. * Returns the current locale of the current input method.
  95. * Returns null if the input context does not have a current
  96. * input method or the input method's
  97. * {@link java.awt.im.spi.InputMethod#getLocale()} returns null.
  98. *
  99. * @return the current locale of the current input method
  100. * @since 1.3
  101. */
  102. public Locale getLocale() {
  103. // real implementation is in sun.awt.im.InputContext
  104. return null;
  105. }
  106. /**
  107. * Sets the subsets of the Unicode character set that input methods of this input
  108. * context should be allowed to input. Null may be passed in to
  109. * indicate that all characters are allowed. The initial value
  110. * is null. The setting applies to the current input method as well
  111. * as input methods selected after this call is made. However,
  112. * applications cannot rely on this call having the desired effect,
  113. * since this setting cannot be passed on to all host input methods -
  114. * applications still need to apply their own character validation.
  115. * If no input methods are available, then this method has no effect.
  116. *
  117. * @param subsets The subsets of the Unicode character set from which characters may be input
  118. */
  119. public void setCharacterSubsets(Subset[] subsets) {
  120. // real implementation is in sun.awt.im.InputContext
  121. }
  122. /**
  123. * Enables or disables the current input method for composition,
  124. * depending on the value of the parameter <code>enable</code>.
  125. * <p>
  126. * An input method that is enabled for composition interprets incoming
  127. * events for both composition and control purposes, while a
  128. * disabled input method does not interpret events for composition.
  129. * Note however that events are passed on to the input method regardless
  130. * whether it is enabled or not, and that an input method that is disabled
  131. * for composition may still interpret events for control purposes,
  132. * including to enable or disable itself for composition.
  133. *
  134. * @param enable whether to enable the current input method for composition
  135. * @throws UnsupportedOperationException if there is no current input
  136. * method available or the current input method does not support
  137. * the enabling/disabling operation
  138. * @see #isCompositionEnabled
  139. * @since 1.3
  140. */
  141. public void setCompositionEnabled(boolean enable) {
  142. // real implementation is in sun.awt.im.InputContext
  143. }
  144. /**
  145. * Determines whether the current input method is enabled for composition.
  146. * An input method that is enabled for composition interprets incoming
  147. * events for both composition and control purposes, while a
  148. * disabled input method does not interpret events for composition.
  149. *
  150. * @return <code>true</code> if the current input method is enabled for
  151. * composition; <code>false</code> otherwise
  152. * @throws UnsupportedOperationException if there is no current input
  153. * method available or the current input method does not support
  154. * checking whether it is enabled for composition
  155. * @see #setCompositionEnabled
  156. * @since 1.3
  157. */
  158. public boolean isCompositionEnabled() {
  159. // real implementation is in sun.awt.im.InputContext
  160. return false;
  161. }
  162. /**
  163. * Asks the current input method to reconvert text from the
  164. * current client component. The input method obtains the text to
  165. * be reconverted from the client component using the
  166. * {@link InputMethodRequests#getSelectedText InputMethodRequests.getSelectedText}
  167. * method. The other <code>InputMethodRequests</code> methods
  168. * must be prepared to deal with further information requests by
  169. * the input method. The composed and/or committed text will be
  170. * sent to the client component as a sequence of
  171. * <code>InputMethodEvent</code>s. If the input method cannot
  172. * reconvert the given text, the text is returned as committed
  173. * text in an <code>InputMethodEvent</code>.
  174. *
  175. * @throws UnsupportedOperationException if there is no current input
  176. * method available or the current input method does not support
  177. * the reconversion operation.
  178. *
  179. * @since 1.3
  180. */
  181. public void reconvert() {
  182. // real implementation is in sun.awt.im.InputContext
  183. }
  184. /**
  185. * Dispatches an event to the active input method. Called by AWT.
  186. * If no input method is available, then the event will never be consumed.
  187. *
  188. * @param event The event
  189. * @exception NullPointerException if <code>event</code> is null
  190. */
  191. public void dispatchEvent(AWTEvent event) {
  192. // real implementation is in sun.awt.im.InputContext
  193. }
  194. /**
  195. * Notifies the input context that a client component has been
  196. * removed from its containment hierarchy, or that input method
  197. * support has been disabled for the component. This method is
  198. * usually called from the client component's
  199. * {@link java.awt.Component#removeNotify() Component.removeNotify}
  200. * method. Potentially pending input from input methods
  201. * for this component is discarded.
  202. * If no input methods are available, then this method has no effect.
  203. *
  204. * @param client Client component
  205. * @exception NullPointerException if <code>client</code> is null
  206. */
  207. public void removeNotify(Component client) {
  208. // real implementation is in sun.awt.im.InputContext
  209. }
  210. /**
  211. * Ends any input composition that may currently be going on in this
  212. * context. Depending on the platform and possibly user preferences,
  213. * this may commit or delete uncommitted text. Any changes to the text
  214. * are communicated to the active component using an input method event.
  215. * If no input methods are available, then this method has no effect.
  216. *
  217. * <p>
  218. * A text editing component may call this in a variety of situations,
  219. * for example, when the user moves the insertion point within the text
  220. * (but outside the composed text), or when the component's text is
  221. * saved to a file or copied to the clipboard.
  222. *
  223. */
  224. public void endComposition() {
  225. // real implementation is in sun.awt.im.InputContext
  226. }
  227. /**
  228. * Disposes of the input context and release the resources used by it.
  229. * Called by AWT for the default input context of each Window.
  230. * If no input methods are available, then this method
  231. * has no effect.
  232. */
  233. public void dispose() {
  234. // real implementation is in sun.awt.im.InputContext
  235. }
  236. /**
  237. * Returns a control object from the current input method, or null. A
  238. * control object provides methods that control the behavior of the
  239. * input method or obtain information from the input method. The type
  240. * of the object is an input method specific class. Clients have to
  241. * compare the result against known input method control object
  242. * classes and cast to the appropriate class to invoke the methods
  243. * provided.
  244. * <p>
  245. * If no input methods are available or the current input method does
  246. * not provide an input method control object, then null is returned.
  247. *
  248. * @return A control object from the current input method, or null.
  249. */
  250. public Object getInputMethodControlObject() {
  251. // real implementation is in sun.awt.im.InputContext
  252. return null;
  253. }
  254. }