Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/accessibility/AccessibleText.java
38829 views
/*1* Copyright (c) 1997, 2013, 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;262728import java.util.*;29import java.awt.*;30import javax.swing.text.*;313233/**34* <P>The AccessibleText interface should be implemented by all35* classes that present textual information on the display. This interface36* provides the standard mechanism for an assistive technology to access37* that text via its content, attributes, and spatial location.38* Applications can determine if an object supports the AccessibleText39* interface by first obtaining its AccessibleContext (see {@link Accessible})40* and then calling the {@link AccessibleContext#getAccessibleText} method of41* AccessibleContext. If the return value is not null, the object supports this42* interface.43*44* @see Accessible45* @see Accessible#getAccessibleContext46* @see AccessibleContext47* @see AccessibleContext#getAccessibleText48*49* @author Peter Korn50*/51public interface AccessibleText {5253/**54* Constant used to indicate that the part of the text that should be55* retrieved is a character.56*57* @see #getAtIndex58* @see #getAfterIndex59* @see #getBeforeIndex60*/61public static final int CHARACTER = 1;6263/**64* Constant used to indicate that the part of the text that should be65* retrieved is a word.66*67* @see #getAtIndex68* @see #getAfterIndex69* @see #getBeforeIndex70*/71public static final int WORD = 2;7273/**74* Constant used to indicate that the part of the text that should be75* retrieved is a sentence.76*77* A sentence is a string of words which expresses an assertion,78* a question, a command, a wish, an exclamation, or the performance79* of an action. In English locales, the string usually begins with80* a capital letter and concludes with appropriate end punctuation;81* such as a period, question or exclamation mark. Other locales may82* use different capitalization and/or punctuation.83*84* @see #getAtIndex85* @see #getAfterIndex86* @see #getBeforeIndex87*/88public static final int SENTENCE = 3;8990/**91* Given a point in local coordinates, return the zero-based index92* of the character under that Point. If the point is invalid,93* this method returns -1.94*95* @param p the Point in local coordinates96* @return the zero-based index of the character under Point p; if97* Point is invalid return -1.98*/99public int getIndexAtPoint(Point p);100101/**102* Determines the bounding box of the character at the given103* index into the string. The bounds are returned in local104* coordinates. If the index is invalid an empty rectangle is returned.105*106* @param i the index into the String107* @return the screen coordinates of the character's bounding box,108* if index is invalid return an empty rectangle.109*/110public Rectangle getCharacterBounds(int i);111112/**113* Returns the number of characters (valid indicies)114*115* @return the number of characters116*/117public int getCharCount();118119/**120* Returns the zero-based offset of the caret.121*122* Note: That to the right of the caret will have the same index123* value as the offset (the caret is between two characters).124* @return the zero-based offset of the caret.125*/126public int getCaretPosition();127128/**129* Returns the String at a given index.130*131* @param part the CHARACTER, WORD, or SENTENCE to retrieve132* @param index an index within the text133* @return the letter, word, or sentence134*/135public String getAtIndex(int part, int index);136137/**138* Returns the String after a given index.139*140* @param part the CHARACTER, WORD, or SENTENCE to retrieve141* @param index an index within the text142* @return the letter, word, or sentence143*/144public String getAfterIndex(int part, int index);145146/**147* Returns the String before a given index.148*149* @param part the CHARACTER, WORD, or SENTENCE to retrieve150* @param index an index within the text151* @return the letter, word, or sentence152*/153public String getBeforeIndex(int part, int index);154155/**156* Returns the AttributeSet for a given character at a given index157*158* @param i the zero-based index into the text159* @return the AttributeSet of the character160*/161public AttributeSet getCharacterAttribute(int i);162163/**164* Returns the start offset within the selected text.165* If there is no selection, but there is166* a caret, the start and end offsets will be the same.167*168* @return the index into the text of the start of the selection169*/170public int getSelectionStart();171172/**173* Returns the end offset within the selected text.174* If there is no selection, but there is175* a caret, the start and end offsets will be the same.176*177* @return the index into the text of the end of the selection178*/179public int getSelectionEnd();180181/**182* Returns the portion of the text that is selected.183*184* @return the String portion of the text that is selected185*/186public String getSelectedText();187}188189190