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