1. /*
  2. * @(#)InputMethod.java 1.26 03/01/23
  3. *
  4. * Copyright 2003 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.26, 01/23/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. * This method is called
  104. * <ul>
  105. * <li>by {@link java.awt.im.InputContext#setCompositionEnabled InputContext.setCompositionEnabled},
  106. * <li>when switching to this input method from a different one using the
  107. * user interface or
  108. * {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod},
  109. * if the previously selected input method's
  110. * {@link java.awt.im.spi.InputMethod#isCompositionEnabled isCompositionEnabled}
  111. * method returns without throwing an exception.
  112. * </ul>
  113. *
  114. * @param enable whether to enable the input method for composition
  115. * @throws UnsupportedOperationException if this input method does not
  116. * support the enabling/disabling operation
  117. * @see #isCompositionEnabled
  118. */
  119. public void setCompositionEnabled(boolean enable);
  120. /**
  121. * Determines whether this input method is enabled.
  122. * An input method that is enabled for composition interprets incoming
  123. * events for both composition and control purposes, while a
  124. * disabled input method does not interpret events for composition.
  125. * <p>
  126. * This method is called
  127. * <ul>
  128. * <li>by {@link java.awt.im.InputContext#isCompositionEnabled InputContext.isCompositionEnabled} and
  129. * <li>when switching from this input method to a different one using the
  130. * user interface or
  131. * {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod}.
  132. * </ul>
  133. *
  134. * @return <code>true</code> if this input method is enabled for
  135. * composition; <code>false</code> otherwise.
  136. * @throws UnsupportedOperationException if this input method does not
  137. * support checking whether it is enabled for composition
  138. * @see #setCompositionEnabled
  139. */
  140. public boolean isCompositionEnabled();
  141. /**
  142. * Starts the reconversion operation. The input method obtains the
  143. * text to be reconverted from the current client component using the
  144. * {@link java.awt.im.InputMethodRequests#getSelectedText InputMethodRequests.getSelectedText}
  145. * method. It can use other <code>InputMethodRequests</code>
  146. * methods to request additional information required for the
  147. * reconversion operation. The composed and committed text
  148. * produced by the operation is sent to the client component as a
  149. * sequence of <code>InputMethodEvent</code>s. If the given text
  150. * cannot be reconverted, the same text should be sent to the
  151. * client component as committed text.
  152. * <p>
  153. * This method is called by
  154. * {@link java.awt.im.InputContext#reconvert() InputContext.reconvert}.
  155. *
  156. * @throws UnsupportedOperationException if the input method does not
  157. * support the reconversion operation.
  158. */
  159. public void reconvert();
  160. /**
  161. * Dispatches the event to the input method. If input method support is
  162. * enabled for the focussed component, incoming events of certain types
  163. * are dispatched to the current input method for this component before
  164. * they are dispatched to the component's methods or event listeners.
  165. * The input method decides whether it needs to handle the event. If it
  166. * does, it also calls the event's <code>consume</code> method; this
  167. * causes the event to not get dispatched to the component's event
  168. * processing methods or event listeners.
  169. * <p>
  170. * Events are dispatched if they are instances of InputEvent or its
  171. * subclasses.
  172. * This includes instances of the AWT classes KeyEvent and MouseEvent.
  173. * <p>
  174. * This method is called by {@link java.awt.im.InputContext#dispatchEvent InputContext.dispatchEvent}.
  175. *
  176. * @param event the event being dispatched to the input method
  177. * @exception NullPointerException if <code>event</code> is null
  178. */
  179. public void dispatchEvent(AWTEvent event);
  180. /**
  181. * Notifies this input method of changes in the client window
  182. * location or state. This method is called while this input
  183. * method is the current input method of its input context and
  184. * notifications for it are enabled (see {@link
  185. * InputMethodContext#enableClientWindowNotification
  186. * InputMethodContext.enableClientWindowNotification}). Calls
  187. * to this method are temporarily suspended if the input context's
  188. * {@link java.awt.im.InputContext#removeNotify removeNotify}
  189. * method is called, and resume when the input method is activated
  190. * for a new client component. It is called in the following
  191. * situations:
  192. * <ul>
  193. * <li>
  194. * when the window containing the current client component changes
  195. * in location, size, visibility, iconification state, or when the
  196. * window is closed.</li>
  197. * <li>
  198. * from <code> enableClientWindowNotification(inputMethod,
  199. * true)</code> if the current client component exists,</li>
  200. * <li>
  201. * when activating the input method for the first time after it
  202. * called
  203. * <code>enableClientWindowNotification(inputMethod,
  204. * true)</code> if during the call no current client component was
  205. * available,</li>
  206. * <li>
  207. * when activating the input method for a new client component
  208. * after the input context's removeNotify method has been
  209. * called.</li>
  210. * </ul>
  211. * @param bounds client window's {@link
  212. * java.awt.Component#getBounds bounds} on the screen; or null if
  213. * the client window is iconified or invisible
  214. */
  215. public void notifyClientWindowChange(Rectangle bounds);
  216. /**
  217. * Activates the input method for immediate input processing.
  218. * <p>
  219. * If an input method provides its own windows, it should make sure
  220. * at this point that all necessary windows are open and visible.
  221. * <p>
  222. * This method is called
  223. * <ul>
  224. * <li>by {@link java.awt.im.InputContext#dispatchEvent InputContext.dispatchEvent}
  225. * when a client component receives a FOCUS_GAINED event,
  226. * <li>when switching to this input method from a different one using the
  227. * user interface or
  228. * {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod}.
  229. * </ul>
  230. * The method is only called when the input method is inactive.
  231. * A newly instantiated input method is assumed to be inactive.
  232. */
  233. public void activate();
  234. /**
  235. * Deactivates the input method.
  236. * The isTemporary argument has the same meaning as in
  237. * {@link java.awt.event.FocusEvent#isTemporary FocusEvent.isTemporary}.
  238. * <p>
  239. * If an input method provides its own windows, only windows that relate
  240. * to the current composition (such as a lookup choice window) should be
  241. * closed at this point.
  242. * It is possible that the input method will be immediately activated again
  243. * for a different client component, and closing and reopening more
  244. * persistent windows (such as a control panel) would create unnecessary
  245. * screen flicker.
  246. * Before an instance of a different input method class is activated,
  247. * {@link #hideWindows} is called on the current input method.
  248. * <p>
  249. * This method is called
  250. * <ul>
  251. * <li>by {@link java.awt.im.InputContext#dispatchEvent InputContext.dispatchEvent}
  252. * when a client component receives a FOCUS_LOST event,
  253. * <li>when switching from this input method to a different one using the
  254. * user interface or
  255. * {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod},
  256. * <li>before {@link #removeNotify removeNotify} if the current client component is
  257. * removed.
  258. * </ul>
  259. * The method is only called when the input method is active.
  260. *
  261. * @param isTemporary whether the focus change is temporary
  262. */
  263. public void deactivate(boolean isTemporary);
  264. /**
  265. * Closes or hides all windows opened by this input method instance or
  266. * its class.
  267. * <p>
  268. * This method is called
  269. * <ul>
  270. * <li>before calling {@link #activate activate} on an instance of a different input
  271. * method class,
  272. * <li>before calling {@link #dispose dispose} on this input method.
  273. * </ul>
  274. * The method is only called when the input method is inactive.
  275. */
  276. public void hideWindows();
  277. /**
  278. * Notifies the input method that a client component has been
  279. * removed from its containment hierarchy, or that input method
  280. * support has been disabled for the component.
  281. * <p>
  282. * This method is called by {@link java.awt.im.InputContext#removeNotify InputContext.removeNotify}.
  283. * <p>
  284. * The method is only called when the input method is inactive.
  285. */
  286. public void removeNotify();
  287. /**
  288. * Ends any input composition that may currently be going on in this
  289. * context. Depending on the platform and possibly user preferences,
  290. * this may commit or delete uncommitted text. Any changes to the text
  291. * are communicated to the active component using an input method event.
  292. *
  293. * <p>
  294. * A text editing component may call this in a variety of situations,
  295. * for example, when the user moves the insertion point within the text
  296. * (but outside the composed text), or when the component's text is
  297. * saved to a file or copied to the clipboard.
  298. * <p>
  299. * This method is called
  300. * <ul>
  301. * <li>by {@link java.awt.im.InputContext#endComposition InputContext.endComposition},
  302. * <li>by {@link java.awt.im.InputContext#dispatchEvent InputContext.dispatchEvent}
  303. * when switching to a different client component
  304. * <li>when switching from this input method to a different one using the
  305. * user interface or
  306. * {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod}.
  307. * </ul>
  308. */
  309. public void endComposition();
  310. /**
  311. * Disposes of the input method and releases the resources used by it.
  312. * In particular, the input method should dispose windows and close files that are no
  313. * longer needed.
  314. * <p>
  315. * This method is called by {@link java.awt.im.InputContext#dispose InputContext.dispose}.
  316. * <p>
  317. * The method is only called when the input method is inactive.
  318. * No method of this interface is called on this instance after dispose.
  319. */
  320. public void dispose();
  321. /**
  322. * Returns a control object from this input method, or null. A
  323. * control object provides methods that control the behavior of the
  324. * input method or obtain information from the input method. The type
  325. * of the object is an input method specific class. Clients have to
  326. * compare the result against known input method control object
  327. * classes and cast to the appropriate class to invoke the methods
  328. * provided.
  329. * <p>
  330. * This method is called by
  331. * {@link java.awt.im.InputContext#getInputMethodControlObject InputContext.getInputMethodControlObject}.
  332. *
  333. * @return a control object from this input method, or null
  334. */
  335. public Object getControlObject();
  336. }