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