1. /*
  2. * @(#)InputContext.java 1.15 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.awt.im;
  8. import java.awt.Component;
  9. import java.util.Locale;
  10. import java.awt.AWTEvent;
  11. import java.lang.Character.Subset;
  12. import sun.awt.im.InputMethod;
  13. import sun.awt.im.InputMethodContext;
  14. /**
  15. * An InputContext object manages the communication between text editing
  16. * components and input methods. It dispatches events between them, and
  17. * forwards requests for information from the input method to the text
  18. * editing component. It also lets text editing components select input
  19. * methods by locale.
  20. *
  21. * <p>
  22. * By default, one InputContext instance is created per Window instance,
  23. * and this input context is shared by all components within the window's
  24. * container hierarchy. However, this means that only one text input
  25. * operation is possible at any one time within a window, and that the
  26. * text needs to be committed when moving the focus from one text component
  27. * to another. If this is not desired, text components can create their
  28. * own input context instances.
  29. *
  30. * <p>
  31. * Not all platforms and locales support input methods. Where input methods are
  32. * unavailable, input contexts can still be created and used; the
  33. * InputContext instance methods return without doing anything (selectLocale
  34. * returns false).
  35. *
  36. * @see java.awt.Component#getInputContext
  37. * @see java.awt.Component#enableInputMethods
  38. * @version 1.15 11/29/01
  39. * @author JavaSoft Asia/Pacific
  40. */
  41. public class InputContext {
  42. /**
  43. * Constructs an InputContext.
  44. */
  45. protected InputContext() {
  46. // real implementation is in sun.awt.im.InputContext
  47. }
  48. /**
  49. * Returns a new InputContext instance.
  50. */
  51. public static InputContext getInstance() {
  52. return new InputMethodContext();
  53. }
  54. /**
  55. * Selects an input method that supports the given locale.
  56. * If the currently selected input method supports the desired locale
  57. * or if there's no input method available that supports the desired
  58. * locale, the current input method remains active. Otherwise, an input
  59. * method is selected that supports text input for the desired locale.
  60. * Before switching to a different input method, any currently uncommitted
  61. * text is committed.
  62. * If the platform does not support input methods or the desired locale,
  63. * then false is returned.
  64. *
  65. * <p>
  66. * A text editing component may call this method, for example, when
  67. * the user changes the insertion point, so that the user can
  68. * immediately continue typing in the language of the surrounding text.
  69. *
  70. * @param locale The desired new locale.
  71. * @return Whether the input method that's active after this call
  72. * supports the desired locale.
  73. */
  74. public boolean selectInputMethod(Locale locale) {
  75. // real implementation is in sun.awt.im.InputContext
  76. return false;
  77. }
  78. /**
  79. * Sets the subsets of the Unicode character set that input methods of this input
  80. * context should be allowed to input. Null may be passed in to
  81. * indicate that all characters are allowed. The initial value
  82. * is null. The setting applies to the current input method as well
  83. * as input methods selected after this call is made. However,
  84. * applications cannot rely on this call having the desired effect,
  85. * since this setting cannot be passed on to all host input methods -
  86. * applications still need to apply their own character validation.
  87. * If the platform does not support input methods, then this method
  88. * has no effect.
  89. *
  90. * @param subsets The subsets of the Unicode character set from which characters may be input
  91. */
  92. public void setCharacterSubsets(Subset[] subsets) {
  93. // real implementation is in sun.awt.im.InputContext
  94. }
  95. /**
  96. * Dispatches an event to the active input method. Called by AWT.
  97. * If the platform does not support input methods, then the event
  98. * will never be consumed.
  99. *
  100. * @param event The event
  101. */
  102. public synchronized void dispatchEvent(AWTEvent event) {
  103. // real implementation is in sun.awt.im.InputContext
  104. }
  105. /**
  106. * Notifies the input context that a client component has been
  107. * removed from its containment hierarchy, or that input method
  108. * support has been disabled for the component. This method is
  109. * usually called from java.awt.Component.removeNotify() of the
  110. * client component. Potentially pending input from input methods
  111. * for this component is discarded.
  112. *
  113. * @param client Client component
  114. */
  115. public void removeNotify(Component client) {
  116. // real implementation is in sun.awt.im.InputContext
  117. }
  118. /**
  119. * Ends any input composition that may currently be going on in this
  120. * context. Depending on the platform and possibly user preferences,
  121. * this may commit or delete uncommitted text. Any changes to the text
  122. * are communicated to the active component using an input method event.
  123. * If the platform does not support input methods, then this method
  124. * has no effect.
  125. *
  126. * <p>
  127. * A text editing component may call this in a variety of situations,
  128. * for example, when the user moves the insertion point within the text
  129. * (but outside the composed text), or when the component's text is
  130. * saved to a file or copied to the clipboard.
  131. *
  132. */
  133. public synchronized void endComposition() {
  134. // real implementation is in sun.awt.im.InputContext
  135. }
  136. /**
  137. * Disposes of the input context and release the resources used by it.
  138. * Called by AWT.
  139. * If the platform does not support input methods, then this method
  140. * has no effect.
  141. */
  142. public void dispose() {
  143. // real implementation is in sun.awt.im.InputContext
  144. }
  145. /**
  146. * Returns a control object from the current input method, or null. A
  147. * control object provides methods that control the behavior of the
  148. * input method or obtain information from the input method. The type
  149. * of the object is an input method specific class. Clients have to
  150. * compare the result against known input method control object
  151. * classes and cast to the appropriate class to invoke the methods
  152. * provided.
  153. * If the platform does not support input methods, then null
  154. * is returned.
  155. *
  156. * @return A control object from the current input method, or null.
  157. */
  158. public Object getInputMethodControlObject() {
  159. // real implementation is in sun.awt.im.InputContext
  160. return null;
  161. }
  162. }