001 /*
002 * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.accessibility;
027
028 import java.util.*;
029 import java.awt.*;
030 import javax.swing.text.*;
031
032 /**
033 * <P>The AccessibleText interface should be implemented by all
034 * classes that present textual information on the display. This interface
035 * provides the standard mechanism for an assistive technology to access
036 * that text via its content, attributes, and spatial location.
037 * Applications can determine if an object supports the AccessibleText
038 * interface by first obtaining its AccessibleContext (see {@link Accessible})
039 * and then calling the {@link AccessibleContext#getAccessibleText} method of
040 * AccessibleContext. If the return value is not null, the object supports this
041 * interface.
042 *
043 * @see Accessible
044 * @see Accessible#getAccessibleContext
045 * @see AccessibleContext
046 * @see AccessibleContext#getAccessibleText
047 *
048 * @version 1.36 05/05/07
049 * @author Peter Korn
050 */
051 public interface AccessibleText {
052
053 /**
054 * Constant used to indicate that the part of the text that should be
055 * retrieved is a character.
056 *
057 * @see #getAtIndex
058 * @see #getAfterIndex
059 * @see #getBeforeIndex
060 */
061 public static final int CHARACTER = 1;
062
063 /**
064 * Constant used to indicate that the part of the text that should be
065 * retrieved is a word.
066 *
067 * @see #getAtIndex
068 * @see #getAfterIndex
069 * @see #getBeforeIndex
070 */
071 public static final int WORD = 2;
072
073 /**
074 * Constant used to indicate that the part of the text that should be
075 * retrieved is a sentence.
076 *
077 * A sentence is a string of words which expresses an assertion,
078 * a question, a command, a wish, an exclamation, or the performance
079 * of an action. In English locales, the string usually begins with
080 * a capital letter and concludes with appropriate end punctuation;
081 * such as a period, question or exclamation mark. Other locales may
082 * use different capitalization and/or punctuation.
083 *
084 * @see #getAtIndex
085 * @see #getAfterIndex
086 * @see #getBeforeIndex
087 */
088 public static final int SENTENCE = 3;
089
090 /**
091 * Given a point in local coordinates, return the zero-based index
092 * of the character under that Point. If the point is invalid,
093 * this method returns -1.
094 *
095 * @param p the Point in local coordinates
096 * @return the zero-based index of the character under Point p; if
097 * Point is invalid return -1.
098 */
099 public int getIndexAtPoint(Point p);
100
101 /**
102 * Determines the bounding box of the character at the given
103 * index into the string. The bounds are returned in local
104 * coordinates. If the index is invalid an empty rectangle is returned.
105 *
106 * @param i the index into the String
107 * @return the screen coordinates of the character's bounding box,
108 * if index is invalid return an empty rectangle.
109 */
110 public Rectangle getCharacterBounds(int i);
111
112 /**
113 * Returns the number of characters (valid indicies)
114 *
115 * @return the number of characters
116 */
117 public int getCharCount();
118
119 /**
120 * Returns the zero-based offset of the caret.
121 *
122 * Note: That to the right of the caret will have the same index
123 * value as the offset (the caret is between two characters).
124 * @return the zero-based offset of the caret.
125 */
126 public int getCaretPosition();
127
128 /**
129 * Returns the String at a given index.
130 *
131 * @param part the CHARACTER, WORD, or SENTENCE to retrieve
132 * @param index an index within the text
133 * @return the letter, word, or sentence
134 */
135 public String getAtIndex(int part, int index);
136
137 /**
138 * Returns the String after a given index.
139 *
140 * @param part the CHARACTER, WORD, or SENTENCE to retrieve
141 * @param index an index within the text
142 * @return the letter, word, or sentence
143 */
144 public String getAfterIndex(int part, int index);
145
146 /**
147 * Returns the String before a given index.
148 *
149 * @param part the CHARACTER, WORD, or SENTENCE to retrieve
150 * @param index an index within the text
151 * @return the letter, word, or sentence
152 */
153 public String getBeforeIndex(int part, int index);
154
155 /**
156 * Returns the AttributeSet for a given character at a given index
157 *
158 * @param i the zero-based index into the text
159 * @return the AttributeSet of the character
160 */
161 public AttributeSet getCharacterAttribute(int i);
162
163 /**
164 * Returns the start offset within the selected text.
165 * If there is no selection, but there is
166 * a caret, the start and end offsets will be the same.
167 *
168 * @return the index into the text of the start of the selection
169 */
170 public int getSelectionStart();
171
172 /**
173 * Returns the end offset within the selected text.
174 * If there is no selection, but there is
175 * a caret, the start and end offsets will be the same.
176 *
177 * @return the index into teh text of the end of the selection
178 */
179 public int getSelectionEnd();
180
181 /**
182 * Returns the portion of the text that is selected.
183 *
184 * @return the String portion of the text that is selected
185 */
186 public String getSelectedText();
187 }
|