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