Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/accessibility/AccessibleContext.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;2627import sun.awt.AWTAccessor;28import sun.awt.AppContext;2930import java.util.Locale;31import java.beans.PropertyChangeListener;32import java.beans.PropertyChangeSupport;33import java.beans.PropertyChangeEvent;34import java.awt.IllegalComponentStateException;3536/**37* AccessibleContext represents the minimum information all accessible objects38* return. This information includes the accessible name, description, role,39* and state of the object, as well as information about its parent and40* children. AccessibleContext also contains methods for41* obtaining more specific accessibility information about a component.42* If the component supports them, these methods will return an object that43* implements one or more of the following interfaces:44* <P><ul>45* <li>{@link AccessibleAction} - the object can perform one or more actions.46* This interface provides the standard mechanism for an assistive47* technology to determine what those actions are and tell the object48* to perform them. Any object that can be manipulated should49* support this interface.50* <li>{@link AccessibleComponent} - the object has a graphical representation.51* This interface provides the standard mechanism for an assistive52* technology to determine and set the graphical representation of the53* object. Any object that is rendered on the screen should support54* this interface.55* <li>{@link AccessibleSelection} - the object allows its children to be56* selected. This interface provides the standard mechanism for an57* assistive technology to determine the currently selected children of the object58* as well as modify its selection set. Any object that has children59* that can be selected should support this interface.60* <li>{@link AccessibleText} - the object presents editable textual information61* on the display. This interface provides the standard mechanism for62* an assistive technology to access that text via its content, attributes,63* and spatial location. Any object that contains editable text should64* support this interface.65* <li>{@link AccessibleValue} - the object supports a numerical value. This66* interface provides the standard mechanism for an assistive technology67* to determine and set the current value of the object, as well as obtain its68* minimum and maximum values. Any object that supports a numerical value69* should support this interface.</ul>70*71*72* @beaninfo73* attribute: isContainer false74* description: Minimal information that all accessible objects return75*7677* @author Peter Korn78* @author Hans Muller79* @author Willie Walker80* @author Lynn Monsanto81*/82public abstract class AccessibleContext {8384/**85* The AppContext that should be used to dispatch events for this86* AccessibleContext87*/88private volatile AppContext targetAppContext;8990static {91AWTAccessor.setAccessibleContextAccessor(new AWTAccessor.AccessibleContextAccessor() {92@Override93public void setAppContext(AccessibleContext accessibleContext, AppContext appContext) {94accessibleContext.targetAppContext = appContext;95}9697@Override98public AppContext getAppContext(AccessibleContext accessibleContext) {99return accessibleContext.targetAppContext;100}101});102}103104/**105* Constant used to determine when the accessibleName property has106* changed. The old value in the PropertyChangeEvent will be the old107* accessibleName and the new value will be the new accessibleName.108*109* @see #getAccessibleName110* @see #addPropertyChangeListener111*/112public static final String ACCESSIBLE_NAME_PROPERTY = "AccessibleName";113114/**115* Constant used to determine when the accessibleDescription property has116* changed. The old value in the PropertyChangeEvent will be the117* old accessibleDescription and the new value will be the new118* accessibleDescription.119*120* @see #getAccessibleDescription121* @see #addPropertyChangeListener122*/123public static final String ACCESSIBLE_DESCRIPTION_PROPERTY = "AccessibleDescription";124125/**126* Constant used to determine when the accessibleStateSet property has127* changed. The old value will be the old AccessibleState and the new128* value will be the new AccessibleState in the accessibleStateSet.129* For example, if a component that supports the vertical and horizontal130* states changes its orientation from vertical to horizontal, the old131* value will be AccessibleState.VERTICAL and the new value will be132* AccessibleState.HORIZONTAL. Please note that either value can also133* be null. For example, when a component changes from being enabled134* to disabled, the old value will be AccessibleState.ENABLED135* and the new value will be null.136*137* @see #getAccessibleStateSet138* @see AccessibleState139* @see AccessibleStateSet140* @see #addPropertyChangeListener141*/142public static final String ACCESSIBLE_STATE_PROPERTY = "AccessibleState";143144/**145* Constant used to determine when the accessibleValue property has146* changed. The old value in the PropertyChangeEvent will be a Number147* representing the old value and the new value will be a Number148* representing the new value149*150* @see #getAccessibleValue151* @see #addPropertyChangeListener152*/153public static final String ACCESSIBLE_VALUE_PROPERTY = "AccessibleValue";154155/**156* Constant used to determine when the accessibleSelection has changed.157* The old and new values in the PropertyChangeEvent are currently158* reserved for future use.159*160* @see #getAccessibleSelection161* @see #addPropertyChangeListener162*/163public static final String ACCESSIBLE_SELECTION_PROPERTY = "AccessibleSelection";164165/**166* Constant used to determine when the accessibleText caret has changed.167* The old value in the PropertyChangeEvent will be an168* integer representing the old caret position, and the new value will169* be an integer representing the new/current caret position.170*171* @see #addPropertyChangeListener172*/173public static final String ACCESSIBLE_CARET_PROPERTY = "AccessibleCaret";174175/**176* Constant used to determine when the visual appearance of the object177* has changed. The old and new values in the PropertyChangeEvent are178* currently reserved for future use.179*180* @see #addPropertyChangeListener181*/182public static final String ACCESSIBLE_VISIBLE_DATA_PROPERTY = "AccessibleVisibleData";183184/**185* Constant used to determine when Accessible children are added/removed186* from the object. If an Accessible child is being added, the old187* value will be null and the new value will be the Accessible child. If an188* Accessible child is being removed, the old value will be the Accessible189* child, and the new value will be null.190*191* @see #addPropertyChangeListener192*/193public static final String ACCESSIBLE_CHILD_PROPERTY = "AccessibleChild";194195/**196* Constant used to determine when the active descendant of a component197* has changed. The active descendant is used for objects such as198* list, tree, and table, which may have transient children. When the199* active descendant has changed, the old value of the property change200* event will be the Accessible representing the previous active child, and201* the new value will be the Accessible representing the current active202* child.203*204* @see #addPropertyChangeListener205*/206public static final String ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY = "AccessibleActiveDescendant";207208/**209* Constant used to indicate that the table caption has changed210* The old value in the PropertyChangeEvent will be an Accessible211* representing the previous table caption and the new value will212* be an Accessible representing the new table caption.213* @see Accessible214* @see AccessibleTable215*/216public static final String ACCESSIBLE_TABLE_CAPTION_CHANGED =217"accessibleTableCaptionChanged";218219/**220* Constant used to indicate that the table summary has changed221* The old value in the PropertyChangeEvent will be an Accessible222* representing the previous table summary and the new value will223* be an Accessible representing the new table summary.224* @see Accessible225* @see AccessibleTable226*/227public static final String ACCESSIBLE_TABLE_SUMMARY_CHANGED =228"accessibleTableSummaryChanged";229230/**231* Constant used to indicate that table data has changed.232* The old value in the PropertyChangeEvent will be null and the233* new value will be an AccessibleTableModelChange representing234* the table change.235* @see AccessibleTable236* @see AccessibleTableModelChange237*/238public static final String ACCESSIBLE_TABLE_MODEL_CHANGED =239"accessibleTableModelChanged";240241/**242* Constant used to indicate that the row header has changed243* The old value in the PropertyChangeEvent will be null and the244* new value will be an AccessibleTableModelChange representing245* the header change.246* @see AccessibleTable247* @see AccessibleTableModelChange248*/249public static final String ACCESSIBLE_TABLE_ROW_HEADER_CHANGED =250"accessibleTableRowHeaderChanged";251252/**253* Constant used to indicate that the row description has changed254* The old value in the PropertyChangeEvent will be null and the255* new value will be an Integer representing the row index.256* @see AccessibleTable257*/258public static final String ACCESSIBLE_TABLE_ROW_DESCRIPTION_CHANGED =259"accessibleTableRowDescriptionChanged";260261/**262* Constant used to indicate that the column header has changed263* The old value in the PropertyChangeEvent will be null and the264* new value will be an AccessibleTableModelChange representing265* the header change.266* @see AccessibleTable267* @see AccessibleTableModelChange268*/269public static final String ACCESSIBLE_TABLE_COLUMN_HEADER_CHANGED =270"accessibleTableColumnHeaderChanged";271272/**273* Constant used to indicate that the column description has changed274* The old value in the PropertyChangeEvent will be null and the275* new value will be an Integer representing the column index.276* @see AccessibleTable277*/278public static final String ACCESSIBLE_TABLE_COLUMN_DESCRIPTION_CHANGED =279"accessibleTableColumnDescriptionChanged";280281/**282* Constant used to indicate that the supported set of actions283* has changed. The old value in the PropertyChangeEvent will284* be an Integer representing the old number of actions supported285* and the new value will be an Integer representing the new286* number of actions supported.287* @see AccessibleAction288*/289public static final String ACCESSIBLE_ACTION_PROPERTY =290"accessibleActionProperty";291292/**293* Constant used to indicate that a hypertext element has received focus.294* The old value in the PropertyChangeEvent will be an Integer295* representing the start index in the document of the previous element296* that had focus and the new value will be an Integer representing297* the start index in the document of the current element that has298* focus. A value of -1 indicates that an element does not or did299* not have focus.300* @see AccessibleHyperlink301*/302public static final String ACCESSIBLE_HYPERTEXT_OFFSET =303"AccessibleHypertextOffset";304305/**306* PropertyChangeEvent which indicates that text has changed.307* <br>308* For text insertion, the oldValue is null and the newValue309* is an AccessibleTextSequence specifying the text that was310* inserted.311* <br>312* For text deletion, the oldValue is an AccessibleTextSequence313* specifying the text that was deleted and the newValue is null.314* <br>315* For text replacement, the oldValue is an AccessibleTextSequence316* specifying the old text and the newValue is an AccessibleTextSequence317* specifying the new text.318*319* @see #getAccessibleText320* @see #addPropertyChangeListener321* @see AccessibleTextSequence322*/323public static final String ACCESSIBLE_TEXT_PROPERTY324= "AccessibleText";325326/**327* PropertyChangeEvent which indicates that a significant change328* has occurred to the children of a component like a tree or text.329* This change notifies the event listener that it needs to330* reacquire the state of the subcomponents. The oldValue is331* null and the newValue is the component whose children have332* become invalid.333*334* @see #getAccessibleText335* @see #addPropertyChangeListener336* @see AccessibleTextSequence337*338* @since 1.5339*/340public static final String ACCESSIBLE_INVALIDATE_CHILDREN =341"accessibleInvalidateChildren";342343/**344* PropertyChangeEvent which indicates that text attributes have changed.345* <br>346* For attribute insertion, the oldValue is null and the newValue347* is an AccessibleAttributeSequence specifying the attributes that were348* inserted.349* <br>350* For attribute deletion, the oldValue is an AccessibleAttributeSequence351* specifying the attributes that were deleted and the newValue is null.352* <br>353* For attribute replacement, the oldValue is an AccessibleAttributeSequence354* specifying the old attributes and the newValue is an355* AccessibleAttributeSequence specifying the new attributes.356*357* @see #getAccessibleText358* @see #addPropertyChangeListener359* @see AccessibleAttributeSequence360*361* @since 1.5362*/363public static final String ACCESSIBLE_TEXT_ATTRIBUTES_CHANGED =364"accessibleTextAttributesChanged";365366/**367* PropertyChangeEvent which indicates that a change has occurred368* in a component's bounds.369* The oldValue is the old component bounds and the newValue is370* the new component bounds.371*372* @see #addPropertyChangeListener373*374* @since 1.5375*/376public static final String ACCESSIBLE_COMPONENT_BOUNDS_CHANGED =377"accessibleComponentBoundsChanged";378379/**380* The accessible parent of this object.381*382* @see #getAccessibleParent383* @see #setAccessibleParent384*/385protected Accessible accessibleParent = null;386387/**388* A localized String containing the name of the object.389*390* @see #getAccessibleName391* @see #setAccessibleName392*/393protected String accessibleName = null;394395/**396* A localized String containing the description of the object.397*398* @see #getAccessibleDescription399* @see #setAccessibleDescription400*/401protected String accessibleDescription = null;402403/**404* Used to handle the listener list for property change events.405*406* @see #addPropertyChangeListener407* @see #removePropertyChangeListener408* @see #firePropertyChangeListener409*/410private PropertyChangeSupport accessibleChangeSupport = null;411412/**413* Used to represent the context's relation set414* @see #getAccessibleRelationSet415*/416private AccessibleRelationSet relationSet417= new AccessibleRelationSet();418419private Object nativeAXResource;420421/**422* Gets the accessibleName property of this object. The accessibleName423* property of an object is a localized String that designates the purpose424* of the object. For example, the accessibleName property of a label425* or button might be the text of the label or button itself. In the426* case of an object that doesn't display its name, the accessibleName427* should still be set. For example, in the case of a text field used428* to enter the name of a city, the accessibleName for the en_US locale429* could be 'city.'430*431* @return the localized name of the object; null if this432* object does not have a name433*434* @see #setAccessibleName435*/436public String getAccessibleName() {437return accessibleName;438}439440/**441* Sets the localized accessible name of this object. Changing the442* name will cause a PropertyChangeEvent to be fired for the443* ACCESSIBLE_NAME_PROPERTY property.444*445* @param s the new localized name of the object.446*447* @see #getAccessibleName448* @see #addPropertyChangeListener449*450* @beaninfo451* preferred: true452* description: Sets the accessible name for the component.453*/454public void setAccessibleName(String s) {455String oldName = accessibleName;456accessibleName = s;457firePropertyChange(ACCESSIBLE_NAME_PROPERTY,oldName,accessibleName);458}459460/**461* Gets the accessibleDescription property of this object. The462* accessibleDescription property of this object is a short localized463* phrase describing the purpose of the object. For example, in the464* case of a 'Cancel' button, the accessibleDescription could be465* 'Ignore changes and close dialog box.'466*467* @return the localized description of the object; null if468* this object does not have a description469*470* @see #setAccessibleDescription471*/472public String getAccessibleDescription() {473return accessibleDescription;474}475476/**477* Sets the accessible description of this object. Changing the478* name will cause a PropertyChangeEvent to be fired for the479* ACCESSIBLE_DESCRIPTION_PROPERTY property.480*481* @param s the new localized description of the object482*483* @see #setAccessibleName484* @see #addPropertyChangeListener485*486* @beaninfo487* preferred: true488* description: Sets the accessible description for the component.489*/490public void setAccessibleDescription(String s) {491String oldDescription = accessibleDescription;492accessibleDescription = s;493firePropertyChange(ACCESSIBLE_DESCRIPTION_PROPERTY,494oldDescription,accessibleDescription);495}496497/**498* Gets the role of this object. The role of the object is the generic499* purpose or use of the class of this object. For example, the role500* of a push button is AccessibleRole.PUSH_BUTTON. The roles in501* AccessibleRole are provided so component developers can pick from502* a set of predefined roles. This enables assistive technologies to503* provide a consistent interface to various tweaked subclasses of504* components (e.g., use AccessibleRole.PUSH_BUTTON for all components505* that act like a push button) as well as distinguish between subclasses506* that behave differently (e.g., AccessibleRole.CHECK_BOX for check boxes507* and AccessibleRole.RADIO_BUTTON for radio buttons).508* <p>Note that the AccessibleRole class is also extensible, so509* custom component developers can define their own AccessibleRole's510* if the set of predefined roles is inadequate.511*512* @return an instance of AccessibleRole describing the role of the object513* @see AccessibleRole514*/515public abstract AccessibleRole getAccessibleRole();516517/**518* Gets the state set of this object. The AccessibleStateSet of an object519* is composed of a set of unique AccessibleStates. A change in the520* AccessibleStateSet of an object will cause a PropertyChangeEvent to521* be fired for the ACCESSIBLE_STATE_PROPERTY property.522*523* @return an instance of AccessibleStateSet containing the524* current state set of the object525* @see AccessibleStateSet526* @see AccessibleState527* @see #addPropertyChangeListener528*/529public abstract AccessibleStateSet getAccessibleStateSet();530531/**532* Gets the Accessible parent of this object.533*534* @return the Accessible parent of this object; null if this535* object does not have an Accessible parent536*/537public Accessible getAccessibleParent() {538return accessibleParent;539}540541/**542* Sets the Accessible parent of this object. This is meant to be used543* only in the situations where the actual component's parent should544* not be treated as the component's accessible parent and is a method545* that should only be called by the parent of the accessible child.546*547* @param a - Accessible to be set as the parent548*/549public void setAccessibleParent(Accessible a) {550accessibleParent = a;551}552553/**554* Gets the 0-based index of this object in its accessible parent.555*556* @return the 0-based index of this object in its parent; -1 if this557* object does not have an accessible parent.558*559* @see #getAccessibleParent560* @see #getAccessibleChildrenCount561* @see #getAccessibleChild562*/563public abstract int getAccessibleIndexInParent();564565/**566* Returns the number of accessible children of the object.567*568* @return the number of accessible children of the object.569*/570public abstract int getAccessibleChildrenCount();571572/**573* Returns the specified Accessible child of the object. The Accessible574* children of an Accessible object are zero-based, so the first child575* of an Accessible child is at index 0, the second child is at index 1,576* and so on.577*578* @param i zero-based index of child579* @return the Accessible child of the object580* @see #getAccessibleChildrenCount581*/582public abstract Accessible getAccessibleChild(int i);583584/**585* Gets the locale of the component. If the component does not have a586* locale, then the locale of its parent is returned.587*588* @return this component's locale. If this component does not have589* a locale, the locale of its parent is returned.590*591* @exception IllegalComponentStateException592* If the Component does not have its own locale and has not yet been593* added to a containment hierarchy such that the locale can be594* determined from the containing parent.595*/596public abstract Locale getLocale() throws IllegalComponentStateException;597598/**599* Adds a PropertyChangeListener to the listener list.600* The listener is registered for all Accessible properties and will601* be called when those properties change.602*603* @see #ACCESSIBLE_NAME_PROPERTY604* @see #ACCESSIBLE_DESCRIPTION_PROPERTY605* @see #ACCESSIBLE_STATE_PROPERTY606* @see #ACCESSIBLE_VALUE_PROPERTY607* @see #ACCESSIBLE_SELECTION_PROPERTY608* @see #ACCESSIBLE_TEXT_PROPERTY609* @see #ACCESSIBLE_VISIBLE_DATA_PROPERTY610*611* @param listener The PropertyChangeListener to be added612*/613public void addPropertyChangeListener(PropertyChangeListener listener) {614if (accessibleChangeSupport == null) {615accessibleChangeSupport = new PropertyChangeSupport(this);616}617accessibleChangeSupport.addPropertyChangeListener(listener);618}619620/**621* Removes a PropertyChangeListener from the listener list.622* This removes a PropertyChangeListener that was registered623* for all properties.624*625* @param listener The PropertyChangeListener to be removed626*/627public void removePropertyChangeListener(PropertyChangeListener listener) {628if (accessibleChangeSupport != null) {629accessibleChangeSupport.removePropertyChangeListener(listener);630}631}632633/**634* Gets the AccessibleAction associated with this object that supports635* one or more actions.636*637* @return AccessibleAction if supported by object; else return null638* @see AccessibleAction639*/640public AccessibleAction getAccessibleAction() {641return null;642}643644/**645* Gets the AccessibleComponent associated with this object that has a646* graphical representation.647*648* @return AccessibleComponent if supported by object; else return null649* @see AccessibleComponent650*/651public AccessibleComponent getAccessibleComponent() {652return null;653}654655/**656* Gets the AccessibleSelection associated with this object which allows its657* Accessible children to be selected.658*659* @return AccessibleSelection if supported by object; else return null660* @see AccessibleSelection661*/662public AccessibleSelection getAccessibleSelection() {663return null;664}665666/**667* Gets the AccessibleText associated with this object presenting668* text on the display.669*670* @return AccessibleText if supported by object; else return null671* @see AccessibleText672*/673public AccessibleText getAccessibleText() {674return null;675}676677/**678* Gets the AccessibleEditableText associated with this object679* presenting editable text on the display.680*681* @return AccessibleEditableText if supported by object; else return null682* @see AccessibleEditableText683* @since 1.4684*/685public AccessibleEditableText getAccessibleEditableText() {686return null;687}688689690/**691* Gets the AccessibleValue associated with this object that supports a692* Numerical value.693*694* @return AccessibleValue if supported by object; else return null695* @see AccessibleValue696*/697public AccessibleValue getAccessibleValue() {698return null;699}700701/**702* Gets the AccessibleIcons associated with an object that has703* one or more associated icons704*705* @return an array of AccessibleIcon if supported by object;706* otherwise return null707* @see AccessibleIcon708* @since 1.3709*/710public AccessibleIcon [] getAccessibleIcon() {711return null;712}713714/**715* Gets the AccessibleRelationSet associated with an object716*717* @return an AccessibleRelationSet if supported by object;718* otherwise return null719* @see AccessibleRelationSet720* @since 1.3721*/722public AccessibleRelationSet getAccessibleRelationSet() {723return relationSet;724}725726/**727* Gets the AccessibleTable associated with an object728*729* @return an AccessibleTable if supported by object;730* otherwise return null731* @see AccessibleTable732* @since 1.3733*/734public AccessibleTable getAccessibleTable() {735return null;736}737738/**739* Support for reporting bound property changes. If oldValue and740* newValue are not equal and the PropertyChangeEvent listener list741* is not empty, then fire a PropertyChange event to each listener.742* In general, this is for use by the Accessible objects themselves743* and should not be called by an application program.744* @param propertyName The programmatic name of the property that745* was changed.746* @param oldValue The old value of the property.747* @param newValue The new value of the property.748* @see java.beans.PropertyChangeSupport749* @see #addPropertyChangeListener750* @see #removePropertyChangeListener751* @see #ACCESSIBLE_NAME_PROPERTY752* @see #ACCESSIBLE_DESCRIPTION_PROPERTY753* @see #ACCESSIBLE_STATE_PROPERTY754* @see #ACCESSIBLE_VALUE_PROPERTY755* @see #ACCESSIBLE_SELECTION_PROPERTY756* @see #ACCESSIBLE_TEXT_PROPERTY757* @see #ACCESSIBLE_VISIBLE_DATA_PROPERTY758*/759public void firePropertyChange(String propertyName,760Object oldValue,761Object newValue) {762if (accessibleChangeSupport != null) {763if (newValue instanceof PropertyChangeEvent) {764PropertyChangeEvent pce = (PropertyChangeEvent)newValue;765accessibleChangeSupport.firePropertyChange(pce);766} else {767accessibleChangeSupport.firePropertyChange(propertyName,768oldValue,769newValue);770}771}772}773}774775776