001    /* AccessibleText.java -- aids in accessibly manipulating text
002       Copyright (C) 2000, 2002, 2004, 2005  Free Software Foundation, Inc.
003    
004    This file is part of GNU Classpath.
005    
006    GNU Classpath is free software; you can redistribute it and/or modify
007    it under the terms of the GNU General Public License as published by
008    the Free Software Foundation; either version 2, or (at your option)
009    any later version.
010    
011    GNU Classpath is distributed in the hope that it will be useful, but
012    WITHOUT ANY WARRANTY; without even the implied warranty of
013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014    General Public License for more details.
015    
016    You should have received a copy of the GNU General Public License
017    along with GNU Classpath; see the file COPYING.  If not, write to the
018    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019    02110-1301 USA.
020    
021    Linking this library statically or dynamically with other modules is
022    making a combined work based on this library.  Thus, the terms and
023    conditions of the GNU General Public License cover the whole
024    combination.
025    
026    As a special exception, the copyright holders of this library give you
027    permission to link this library with independent modules to produce an
028    executable, regardless of the license terms of these independent
029    modules, and to copy and distribute the resulting executable under
030    terms of your choice, provided that you also meet, for each linked
031    independent module, the terms and conditions of the license of that
032    module.  An independent module is a module which is not derived from
033    or based on this library.  If you modify this library, you may extend
034    this exception to your version of the library, but you are not
035    obligated to do so.  If you do not wish to do so, delete this
036    exception statement from your version. */
037    
038    
039    package javax.accessibility;
040    
041    import java.awt.Point;
042    import java.awt.Rectangle;
043    
044    import javax.swing.text.AttributeSet;
045    
046    /**
047     * Objects which present textual information on the display should implement
048     * this interface.  Accessibility software can use the implementations of
049     * this interface to change the attributes and spacial location of the text.
050     *
051     * <p>The <code>AccessibleContext.getAccessibleText()</code> method
052     * should return <code>null</code> if an object does not implement this
053     * interface.
054     *
055     * @author Eric Blake (ebb9@email.byu.edu)
056     * @see Accessible
057     * @see AccessibleContext
058     * @see AccessibleContext#getAccessibleText()
059     * @since 1.2
060     * @status updated to 1.4
061     */
062    public interface AccessibleText
063    {
064      /**
065       * Constant designating that the next selection should be a character.
066       *
067       * @see #getAtIndex(int, int)
068       * @see #getAfterIndex(int, int)
069       * @see #getBeforeIndex(int, int)
070       */
071      int CHARACTER = 1;
072    
073      /**
074       * Constant designating that the next selection should be a word.
075       *
076       * @see #getAtIndex(int, int)
077       * @see #getAfterIndex(int, int)
078       * @see #getBeforeIndex(int, int)
079       */
080      int WORD = 2;
081    
082      /**
083       * Constant designating that the next selection should be a sentence.
084       *
085       * @see #getAtIndex(int, int)
086       * @see #getAfterIndex(int, int)
087       * @see #getBeforeIndex(int, int)
088       */
089      int SENTENCE = 3;
090    
091      /**
092       * Given a point in the coordinate system of this object, return the
093       * 0-based index of the character at that point, or -1 if there is none.
094       *
095       * @param point the point to look at
096       * @return the character index, or -1
097       */
098      int getIndexAtPoint(Point point);
099    
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       */
107      Rectangle getCharacterBounds(int index);
108    
109      /**
110       * Return the number of characters.
111       *
112       * @return the character count
113       */
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       */
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       */
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       */
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       */
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       */
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       */
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       */
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       */
184      String getSelectedText();
185    } // interface AccessibleText