1. /*
  2. * @(#)InputMethodRequests.java 1.18 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;
  8. import java.awt.Rectangle;
  9. import java.awt.font.TextHitInfo;
  10. import java.text.AttributedCharacterIterator;
  11. import java.text.AttributedCharacterIterator.Attribute;
  12. /**
  13. * InputMethodRequests defines the requests that a text editing component
  14. * has to handle in order to work with input methods. The component
  15. * can implement this interface itself or use a separate object that
  16. * implements it. The object implementing this interface must be returned
  17. * from the component's getInputMethodRequests method.
  18. *
  19. * <p>
  20. * The text editing component also has to provide an input method event
  21. * listener.
  22. *
  23. * <p>
  24. * The interface is designed to support one of two input user interfaces:
  25. * <ul>
  26. * <li><em>on-the-spot</em> input, where the composed text is displayed as part
  27. * of the text component's text body.
  28. * <li><em>below-the-spot</em> input, where the composed text is displayed in
  29. * a separate composition window just below the insertion point where
  30. * the text will be inserted when it is committed. Note that, if text is
  31. * selected within the component's text body, this text will be replaced by
  32. * the committed text upon commitment; therefore it is not considered part
  33. * of the context that the text is input into.
  34. * </ul>
  35. *
  36. * @see java.awt.Component#getInputMethodRequests
  37. * @see java.awt.event.InputMethodListener
  38. *
  39. * @version 1.18, 12/19/03
  40. * @author JavaSoft Asia/Pacific
  41. * @since 1.2
  42. */
  43. public interface InputMethodRequests {
  44. /**
  45. * Gets the location of a specified offset in the current composed text,
  46. * or of the selection in committed text.
  47. * This information is, for example, used to position the candidate window
  48. * near the composed text, or a composition window near the location
  49. * where committed text will be inserted.
  50. *
  51. * <p>
  52. * If the component has composed text (because the most recent
  53. * InputMethodEvent sent to it contained composed text), then the offset is
  54. * relative to the composed text - offset 0 indicates the first character
  55. * in the composed text. The location returned should be for this character.
  56. *
  57. * <p>
  58. * If the component doesn't have composed text, the offset should be ignored,
  59. * and the location returned should reflect the beginning (in line
  60. * direction) of the highlight in the last line containing selected text.
  61. * For example, for horizontal left-to-right text (such as English), the
  62. * location to the left of the left-most character on the last line
  63. * containing selected text is returned. For vertical top-to-bottom text,
  64. * with lines proceding from right to left, the location to the top of the
  65. * left-most line containing selected text is returned.
  66. *
  67. * <p>
  68. * The location is represented as a 0-thickness caret, that is, it has 0
  69. * width if the text is drawn horizontally, and 0 height if the text is
  70. * drawn vertically. Other text orientations need to be mapped to
  71. * horizontal or vertical orientation. The rectangle uses absolute screen
  72. * coordinates.
  73. *
  74. * @param offset the offset within the composed text, if there is composed
  75. * text; null otherwise
  76. * @return a rectangle representing the screen location of the offset
  77. */
  78. Rectangle getTextLocation(TextHitInfo offset);
  79. /**
  80. * Gets the offset within the composed text for the specified absolute x
  81. * and y coordinates on the screen. This information is used, for example
  82. * to handle mouse clicks and the mouse cursor. The offset is relative to
  83. * the composed text, so offset 0 indicates the beginning of the composed
  84. * text.
  85. *
  86. * <p>
  87. * Return null if the location is outside the area occupied by the composed
  88. * text.
  89. *
  90. * @param x the absolute x coordinate on screen
  91. * @param y the absolute y coordinate on screen
  92. * @return a text hit info describing the offset in the composed text.
  93. */
  94. TextHitInfo getLocationOffset(int x, int y);
  95. /**
  96. * Gets the offset of the insert position in the committed text contained
  97. * in the text editing component. This is the offset at which characters
  98. * entered through an input method are inserted. This information is used
  99. * by an input method, for example, to examine the text surrounding the
  100. * insert position.
  101. *
  102. * @return the offset of the insert position
  103. */
  104. int getInsertPositionOffset();
  105. /**
  106. * Gets an iterator providing access to the entire text and attributes
  107. * contained in the text editing component except for uncommitted
  108. * text. Uncommitted (composed) text should be ignored for index
  109. * calculations and should not be made accessible through the iterator.
  110. *
  111. * <p>
  112. * The input method may provide a list of attributes that it is
  113. * interested in. In that case, information about other attributes that
  114. * the implementor may have need not be made accessible through the
  115. * iterator. If the list is null, all available attribute information
  116. * should be made accessible.
  117. *
  118. * @param beginIndex the index of the first character
  119. * @param endIndex the index of the character following the last character
  120. * @param attributes a list of attributes that the input method is
  121. * interested in
  122. * @return an iterator providing access to the text and its attributes
  123. */
  124. AttributedCharacterIterator getCommittedText(int beginIndex, int endIndex,
  125. Attribute[] attributes);
  126. /**
  127. * Gets the length of the entire text contained in the text
  128. * editing component except for uncommitted (composed) text.
  129. *
  130. * @return the length of the text except for uncommitted text
  131. */
  132. int getCommittedTextLength();
  133. /**
  134. * Gets the latest committed text from the text editing component and
  135. * removes it from the component's text body.
  136. * This is used for the "Undo Commit" feature in some input methods, where
  137. * the committed text reverts to its previous composed state. The composed
  138. * text will be sent to the component using an InputMethodEvent.
  139. *
  140. * <p>
  141. * Generally, this feature should only be supported immediately after the
  142. * text was committed, not after the user performed other operations on the
  143. * text. When the feature is not supported, return null.
  144. *
  145. * <p>
  146. * The input method may provide a list of attributes that it is
  147. * interested in. In that case, information about other attributes that
  148. * the implementor may have need not be made accessible through the
  149. * iterator. If the list is null, all available attribute information
  150. * should be made accessible.
  151. *
  152. * @param attributes a list of attributes that the input method is
  153. * interested in
  154. * @return the latest committed text, or null when the "Undo Commit"
  155. * feature is not supported
  156. */
  157. AttributedCharacterIterator cancelLatestCommittedText(Attribute[] attributes);
  158. /**
  159. * Gets the currently selected text from the text editing component.
  160. * This may be used for a variety of purposes.
  161. * One of them is the "Reconvert" feature in some input methods.
  162. * In this case, the input method will typically send an input method event
  163. * to replace the selected text with composed text. Depending on the input
  164. * method's capabilities, this may be the original composed text for the
  165. * selected text, the latest composed text entered anywhere in the text, or
  166. * a version of the text that's converted back from the selected text.
  167. *
  168. * <p>
  169. * The input method may provide a list of attributes that it is
  170. * interested in. In that case, information about other attributes that
  171. * the implementor may have need not be made accessible through the
  172. * iterator. If the list is null, all available attribute information
  173. * should be made accessible.
  174. *
  175. * @param attributes a list of attributes that the input method is
  176. * interested in
  177. * @return the currently selected text
  178. */
  179. AttributedCharacterIterator getSelectedText(Attribute[] attributes);
  180. }