jdk/src/share/classes/javax/accessibility/AccessibleContext.java

Print this page




  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.accessibility;
  27 
  28 import sun.awt.AWTAccessor;
  29 import sun.awt.AppContext;
  30 
  31 import java.util.Locale;


  32 import java.beans.PropertyChangeListener;
  33 import java.beans.PropertyChangeSupport;
  34 import java.beans.PropertyChangeEvent;
  35 import java.awt.IllegalComponentStateException;
  36 


  37 /**
  38  * AccessibleContext represents the minimum information all accessible objects
  39  * return.  This information includes the accessible name, description, role,
  40  * and state of the object, as well as information about its parent and
  41  * children.  AccessibleContext also contains methods for
  42  * obtaining more specific accessibility information about a component.
  43  * If the component supports them, these methods will return an object that
  44  * implements one or more of the following interfaces:
  45  * <ul>
  46  * <li>{@link AccessibleAction} - the object can perform one or more actions.
  47  * This interface provides the standard mechanism for an assistive
  48  * technology to determine what those actions are and tell the object
  49  * to perform them.  Any object that can be manipulated should
  50  * support this interface.
  51  * <li>{@link AccessibleComponent} - the object has a graphical representation.
  52  * This interface provides the standard mechanism for an assistive
  53  * technology to determine and set the graphical representation of the
  54  * object.  Any object that is rendered on the screen should support
  55  * this interface.
  56  * <li>{@link  AccessibleSelection} - the object allows its children to be
  57  * selected.  This interface provides the standard mechanism for an
  58  * assistive technology to determine the currently selected children of the object
  59  * as well as modify its selection set.  Any object that has children
  60  * that can be selected should support this interface.
  61  * <li>{@link AccessibleText} - the object presents editable textual information
  62  * on the display.  This interface provides the standard mechanism for
  63  * an assistive technology to access that text via its content, attributes,
  64  * and spatial location.  Any object that contains editable text should
  65  * support this interface.
  66  * <li>{@link AccessibleValue} - the object supports a numerical value.  This
  67  * interface provides the standard mechanism for an assistive technology
  68  * to determine and set the current value of the object, as well as obtain its
  69  * minimum and maximum values.  Any object that supports a numerical value
  70  * should support this interface.</ul>
  71  *
  72  *
  73  * @beaninfo
  74  *   attribute: isContainer false
  75  * description: Minimal information that all accessible objects return
  76  *
  77 
  78  * @author      Peter Korn
  79  * @author      Hans Muller
  80  * @author      Willie Walker
  81  * @author      Lynn Monsanto
  82  */


  83 public abstract class AccessibleContext {
  84 
  85     /**
  86      * The AppContext that should be used to dispatch events for this
  87      * AccessibleContext
  88      */
  89     private volatile AppContext targetAppContext;
  90 
  91     static {
  92         AWTAccessor.setAccessibleContextAccessor(new AWTAccessor.AccessibleContextAccessor() {
  93             @Override
  94             public void setAppContext(AccessibleContext accessibleContext, AppContext appContext) {
  95                 accessibleContext.targetAppContext = appContext;
  96             }
  97 
  98             @Override
  99             public AppContext getAppContext(AccessibleContext accessibleContext) {
 100                 return accessibleContext.targetAppContext;
 101             }
 102         });


 430      * could be 'city.'
 431      *
 432      * @return the localized name of the object; null if this
 433      * object does not have a name
 434      *
 435      * @see #setAccessibleName
 436      */
 437     public String getAccessibleName() {
 438         return accessibleName;
 439     }
 440 
 441     /**
 442      * Sets the localized accessible name of this object.  Changing the
 443      * name will cause a PropertyChangeEvent to be fired for the
 444      * ACCESSIBLE_NAME_PROPERTY property.
 445      *
 446      * @param s the new localized name of the object.
 447      *
 448      * @see #getAccessibleName
 449      * @see #addPropertyChangeListener
 450      *
 451      * @beaninfo
 452      *    preferred:   true
 453      *    description: Sets the accessible name for the component.
 454      */


 455     public void setAccessibleName(String s) {
 456         String oldName = accessibleName;
 457         accessibleName = s;
 458         firePropertyChange(ACCESSIBLE_NAME_PROPERTY,oldName,accessibleName);
 459     }
 460 
 461     /**
 462      * Gets the accessibleDescription property of this object.  The
 463      * accessibleDescription property of this object is a short localized
 464      * phrase describing the purpose of the object.  For example, in the
 465      * case of a 'Cancel' button, the accessibleDescription could be
 466      * 'Ignore changes and close dialog box.'
 467      *
 468      * @return the localized description of the object; null if
 469      * this object does not have a description
 470      *
 471      * @see #setAccessibleDescription
 472      */
 473     public String getAccessibleDescription() {
 474         return accessibleDescription;
 475     }
 476 
 477     /**
 478      * Sets the accessible description of this object.  Changing the
 479      * name will cause a PropertyChangeEvent to be fired for the
 480      * ACCESSIBLE_DESCRIPTION_PROPERTY property.
 481      *
 482      * @param s the new localized description of the object
 483      *
 484      * @see #setAccessibleName
 485      * @see #addPropertyChangeListener
 486      *
 487      * @beaninfo
 488      *    preferred:   true
 489      *    description: Sets the accessible description for the component.
 490      */


 491     public void setAccessibleDescription(String s) {
 492         String oldDescription = accessibleDescription;
 493         accessibleDescription = s;
 494         firePropertyChange(ACCESSIBLE_DESCRIPTION_PROPERTY,
 495                            oldDescription,accessibleDescription);
 496     }
 497 
 498     /**
 499      * Gets the role of this object.  The role of the object is the generic
 500      * purpose or use of the class of this object.  For example, the role
 501      * of a push button is AccessibleRole.PUSH_BUTTON.  The roles in
 502      * AccessibleRole are provided so component developers can pick from
 503      * a set of predefined roles.  This enables assistive technologies to
 504      * provide a consistent interface to various tweaked subclasses of
 505      * components (e.g., use AccessibleRole.PUSH_BUTTON for all components
 506      * that act like a push button) as well as distinguish between subclasses
 507      * that behave differently (e.g., AccessibleRole.CHECK_BOX for check boxes
 508      * and AccessibleRole.RADIO_BUTTON for radio buttons).
 509      * <p>Note that the AccessibleRole class is also extensible, so
 510      * custom component developers can define their own AccessibleRole's




  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.accessibility;
  27 
  28 import sun.awt.AWTAccessor;
  29 import sun.awt.AppContext;
  30 
  31 import java.util.Locale;
  32 import java.beans.JavaBean;
  33 import java.beans.BeanProperty;
  34 import java.beans.PropertyChangeListener;
  35 import java.beans.PropertyChangeSupport;
  36 import java.beans.PropertyChangeEvent;
  37 import java.awt.IllegalComponentStateException;
  38 
  39 import javax.swing.SwingContainer;
  40 
  41 /**
  42  * AccessibleContext represents the minimum information all accessible objects
  43  * return.  This information includes the accessible name, description, role,
  44  * and state of the object, as well as information about its parent and
  45  * children.  AccessibleContext also contains methods for
  46  * obtaining more specific accessibility information about a component.
  47  * If the component supports them, these methods will return an object that
  48  * implements one or more of the following interfaces:
  49  * <ul>
  50  * <li>{@link AccessibleAction} - the object can perform one or more actions.
  51  * This interface provides the standard mechanism for an assistive
  52  * technology to determine what those actions are and tell the object
  53  * to perform them.  Any object that can be manipulated should
  54  * support this interface.
  55  * <li>{@link AccessibleComponent} - the object has a graphical representation.
  56  * This interface provides the standard mechanism for an assistive
  57  * technology to determine and set the graphical representation of the
  58  * object.  Any object that is rendered on the screen should support
  59  * this interface.
  60  * <li>{@link  AccessibleSelection} - the object allows its children to be
  61  * selected.  This interface provides the standard mechanism for an
  62  * assistive technology to determine the currently selected children of the object
  63  * as well as modify its selection set.  Any object that has children
  64  * that can be selected should support this interface.
  65  * <li>{@link AccessibleText} - the object presents editable textual information
  66  * on the display.  This interface provides the standard mechanism for
  67  * an assistive technology to access that text via its content, attributes,
  68  * and spatial location.  Any object that contains editable text should
  69  * support this interface.
  70  * <li>{@link AccessibleValue} - the object supports a numerical value.  This
  71  * interface provides the standard mechanism for an assistive technology
  72  * to determine and set the current value of the object, as well as obtain its
  73  * minimum and maximum values.  Any object that supports a numerical value
  74  * should support this interface.</ul>
  75  *






  76  * @author      Peter Korn
  77  * @author      Hans Muller
  78  * @author      Willie Walker
  79  * @author      Lynn Monsanto
  80  */
  81 @JavaBean(description = "Minimal information that all accessible objects return")
  82 @SwingContainer(false)
  83 public abstract class AccessibleContext {
  84 
  85     /**
  86      * The AppContext that should be used to dispatch events for this
  87      * AccessibleContext
  88      */
  89     private volatile AppContext targetAppContext;
  90 
  91     static {
  92         AWTAccessor.setAccessibleContextAccessor(new AWTAccessor.AccessibleContextAccessor() {
  93             @Override
  94             public void setAppContext(AccessibleContext accessibleContext, AppContext appContext) {
  95                 accessibleContext.targetAppContext = appContext;
  96             }
  97 
  98             @Override
  99             public AppContext getAppContext(AccessibleContext accessibleContext) {
 100                 return accessibleContext.targetAppContext;
 101             }
 102         });


 430      * could be 'city.'
 431      *
 432      * @return the localized name of the object; null if this
 433      * object does not have a name
 434      *
 435      * @see #setAccessibleName
 436      */
 437     public String getAccessibleName() {
 438         return accessibleName;
 439     }
 440 
 441     /**
 442      * Sets the localized accessible name of this object.  Changing the
 443      * name will cause a PropertyChangeEvent to be fired for the
 444      * ACCESSIBLE_NAME_PROPERTY property.
 445      *
 446      * @param s the new localized name of the object.
 447      *
 448      * @see #getAccessibleName
 449      * @see #addPropertyChangeListener




 450      */
 451     @BeanProperty(preferred = true, description
 452             = "Sets the accessible name for the component.")
 453     public void setAccessibleName(String s) {
 454         String oldName = accessibleName;
 455         accessibleName = s;
 456         firePropertyChange(ACCESSIBLE_NAME_PROPERTY,oldName,accessibleName);
 457     }
 458 
 459     /**
 460      * Gets the accessibleDescription property of this object.  The
 461      * accessibleDescription property of this object is a short localized
 462      * phrase describing the purpose of the object.  For example, in the
 463      * case of a 'Cancel' button, the accessibleDescription could be
 464      * 'Ignore changes and close dialog box.'
 465      *
 466      * @return the localized description of the object; null if
 467      * this object does not have a description
 468      *
 469      * @see #setAccessibleDescription
 470      */
 471     public String getAccessibleDescription() {
 472         return accessibleDescription;
 473     }
 474 
 475     /**
 476      * Sets the accessible description of this object.  Changing the
 477      * name will cause a PropertyChangeEvent to be fired for the
 478      * ACCESSIBLE_DESCRIPTION_PROPERTY property.
 479      *
 480      * @param s the new localized description of the object
 481      *
 482      * @see #setAccessibleName
 483      * @see #addPropertyChangeListener




 484      */
 485     @BeanProperty(preferred = true, description
 486             = "Sets the accessible description for the component.")
 487     public void setAccessibleDescription(String s) {
 488         String oldDescription = accessibleDescription;
 489         accessibleDescription = s;
 490         firePropertyChange(ACCESSIBLE_DESCRIPTION_PROPERTY,
 491                            oldDescription,accessibleDescription);
 492     }
 493 
 494     /**
 495      * Gets the role of this object.  The role of the object is the generic
 496      * purpose or use of the class of this object.  For example, the role
 497      * of a push button is AccessibleRole.PUSH_BUTTON.  The roles in
 498      * AccessibleRole are provided so component developers can pick from
 499      * a set of predefined roles.  This enables assistive technologies to
 500      * provide a consistent interface to various tweaked subclasses of
 501      * components (e.g., use AccessibleRole.PUSH_BUTTON for all components
 502      * that act like a push button) as well as distinguish between subclasses
 503      * that behave differently (e.g., AccessibleRole.CHECK_BOX for check boxes
 504      * and AccessibleRole.RADIO_BUTTON for radio buttons).
 505      * <p>Note that the AccessibleRole class is also extensible, so
 506      * custom component developers can define their own AccessibleRole's