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