Path: blob/master/src/java.desktop/share/classes/javax/accessibility/AccessibleText.java
41153 views
/*1* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.accessibility;2627import java.awt.Point;28import java.awt.Rectangle;2930import javax.swing.text.AttributeSet;3132/**33* The {@code AccessibleText} interface should be implemented by all classes34* that present textual information on the display. This interface provides the35* standard mechanism for an assistive technology to access that text via its36* content, attributes, and spatial location. Applications can determine if an37* object supports the {@code AccessibleText} interface by first obtaining its38* {@code AccessibleContext} (see {@link Accessible}) and then calling the39* {@link AccessibleContext#getAccessibleText} method of40* {@code AccessibleContext}. If the return value is not {@code null}, the41* object supports this interface.42*43* @author Peter Korn44* @see Accessible45* @see Accessible#getAccessibleContext46* @see AccessibleContext47* @see AccessibleContext#getAccessibleText48*/49public interface AccessibleText {5051/**52* Constant used to indicate that the part of the text that should be53* retrieved is a character.54*55* @see #getAtIndex56* @see #getAfterIndex57* @see #getBeforeIndex58*/59public static final int CHARACTER = 1;6061/**62* Constant used to indicate that the part of the text that should be63* retrieved is a word.64*65* @see #getAtIndex66* @see #getAfterIndex67* @see #getBeforeIndex68*/69public static final int WORD = 2;7071/**72* Constant used to indicate that the part of the text that should be73* retrieved is a sentence.74* <p>75* A sentence is a string of words which expresses an assertion, a question,76* a command, a wish, an exclamation, or the performance of an action. In77* English locales, the string usually begins with a capital letter and78* concludes with appropriate end punctuation; such as a period, question or79* exclamation mark. Other locales may use different capitalization and/or80* punctuation.81*82* @see #getAtIndex83* @see #getAfterIndex84* @see #getBeforeIndex85*/86public static final int SENTENCE = 3;8788/**89* Given a point in local coordinates, return the zero-based index of the90* character under that point. If the point is invalid, this method returns91* -1.92*93* @param p the point in local coordinates94* @return the zero-based index of the character under {@code Point p}; if95* point is invalid return -1.96*/97public int getIndexAtPoint(Point p);9899/**100* Determines the bounding box of the character at the given index into the101* string. The bounds are returned in local coordinates. If the index is102* invalid an empty rectangle is returned.103*104* @param i the index into the string105* @return the screen coordinates of the character's bounding box, if index106* is invalid return an empty rectangle.107*/108public Rectangle getCharacterBounds(int i);109110/**111* Returns the number of characters (valid indicies).112*113* @return the number of characters114*/115public int getCharCount();116117/**118* Returns the zero-based offset of the caret.119* <p>120* Note: That to the right of the caret will have the same index value as121* the offset (the caret is between two characters).122*123* @return the zero-based offset of the caret124*/125public int getCaretPosition();126127/**128* Returns the {@code String} at a given index.129*130* @param part the CHARACTER, WORD, or SENTENCE to retrieve131* @param index an index within the text132* @return the letter, word, or sentence133*/134public String getAtIndex(int part, int index);135136/**137* Returns the {@code String} after a given index.138*139* @param part the CHARACTER, WORD, or SENTENCE to retrieve140* @param index an index within the text141* @return the letter, word, or sentence142*/143public String getAfterIndex(int part, int index);144145/**146* Returns the {@code String} before a given index.147*148* @param part the CHARACTER, WORD, or SENTENCE to retrieve149* @param index an index within the text150* @return the letter, word, or sentence151*/152public String getBeforeIndex(int part, int index);153154/**155* Returns the {@code AttributeSet} for a given character at a given index.156*157* @param i the zero-based index into the text158* @return the {@code AttributeSet} of the character159*/160public AttributeSet getCharacterAttribute(int i);161162/**163* Returns the start offset within the selected text. If there is no164* selection, but there is a caret, the start and end offsets will be the165* same.166*167* @return the index into the text of the start of the selection168*/169public int getSelectionStart();170171/**172* Returns the end offset within the selected text. If there is no173* selection, but there is a caret, the start and end offsets will be the174* same.175*176* @return the index into the text of the end of the selection177*/178public int getSelectionEnd();179180/**181* Returns the portion of the text that is selected.182*183* @return the {@code String} portion of the text that is selected184*/185public String getSelectedText();186}187188189