PageRenderTime 122ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/libjava/classpath/javax/accessibility/AccessibleContext.java

https://bitbucket.org/pizzafactory/pf-gcc
Java | 619 lines | 140 code | 53 blank | 426 comment | 0 complexity | 161adc7caecc2382cec82f2649f95e24 MD5 | raw file
  1. /* AccessibleContext.java -- the context of an accessible object
  2. Copyright (C) 2002 Free Software Foundation
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package javax.accessibility;
  32. import java.beans.PropertyChangeListener;
  33. import java.beans.PropertyChangeSupport;
  34. import java.util.Locale;
  35. /**
  36. * The minimum information that all accessible objects return. This includes
  37. * name, description, role, and state of the object, parents and children,
  38. * and any other useful information. If a component supports further details,
  39. * it should implement one of the following:<ul>
  40. * <li>{@link AccessibleAction} - the object can perform actions</li>
  41. * <li>{@link AccessibleComponent} - the object has a graphical
  42. * representation</li>
  43. * <li>{@link AccessibleSelection} - the object allows its children to be
  44. * selected</li>
  45. * <li>{@link AccessibleText} - the object represents editable text</li>
  46. * <li>{@link AccessibleValue} - the object represents a numerical value</li>
  47. * </ul>
  48. *
  49. * @author Eric Blake (ebb9@email.byu.edu)
  50. * @since 1.2
  51. * @status updated to 1.4
  52. */
  53. public abstract class AccessibleContext
  54. {
  55. /**
  56. * Constant used when the accessible name has changed. Both the old and new
  57. * values are listed in the event.
  58. *
  59. * @see #getAccessibleName()
  60. * @see #addPropertyChangeListener(PropertyChangeListener)
  61. */
  62. public static final String ACCESSIBLE_NAME_PROPERTY
  63. = "AccessibleName";
  64. /**
  65. * Constant used when the accessible description has changed. Both the old
  66. * and new values are listed in the event.
  67. *
  68. * @see #getAccessibleDescription()
  69. * @see #addPropertyChangeListener(PropertyChangeListener)
  70. */
  71. public static final String ACCESSIBLE_DESCRIPTION_PROPERTY
  72. = "AccessibleDescription";
  73. /**
  74. * Constant used when the accessibleStateSet has changed. Both the old and
  75. * new values are listed in the event, although either may be null if a
  76. * state was disabled at that time.
  77. *
  78. * @see #getAccessibleStateSet()
  79. * @see AccessibleState
  80. * @see AccessibleStateSet
  81. * @see #addPropertyChangeListener(PropertyChangeListener)
  82. */
  83. public static final String ACCESSIBLE_STATE_PROPERTY
  84. = "AccessibleState";
  85. /**
  86. * Constant used when the accessibleValue has changed. Both the old and new
  87. * values are listed in the event.
  88. *
  89. * @see #getAccessibleValue()
  90. * @see #addPropertyChangeListener(PropertyChangeListener)
  91. */
  92. public static final String ACCESSIBLE_VALUE_PROPERTY
  93. = "AccessibleValue";
  94. /**
  95. * Constant used when the accessibleSelection has changed. Both the old and
  96. * new values of the event are reserved for future use.
  97. *
  98. * @see #getAccessibleSelection()
  99. * @see #addPropertyChangeListener(PropertyChangeListener)
  100. */
  101. public static final String ACCESSIBLE_SELECTION_PROPERTY
  102. = "AccessibleSelection";
  103. /**
  104. * Constant used when the accessibleText has changed. Both the old and new
  105. * values of the event are reserved for future use.
  106. *
  107. * @see #getAccessibleText()
  108. * @see #addPropertyChangeListener(PropertyChangeListener)
  109. */
  110. public static final String ACCESSIBLE_TEXT_PROPERTY
  111. = "AccessibleText";
  112. /**
  113. * Constant used when the accessibleText caret has changed. Both the old and
  114. * new values are listed in the event.
  115. *
  116. * @see #addPropertyChangeListener(PropertyChangeListener)
  117. */
  118. public static final String ACCESSIBLE_CARET_PROPERTY
  119. = "AccessibleCaret";
  120. /**
  121. * Constant used when the visible data has changed. Both the old and new
  122. * values of the event are reserved for future use.
  123. *
  124. * @see #addPropertyChangeListener(PropertyChangeListener)
  125. */
  126. public static final String ACCESSIBLE_VISIBLE_DATA_PROPERTY
  127. = "AccessibleVisibleData";
  128. /**
  129. * Constant used when children are added or removed. On addition, the new
  130. * value of the event holds the new child; on removal, the old value holds
  131. * the removed child.
  132. *
  133. * @see #addPropertyChangeListener(PropertyChangeListener)
  134. */
  135. public static final String ACCESSIBLE_CHILD_PROPERTY
  136. = "AccessibleChild";
  137. /**
  138. * Constant used when active descendent of a component has changed. Both
  139. * the old and new values are listed in the event.
  140. *
  141. * @see #addPropertyChangeListener(PropertyChangeListener)
  142. */
  143. public static final String ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY
  144. = "AccessibleActiveDescendant";
  145. /**
  146. * Constant used when the accessible table caption has changed. Both the
  147. * old and new values are listed in the event.
  148. *
  149. * @see Accessible
  150. * @see AccessibleTable
  151. */
  152. public static final String ACCESSIBLE_TABLE_CAPTION_CHANGED
  153. = "accessibleTableCaptionChanged";
  154. /**
  155. * Constant used when the accessible table summary has changed. Both the
  156. * old and new values are listed in the event.
  157. *
  158. * @see Accessible
  159. * @see AccessibleTable
  160. */
  161. public static final String ACCESSIBLE_TABLE_SUMMARY_CHANGED
  162. = "accessibleTableSummaryChanged";
  163. /**
  164. * Constant used when the accessible table model has changed. Only the new
  165. * value of the event has meaning.
  166. *
  167. * @see AccessibleTable
  168. * @see AccessibleTableModelChange
  169. */
  170. public static final String ACCESSIBLE_TABLE_MODEL_CHANGED
  171. = "accessibleTableModelChanged";
  172. /**
  173. * Constant used when the accessible table row header has changed. Only the
  174. * new value of the event has meaning.
  175. *
  176. * @see AccessibleTable
  177. * @see AccessibleTableModelChange
  178. */
  179. public static final String ACCESSIBLE_TABLE_ROW_HEADER_CHANGED
  180. = "accessibleTableRowHeaderChanged";
  181. /**
  182. * Constant used when the accessible table row description has changed. Only
  183. * the new value of the event has meaning.
  184. *
  185. * @see AccessibleTable
  186. */
  187. public static final String ACCESSIBLE_TABLE_ROW_DESCRIPTION_CHANGED
  188. = "accessibleTableRowDescriptionChanged";
  189. /**
  190. * Constant used when the accessible table column header has changed. Only
  191. * the new value of the event has meaning.
  192. *
  193. * @see AccessibleTable
  194. * @see AccessibleTableModelChange
  195. */
  196. public static final String ACCESSIBLE_TABLE_COLUMN_HEADER_CHANGED
  197. = "accessibleTableColumnHeaderChanged";
  198. /**
  199. * Constant used when the accessible table column description has changed.
  200. * Only the new value of the event has meaning.
  201. *
  202. * @see AccessibleTable
  203. */
  204. public static final String ACCESSIBLE_TABLE_COLUMN_DESCRIPTION_CHANGED
  205. = "accessibleTableColumnDescriptionChanged";
  206. /**
  207. * Constant used when supported set of actions has changed. Both the old
  208. * and new values are listed in the event.
  209. *
  210. * @see AccessibleAction
  211. */
  212. public static final String ACCESSIBLE_ACTION_PROPERTY
  213. = "accessibleActionProperty";
  214. /**
  215. * Constant used when a hypertext element received focus. Both the old
  216. * and new values are listed in the event, with -1 indicating that no link
  217. * had focus.
  218. *
  219. * @see AccessibleHyperlink
  220. */
  221. public static final String ACCESSIBLE_HYPERTEXT_OFFSET
  222. = "AccessibleHypertextOffset";
  223. /**
  224. * Constant used when a component's bounds have changed. The old and
  225. * new bounds are given in the event.
  226. * @since 1.5
  227. */
  228. public static final String ACCESSIBLE_COMPONENT_BOUNDS_CHANGED
  229. = "accessibleComponentBoundsChanged";
  230. /**
  231. * Constant used when the state of child objects changes. The old
  232. * value in the event is always null, and the new value is the component
  233. * whose children have changed.
  234. * @since 1.5
  235. */
  236. public static final String ACCESSIBLE_INVALIDATE_CHILDREN
  237. = "accessibleInvalidateChildren";
  238. /**
  239. * Constant used when the attributes of some text have changed.
  240. * On insertion, the old value is null and the new value is an
  241. * {@link AccessibleAttributeSequence} describing the insertion.
  242. * On deletion, the old value is an {@link AccessibleAttributeSequence}
  243. * and the new value is null. For replacement, both the old
  244. * and new values are {@link AccessibleAttributeSequence} objects.
  245. * @since 1.5
  246. */
  247. public static final String ACCESSIBLE_TEXT_ATTRIBUTES_CHANGED
  248. = "accessibleTextAttributesChanged";
  249. /**
  250. * The accessible parent of this object.
  251. *
  252. * @see #getAccessibleParent()
  253. * @see #setAccessibleParent(Accessible)
  254. */
  255. protected Accessible accessibleParent;
  256. /**
  257. * A localized string naming this object.
  258. *
  259. * @see #getAccessibleName()
  260. * @see #setAccessibleName(String)
  261. */
  262. protected String accessibleName;
  263. /**
  264. * A localized string describing this object.
  265. *
  266. * @see #getAccessibleDescription()
  267. * @see #setAccessibleDescription(String)
  268. */
  269. protected String accessibleDescription;
  270. /**
  271. * The listener tool.
  272. *
  273. * @see #addPropertyChangeListener(PropertyChangeListener)
  274. * @see #removePropertyChangeListener(PropertyChangeListener)
  275. * @see #firePropertyChange(String, Object, Object)
  276. */
  277. private final PropertyChangeSupport listeners
  278. = new PropertyChangeSupport(this);
  279. /**
  280. * Default constructor.
  281. */
  282. public AccessibleContext()
  283. {
  284. }
  285. /**
  286. * Get the localized name of the object. For example, a label may just
  287. * return the text of the label, while an entry field for city may return
  288. * "city" in en_US.
  289. *
  290. * @return the accessible object's name, or null if it is unnamed
  291. * @see #setAccessibleName(String)
  292. */
  293. public String getAccessibleName()
  294. {
  295. return accessibleName;
  296. }
  297. /**
  298. * Set the localized name of the object. This will fire a
  299. * PropertyChangeEvent with ACCESSIBLE_NAME_PROPERTY.
  300. *
  301. * @param s the new name
  302. * @see #getAccessibleName()
  303. * @see #addPropertyChangeListener(PropertyChangeListener)
  304. */
  305. public void setAccessibleName(String s)
  306. {
  307. listeners.firePropertyChange(ACCESSIBLE_NAME_PROPERTY, accessibleName, s);
  308. accessibleName = s;
  309. }
  310. /**
  311. * Get the localized description of the object. For example, a 'Cancel'
  312. * button may be described as "Ignore changes and close dialog box" in
  313. * en_US.
  314. *
  315. * @return the accessible object's description, or null if there is none
  316. * @see #setAccessibleDescription(String)
  317. */
  318. public String getAccessibleDescription()
  319. {
  320. return accessibleDescription;
  321. }
  322. /**
  323. * Set the localized name of the object. This will fire a
  324. * PropertyChangeEvent with ACCESSIBLE_DESCRIPTION_PROPERTY.
  325. *
  326. * @param s the new description
  327. * @see #getAccessibleDescription()
  328. * @see #addPropertyChangeListener(PropertyChangeListener)
  329. */
  330. public void setAccessibleDescription(String s)
  331. {
  332. listeners.firePropertyChange(ACCESSIBLE_DESCRIPTION_PROPERTY,
  333. accessibleDescription, s);
  334. accessibleDescription = s;
  335. }
  336. /**
  337. * Gets the role of this object. For example, a button serves the role of
  338. * AccessibleRole.PUSH_BUTTON. This allows assistive technologies to funnel
  339. * similar objects into the same assistance classes. Note that the class
  340. * is extensible, to define new roles if necessary.
  341. *
  342. * @return the role of the object
  343. * @see AccessibleRole
  344. */
  345. public abstract AccessibleRole getAccessibleRole();
  346. /**
  347. * Gets the state set of this object. A change in the state of the object
  348. * will fire a PropertyChangeEvent for ACCESSIBLE_STATE_PROPERTY.
  349. *
  350. * @return the current state of the object
  351. * @see AccessibleState
  352. * @see AccessibleStateSet
  353. * @see #addPropertyChangeListener(PropertyChangeListener)
  354. */
  355. public abstract AccessibleStateSet getAccessibleStateSet();
  356. /**
  357. * Return the accessible parent of this object.
  358. *
  359. * @return the accessible parent, or null if there is none
  360. */
  361. public Accessible getAccessibleParent()
  362. {
  363. return accessibleParent;
  364. }
  365. /**
  366. * Sets the accessible parent of this object. This should only be used when
  367. * the current parent object should not be the accessible parent; only the
  368. * parent of the accessible child should call this method.
  369. *
  370. * @param a the new parent
  371. */
  372. public void setAccessibleParent(Accessible a)
  373. {
  374. accessibleParent = a;
  375. }
  376. /**
  377. * Gets the index of this object within its accessible parent.
  378. *
  379. * @return the 0-based index, or -1 if there is no accessible parent
  380. * @see #getAccessibleParent()
  381. * @see #getAccessibleChildrenCount()
  382. * @see #getAccessibleChild(int)
  383. */
  384. public abstract int getAccessibleIndexInParent();
  385. /**
  386. * Returns the number of accessible children of this object.
  387. *
  388. * @return the number of accessible children
  389. * @see #getAccessibleChild(int)
  390. */
  391. public abstract int getAccessibleChildrenCount();
  392. /**
  393. * Returns the specified accessible chile.
  394. *
  395. * @param i the 0-based index to get
  396. * @return the child, or null if out of bounds
  397. * @see #getAccessibleChildrenCount()
  398. */
  399. public abstract Accessible getAccessibleChild(int i);
  400. /**
  401. * Gets the component locale, deferring to the parent if one is not declared.
  402. *
  403. * @return the locale
  404. * @throws java.awt.IllegalComponentStateException if there is no locale
  405. * or parent
  406. */
  407. public abstract Locale getLocale();
  408. /**
  409. * Add a PropertyChangeListener to the listener list. This listener will
  410. * be notified of all property changes to the accessible object.
  411. *
  412. * @param l the listener to add
  413. * @see #ACCESSIBLE_NAME_PROPERTY
  414. * @see #ACCESSIBLE_DESCRIPTION_PROPERTY
  415. * @see #ACCESSIBLE_STATE_PROPERTY
  416. * @see #ACCESSIBLE_VALUE_PROPERTY
  417. * @see #ACCESSIBLE_SELECTION_PROPERTY
  418. * @see #ACCESSIBLE_TEXT_PROPERTY
  419. * @see #ACCESSIBLE_VISIBLE_DATA_PROPERTY
  420. * @see #removePropertyChangeListener(PropertyChangeListener)
  421. */
  422. public void addPropertyChangeListener(PropertyChangeListener l)
  423. {
  424. listeners.addPropertyChangeListener(l);
  425. }
  426. /**
  427. * Remove a PropertyChangeListener from the listener list.
  428. *
  429. * @param l the listener to remove
  430. * @see #addPropertyChangeListener(PropertyChangeListener)
  431. */
  432. public void removePropertyChangeListener(PropertyChangeListener l)
  433. {
  434. listeners.removePropertyChangeListener(l);
  435. }
  436. /**
  437. * Get any supported accessible actions. The default implementation returns
  438. * null.
  439. *
  440. * @return the supported action, or null
  441. * @see AccessibleAction
  442. */
  443. public AccessibleAction getAccessibleAction()
  444. {
  445. return null;
  446. }
  447. /**
  448. * Get any supported accessible component. The default implementation returns
  449. * null.
  450. *
  451. * @return the supported component, or null
  452. * @see AccessibleComponent
  453. */
  454. public AccessibleComponent getAccessibleComponent()
  455. {
  456. return null;
  457. }
  458. /**
  459. * Get any supported accessible selection. The default implementation returns
  460. * null.
  461. *
  462. * @return the supported selection, or null
  463. * @see AccessibleSelection
  464. */
  465. public AccessibleSelection getAccessibleSelection()
  466. {
  467. return null;
  468. }
  469. /**
  470. * Get any supported accessible text. The default implementation returns
  471. * null.
  472. *
  473. * @return the supported text, or null
  474. * @see AccessibleText
  475. */
  476. public AccessibleText getAccessibleText()
  477. {
  478. return null;
  479. }
  480. /**
  481. * Get any supported accessible editable text. The default implementation
  482. * returns null.
  483. *
  484. * @return the supported editable text, or null
  485. * @see AccessibleEditableText
  486. */
  487. public AccessibleEditableText getAccessibleEditableText()
  488. {
  489. return null;
  490. }
  491. /**
  492. * Get any supported accessible value. The default implementation returns
  493. * null.
  494. *
  495. * @return the supported value, or null
  496. * @see AccessibleValue
  497. */
  498. public AccessibleValue getAccessibleValue()
  499. {
  500. return null;
  501. }
  502. /**
  503. * Get all supported accessible icons. The default implementation returns
  504. * null.
  505. *
  506. * @return the supported icons, or null
  507. * @see AccessibleIcon
  508. */
  509. public AccessibleIcon[] getAccessibleIcon()
  510. {
  511. return null;
  512. }
  513. /**
  514. * Get any supported accessible relation set. The default implementation
  515. * returns an empty AccessibleRelationSet.
  516. *
  517. * @return the supported relation set, or <code>null</code>
  518. *
  519. * @see AccessibleRelationSet
  520. */
  521. public AccessibleRelationSet getAccessibleRelationSet()
  522. {
  523. return new AccessibleRelationSet();
  524. }
  525. /**
  526. * Get any supported accessible table. The default implementation returns
  527. * null.
  528. *
  529. * @return the supported table, or null
  530. * @see AccessibleTable
  531. */
  532. public AccessibleTable getAccessibleTable()
  533. {
  534. return null;
  535. }
  536. /**
  537. * Fire an event to report property changes. This is intended for use by
  538. * the accessible objects, not general application programs. If oldValue and
  539. * newValue differ, and the listenter list is not empty, a PropertyChange
  540. * event is fired to each listener.
  541. *
  542. * @param name the property name
  543. * @param oldValue the prior value
  544. * @param newValue the updated value
  545. * @see PropertyChangeSupport
  546. * @see #addPropertyChangeListener(PropertyChangeListener)
  547. * @see #removePropertyChangeListener(PropertyChangeListener)
  548. * @see #ACCESSIBLE_NAME_PROPERTY
  549. * @see #ACCESSIBLE_DESCRIPTION_PROPERTY
  550. * @see #ACCESSIBLE_STATE_PROPERTY
  551. * @see #ACCESSIBLE_VALUE_PROPERTY
  552. * @see #ACCESSIBLE_SELECTION_PROPERTY
  553. * @see #ACCESSIBLE_TEXT_PROPERTY
  554. * @see #ACCESSIBLE_VISIBLE_DATA_PROPERTY
  555. */
  556. public void firePropertyChange(String name, Object oldValue, Object newValue)
  557. {
  558. listeners.firePropertyChange(name, oldValue, newValue);
  559. }
  560. } // class AccessibleContext