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