1. /*
  2. * @(#)Choice.java 1.83 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 java.awt;
  8. import java.util.*;
  9. import java.awt.peer.ChoicePeer;
  10. import java.awt.event.*;
  11. import java.util.EventListener;
  12. import java.io.ObjectOutputStream;
  13. import java.io.ObjectInputStream;
  14. import java.io.IOException;
  15. import javax.accessibility.*;
  16. /**
  17. * The <code>Choice</code> class presents a pop-up menu of choices.
  18. * The current choice is displayed as the title of the menu.
  19. * <p>
  20. * The following code example produces a pop-up menu:
  21. * <p>
  22. * <hr><blockquote><pre>
  23. * Choice ColorChooser = new Choice();
  24. * ColorChooser.add("Green");
  25. * ColorChooser.add("Red");
  26. * ColorChooser.add("Blue");
  27. * </pre></blockquote><hr>
  28. * <p>
  29. * After this choice menu has been added to a panel,
  30. * it appears as follows in its normal state:
  31. * <p>
  32. * <img src="doc-files/Choice-1.gif" alt="The following text describes the graphic"
  33. * ALIGN=center HSPACE=10 VSPACE=7>
  34. * <p>
  35. * In the picture, <code>"Green"</code> is the current choice.
  36. * Pushing the mouse button down on the object causes a menu to
  37. * appear with the current choice highlighted.
  38. * <p>
  39. * Some native platforms do not support arbitrary resizing of
  40. * <code>Choice</code> components and the behavior of
  41. * <code>setSize()/getSize()</code> is bound by
  42. * such limitations.
  43. * Native GUI <code>Choice</code> components' size are often bound by such
  44. * attributes as font size and length of items contained within
  45. * the <code>Choice</code>.
  46. * <p>
  47. * @version 1.83 01/23/03
  48. * @author Sami Shaio
  49. * @author Arthur van Hoff
  50. * @since JDK1.0
  51. */
  52. public class Choice extends Component implements ItemSelectable, Accessible {
  53. /**
  54. * The items for the <code>Choice</code>.
  55. * This can be a <code>null</code> value.
  56. * @serial
  57. * @see #add(String)
  58. * @see #addItem(String)
  59. * @see #getItem(int)
  60. * @see #getItemCount()
  61. * @see #insert(String, int)
  62. * @see #remove(String)
  63. */
  64. Vector pItems;
  65. /**
  66. * The index of the current choice for this <code>Choice</code>
  67. * or -1 if nothing is selected.
  68. * @serial
  69. * @see #getSelectedItem()
  70. * @see #select(int)
  71. */
  72. int selectedIndex = -1;
  73. transient ItemListener itemListener;
  74. private static final String base = "choice";
  75. private static int nameCounter = 0;
  76. /*
  77. * JDK 1.1 serialVersionUID
  78. */
  79. private static final long serialVersionUID = -4075310674757313071L;
  80. /**
  81. * Creates a new choice menu. The menu initially has no items in it.
  82. * <p>
  83. * By default, the first item added to the choice menu becomes the
  84. * selected item, until a different selection is made by the user
  85. * by calling one of the <code>select</code> methods.
  86. * @exception HeadlessException if GraphicsEnvironment.isHeadless()
  87. * returns true
  88. * @see java.awt.GraphicsEnvironment#isHeadless
  89. * @see #select(int)
  90. * @see #select(java.lang.String)
  91. */
  92. public Choice() throws HeadlessException {
  93. GraphicsEnvironment.checkHeadless();
  94. pItems = new Vector();
  95. }
  96. /**
  97. * Constructs a name for this component. Called by
  98. * <code>getName</code> when the name is <code>null</code>.
  99. */
  100. String constructComponentName() {
  101. synchronized (getClass()) {
  102. return base + nameCounter++;
  103. }
  104. }
  105. /**
  106. * Creates the <code>Choice</code>'s peer. This peer allows us
  107. * to change the look
  108. * of the <code>Choice</code> without changing its functionality.
  109. * @see java.awt.Toolkit#createChoice(java.awt.Choice)
  110. * @see java.awt.Component#getToolkit()
  111. */
  112. public void addNotify() {
  113. synchronized (getTreeLock()) {
  114. if (peer == null)
  115. peer = getToolkit().createChoice(this);
  116. super.addNotify();
  117. }
  118. }
  119. /**
  120. * Returns the number of items in this <code>Choice</code> menu.
  121. * @return the number of items in this <code>Choice</code> menu
  122. * @see #getItem
  123. * @since JDK1.1
  124. */
  125. public int getItemCount() {
  126. return countItems();
  127. }
  128. /**
  129. * @deprecated As of JDK version 1.1,
  130. * replaced by <code>getItemCount()</code>.
  131. */
  132. public int countItems() {
  133. return pItems.size();
  134. }
  135. /**
  136. * Gets the string at the specified index in this
  137. * <code>Choice</code> menu.
  138. * @param index the index at which to begin
  139. * @see #getItemCount
  140. */
  141. public String getItem(int index) {
  142. return getItemImpl(index);
  143. }
  144. /*
  145. * This is called by the native code, so client code can't
  146. * be called on the toolkit thread.
  147. */
  148. final String getItemImpl(int index) {
  149. return (String)pItems.elementAt(index);
  150. }
  151. /**
  152. * Adds an item to this <code>Choice</code> menu.
  153. * @param item the item to be added
  154. * @exception NullPointerException if the item's value is
  155. * <code>null</code>
  156. * @since JDK1.1
  157. */
  158. public void add(String item) {
  159. addItem(item);
  160. }
  161. /**
  162. * Obsolete as of Java 2 platform v1.1. Please use the
  163. * <code>add</code> method instead.
  164. * <p>
  165. * Adds an item to this <code>Choice</code> menu.
  166. * @param item the item to be added
  167. * @exception NullPointerException if the item's value is equal to
  168. * <code>null</code>
  169. */
  170. public void addItem(String item) {
  171. synchronized (this) {
  172. addItemNoInvalidate(item);
  173. }
  174. // This could change the preferred size of the Component.
  175. if (valid) {
  176. invalidate();
  177. }
  178. }
  179. /**
  180. * Adds an item to this <code>Choice</code>,
  181. * but does not invalidate the <code>Choice</code>.
  182. * Client methods must provide their own synchronization before
  183. * invoking this method.
  184. * @param item the item to be added
  185. * @exception NullPointerException if the item's value is equal to
  186. * <code>null</code>
  187. */
  188. private void addItemNoInvalidate(String item) {
  189. if (item == null) {
  190. throw new
  191. NullPointerException("cannot add null item to Choice");
  192. }
  193. pItems.addElement(item);
  194. ChoicePeer peer = (ChoicePeer)this.peer;
  195. if (peer != null) {
  196. peer.addItem(item, pItems.size() - 1);
  197. }
  198. if (selectedIndex < 0) {
  199. select(0);
  200. }
  201. }
  202. /**
  203. * Inserts the item into this choice at the specified position.
  204. * Existing items at an index greater than or equal to
  205. * <code>index</code> are shifted up by one to accommodate
  206. * the new item. If <code>index</code> is greater than or
  207. * equal to the number of items in this choice,
  208. * <code>item</code> is added to the end of this choice.
  209. * <p>
  210. * If the item is the first one being added to the choice,
  211. * then the item becomes selected. Otherwise, if the
  212. * selected item was one of the items shifted, the first
  213. * item in the choice becomes the selected item. If the
  214. * selected item was no among those shifted, it remains
  215. * the selected item.
  216. * @param item the non-<code>null</code> item to be inserted
  217. * @param index the position at which the item should be inserted
  218. * @exception IllegalArgumentException if index is less than 0
  219. */
  220. public void insert(String item, int index) {
  221. synchronized (this) {
  222. if (index < 0) {
  223. throw new IllegalArgumentException("index less than zero.");
  224. }
  225. int nitems = getItemCount();
  226. Vector tempItems = new Vector();
  227. /* Remove the item at index, nitems-index times
  228. storing them in a temporary vector in the
  229. order they appear on the choice menu.
  230. */
  231. for (int i = index ; i < nitems; i++) {
  232. tempItems.addElement(getItem(index));
  233. removeNoInvalidate(index);
  234. }
  235. addItemNoInvalidate(item);
  236. /* Add the removed items back to the choice menu, they
  237. are already in the correct order in the temp vector.
  238. */
  239. for (int i = 0; i < tempItems.size() ; i++) {
  240. addItemNoInvalidate((String)tempItems.elementAt(i));
  241. }
  242. }
  243. // This could change the preferred size of the Component.
  244. if (valid) {
  245. invalidate();
  246. }
  247. }
  248. /**
  249. * Removes the first occurrence of <code>item</code>
  250. * from the <code>Choice</code> menu. If the item
  251. * being removed is the currently selected item,
  252. * then the first item in the choice becomes the
  253. * selected item. Otherwise, the currently selected
  254. * item remains selected (and the selected index is
  255. * updated accordingly).
  256. * @param item the item to remove from this <code>Choice</code> menu
  257. * @exception IllegalArgumentException if the item doesn't
  258. * exist in the choice menu
  259. * @since JDK1.1
  260. */
  261. public void remove(String item) {
  262. synchronized (this) {
  263. int index = pItems.indexOf(item);
  264. if (index < 0) {
  265. throw new IllegalArgumentException("item " + item +
  266. " not found in choice");
  267. } else {
  268. removeNoInvalidate(index);
  269. }
  270. }
  271. // This could change the preferred size of the Component.
  272. if (valid) {
  273. invalidate();
  274. }
  275. }
  276. /**
  277. * Removes an item from the choice menu
  278. * at the specified position. If the item
  279. * being removed is the currently selected item,
  280. * then the first item in the choice becomes the
  281. * selected item. Otherwise, the currently selected
  282. * item remains selected (and the selected index is
  283. * @param position the position of the item
  284. * @throws IndexOutOfBoundsException if the specified
  285. * position is out of bounds
  286. * @since JDK1.1
  287. */
  288. public void remove(int position) {
  289. synchronized (this) {
  290. removeNoInvalidate(position);
  291. }
  292. // This could change the preferred size of the Component.
  293. if (valid) {
  294. invalidate();
  295. }
  296. }
  297. /**
  298. * Removes an item from the <code>Choice</code> at the
  299. * specified position, but does not invalidate the <code>Choice</code>.
  300. * Client methods must provide their
  301. * own synchronization before invoking this method.
  302. * @param position the position of the item
  303. */
  304. private void removeNoInvalidate(int position) {
  305. pItems.removeElementAt(position);
  306. ChoicePeer peer = (ChoicePeer)this.peer;
  307. if (peer != null) {
  308. peer.remove(position);
  309. }
  310. /* Adjust selectedIndex if selected item was removed. */
  311. if (pItems.size() == 0) {
  312. selectedIndex = -1;
  313. } else if (selectedIndex == position) {
  314. select(0);
  315. } else if (selectedIndex > position) {
  316. select(selectedIndex-1);
  317. }
  318. }
  319. /**
  320. * Removes all items from the choice menu.
  321. * @see #remove
  322. * @since JDK1.1
  323. */
  324. public void removeAll() {
  325. synchronized (this) {
  326. if (peer != null) {
  327. ((ChoicePeer)peer).removeAll();
  328. }
  329. pItems.removeAllElements();
  330. selectedIndex = -1;
  331. }
  332. // This could change the preferred size of the Component.
  333. if (valid) {
  334. invalidate();
  335. }
  336. }
  337. /**
  338. * Gets a representation of the current choice as a string.
  339. * @return a string representation of the currently
  340. * selected item in this choice menu
  341. * @see #getSelectedIndex
  342. */
  343. public synchronized String getSelectedItem() {
  344. return (selectedIndex >= 0) ? getItem(selectedIndex) : null;
  345. }
  346. /**
  347. * Returns an array (length 1) containing the currently selected
  348. * item. If this choice has no items, returns <code>null</code>.
  349. * @see ItemSelectable
  350. */
  351. public synchronized Object[] getSelectedObjects() {
  352. if (selectedIndex >= 0) {
  353. Object[] items = new Object[1];
  354. items[0] = getItem(selectedIndex);
  355. return items;
  356. }
  357. return null;
  358. }
  359. /**
  360. * Returns the index of the currently selected item.
  361. * If nothing is selected, returns -1.
  362. *
  363. * @return the index of the currently selected item, or -1 if nothing
  364. * is currently selected
  365. * @see #getSelectedItem
  366. */
  367. public int getSelectedIndex() {
  368. return selectedIndex;
  369. }
  370. /**
  371. * Sets the selected item in this <code>Choice</code> menu to be the
  372. * item at the specified position.
  373. *
  374. * <p>Note that this method should be primarily used to
  375. * initially select an item in this component.
  376. * Programmatically calling this method will <i>not</i> trigger
  377. * an <code>ItemEvent</code>. The only way to trigger an
  378. * <code>ItemEvent</code> is by user interaction.
  379. *
  380. * @param pos the positon of the selected item
  381. * @exception IllegalArgumentException if the specified
  382. * position is greater than the
  383. * number of items or less than zero
  384. * @see #getSelectedItem
  385. * @see #getSelectedIndex
  386. */
  387. public synchronized void select(int pos) {
  388. if ((pos >= pItems.size()) || (pos < 0)) {
  389. throw new IllegalArgumentException("illegal Choice item position: " + pos);
  390. }
  391. if (pItems.size() > 0) {
  392. selectedIndex = pos;
  393. ChoicePeer peer = (ChoicePeer)this.peer;
  394. if (peer != null) {
  395. peer.select(pos);
  396. }
  397. }
  398. }
  399. /**
  400. * Sets the selected item in this <code>Choice</code> menu
  401. * to be the item whose name is equal to the specified string.
  402. * If more than one item matches (is equal to) the specified string,
  403. * the one with the smallest index is selected.
  404. *
  405. * <p>Note that this method should be primarily used to
  406. * initially select an item in this component.
  407. * Programmatically calling this method will <i>not</i> trigger
  408. * an <code>ItemEvent</code>. The only way to trigger an
  409. * <code>ItemEvent</code> is by user interaction.
  410. *
  411. * @param str the specified string
  412. * @see #getSelectedItem
  413. * @see #getSelectedIndex
  414. */
  415. public synchronized void select(String str) {
  416. int index = pItems.indexOf(str);
  417. if (index >= 0) {
  418. select(index);
  419. }
  420. }
  421. /**
  422. * Adds the specified item listener to receive item events from
  423. * this <code>Choice</code> menu. Item events are sent in response
  424. * to user input, but not in response to calls to <code>select</code>.
  425. * If l is <code>null</code>, no exception is thrown and no action
  426. * is performed.
  427. * @param l the item listener
  428. * @see #removeItemListener
  429. * @see #getItemListeners
  430. * @see #select
  431. * @see java.awt.event.ItemEvent
  432. * @see java.awt.event.ItemListener
  433. * @since JDK1.1
  434. */
  435. public synchronized void addItemListener(ItemListener l) {
  436. if (l == null) {
  437. return;
  438. }
  439. itemListener = AWTEventMulticaster.add(itemListener, l);
  440. newEventsOnly = true;
  441. }
  442. /**
  443. * Removes the specified item listener so that it no longer receives
  444. * item events from this <code>Choice</code> menu.
  445. * If l is <code>null</code>, no exception is thrown and no
  446. * action is performed.
  447. * @param l the item listener
  448. * @see #addItemListener
  449. * @see #getItemListeners
  450. * @see java.awt.event.ItemEvent
  451. * @see java.awt.event.ItemListener
  452. * @since JDK1.1
  453. */
  454. public synchronized void removeItemListener(ItemListener l) {
  455. if (l == null) {
  456. return;
  457. }
  458. itemListener = AWTEventMulticaster.remove(itemListener, l);
  459. }
  460. /**
  461. * Returns an array of all the item listeners
  462. * registered on this choice.
  463. *
  464. * @return all of this choice's <code>ItemListener</code>s
  465. * or an empty array if no item
  466. * listeners are currently registered
  467. *
  468. * @see #addItemListener
  469. * @see #removeItemListener
  470. * @see java.awt.event.ItemEvent
  471. * @see java.awt.event.ItemListener
  472. * @since 1.4
  473. */
  474. public synchronized ItemListener[] getItemListeners() {
  475. return (ItemListener[])(getListeners(ItemListener.class));
  476. }
  477. /**
  478. * Returns an array of all the objects currently registered
  479. * as <code><em>Foo</em>Listener</code>s
  480. * upon this <code>Choice</code>.
  481. * <code><em>Foo</em>Listener</code>s are registered using the
  482. * <code>add<em>Foo</em>Listener</code> method.
  483. *
  484. * <p>
  485. * You can specify the <code>listenerType</code> argument
  486. * with a class literal, such as
  487. * <code><em>Foo</em>Listener.class</code>.
  488. * For example, you can query a
  489. * <code>Choice</code> <code>c</code>
  490. * for its item listeners with the following code:
  491. *
  492. * <pre>ItemListener[] ils = (ItemListener[])(c.getListeners(ItemListener.class));</pre>
  493. *
  494. * If no such listeners exist, this method returns an empty array.
  495. *
  496. * @param listenerType the type of listeners requested; this parameter
  497. * should specify an interface that descends from
  498. * <code>java.util.EventListener</code>
  499. * @return an array of all objects registered as
  500. * <code><em>Foo</em>Listener</code>s on this choice,
  501. * or an empty array if no such
  502. * listeners have been added
  503. * @exception ClassCastException if <code>listenerType</code>
  504. * doesn't specify a class or interface that implements
  505. * <code>java.util.EventListener</code>
  506. *
  507. * @see #getItemListeners
  508. * @since 1.3
  509. */
  510. public EventListener[] getListeners(Class listenerType) {
  511. EventListener l = null;
  512. if (listenerType == ItemListener.class) {
  513. l = itemListener;
  514. } else {
  515. return super.getListeners(listenerType);
  516. }
  517. return AWTEventMulticaster.getListeners(l, listenerType);
  518. }
  519. // REMIND: remove when filtering is done at lower level
  520. boolean eventEnabled(AWTEvent e) {
  521. if (e.id == ItemEvent.ITEM_STATE_CHANGED) {
  522. if ((eventMask & AWTEvent.ITEM_EVENT_MASK) != 0 ||
  523. itemListener != null) {
  524. return true;
  525. }
  526. return false;
  527. }
  528. return super.eventEnabled(e);
  529. }
  530. /**
  531. * Processes events on this choice. If the event is an
  532. * instance of <code>ItemEvent</code>, it invokes the
  533. * <code>processItemEvent</code> method. Otherwise, it calls its
  534. * superclass's <code>processEvent</code> method.
  535. * <p>Note that if the event parameter is <code>null</code>
  536. * the behavior is unspecified and may result in an
  537. * exception.
  538. *
  539. * @param e the event
  540. * @see java.awt.event.ItemEvent
  541. * @see #processItemEvent
  542. * @since JDK1.1
  543. */
  544. protected void processEvent(AWTEvent e) {
  545. if (e instanceof ItemEvent) {
  546. processItemEvent((ItemEvent)e);
  547. return;
  548. }
  549. super.processEvent(e);
  550. }
  551. /**
  552. * Processes item events occurring on this <code>Choice</code>
  553. * menu by dispatching them to any registered
  554. * <code>ItemListener</code> objects.
  555. * <p>
  556. * This method is not called unless item events are
  557. * enabled for this component. Item events are enabled
  558. * when one of the following occurs:
  559. * <p><ul>
  560. * <li>An <code>ItemListener</code> object is registered
  561. * via <code>addItemListener</code>.
  562. * <li>Item events are enabled via <code>enableEvents</code>.
  563. * </ul>
  564. * <p>Note that if the event parameter is <code>null</code>
  565. * the behavior is unspecified and may result in an
  566. * exception.
  567. *
  568. * @param e the item event
  569. * @see java.awt.event.ItemEvent
  570. * @see java.awt.event.ItemListener
  571. * @see #addItemListener(ItemListener)
  572. * @see java.awt.Component#enableEvents
  573. * @since JDK1.1
  574. */
  575. protected void processItemEvent(ItemEvent e) {
  576. ItemListener listener = itemListener;
  577. if (listener != null) {
  578. listener.itemStateChanged(e);
  579. }
  580. }
  581. /**
  582. * Returns a string representing the state of this <code>Choice</code>
  583. * menu. This method is intended to be used only for debugging purposes,
  584. * and the content and format of the returned string may vary between
  585. * implementations. The returned string may be empty but may not be
  586. * <code>null</code>.
  587. *
  588. * @return the parameter string of this <code>Choice</code> menu
  589. */
  590. protected String paramString() {
  591. return super.paramString() + ",current=" + getSelectedItem();
  592. }
  593. /* Serialization support.
  594. */
  595. /*
  596. * Choice Serial Data Version.
  597. * @serial
  598. */
  599. private int choiceSerializedDataVersion = 1;
  600. /**
  601. * Writes default serializable fields to stream. Writes
  602. * a list of serializable <code>ItemListeners</code>
  603. * as optional data. The non-serializable
  604. * <code>ItemListeners</code> are detected and
  605. * no attempt is made to serialize them.
  606. *
  607. * @param s the <code>ObjectOutputStream</code> to write
  608. * @serialData <code>null</code> terminated sequence of 0
  609. * or more pairs; the pair consists of a <code>String</code>
  610. * and an <code>Object</code> the <code>String</code> indicates
  611. * the type of object and is one of the following:
  612. * <code>itemListenerK</code> indicating an
  613. * <code>ItemListener</code> object
  614. *
  615. * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
  616. * @see java.awt.Component#itemListenerK
  617. * @see #readObject(ObjectInputStream)
  618. */
  619. private void writeObject(ObjectOutputStream s)
  620. throws java.io.IOException
  621. {
  622. s.defaultWriteObject();
  623. AWTEventMulticaster.save(s, itemListenerK, itemListener);
  624. s.writeObject(null);
  625. }
  626. /**
  627. * Reads the <code>ObjectInputStream</code> and if it
  628. * isn't <code>null</code> adds a listener to receive
  629. * item events fired by the <code>Choice</code> item.
  630. * Unrecognized keys or values will be ignored.
  631. *
  632. * @param s the <code>ObjectInputStream</code> to read
  633. * @exception HeadlessException if
  634. * <code>GraphicsEnvironment.isHeadless</code> returns
  635. * <code>true</code>
  636. * @serial
  637. * @see #removeItemListener(ItemListener)
  638. * @see #addItemListener(ItemListener)
  639. * @see java.awt.GraphicsEnvironment#isHeadless
  640. * @see #writeObject(ObjectOutputStream)
  641. */
  642. private void readObject(ObjectInputStream s)
  643. throws ClassNotFoundException, IOException, HeadlessException
  644. {
  645. GraphicsEnvironment.checkHeadless();
  646. s.defaultReadObject();
  647. Object keyOrNull;
  648. while(null != (keyOrNull = s.readObject())) {
  649. String key = ((String)keyOrNull).intern();
  650. if (itemListenerK == key)
  651. addItemListener((ItemListener)(s.readObject()));
  652. else // skip value for unrecognized key
  653. s.readObject();
  654. }
  655. }
  656. /////////////////
  657. // Accessibility support
  658. ////////////////
  659. /**
  660. * Gets the <code>AccessibleContext</code> associated with this
  661. * <code>Choice</code>. For <code>Choice</code> components,
  662. * the <code>AccessibleContext</code> takes the form of an
  663. * <code>AccessibleAWTChoice</code>. A new <code>AccessibleAWTChoice</code>
  664. * instance is created if necessary.
  665. *
  666. * @return an <code>AccessibleAWTChoice</code> that serves as the
  667. * <code>AccessibleContext</code> of this <code>Choice</code>
  668. */
  669. public AccessibleContext getAccessibleContext() {
  670. if (accessibleContext == null) {
  671. accessibleContext = new AccessibleAWTChoice();
  672. }
  673. return accessibleContext;
  674. }
  675. /**
  676. * This class implements accessibility support for the
  677. * <code>Choice</code> class. It provides an implementation of the
  678. * Java Accessibility API appropriate to choice user-interface elements.
  679. */
  680. protected class AccessibleAWTChoice extends AccessibleAWTComponent
  681. implements AccessibleAction {
  682. public AccessibleAWTChoice() {
  683. super();
  684. }
  685. /**
  686. * Get the AccessibleAction associated with this object. In the
  687. * implementation of the Java Accessibility API for this class,
  688. * return this object, which is responsible for implementing the
  689. * AccessibleAction interface on behalf of itself.
  690. *
  691. * @return this object
  692. * @see AccessibleAction
  693. */
  694. public AccessibleAction getAccessibleAction() {
  695. return this;
  696. }
  697. /**
  698. * Get the role of this object.
  699. *
  700. * @return an instance of AccessibleRole describing the role of the
  701. * object
  702. * @see AccessibleRole
  703. */
  704. public AccessibleRole getAccessibleRole() {
  705. return AccessibleRole.COMBO_BOX;
  706. }
  707. /**
  708. * Returns the number of accessible actions available in this object
  709. * If there are more than one, the first one is considered the "default"
  710. * action of the object.
  711. *
  712. * @return the zero-based number of Actions in this object
  713. */
  714. public int getAccessibleActionCount() {
  715. return 0; // To be fully implemented in a future release
  716. }
  717. /**
  718. * Returns a description of the specified action of the object.
  719. *
  720. * @param i zero-based index of the actions
  721. * @return a String description of the action
  722. * @see #getAccessibleActionCount
  723. */
  724. public String getAccessibleActionDescription(int i) {
  725. return null; // To be fully implemented in a future release
  726. }
  727. /**
  728. * Perform the specified Action on the object
  729. *
  730. * @param i zero-based index of actions
  731. * @return true if the action was performed; otherwise false.
  732. * @see #getAccessibleActionCount
  733. */
  734. public boolean doAccessibleAction(int i) {
  735. return false; // To be fully implemented in a future release
  736. }
  737. } // inner class AccessibleAWTChoice
  738. }