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