1. /*
  2. * @(#)AccessibleText.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 javax.accessibility;
  11. import java.lang.*;
  12. import java.util.*;
  13. import java.awt.*;
  14. import javax.swing.text.*;
  15. /**
  16. * <P>The AccessibleText interface should be implemented by all
  17. * classes that present textual information on the display. This interface
  18. * provides the standard mechanism for an assistive technology to access
  19. * that text via its content, attributes, and spatial location.
  20. * Applications can determine if an object supports the AccessibleText
  21. * interface by first obtaining its AccessibleContext (see {@link Accessible})
  22. * and then calling the {@link AccessibleContext#getAccessibleText} method of
  23. * AccessibleContext. If the return value is not null, the object supports this
  24. * interface.
  25. *
  26. * @see Accessible
  27. * @see Accessible#getAccessibleContext
  28. * @see AccessibleContext
  29. * @see AccessibleContext#getAccessibleText
  30. *
  31. * @version 1.13 01/20/98 07:53:43
  32. * @author Peter Korn
  33. */
  34. public interface AccessibleText {
  35. /**
  36. * Constant used to indicate that the part of the text that should be
  37. * retrieved is a character.
  38. *
  39. * @see #getAtIndex
  40. * @see #getAfterIndex
  41. * @see #getBeforeIndex
  42. */
  43. public static final int CHARACTER = 1;
  44. /**
  45. * Constant used to indicate that the part of the text that should be
  46. * retrieved is a word.
  47. *
  48. * @see #getAtIndex
  49. * @see #getAfterIndex
  50. * @see #getBeforeIndex
  51. */
  52. public static final int WORD = 2;
  53. /**
  54. * Constant used to indicate that the part of the text that should be
  55. * retrieved is a sentence.
  56. *
  57. * @see #getAtIndex
  58. * @see #getAfterIndex
  59. * @see #getBeforeIndex
  60. */
  61. public static final int SENTENCE = 3;
  62. /**
  63. * Given a point in local coordinates, return the zero-based index
  64. * of the character under that Point. If the point is invalid,
  65. * this method returns -1.
  66. *
  67. * @param p the Point in local coordinates
  68. * @return the zero-based index of the character under Point p; if
  69. * Point is invalid return -1.
  70. */
  71. public int getIndexAtPoint(Point p);
  72. /**
  73. * Determines the bounding box of the character at the given
  74. * index into the string. The bounds are returned in local
  75. * coordinates. If the index is invalid an empty rectangle is returned.
  76. *
  77. * @param i the index into the String
  78. * @return the screen coordinates of the character's bounding box,
  79. * if index is invalid return an empty rectangle.
  80. */
  81. public Rectangle getCharacterBounds(int i);
  82. /**
  83. * Returns the number of characters (valid indicies)
  84. *
  85. * @return the number of characters
  86. */
  87. public int getCharCount();
  88. /**
  89. * Returns the zero-based offset of the caret.
  90. *
  91. * Note: That to the right of the caret will have the same index
  92. * value as the offset (the caret is between two characters).
  93. * @return the zero-based offset of the caret.
  94. */
  95. public int getCaretPosition();
  96. /**
  97. * Returns the String at a given index.
  98. *
  99. * @param part the CHARACTER, WORD, or SENTENCE to retrieve
  100. * @param index an index within the text
  101. * @return the letter, word, or sentence
  102. */
  103. public String getAtIndex(int part, int index);
  104. /**
  105. * Returns the String after a given index.
  106. *
  107. * @param part the CHARACTER, WORD, or SENTENCE to retrieve
  108. * @param index an index within the text
  109. * @return the letter, word, or sentence
  110. */
  111. public String getAfterIndex(int part, int index);
  112. /**
  113. * Returns the String before a given index.
  114. *
  115. * @param part the CHARACTER, WORD, or SENTENCE to retrieve
  116. * @param index an index within the text
  117. * @return the letter, word, or sentence
  118. */
  119. public String getBeforeIndex(int part, int index);
  120. /**
  121. * Returns the AttributeSet for a given character at a given index
  122. *
  123. * @param i the zero-based index into the text
  124. * @return the AttributeSet of the character
  125. */
  126. public AttributeSet getCharacterAttribute(int i);
  127. /**
  128. * Returns the start offset within the selected text.
  129. * If there is no selection, but there is
  130. * a caret, the start and end offsets will be the same.
  131. *
  132. * @return the index into the text of the start of the selection
  133. */
  134. public int getSelectionStart();
  135. /**
  136. * Returns the end offset within the selected text.
  137. * If there is no selection, but there is
  138. * a caret, the start and end offsets will be the same.
  139. *
  140. * @return the index into teh text of the end of the selection
  141. */
  142. public int getSelectionEnd();
  143. /**
  144. * Returns the portion of the text that is selected.
  145. *
  146. * @return the String portion of the text that is selected
  147. */
  148. public String getSelectedText();
  149. }