1. /*
  2. * @(#)InputMethod.java 1.29 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.awt.im.spi;
  8. import java.util.Locale;
  9. import java.awt.AWTEvent;
  10. import java.awt.Rectangle;
  11. import java.lang.Character.Subset;
  12. /**
  13. * Defines the interface for an input method that supports complex text input.
  14. * Input methods traditionally support text input for languages that have
  15. * more characters than can be represented on a standard-size keyboard,
  16. * such as Chinese, Japanese, and Korean. However, they may also be used to
  17. * support phonetic text input for English or character reordering for Thai.
  18. * <p>
  19. * Subclasses of InputMethod can be loaded by the input method framework; they
  20. * can then be selected either through the API
  21. * ({@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod})
  22. * or the user interface (the input method selection menu).
  23. *
  24. * @since 1.3
  25. *
  26. * @version 1.29, 12/19/03
  27. * @author JavaSoft International
  28. */
  29. public interface InputMethod {
  30. /**
  31. * Sets the input method context, which is used to dispatch input method
  32. * events to the client component and to request information from
  33. * the client component.
  34. * <p>
  35. * This method is called once immediately after instantiating this input
  36. * method.
  37. *
  38. * @param context the input method context for this input method
  39. * @exception NullPointerException if <code>context</code> is null
  40. */
  41. public void setInputMethodContext(InputMethodContext context);
  42. /**
  43. * Attempts to set the input locale. If the input method supports the
  44. * desired locale, it changes its behavior to support input for the locale
  45. * and returns true.
  46. * Otherwise, it returns false and does not change its behavior.
  47. * <p>
  48. * This method is called
  49. * <ul>
  50. * <li>by {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod},
  51. * <li>when switching to this input method through the user interface if the user
  52. * specified a locale or if the previously selected input method's
  53. * {@link java.awt.im.spi.InputMethod#getLocale getLocale} method
  54. * returns a non-null value.
  55. * </ul>
  56. *
  57. * @param locale locale to input
  58. * @return whether the specified locale is supported
  59. * @exception NullPointerException if <code>locale</code> is null
  60. */
  61. public boolean setLocale(Locale locale);
  62. /**
  63. * Returns the current input locale. Might return null in exceptional cases.
  64. * <p>
  65. * This method is called
  66. * <ul>
  67. * <li>by {@link java.awt.im.InputContext#getLocale InputContext.getLocale} and
  68. * <li>when switching from this input method to a different one through the
  69. * user interface.
  70. * </ul>
  71. *
  72. * @return the current input locale, or null
  73. */
  74. public Locale getLocale();
  75. /**
  76. * Sets the subsets of the Unicode character set that this input method
  77. * is allowed to input. Null may be passed in to indicate that all
  78. * characters are allowed.
  79. * <p>
  80. * This method is called
  81. * <ul>
  82. * <li>immediately after instantiating this input method,
  83. * <li>when switching to this input method from a different one, and
  84. * <li>by {@link java.awt.im.InputContext#setCharacterSubsets InputContext.setCharacterSubsets}.
  85. * </ul>
  86. *
  87. * @param subsets the subsets of the Unicode character set from which
  88. * characters may be input
  89. */
  90. public void setCharacterSubsets(Subset[] subsets);
  91. /**
  92. * Enables or disables this input method for composition,
  93. * depending on the value of the parameter <code>enable</code>.
  94. * <p>
  95. * An input method that is enabled for composition interprets incoming
  96. * events for both composition and control purposes, while a
  97. * disabled input method does not interpret events for composition.
  98. * Note however that events are passed on to the input method regardless
  99. * whether it is enabled or not, and that an input method that is disabled
  100. * for composition may still interpret events for control purposes,
  101. * including to enable or disable itself for composition.
  102. * <p>
  103. * For input methods provided by host operating systems, it is not always possible to
  104. * determine whether this operation is supported. For example, an input method may enable
  105. * composition only for some locales, and do nothing for other locales. For such input
  106. * methods, it is possible that this method does not throw
  107. * {@link java.lang.UnsupportedOperationException UnsupportedOperationException},
  108. * but also does not affect whether composition is enabled.
  109. * <p>
  110. * This method is called
  111. * <ul>
  112. * <li>by {@link java.awt.im.InputContext#setCompositionEnabled InputContext.setCompositionEnabled},
  113. * <li>when switching to this input method from a different one using the
  114. * user interface or
  115. * {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod},
  116. * if the previously selected input method's
  117. * {@link java.awt.im.spi.InputMethod#isCompositionEnabled isCompositionEnabled}
  118. * method returns without throwing an exception.
  119. * </ul>
  120. *
  121. * @param enable whether to enable the input method for composition
  122. * @throws UnsupportedOperationException if this input method does not
  123. * support the enabling/disabling operation
  124. * @see #isCompositionEnabled
  125. */
  126. public void setCompositionEnabled(boolean enable);
  127. /**
  128. * Determines whether this input method is enabled.
  129. * An input method that is enabled for composition interprets incoming
  130. * events for both composition and control purposes, while a
  131. * disabled input method does not interpret events for composition.
  132. * <p>
  133. * This method is called
  134. * <ul>
  135. * <li>by {@link java.awt.im.InputContext#isCompositionEnabled InputContext.isCompositionEnabled} and
  136. * <li>when switching from this input method to a different one using the
  137. * user interface or
  138. * {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod}.
  139. * </ul>
  140. *
  141. * @return <code>true</code> if this input method is enabled for
  142. * composition; <code>false</code> otherwise.
  143. * @throws UnsupportedOperationException if this input method does not
  144. * support checking whether it is enabled for composition
  145. * @see #setCompositionEnabled
  146. */
  147. public boolean isCompositionEnabled();
  148. /**
  149. * Starts the reconversion operation. The input method obtains the
  150. * text to be reconverted from the current client component using the
  151. * {@link java.awt.im.InputMethodRequests#getSelectedText InputMethodRequests.getSelectedText}
  152. * method. It can use other <code>InputMethodRequests</code>
  153. * methods to request additional information required for the
  154. * reconversion operation. The composed and committed text
  155. * produced by the operation is sent to the client component as a
  156. * sequence of <code>InputMethodEvent</code>s. If the given text
  157. * cannot be reconverted, the same text should be sent to the
  158. * client component as committed text.
  159. * <p>
  160. * This method is called by
  161. * {@link java.awt.im.InputContext#reconvert() InputContext.reconvert}.
  162. *
  163. * @throws UnsupportedOperationException if the input method does not
  164. * support the reconversion operation.
  165. */
  166. public void reconvert();
  167. /**
  168. * Dispatches the event to the input method. If input method support is
  169. * enabled for the focussed component, incoming events of certain types
  170. * are dispatched to the current input method for this component before
  171. * they are dispatched to the component's methods or event listeners.
  172. * The input method decides whether it needs to handle the event. If it
  173. * does, it also calls the event's <code>consume</code> method; this
  174. * causes the event to not get dispatched to the component's event
  175. * processing methods or event listeners.
  176. * <p>
  177. * Events are dispatched if they are instances of InputEvent or its
  178. * subclasses.
  179. * This includes instances of the AWT classes KeyEvent and MouseEvent.
  180. * <p>
  181. * This method is called by {@link java.awt.im.InputContext#dispatchEvent InputContext.dispatchEvent}.
  182. *
  183. * @param event the event being dispatched to the input method
  184. * @exception NullPointerException if <code>event</code> is null
  185. */
  186. public void dispatchEvent(AWTEvent event);
  187. /**
  188. * Notifies this input method of changes in the client window
  189. * location or state. This method is called while this input
  190. * method is the current input method of its input context and
  191. * notifications for it are enabled (see {@link
  192. * InputMethodContext#enableClientWindowNotification
  193. * InputMethodContext.enableClientWindowNotification}). Calls
  194. * to this method are temporarily suspended if the input context's
  195. * {@link java.awt.im.InputContext#removeNotify removeNotify}
  196. * method is called, and resume when the input method is activated
  197. * for a new client component. It is called in the following
  198. * situations:
  199. * <ul>
  200. * <li>
  201. * when the window containing the current client component changes
  202. * in location, size, visibility, iconification state, or when the
  203. * window is closed.</li>
  204. * <li>
  205. * from <code> enableClientWindowNotification(inputMethod,
  206. * true)</code> if the current client component exists,</li>
  207. * <li>
  208. * when activating the input method for the first time after it
  209. * called
  210. * <code>enableClientWindowNotification(inputMethod,
  211. * true)</code> if during the call no current client component was
  212. * available,</li>
  213. * <li>
  214. * when activating the input method for a new client component
  215. * after the input context's removeNotify method has been
  216. * called.</li>
  217. * </ul>
  218. * @param bounds client window's {@link
  219. * java.awt.Component#getBounds bounds} on the screen; or null if
  220. * the client window is iconified or invisible
  221. */
  222. public void notifyClientWindowChange(Rectangle bounds);
  223. /**
  224. * Activates the input method for immediate input processing.
  225. * <p>
  226. * If an input method provides its own windows, it should make sure
  227. * at this point that all necessary windows are open and visible.
  228. * <p>
  229. * This method is called
  230. * <ul>
  231. * <li>by {@link java.awt.im.InputContext#dispatchEvent InputContext.dispatchEvent}
  232. * when a client component receives a FOCUS_GAINED event,
  233. * <li>when switching to this input method from a different one using the
  234. * user interface or
  235. * {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod}.
  236. * </ul>
  237. * The method is only called when the input method is inactive.
  238. * A newly instantiated input method is assumed to be inactive.
  239. */
  240. public void activate();
  241. /**
  242. * Deactivates the input method.
  243. * The isTemporary argument has the same meaning as in
  244. * {@link java.awt.event.FocusEvent#isTemporary FocusEvent.isTemporary}.
  245. * <p>
  246. * If an input method provides its own windows, only windows that relate
  247. * to the current composition (such as a lookup choice window) should be
  248. * closed at this point.
  249. * It is possible that the input method will be immediately activated again
  250. * for a different client component, and closing and reopening more
  251. * persistent windows (such as a control panel) would create unnecessary
  252. * screen flicker.
  253. * Before an instance of a different input method class is activated,
  254. * {@link #hideWindows} is called on the current input method.
  255. * <p>
  256. * This method is called
  257. * <ul>
  258. * <li>by {@link java.awt.im.InputContext#dispatchEvent InputContext.dispatchEvent}
  259. * when a client component receives a FOCUS_LOST event,
  260. * <li>when switching from this input method to a different one using the
  261. * user interface or
  262. * {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod},
  263. * <li>before {@link #removeNotify removeNotify} if the current client component is
  264. * removed.
  265. * </ul>
  266. * The method is only called when the input method is active.
  267. *
  268. * @param isTemporary whether the focus change is temporary
  269. */
  270. public void deactivate(boolean isTemporary);
  271. /**
  272. * Closes or hides all windows opened by this input method instance or
  273. * its class.
  274. * <p>
  275. * This method is called
  276. * <ul>
  277. * <li>before calling {@link #activate activate} on an instance of a different input
  278. * method class,
  279. * <li>before calling {@link #dispose dispose} on this input method.
  280. * </ul>
  281. * The method is only called when the input method is inactive.
  282. */
  283. public void hideWindows();
  284. /**
  285. * Notifies the input method that a client component has been
  286. * removed from its containment hierarchy, or that input method
  287. * support has been disabled for the component.
  288. * <p>
  289. * This method is called by {@link java.awt.im.InputContext#removeNotify InputContext.removeNotify}.
  290. * <p>
  291. * The method is only called when the input method is inactive.
  292. */
  293. public void removeNotify();
  294. /**
  295. * Ends any input composition that may currently be going on in this
  296. * context. Depending on the platform and possibly user preferences,
  297. * this may commit or delete uncommitted text. Any changes to the text
  298. * are communicated to the active component using an input method event.
  299. *
  300. * <p>
  301. * A text editing component may call this in a variety of situations,
  302. * for example, when the user moves the insertion point within the text
  303. * (but outside the composed text), or when the component's text is
  304. * saved to a file or copied to the clipboard.
  305. * <p>
  306. * This method is called
  307. * <ul>
  308. * <li>by {@link java.awt.im.InputContext#endComposition InputContext.endComposition},
  309. * <li>by {@link java.awt.im.InputContext#dispatchEvent InputContext.dispatchEvent}
  310. * when switching to a different client component
  311. * <li>when switching from this input method to a different one using the
  312. * user interface or
  313. * {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod}.
  314. * </ul>
  315. */
  316. public void endComposition();
  317. /**
  318. * Disposes of the input method and releases the resources used by it.
  319. * In particular, the input method should dispose windows and close files that are no
  320. * longer needed.
  321. * <p>
  322. * This method is called by {@link java.awt.im.InputContext#dispose InputContext.dispose}.
  323. * <p>
  324. * The method is only called when the input method is inactive.
  325. * No method of this interface is called on this instance after dispose.
  326. */
  327. public void dispose();
  328. /**
  329. * Returns a control object from this input method, or null. A
  330. * control object provides methods that control the behavior of the
  331. * input method or obtain information from the input method. The type
  332. * of the object is an input method specific class. Clients have to
  333. * compare the result against known input method control object
  334. * classes and cast to the appropriate class to invoke the methods
  335. * provided.
  336. * <p>
  337. * This method is called by
  338. * {@link java.awt.im.InputContext#getInputMethodControlObject InputContext.getInputMethodControlObject}.
  339. *
  340. * @return a control object from this input method, or null
  341. */
  342. public Object getControlObject();
  343. }