1. /*
  2. * @(#)AccessibleContext.java 1.39 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.accessibility;
  8. import java.util.Locale;
  9. import java.beans.PropertyChangeListener;
  10. import java.beans.PropertyChangeSupport;
  11. import java.beans.PropertyChangeEvent;
  12. import java.awt.IllegalComponentStateException;
  13. /**
  14. * AccessibleContext represents the minimum information all accessible objects
  15. * return. This information includes the accessible name, description, role,
  16. * and state of the object, as well as information about its parent and
  17. * children. AccessibleContext also contains methods for
  18. * obtaining more specific accessibility information about a component.
  19. * If the component supports them, these methods will return an object that
  20. * implements one or more of the following interfaces:
  21. * <P><ul>
  22. * <li>{@link AccessibleAction} - the object can perform one or more actions.
  23. * This interface provides the standard mechanism for an assistive
  24. * technology to determine what those actions are and tell the object
  25. * to perform them. Any object that can be manipulated should
  26. * support this interface.
  27. * <li>{@link AccessibleComponent} - the object has a graphical representation.
  28. * This interface provides the standard mechanism for an assistive
  29. * technology to determine and set the graphical representation of the
  30. * object. Any object that is rendered on the screen should support
  31. * this interface.
  32. * <li>{@link AccessibleSelection} - the object allows its children to be
  33. * selected. This interface provides the standard mechanism for an
  34. * assistive technology to determine the currently selected children of the object
  35. * as well as modify its selection set. Any object that has children
  36. * that can be selected should support this interface.
  37. * <li>{@link AccessibleText} - the object presents editable textual information
  38. * on the display. This interface provides the standard mechanism for
  39. * an assistive technology to access that text via its content, attributes,
  40. * and spatial location. Any object that contains editable text should
  41. * support this interface.
  42. * <li>{@link AccessibleValue} - the object supports a numerical value. This
  43. * interface provides the standard mechanism for an assistive technology
  44. * to determine and set the current value of the object, as well as obtain its
  45. * minimum and maximum values. Any object that supports a numerical value
  46. * should support this interface.</ul>
  47. *
  48. *
  49. * @beaninfo
  50. * attribute: isContainer false
  51. * description: Minimal information that all accessible objects return
  52. *
  53. * @version 1.29 10/05/99
  54. * @author Peter Korn
  55. * @author Hans Muller
  56. * @author Willie Walker
  57. * @author Lynn Monsanto
  58. */
  59. public abstract class AccessibleContext {
  60. /**
  61. * Constant used to determine when the accessibleName property has
  62. * changed. The old value in the PropertyChangeEvent will be the old
  63. * accessibleName and the new value will be the new accessibleName.
  64. *
  65. * @see #getAccessibleName
  66. * @see #addPropertyChangeListener
  67. */
  68. public static final String ACCESSIBLE_NAME_PROPERTY = "AccessibleName";
  69. /**
  70. * Constant used to determine when the accessibleDescription property has
  71. * changed. The old value in the PropertyChangeEvent will be the
  72. * old accessibleDescription and the new value will be the new
  73. * accessibleDescription.
  74. *
  75. * @see #getAccessibleDescription
  76. * @see #addPropertyChangeListener
  77. */
  78. public static final String ACCESSIBLE_DESCRIPTION_PROPERTY = "AccessibleDescription";
  79. /**
  80. * Constant used to determine when the accessibleStateSet property has
  81. * changed. The old value will be the old AccessibleState and the new
  82. * value will be the new AccessibleState in the accessibleStateSet.
  83. * For example, if a component that supports the vertical and horizontal
  84. * states changes its orientation from vertical to horizontal, the old
  85. * value will be AccessibleState.VERTICAL and the new value will be
  86. * AccessibleState.HORIZONTAL. Please note that either value can also
  87. * be null. For example, when a component changes from being enabled
  88. * to disabled, the old value will be AccessibleState.ENABLED
  89. * and the new value will be null.
  90. *
  91. * @see #getAccessibleStateSet
  92. * @see AccessibleState
  93. * @see AccessibleStateSet
  94. * @see #addPropertyChangeListener
  95. */
  96. public static final String ACCESSIBLE_STATE_PROPERTY = "AccessibleState";
  97. /**
  98. * Constant used to determine when the accessibleValue property has
  99. * changed. The old value in the PropertyChangeEvent will be a Number
  100. * representing the old value and the new value will be a Number
  101. * representing the new value
  102. *
  103. * @see #getAccessibleValue
  104. * @see #addPropertyChangeListener
  105. */
  106. public static final String ACCESSIBLE_VALUE_PROPERTY = "AccessibleValue";
  107. /**
  108. * Constant used to determine when the accessibleSelection has changed.
  109. * The old and new values in the PropertyChangeEvent are currently
  110. * reserved for future use.
  111. *
  112. * @see #getAccessibleSelection
  113. * @see #addPropertyChangeListener
  114. */
  115. public static final String ACCESSIBLE_SELECTION_PROPERTY = "AccessibleSelection";
  116. /**
  117. * Constant used to determine when the accessibleText has changed.
  118. * The old and new values in the PropertyChangeEvent are currently
  119. * reserved for future use.
  120. *
  121. * @see #getAccessibleText
  122. * @see #addPropertyChangeListener
  123. */
  124. public static final String ACCESSIBLE_TEXT_PROPERTY = "AccessibleText";
  125. /**
  126. * Constant used to determine when the accessibleText caret has changed.
  127. * The old value in the PropertyChangeEvent will be an
  128. * integer representing the old caret position, and the new value will
  129. * be an integer representing the new/current caret position.
  130. *
  131. * @see #addPropertyChangeListener
  132. */
  133. public static final String ACCESSIBLE_CARET_PROPERTY = "AccessibleCaret";
  134. /**
  135. * Constant used to determine when the visual appearance of the object
  136. * has changed. The old and new values in the PropertyChangeEvent are
  137. * currently reserved for future use.
  138. *
  139. * @see #addPropertyChangeListener
  140. */
  141. public static final String ACCESSIBLE_VISIBLE_DATA_PROPERTY = "AccessibleVisibleData";
  142. /**
  143. * Constant used to determine when Accessible children are added/removed
  144. * from the object. If an Accessible child is being added, the old
  145. * value will be null and the new value will be the Accessible child. If an
  146. * Accessible child is being removed, the old value will be the Accessible
  147. * child, and the new value will be null.
  148. *
  149. * @see #addPropertyChangeListener
  150. */
  151. public static final String ACCESSIBLE_CHILD_PROPERTY = "AccessibleChild";
  152. /**
  153. * Constant used to determine when the active descendant of a component
  154. * has changed. The active descendant is used for objects such as
  155. * list, tree, and table, which may have transient children. When the
  156. * active descendant has changed, the old value of the property change
  157. * event will be the Accessible representing the previous active child, and
  158. * the new value will be the Accessible representing the current active
  159. * child.
  160. *
  161. * @see #addPropertyChangeListener
  162. */
  163. public static final String ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY = "AccessibleActiveDescendant";
  164. /**
  165. * Constant used to indicate that the table caption has changed
  166. * The old value in the PropertyChangeEvent will be an Accessible
  167. * representing the previous table caption and the new value will
  168. * be an Accessible representing the new table caption.
  169. * @see Accessible
  170. * @see AccessibleTable
  171. */
  172. public static final String ACCESSIBLE_TABLE_CAPTION_CHANGED =
  173. "accessibleTableCaptionChanged";
  174. /**
  175. * Constant used to indicate that the table summary has changed
  176. * The old value in the PropertyChangeEvent will be an Accessible
  177. * representing the previous table summary and the new value will
  178. * be an Accessible representing the new table summary.
  179. * @see Accessible
  180. * @see AccessibleTable
  181. */
  182. public static final String ACCESSIBLE_TABLE_SUMMARY_CHANGED =
  183. "accessibleTableSummaryChanged";
  184. /**
  185. * Constant used to indicate that table data has changed.
  186. * The old value in the PropertyChangeEvent will be null and the
  187. * new value will be an AccessibleTableModelChange representing
  188. * the table change.
  189. * @see AccessibleTable
  190. * @see AccessibleTableModelChange
  191. */
  192. public static final String ACCESSIBLE_TABLE_MODEL_CHANGED =
  193. "accessibleTableModelChanged";
  194. /**
  195. * Constant used to indicate that the row header has changed
  196. * The old value in the PropertyChangeEvent will be null and the
  197. * new value will be an AccessibleTableModelChange representing
  198. * the header change.
  199. * @see AccessibleTable
  200. * @see AccessibleTableModelChange
  201. */
  202. public static final String ACCESSIBLE_TABLE_ROW_HEADER_CHANGED =
  203. "accessibleTableRowHeaderChanged";
  204. /**
  205. * Constant used to indicate that the row description has changed
  206. * The old value in the PropertyChangeEvent will be null and the
  207. * new value will be an Integer representing the row index.
  208. * @see AccessibleTable
  209. */
  210. public static final String ACCESSIBLE_TABLE_ROW_DESCRIPTION_CHANGED =
  211. "accessibleTableRowDescriptionChanged";
  212. /**
  213. * Constant used to indicate that the column header has changed
  214. * The old value in the PropertyChangeEvent will be null and the
  215. * new value will be an AccessibleTableModelChange representing
  216. * the header change.
  217. * @see AccessibleTable
  218. * @see AccessibleTableModelChange
  219. */
  220. public static final String ACCESSIBLE_TABLE_COLUMN_HEADER_CHANGED =
  221. "accessibleTableColumnHeaderChanged";
  222. /**
  223. * Constant used to indicate that the column description has changed
  224. * The old value in the PropertyChangeEvent will be null and the
  225. * new value will be an Integer representing the column index.
  226. * @see AccessibleTable
  227. */
  228. public static final String ACCESSIBLE_TABLE_COLUMN_DESCRIPTION_CHANGED =
  229. "accessibleTableColumnDescriptionChanged";
  230. /**
  231. * Constant used to indicate that the supported set of actions
  232. * has changed. The old value in the PropertyChangeEvent will
  233. * be an Integer representing the old number of actions supported
  234. * and the new value will be an Integer representing the new
  235. * number of actions supported.
  236. * @see AccessibleAction
  237. */
  238. public static final String ACCESSIBLE_ACTION_PROPERTY =
  239. "accessibleActionProperty";
  240. /**
  241. * Constant used to indicate that a hypertext element has received focus.
  242. * The old value in the PropertyChangeEvent will be an Integer
  243. * representing the start index in the document of the previous element
  244. * that had focus and the new value will be an Integer representing
  245. * the start index in the document of the current element that has
  246. * focus. A value of -1 indicates that an element does not or did
  247. * not have focus.
  248. * @see AccessibleHyperlink
  249. */
  250. public static final String ACCESSIBLE_HYPERTEXT_OFFSET =
  251. "AccessibleHypertextOffset";
  252. /**
  253. * The accessible parent of this object.
  254. *
  255. * @see #getAccessibleParent
  256. * @see #setAccessibleParent
  257. */
  258. protected Accessible accessibleParent = null;
  259. /**
  260. * A localized String containing the name of the object.
  261. *
  262. * @see #getAccessibleName
  263. * @see #setAccessibleName
  264. */
  265. protected String accessibleName = null;
  266. /**
  267. * A localized String containing the description of the object.
  268. *
  269. * @see #getAccessibleDescription
  270. * @see #setAccessibleDescription
  271. */
  272. protected String accessibleDescription = null;
  273. /**
  274. * Used to handle the listener list for property change events.
  275. *
  276. * @see #addPropertyChangeListener
  277. * @see #removePropertyChangeListener
  278. * @see #firePropertyChangeListener
  279. */
  280. private PropertyChangeSupport accessibleChangeSupport = null;
  281. /**
  282. * Used to represent the context's relation set
  283. * @see #getAccessibleRelationSet
  284. */
  285. private AccessibleRelationSet relationSet
  286. = new AccessibleRelationSet();
  287. /**
  288. * Gets the accessibleName property of this object. The accessibleName
  289. * property of an object is a localized String that designates the purpose
  290. * of the object. For example, the accessibleName property of a label
  291. * or button might be the text of the label or button itself. In the
  292. * case of an object that doesn't display its name, the accessibleName
  293. * should still be set. For example, in the case of a text field used
  294. * to enter the name of a city, the accessibleName for the en_US locale
  295. * could be 'city.'
  296. *
  297. * @return the localized name of the object; null if this
  298. * object does not have a name
  299. *
  300. * @see #setAccessibleName
  301. */
  302. public String getAccessibleName() {
  303. return accessibleName;
  304. }
  305. /**
  306. * Sets the localized accessible name of this object. Changing the
  307. * name will cause a PropertyChangeEvent to be fired for the
  308. * ACCESSIBLE_NAME_PROPERTY property.
  309. *
  310. * @param s the new localized name of the object.
  311. *
  312. * @see #getAccessibleName
  313. * @see #addPropertyChangeListener
  314. *
  315. * @beaninfo
  316. * preferred: true
  317. * description: Sets the accessible name for the component.
  318. */
  319. public void setAccessibleName(String s) {
  320. String oldName = accessibleName;
  321. accessibleName = s;
  322. firePropertyChange(ACCESSIBLE_NAME_PROPERTY,oldName,accessibleName);
  323. }
  324. /**
  325. * Gets the accessibleDescription property of this object. The
  326. * accessibleDescription property of this object is a short localized
  327. * phrase describing the purpose of the object. For example, in the
  328. * case of a 'Cancel' button, the accessibleDescription could be
  329. * 'Ignore changes and close dialog box.'
  330. *
  331. * @return the localized description of the object; null if
  332. * this object does not have a description
  333. *
  334. * @see #setAccessibleDescription
  335. */
  336. public String getAccessibleDescription() {
  337. return accessibleDescription;
  338. }
  339. /**
  340. * Sets the accessible description of this object. Changing the
  341. * name will cause a PropertyChangeEvent to be fired for the
  342. * ACCESSIBLE_DESCRIPTION_PROPERTY property.
  343. *
  344. * @param s the new localized description of the object
  345. *
  346. * @see #setAccessibleName
  347. * @see #addPropertyChangeListener
  348. *
  349. * @beaninfo
  350. * preferred: true
  351. * description: Sets the accessible description for the component.
  352. */
  353. public void setAccessibleDescription(String s) {
  354. String oldDescription = accessibleDescription;
  355. accessibleDescription = s;
  356. firePropertyChange(ACCESSIBLE_DESCRIPTION_PROPERTY,
  357. oldDescription,accessibleDescription);
  358. }
  359. /**
  360. * Gets the role of this object. The role of the object is the generic
  361. * purpose or use of the class of this object. For example, the role
  362. * of a push button is AccessibleRole.PUSH_BUTTON. The roles in
  363. * AccessibleRole are provided so component developers can pick from
  364. * a set of predefined roles. This enables assistive technologies to
  365. * provide a consistent interface to various tweaked subclasses of
  366. * components (e.g., use AccessibleRole.PUSH_BUTTON for all components
  367. * that act like a push button) as well as distinguish between sublasses
  368. * that behave differently (e.g., AccessibleRole.CHECK_BOX for check boxes
  369. * and AccessibleRole.RADIO_BUTTON for radio buttons).
  370. * <p>Note that the AccessibleRole class is also extensible, so
  371. * custom component developers can define their own AccessibleRole's
  372. * if the set of predefined roles is inadequate.
  373. *
  374. * @return an instance of AccessibleRole describing the role of the object
  375. * @see AccessibleRole
  376. */
  377. public abstract AccessibleRole getAccessibleRole();
  378. /**
  379. * Gets the state set of this object. The AccessibleStateSet of an object
  380. * is composed of a set of unique AccessibleStates. A change in the
  381. * AccessibleStateSet of an object will cause a PropertyChangeEvent to
  382. * be fired for the ACCESSIBLE_STATE_PROPERTY property.
  383. *
  384. * @return an instance of AccessibleStateSet containing the
  385. * current state set of the object
  386. * @see AccessibleStateSet
  387. * @see AccessibleState
  388. * @see #addPropertyChangeListener
  389. */
  390. public abstract AccessibleStateSet getAccessibleStateSet();
  391. /**
  392. * Gets the Accessible parent of this object.
  393. *
  394. * @return the Accessible parent of this object; null if this
  395. * object does not have an Accessible parent
  396. */
  397. public Accessible getAccessibleParent() {
  398. return accessibleParent;
  399. }
  400. /**
  401. * Sets the Accessible parent of this object. This is meant to be used
  402. * only in the situations where the actual component's parent should
  403. * not be treated as the component's accessible parent and is a method
  404. * that should only be called by the parent of the accessible child.
  405. *
  406. * @param a - Accessible to be set as the parent
  407. */
  408. public void setAccessibleParent(Accessible a) {
  409. accessibleParent = a;
  410. }
  411. /**
  412. * Gets the 0-based index of this object in its accessible parent.
  413. *
  414. * @return the 0-based index of this object in its parent; -1 if this
  415. * object does not have an accessible parent.
  416. *
  417. * @see #getAccessibleParent
  418. * @see #getAccessibleChildrenCount
  419. * @see #getAccessibleChild
  420. */
  421. public abstract int getAccessibleIndexInParent();
  422. /**
  423. * Returns the number of accessible children of the object.
  424. *
  425. * @return the number of accessible children of the object.
  426. */
  427. public abstract int getAccessibleChildrenCount();
  428. /**
  429. * Returns the specified Accessible child of the object. The Accessible
  430. * children of an Accessible object are zero-based, so the first child
  431. * of an Accessible child is at index 0, the second child is at index 1,
  432. * and so on.
  433. *
  434. * @param i zero-based index of child
  435. * @return the Accessible child of the object
  436. * @see #getAccessibleChildrenCount
  437. */
  438. public abstract Accessible getAccessibleChild(int i);
  439. /**
  440. * Gets the locale of the component. If the component does not have a
  441. * locale, then the locale of its parent is returned.
  442. *
  443. * @return this component's locale. If this component does not have
  444. * a locale, the locale of its parent is returned.
  445. *
  446. * @exception IllegalComponentStateException
  447. * If the Component does not have its own locale and has not yet been
  448. * added to a containment hierarchy such that the locale can be
  449. * determined from the containing parent.
  450. */
  451. public abstract Locale getLocale() throws IllegalComponentStateException;
  452. /**
  453. * Adds a PropertyChangeListener to the listener list.
  454. * The listener is registered for all Accessible properties and will
  455. * be called when those properties change.
  456. *
  457. * @see #ACCESSIBLE_NAME_PROPERTY
  458. * @see #ACCESSIBLE_DESCRIPTION_PROPERTY
  459. * @see #ACCESSIBLE_STATE_PROPERTY
  460. * @see #ACCESSIBLE_VALUE_PROPERTY
  461. * @see #ACCESSIBLE_SELECTION_PROPERTY
  462. * @see #ACCESSIBLE_TEXT_PROPERTY
  463. * @see #ACCESSIBLE_VISIBLE_DATA_PROPERTY
  464. *
  465. * @param listener The PropertyChangeListener to be added
  466. */
  467. public void addPropertyChangeListener(PropertyChangeListener listener) {
  468. if (accessibleChangeSupport == null) {
  469. accessibleChangeSupport = new PropertyChangeSupport(this);
  470. }
  471. accessibleChangeSupport.addPropertyChangeListener(listener);
  472. }
  473. /**
  474. * Removes a PropertyChangeListener from the listener list.
  475. * This removes a PropertyChangeListener that was registered
  476. * for all properties.
  477. *
  478. * @param listener The PropertyChangeListener to be removed
  479. */
  480. public void removePropertyChangeListener(PropertyChangeListener listener) {
  481. if (accessibleChangeSupport != null) {
  482. accessibleChangeSupport.removePropertyChangeListener(listener);
  483. }
  484. }
  485. /**
  486. * Gets the AccessibleAction associated with this object that supports
  487. * one or more actions.
  488. *
  489. * @return AccessibleAction if supported by object; else return null
  490. * @see AccessibleAction
  491. */
  492. public AccessibleAction getAccessibleAction() {
  493. return null;
  494. }
  495. /**
  496. * Gets the AccessibleComponent associated with this object that has a
  497. * graphical representation.
  498. *
  499. * @return AccessibleComponent if supported by object; else return null
  500. * @see AccessibleComponent
  501. */
  502. public AccessibleComponent getAccessibleComponent() {
  503. return null;
  504. }
  505. /**
  506. * Gets the AccessibleSelection associated with this object which allows its
  507. * Accessible children to be selected.
  508. *
  509. * @return AccessibleSelection if supported by object; else return null
  510. * @see AccessibleSelection
  511. */
  512. public AccessibleSelection getAccessibleSelection() {
  513. return null;
  514. }
  515. /**
  516. * Gets the AccessibleText associated with this object presenting
  517. * text on the display.
  518. *
  519. * @return AccessibleText if supported by object; else return null
  520. * @see AccessibleText
  521. */
  522. public AccessibleText getAccessibleText() {
  523. return null;
  524. }
  525. /**
  526. * Gets the AccessibleEditableText associated with this object
  527. * presenting editable text on the display.
  528. *
  529. * @return AccessibleEditableText if supported by object; else return null
  530. * @see AccessibleEditableText
  531. */
  532. public AccessibleEditableText getAccessibleEditableText() {
  533. return null;
  534. }
  535. /**
  536. * Gets the AccessibleValue associated with this object that supports a
  537. * Numerical value.
  538. *
  539. * @return AccessibleValue if supported by object; else return null
  540. * @see AccessibleValue
  541. */
  542. public AccessibleValue getAccessibleValue() {
  543. return null;
  544. }
  545. /**
  546. * Gets the AccessibleIcons associated with an object that has
  547. * one or more associated icons
  548. *
  549. * @return an array of AccessibleIcon if supported by object;
  550. * otherwise return null
  551. * @see AccessibleIcon
  552. */
  553. public AccessibleIcon [] getAccessibleIcon() {
  554. return null;
  555. }
  556. /**
  557. * Gets the AccessibleRelationSet associated with an object
  558. *
  559. * @return an AccessibleRelationSet if supported by object;
  560. * otherwise return null
  561. * @see AccessibleRelationSet
  562. */
  563. public AccessibleRelationSet getAccessibleRelationSet() {
  564. return relationSet;
  565. }
  566. /**
  567. * Gets the AccessibleTable associated with an object
  568. *
  569. * @return an AccessibleTable if supported by object;
  570. * otherwise return null
  571. * @see AccessibleTable
  572. */
  573. public AccessibleTable getAccessibleTable() {
  574. return null;
  575. }
  576. /**
  577. * Support for reporting bound property changes. If oldValue and
  578. * newValue are not equal and the PropertyChangeEvent listener list
  579. * is not empty, then fire a PropertyChange event to each listener.
  580. * In general, this is for use by the Accessible objects themselves
  581. * and should not be called by an application program.
  582. * @param propertyName The programmatic name of the property that
  583. * was changed.
  584. * @param oldValue The old value of the property.
  585. * @param newValue The new value of the property.
  586. * @see java.beans.PropertyChangeSupport
  587. * @see #addPropertyChangeListener
  588. * @see #removePropertyChangeListener
  589. * @see #ACCESSIBLE_NAME_PROPERTY
  590. * @see #ACCESSIBLE_DESCRIPTION_PROPERTY
  591. * @see #ACCESSIBLE_STATE_PROPERTY
  592. * @see #ACCESSIBLE_VALUE_PROPERTY
  593. * @see #ACCESSIBLE_SELECTION_PROPERTY
  594. * @see #ACCESSIBLE_TEXT_PROPERTY
  595. * @see #ACCESSIBLE_VISIBLE_DATA_PROPERTY
  596. */
  597. public void firePropertyChange(String propertyName,
  598. Object oldValue,
  599. Object newValue) {
  600. if (accessibleChangeSupport != null) {
  601. if (newValue instanceof PropertyChangeEvent) {
  602. PropertyChangeEvent pce = (PropertyChangeEvent)newValue;
  603. accessibleChangeSupport.firePropertyChange(pce);
  604. } else {
  605. accessibleChangeSupport.firePropertyChange(propertyName,
  606. oldValue,
  607. newValue);
  608. }
  609. }
  610. }
  611. }