AccessibleText.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /* AccessibleText.java -- aids in accessibly manipulating text
  2. Copyright (C) 2000, 2002, 2004, 2005 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package javax.accessibility;
  32. import java.awt.Point;
  33. import java.awt.Rectangle;
  34. import javax.swing.text.AttributeSet;
  35. /**
  36. * Objects which present textual information on the display should implement
  37. * this interface. Accessibility software can use the implementations of
  38. * this interface to change the attributes and spacial location of the text.
  39. *
  40. * <p>The <code>AccessibleContext.getAccessibleText()</code> method
  41. * should return <code>null</code> if an object does not implement this
  42. * interface.
  43. *
  44. * @author Eric Blake (ebb9@email.byu.edu)
  45. * @see Accessible
  46. * @see AccessibleContext
  47. * @see AccessibleContext#getAccessibleText()
  48. * @since 1.2
  49. * @status updated to 1.4
  50. */
  51. public interface AccessibleText
  52. {
  53. /**
  54. * Constant designating that the next selection should be a character.
  55. *
  56. * @see #getAtIndex(int, int)
  57. * @see #getAfterIndex(int, int)
  58. * @see #getBeforeIndex(int, int)
  59. */
  60. int CHARACTER = 1;
  61. /**
  62. * Constant designating that the next selection should be a word.
  63. *
  64. * @see #getAtIndex(int, int)
  65. * @see #getAfterIndex(int, int)
  66. * @see #getBeforeIndex(int, int)
  67. */
  68. int WORD = 2;
  69. /**
  70. * Constant designating that the next selection should be a sentence.
  71. *
  72. * @see #getAtIndex(int, int)
  73. * @see #getAfterIndex(int, int)
  74. * @see #getBeforeIndex(int, int)
  75. */
  76. int SENTENCE = 3;
  77. /**
  78. * Given a point in the coordinate system of this object, return the
  79. * 0-based index of the character at that point, or -1 if there is none.
  80. *
  81. * @param point the point to look at
  82. * @return the character index, or -1
  83. */
  84. int getIndexAtPoint(Point point);
  85. /**
  86. * Determines the bounding box of the indexed character. Returns an empty
  87. * rectangle if the index is out of bounds.
  88. *
  89. * @param index the 0-based character index
  90. * @return the bounding box, may be empty
  91. */
  92. Rectangle getCharacterBounds(int index);
  93. /**
  94. * Return the number of characters.
  95. *
  96. * @return the character count
  97. */
  98. int getCharCount();
  99. /**
  100. * Return the offset of the character. The offset matches the index of the
  101. * character to the right, since the carat lies between characters.
  102. *
  103. * @return the 0-based caret position
  104. */
  105. int getCaretPosition();
  106. /**
  107. * Returns the section of text at the index, or null if the index or part
  108. * is invalid.
  109. *
  110. * @param part {@link #CHARACTER}, {@link #WORD}, or {@link #SENTENCE}
  111. * @param index the 0-based character index
  112. * @return the selection of text at that index, or null
  113. */
  114. String getAtIndex(int part, int index);
  115. /**
  116. * Returns the section of text after the index, or null if the index or part
  117. * is invalid.
  118. *
  119. * @param part {@link #CHARACTER}, {@link #WORD}, or {@link #SENTENCE}
  120. * @param index the 0-based character index
  121. * @return the selection of text after that index, or null
  122. */
  123. String getAfterIndex(int part, int index);
  124. /**
  125. * Returns the section of text before the index, or null if the index or part
  126. * is invalid.
  127. *
  128. * @param part {@link #CHARACTER}, {@link #WORD}, or {@link #SENTENCE}
  129. * @param index the 0-based character index
  130. * @return the selection of text before that index, or null
  131. */
  132. String getBeforeIndex(int part, int index);
  133. /**
  134. * Returns the attributes of a character at an index, or null if the index
  135. * is out of bounds.
  136. *
  137. * @param index the 0-based character index
  138. * @return the character's attributes
  139. */
  140. AttributeSet getCharacterAttribute(int index);
  141. /**
  142. * Returns the start index of the selection. If there is no selection, this
  143. * is the same as the caret location.
  144. *
  145. * @return the 0-based character index of the selection start
  146. */
  147. int getSelectionStart();
  148. /**
  149. * Returns the end index of the selection. If there is no selection, this
  150. * is the same as the caret location.
  151. *
  152. * @return the 0-based character index of the selection end
  153. */
  154. int getSelectionEnd();
  155. /**
  156. * Returns the selected text. This may be null or "" if no text is selected.
  157. *
  158. * @return the selected text
  159. */
  160. String getSelectedText();
  161. } // interface AccessibleText