1. /*
  2. * @(#)List.java 1.78 00/04/06
  3. *
  4. * Copyright 1995-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 java.awt;
  11. import java.util.Vector;
  12. import java.util.Locale;
  13. import java.util.EventListener;
  14. import java.awt.peer.ListPeer;
  15. import java.awt.event.*;
  16. import java.io.ObjectOutputStream;
  17. import java.io.ObjectInputStream;
  18. import java.io.IOException;
  19. import javax.accessibility.*;
  20. /**
  21. * The <code>List</code> component presents the user with a
  22. * scrolling list of text items. The list can be set up so that
  23. * the user can choose either one item or multiple items.
  24. * <p>
  25. * For example, the code . . .
  26. * <p>
  27. * <hr><blockquote><pre>
  28. * List lst = new List(4, false);
  29. * lst.add("Mercury");
  30. * lst.add("Venus");
  31. * lst.add("Earth");
  32. * lst.add("JavaSoft");
  33. * lst.add("Mars");
  34. * lst.add("Jupiter");
  35. * lst.add("Saturn");
  36. * lst.add("Uranus");
  37. * lst.add("Neptune");
  38. * lst.add("Pluto");
  39. * cnt.add(lst);
  40. * </pre></blockquote><hr>
  41. * <p>
  42. * where <code>cnt</code> is a container, produces the following
  43. * scrolling list:
  44. * <p>
  45. * <img src="doc-files/List-1.gif"
  46. * ALIGN=center HSPACE=10 VSPACE=7>
  47. * <p>
  48. * Clicking on an item that isn't selected selects it. Clicking on
  49. * an item that is already selected deselects it. In the preceding
  50. * example, only one item from the scrolling list can be selected
  51. * at a time, since the second argument when creating the new scrolling
  52. * list is <code>false</code>. Selecting an item causes any other
  53. * selected item to be automatically deselected.
  54. * <p>
  55. * Beginning with Java 1.1, the Abstract Window Toolkit
  56. * sends the <code>List</code> object all mouse, keyboard, and focus events
  57. * that occur over it. (The old AWT event model is being maintained
  58. * only for backwards compatibility, and its use is discouraged.)
  59. * <p>
  60. * When an item is selected or deselected, AWT sends an instance
  61. * of <code>ItemEvent</code> to the list.
  62. * When the user double-clicks on an item in a scrolling list,
  63. * AWT sends an instance of <code>ActionEvent</code> to the
  64. * list following the item event. AWT also generates an action event
  65. * when the user presses the return key while an item in the
  66. * list is selected.
  67. * <p>
  68. * If an application wants to perform some action based on an item
  69. * in this list being selected or activated, it should implement
  70. * <code>ItemListener</code> or <code>ActionListener</code>
  71. * as appropriate and register the new listener to receive
  72. * events from this list.
  73. * <p>
  74. * For multiple-selection scrolling lists, it is considered a better
  75. * user interface to use an external gesture (such as clicking on a
  76. * button) to trigger the action.
  77. * @version 1.78, 04/06/00
  78. * @author Sami Shaio
  79. * @see java.awt.event.ItemEvent
  80. * @see java.awt.event.ItemListener
  81. * @see java.awt.event.ActionEvent
  82. * @see java.awt.event.ActionListener
  83. * @since JDK1.0
  84. */
  85. public class List extends Component implements ItemSelectable, Accessible {
  86. /**
  87. * A vector created to contain items which will become
  88. * part of the List Component.
  89. *
  90. * @serial
  91. * @see addItem()
  92. * @see getItem()
  93. */
  94. Vector items = new Vector();
  95. /**
  96. * This field will represent the number of rows in the
  97. * List Component. It is specified only once, and
  98. * that is when the list component is actually
  99. * created. It will never change.
  100. *
  101. * @serial
  102. * @see getRows()
  103. */
  104. int rows = 0;
  105. /**
  106. * <code>multipleMode</code> is a variable that will
  107. * be set to <code>true</code> if a list component is to be set to
  108. * multiple selection mode, that is where the user can
  109. * select more than one item in a list at one time.
  110. * <code>multipleMode</code> will be set to false if the
  111. * list component is set to single selection, that is where
  112. * the user can only select one item on the list at any
  113. * one time.
  114. *
  115. * @serial
  116. * @see isMultipleMode()
  117. * @see setMultipleMode()
  118. */
  119. boolean multipleMode = false;
  120. /**
  121. * <code>selected</code> is an array that will contain
  122. * the indices of items that have been selected.
  123. *
  124. * @serial
  125. * @see getSelectedIndexes()
  126. * @see getSelectedIndex()
  127. */
  128. int selected[] = new int[0];
  129. /**
  130. * This variable contains the value that will be used
  131. * when trying to make a particular list item visible.
  132. *
  133. * @serial
  134. * @see makeVisible()
  135. */
  136. int visibleIndex = -1;
  137. transient ActionListener actionListener;
  138. transient ItemListener itemListener;
  139. private static final String base = "list";
  140. private static int nameCounter = 0;
  141. /*
  142. * JDK 1.1 serialVersionUID
  143. */
  144. private static final long serialVersionUID = -3304312411574666869L;
  145. /**
  146. * Creates a new scrolling list.
  147. * By default, there are four visible lines and multiple selections are
  148. * not allowed.
  149. */
  150. public List() {
  151. this(0, false);
  152. }
  153. /**
  154. * Creates a new scrolling list initialized with the specified
  155. * number of visible lines. By default, multiple selections are
  156. * not allowed.
  157. * @param rows the number of items to show.
  158. * @since JDK1.1
  159. */
  160. public List(int rows) {
  161. this(rows, false);
  162. }
  163. /**
  164. * The default number of visible rows is 4. A list with
  165. * zero rows is unusable and unsightly.
  166. */
  167. final static int DEFAULT_VISIBLE_ROWS = 4;
  168. /**
  169. * Creates a new scrolling list initialized to display the specified
  170. * number of rows. If the value of <code>multipleMode</code> is
  171. * <code>true</code>, then the user can select multiple items from
  172. * the list. If it is <code>false</code>, only one item at a time
  173. * can be selected.
  174. * @param rows the number of items to show.
  175. * @param multipleMode if <code>true</code>,
  176. * then multiple selections are allowed;
  177. * otherwise, only one item can be selected at a time.
  178. */
  179. public List(int rows, boolean multipleMode) {
  180. this.rows = (rows != 0) ? rows : DEFAULT_VISIBLE_ROWS;
  181. this.multipleMode = multipleMode;
  182. }
  183. /**
  184. * Construct a name for this component. Called by getName() when the
  185. * name is null.
  186. */
  187. String constructComponentName() {
  188. synchronized (getClass()) {
  189. return base + nameCounter++;
  190. }
  191. }
  192. /**
  193. * Creates the peer for the list. The peer allows us to modify the
  194. * list's appearance without changing its functionality.
  195. */
  196. public void addNotify() {
  197. synchronized (getTreeLock()) {
  198. if (peer == null)
  199. peer = getToolkit().createList(this);
  200. super.addNotify();
  201. visibleIndex = -1;
  202. }
  203. }
  204. /**
  205. * Removes the peer for this list. The peer allows us to modify the
  206. * list's appearance without changing its functionality.
  207. */
  208. public void removeNotify() {
  209. synchronized (getTreeLock()) {
  210. ListPeer peer = (ListPeer)this.peer;
  211. if (peer != null) {
  212. selected = peer.getSelectedIndexes();
  213. }
  214. super.removeNotify();
  215. }
  216. }
  217. /**
  218. * Gets the number of items in the list.
  219. * @return the number of items in the list.
  220. * @see java.awt.List#getItem
  221. * @since JDK1.1
  222. */
  223. public int getItemCount() {
  224. return countItems();
  225. }
  226. /**
  227. * @deprecated As of JDK version 1.1,
  228. * replaced by <code>getItemCount()</code>.
  229. */
  230. public int countItems() {
  231. return items.size();
  232. }
  233. /**
  234. * Gets the item associated with the specified index.
  235. * @return an item that is associated with
  236. * the specified index.
  237. * @param index the position of the item.
  238. * @see java.awt.List#getItemCount
  239. */
  240. public String getItem(int index) {
  241. return getItemImpl(index);
  242. }
  243. // NOTE: This method may be called by privileged threads.
  244. // We implement this functionality in a package-private method
  245. // to insure that it cannot be overridden by client subclasses.
  246. // DO NOT INVOKE CLIENT CODE ON THIS THREAD!
  247. final String getItemImpl(int index) {
  248. return (String)items.elementAt(index);
  249. }
  250. /**
  251. * Gets the items in the list.
  252. * @return a string array containing items of the list.
  253. * @see java.awt.List#select
  254. * @see java.awt.List#deselect
  255. * @see java.awt.List#isIndexSelected
  256. * @since JDK1.1
  257. */
  258. public synchronized String[] getItems() {
  259. String itemCopies[] = new String[items.size()];
  260. items.copyInto(itemCopies);
  261. return itemCopies;
  262. }
  263. /**
  264. * Adds the specified item to the end of scrolling list.
  265. * @param item the item to be added.
  266. * @since JDK1.1
  267. */
  268. public void add(String item) {
  269. addItem(item);
  270. }
  271. /**
  272. * @deprecated replaced by <code>add(String)</code>.
  273. */
  274. public void addItem(String item) {
  275. addItem(item, -1);
  276. }
  277. /**
  278. * Adds the specified item to the the scrolling list
  279. * at the position indicated by the index. The index is
  280. * zero-based. If the value of the index is less than zero,
  281. * or if the value of the index is greater than or equal to
  282. * the number of items in the list, then the item is added
  283. * to the end of the list.
  284. * @param item the item to be added.
  285. * If this parameter is null then the item is
  286. * treated as an empty string, <code>""</code>.
  287. * @param index the position at which to add the item.
  288. * @since JDK1.1
  289. */
  290. public void add(String item, int index) {
  291. addItem(item, index);
  292. }
  293. /**
  294. * @deprecated replaced by <code>add(String, int)</code>.
  295. */
  296. public synchronized void addItem(String item, int index) {
  297. if (index < -1 || index >= items.size()) {
  298. index = -1;
  299. }
  300. if (item == null) {
  301. item = "";
  302. }
  303. if (index == -1) {
  304. items.addElement(item);
  305. } else {
  306. items.insertElementAt(item, index);
  307. }
  308. ListPeer peer = (ListPeer)this.peer;
  309. if (peer != null) {
  310. peer.addItem(item, index);
  311. }
  312. }
  313. /**
  314. * Replaces the item at the specified index in the scrolling list
  315. * with the new string.
  316. * @param newValue a new string to replace an existing item.
  317. * @param index the position of the item to replace.
  318. */
  319. public synchronized void replaceItem(String newValue, int index) {
  320. remove(index);
  321. add(newValue, index);
  322. }
  323. /**
  324. * Removes all items from this list.
  325. * @see #remove
  326. * @see #delItems
  327. * @since JDK1.1
  328. */
  329. public void removeAll() {
  330. clear();
  331. }
  332. /**
  333. * @deprecated As of JDK version 1.1,
  334. * replaced by <code>removeAll()</code>.
  335. */
  336. public synchronized void clear() {
  337. ListPeer peer = (ListPeer)this.peer;
  338. if (peer != null) {
  339. peer.clear();
  340. }
  341. items = new Vector();
  342. selected = new int[0];
  343. }
  344. /**
  345. * Removes the first occurrence of an item from the list.
  346. * @param item the item to remove from the list.
  347. * @exception IllegalArgumentException
  348. * if the item doesn't exist in the list.
  349. * @since JDK1.1
  350. */
  351. public synchronized void remove(String item) {
  352. int index = items.indexOf(item);
  353. if (index < 0) {
  354. throw new IllegalArgumentException("item " + item +
  355. " not found in list");
  356. } else {
  357. remove(index);
  358. }
  359. }
  360. /**
  361. * Remove the item at the specified position
  362. * from this scrolling list.
  363. * @param position the index of the item to delete.
  364. * @see java.awt.List#add(String, int)
  365. * @since JDK1.1
  366. * @exception ArrayIndexOutOfBoundsException
  367. * if the <code>position</code> is less than 0 or
  368. * greater than <code>getItemCount()-1</code>
  369. */
  370. public void remove(int position) {
  371. delItem(position);
  372. }
  373. /**
  374. * @deprecated replaced by <code>remove(String)</code>
  375. * and <code>remove(int)</code>.
  376. */
  377. public void delItem(int position) {
  378. delItems(position, position);
  379. }
  380. /**
  381. * Gets the index of the selected item on the list,
  382. * @return the index of the selected item, or
  383. * <code>-1</code> if no item is selected,
  384. * or if more that one item is selected.
  385. * @see java.awt.List#select
  386. * @see java.awt.List#deselect
  387. * @see java.awt.List#isIndexSelected
  388. */
  389. public synchronized int getSelectedIndex() {
  390. int sel[] = getSelectedIndexes();
  391. return (sel.length == 1) ? sel[0] : -1;
  392. }
  393. /**
  394. * Gets the selected indexes on the list.
  395. * @return an array of the selected indexes
  396. * of this scrolling list. If no items are
  397. * selected, a zero-length array is returned.
  398. * @see java.awt.List#select
  399. * @see java.awt.List#deselect
  400. * @see java.awt.List#isIndexSelected
  401. */
  402. public synchronized int[] getSelectedIndexes() {
  403. ListPeer peer = (ListPeer)this.peer;
  404. if (peer != null) {
  405. selected = ((ListPeer)peer).getSelectedIndexes();
  406. }
  407. return selected;
  408. }
  409. /**
  410. * Get the selected item on this scrolling list.
  411. * @return the selected item on the list,
  412. * or null if no item is selected.
  413. * @see java.awt.List#select
  414. * @see java.awt.List#deselect
  415. * @see java.awt.List#isIndexSelected
  416. */
  417. public synchronized String getSelectedItem() {
  418. int index = getSelectedIndex();
  419. return (index < 0) ? null : getItem(index);
  420. }
  421. /**
  422. * Get the selected items on this scrolling list.
  423. * @return an array of the selected items
  424. * on this scrolling list.
  425. * @see java.awt.List#select
  426. * @see java.awt.List#deselect
  427. * @see java.awt.List#isIndexSelected
  428. */
  429. public synchronized String[] getSelectedItems() {
  430. int sel[] = getSelectedIndexes();
  431. String str[] = new String[sel.length];
  432. for (int i = 0 ; i < sel.length ; i++) {
  433. str[i] = getItem(sel[i]);
  434. }
  435. return str;
  436. }
  437. /**
  438. * Returns the selected items on the list in an array of Objects.
  439. * @see ItemSelectable
  440. */
  441. public Object[] getSelectedObjects() {
  442. return getSelectedItems();
  443. }
  444. /**
  445. * Selects the item at the specified index in the scrolling list.
  446. * @param index the position of the item to select.
  447. * @see java.awt.List#getSelectedItem
  448. * @see java.awt.List#deselect
  449. * @see java.awt.List#isIndexSelected
  450. */
  451. public void select(int index) {
  452. // Bug #4059614: select can't be synchronized while calling the peer,
  453. // because it is called from the Window Thread. It is sufficient to
  454. // synchronize the code that manipulates 'selected' except for the
  455. // case where the peer changes. To handle this case, we simply
  456. // repeat the selection process.
  457. ListPeer peer;
  458. do {
  459. peer = (ListPeer)this.peer;
  460. if (peer != null) {
  461. peer.select(index);
  462. return;
  463. }
  464. synchronized(this)
  465. {
  466. boolean alreadySelected = false;
  467. for (int i = 0 ; i < selected.length ; i++) {
  468. if (selected[i] == index) {
  469. alreadySelected = true;
  470. break;
  471. }
  472. }
  473. if (!alreadySelected) {
  474. if (!multipleMode) {
  475. selected = new int[1];
  476. selected[0] = index;
  477. } else {
  478. int newsel[] = new int[selected.length + 1];
  479. System.arraycopy(selected, 0, newsel, 0,
  480. selected.length);
  481. newsel[selected.length] = index;
  482. selected = newsel;
  483. }
  484. }
  485. }
  486. } while (peer != this.peer);
  487. }
  488. /**
  489. * Deselects the item at the specified index.
  490. * <p>
  491. * If the item at the specified index is not selected, or if the
  492. * index is out of range, then the operation is ignored.
  493. * @param index the position of the item to deselect.
  494. * @see java.awt.List#select
  495. * @see java.awt.List#getSelectedItem
  496. * @see java.awt.List#isIndexSelected
  497. */
  498. public synchronized void deselect(int index) {
  499. ListPeer peer = (ListPeer)this.peer;
  500. if (peer != null) {
  501. peer.deselect(index);
  502. }
  503. for (int i = 0 ; i < selected.length ; i++) {
  504. if (selected[i] == index) {
  505. int newsel[] = new int[selected.length - 1];
  506. System.arraycopy(selected, 0, newsel, 0, i);
  507. System.arraycopy(selected, i+1, newsel, i, selected.length - (i+1));
  508. selected = newsel;
  509. return;
  510. }
  511. }
  512. }
  513. /**
  514. * Determines if the specified item in this scrolling list is
  515. * selected.
  516. * @param index the item to be checked.
  517. * @return <code>true</code> if the specified item has been
  518. * selected; <code>false</code> otherwise.
  519. * @see java.awt.List#select
  520. * @see java.awt.List#deselect
  521. * @since JDK1.1
  522. */
  523. public boolean isIndexSelected(int index) {
  524. return isSelected(index);
  525. }
  526. /**
  527. * @deprecated As of JDK version 1.1,
  528. * replaced by <code>isIndexSelected(int)</code>.
  529. */
  530. public boolean isSelected(int index) {
  531. int sel[] = getSelectedIndexes();
  532. for (int i = 0 ; i < sel.length ; i++) {
  533. if (sel[i] == index) {
  534. return true;
  535. }
  536. }
  537. return false;
  538. }
  539. /**
  540. * Get the number of visible lines in this list.
  541. * @return the number of visible lines in this scrolling list.
  542. */
  543. public int getRows() {
  544. return rows;
  545. }
  546. /**
  547. * Determines whether this list allows multiple selections.
  548. * @return <code>true</code> if this list allows multiple
  549. * selections; otherwise, <code>false</code>.
  550. * @see java.awt.List#setMultipleMode
  551. * @since JDK1.1
  552. */
  553. public boolean isMultipleMode() {
  554. return allowsMultipleSelections();
  555. }
  556. /**
  557. * @deprecated As of JDK version 1.1,
  558. * replaced by <code>isMultipleMode()</code>.
  559. */
  560. public boolean allowsMultipleSelections() {
  561. return multipleMode;
  562. }
  563. /**
  564. * Sets the flag that determines whether this list
  565. * allows multiple selections.
  566. * @param b if <code>true</code> then multiple selections
  567. * are allowed; otherwise, only one item from
  568. * the list can be selected at once.
  569. * @see java.awt.List#isMultipleMode
  570. * @since JDK1.1
  571. */
  572. public void setMultipleMode(boolean b) {
  573. setMultipleSelections(b);
  574. }
  575. /**
  576. * @deprecated As of JDK version 1.1,
  577. * replaced by <code>setMultipleMode(boolean)</code>.
  578. */
  579. public synchronized void setMultipleSelections(boolean b) {
  580. if (b != multipleMode) {
  581. multipleMode = b;
  582. ListPeer peer = (ListPeer)this.peer;
  583. if (peer != null) {
  584. peer.setMultipleSelections(b);
  585. }
  586. }
  587. }
  588. /**
  589. * Gets the index of the item that was last made visible by
  590. * the method <code>makeVisible</code>.
  591. * @return the index of the item that was last made visible.
  592. * @see java.awt.List#makeVisible
  593. */
  594. public int getVisibleIndex() {
  595. return visibleIndex;
  596. }
  597. /**
  598. * Makes the item at the specified index visible.
  599. * @param index the position of the item.
  600. * @see java.awt.List#getVisibleIndex
  601. */
  602. public synchronized void makeVisible(int index) {
  603. visibleIndex = index;
  604. ListPeer peer = (ListPeer)this.peer;
  605. if (peer != null) {
  606. peer.makeVisible(index);
  607. }
  608. }
  609. /**
  610. * Gets the preferred dimensions for a list with the specified
  611. * number of rows.
  612. * @param rows number of rows in the list.
  613. * @return the preferred dimensions for displaying this scrolling list
  614. * given that the specified number of rows must be visible.
  615. * @see java.awt.Component#getPreferredSize
  616. * @since JDK1.1
  617. */
  618. public Dimension getPreferredSize(int rows) {
  619. return preferredSize(rows);
  620. }
  621. /**
  622. * @deprecated As of JDK version 1.1,
  623. * replaced by <code>getPreferredSize(int)</code>.
  624. */
  625. public Dimension preferredSize(int rows) {
  626. synchronized (getTreeLock()) {
  627. ListPeer peer = (ListPeer)this.peer;
  628. return (peer != null) ?
  629. peer.preferredSize(rows) :
  630. super.preferredSize();
  631. }
  632. }
  633. /**
  634. * Gets the preferred size of this scrolling list.
  635. * @return the preferred dimensions for displaying this scrolling list.
  636. * @see java.awt.Component#getPreferredSize
  637. * @since JDK1.1
  638. */
  639. public Dimension getPreferredSize() {
  640. return preferredSize();
  641. }
  642. /**
  643. * @deprecated As of JDK version 1.1,
  644. * replaced by <code>getPreferredSize()</code>.
  645. */
  646. public Dimension preferredSize() {
  647. synchronized (getTreeLock()) {
  648. return (rows > 0) ?
  649. preferredSize(rows) :
  650. super.preferredSize();
  651. }
  652. }
  653. /**
  654. * Gets the minumum dimensions for a list with the specified
  655. * number of rows.
  656. * @param rows number of rows in the list.
  657. * @return the minimum dimensions for displaying this scrolling list
  658. * given that the specified number of rows must be visible.
  659. * @see java.awt.Component#getMinimumSize
  660. * @since JDK1.1
  661. */
  662. public Dimension getMinimumSize(int rows) {
  663. return minimumSize(rows);
  664. }
  665. /**
  666. * @deprecated As of JDK version 1.1,
  667. * replaced by <code>getMinimumSize(int)</code>.
  668. */
  669. public Dimension minimumSize(int rows) {
  670. synchronized (getTreeLock()) {
  671. ListPeer peer = (ListPeer)this.peer;
  672. return (peer != null) ?
  673. peer.minimumSize(rows) :
  674. super.minimumSize();
  675. }
  676. }
  677. /**
  678. * Determines the minimum size of this scrolling list.
  679. * @return the minimum dimensions needed
  680. * to display this scrolling list.
  681. * @see java.awt.Component#getMinimumSize()
  682. * @since JDK1.1
  683. */
  684. public Dimension getMinimumSize() {
  685. return minimumSize();
  686. }
  687. /**
  688. * @deprecated As of JDK version 1.1,
  689. * replaced by <code>getMinimumSize()</code>.
  690. */
  691. public Dimension minimumSize() {
  692. synchronized (getTreeLock()) {
  693. return (rows > 0) ? minimumSize(rows) : super.minimumSize();
  694. }
  695. }
  696. /**
  697. * Adds the specified item listener to receive item events from
  698. * this list.
  699. * If l is null, no exception is thrown and no action is performed.
  700. *
  701. * @param l the item listener.
  702. * @see java.awt.event.ItemEvent
  703. * @see java.awt.event.ItemListener
  704. * @see java.awt.List#removeItemListener
  705. * @since JDK1.1
  706. */
  707. public synchronized void addItemListener(ItemListener l) {
  708. if (l == null) {
  709. return;
  710. }
  711. itemListener = AWTEventMulticaster.add(itemListener, l);
  712. newEventsOnly = true;
  713. }
  714. /**
  715. * Removes the specified item listener so that it no longer
  716. * receives item events from this list.
  717. * If l is null, no exception is thrown and no action is performed.
  718. *
  719. * @param l the item listener.
  720. * @see java.awt.event.ItemEvent
  721. * @see java.awt.event.ItemListener
  722. * @see java.awt.List#addItemListener
  723. * @since JDK1.1
  724. */
  725. public synchronized void removeItemListener(ItemListener l) {
  726. if (l == null) {
  727. return;
  728. }
  729. itemListener = AWTEventMulticaster.remove(itemListener, l);
  730. }
  731. /**
  732. * Adds the specified action listener to receive action events from
  733. * this list. Action events occur when a user double-clicks
  734. * on a list item.
  735. * If l is null, no exception is thrown and no action is performed.
  736. *
  737. * @param l the action listener.
  738. * @see java.awt.event.ActionEvent
  739. * @see java.awt.event.ActionListener
  740. * @see java.awt.List#removeActionListener
  741. * @since JDK1.1
  742. */
  743. public synchronized void addActionListener(ActionListener l) {
  744. if (l == null) {
  745. return;
  746. }
  747. actionListener = AWTEventMulticaster.add(actionListener, l);
  748. newEventsOnly = true;
  749. }
  750. /**
  751. * Removes the specified action listener so that it no longer
  752. * receives action events from this list. Action events
  753. * occur when a user double-clicks on a list item.
  754. * If l is null, no exception is thrown and no action is performed.
  755. *
  756. * @param l the action listener.
  757. * @see java.awt.event.ActionEvent
  758. * @see java.awt.event.ActionListener
  759. * @see java.awt.List#addActionListener
  760. * @since JDK1.1
  761. */
  762. public synchronized void removeActionListener(ActionListener l) {
  763. if (l == null) {
  764. return;
  765. }
  766. actionListener = AWTEventMulticaster.remove(actionListener, l);
  767. }
  768. /**
  769. * Return an array of all the listeners that were added to the List
  770. * with addXXXListener(), where XXX is the name of the <code>listenerType</code>
  771. * argument. For example, to get all of the ItemListener(s) for the
  772. * given List <code>l</code>, one would write:
  773. * <pre>
  774. * ItemListener[] ils = (ItemListener[])(l.getListeners(ItemListener.class))
  775. * </pre>
  776. * If no such listener list exists, then an empty array is returned.
  777. *
  778. * @param listenerType Type of listeners requested
  779. * @return all of the listeners of the specified type supported by this list
  780. * @since 1.3
  781. */
  782. public EventListener[] getListeners(Class listenerType) {
  783. EventListener l = null;
  784. if (listenerType == ActionListener.class) {
  785. l = actionListener;
  786. } else if (listenerType == ItemListener.class) {
  787. l = itemListener;
  788. } else {
  789. return super.getListeners(listenerType);
  790. }
  791. return AWTEventMulticaster.getListeners(l, listenerType);
  792. }
  793. // REMIND: remove when filtering is done at lower level
  794. boolean eventEnabled(AWTEvent e) {
  795. switch(e.id) {
  796. case ActionEvent.ACTION_PERFORMED:
  797. if ((eventMask & AWTEvent.ACTION_EVENT_MASK) != 0 ||
  798. actionListener != null) {
  799. return true;
  800. }
  801. return false;
  802. case ItemEvent.ITEM_STATE_CHANGED:
  803. if ((eventMask & AWTEvent.ITEM_EVENT_MASK) != 0 ||
  804. itemListener != null) {
  805. return true;
  806. }
  807. return false;
  808. default:
  809. break;
  810. }
  811. return super.eventEnabled(e);
  812. }
  813. /**
  814. * Processes events on this scrolling list. If an event is
  815. * an instance of <code>ItemEvent</code>, it invokes the
  816. * <code>processItemEvent</code> method. Else, if the
  817. * event is an instance of <code>ActionEvent</code>,
  818. * it invokes <code>processActionEvent</code>.
  819. * If the event is not an item event or an action event,
  820. * it invokes <code>processEvent</code> on the superclass.
  821. * @param e the event.
  822. * @see java.awt.event.ActionEvent
  823. * @see java.awt.event.ItemEvent
  824. * @see java.awt.List#processActionEvent
  825. * @see java.awt.List#processItemEvent
  826. * @since JDK1.1
  827. */
  828. protected void processEvent(AWTEvent e) {
  829. if (e instanceof ItemEvent) {
  830. processItemEvent((ItemEvent)e);
  831. return;
  832. } else if (e instanceof ActionEvent) {
  833. processActionEvent((ActionEvent)e);
  834. return;
  835. }
  836. super.processEvent(e);
  837. }
  838. /**
  839. * Processes item events occurring on this list by
  840. * dispatching them to any registered
  841. * <code>ItemListener</code> objects.
  842. * <p>
  843. * This method is not called unless item events are
  844. * enabled for this component. Item events are enabled
  845. * when one of the following occurs:
  846. * <p><ul>
  847. * <li>An <code>ItemListener</code> object is registered
  848. * via <code>addItemListener</code>.
  849. * <li>Item events are enabled via <code>enableEvents</code>.
  850. * </ul>
  851. * @param e the item event.
  852. * @see java.awt.event.ItemEvent
  853. * @see java.awt.event.ItemListener
  854. * @see java.awt.List#addItemListener
  855. * @see java.awt.Component#enableEvents
  856. * @since JDK1.1
  857. */
  858. protected void processItemEvent(ItemEvent e) {
  859. if (itemListener != null) {
  860. itemListener.itemStateChanged(e);
  861. }
  862. }
  863. /**
  864. * Processes action events occurring on this component
  865. * by dispatching them to any registered
  866. * <code>ActionListener</code> objects.
  867. * <p>
  868. * This method is not called unless action events are
  869. * enabled for this component. Action events are enabled
  870. * when one of the following occurs:
  871. * <p><ul>
  872. * <li>An <code>ActionListener</code> object is registered
  873. * via <code>addActionListener</code>.
  874. * <li>Action events are enabled via <code>enableEvents</code>.
  875. * </ul>
  876. * @param e the action event.
  877. * @see java.awt.event.ActionEvent
  878. * @see java.awt.event.ActionListener
  879. * @see java.awt.List#addActionListener
  880. * @see java.awt.Component#enableEvents
  881. * @since JDK1.1
  882. */
  883. protected void processActionEvent(ActionEvent e) {
  884. if (actionListener != null) {
  885. actionListener.actionPerformed(e);
  886. }
  887. }
  888. /**
  889. * Returns the parameter string representing the state of this
  890. * scrolling list. This string is useful for debugging.
  891. * @return the parameter string of this scrolling list.
  892. */
  893. protected String paramString() {
  894. return super.paramString() + ",selected=" + getSelectedItem();
  895. }
  896. /**
  897. * @deprecated As of JDK version 1.1,
  898. * Not for public use in the future.
  899. * This method is expected to be retained only as a package
  900. * private method.
  901. */
  902. public synchronized void delItems(int start, int end) {
  903. for (int i = end; i >= start; i--) {
  904. items.removeElementAt(i);
  905. }
  906. ListPeer peer = (ListPeer)this.peer;
  907. if (peer != null) {
  908. peer.delItems(start, end);
  909. }
  910. }
  911. /*
  912. * Serialization support. Since the value of the selected
  913. * field isn't neccessarily up to date we sync it up with the
  914. * peer before serializing.
  915. */
  916. /**
  917. * The List Components Serialized Data Version.
  918. *
  919. * @serial
  920. */
  921. private int listSerializedDataVersion = 1;
  922. /**
  923. * Writes default serializable fields to stream. Writes
  924. * a list of serializable ItemListener(s) as optional data.
  925. * The non-serializable ItemListner(s) are detected and
  926. * no attempt is made to serialize them.
  927. *
  928. * @serialData Null terminated sequence of 0 or more pairs.
  929. * The pair consists of a String and Object.
  930. * The String indicates the type of object and
  931. * is one of the following :
  932. * itemListenerK indicating and ItemListener object.
  933. *
  934. * @see AWTEventMulticaster.save(ObjectOutputStream, String, EventListener)
  935. * @see java.awt.Component.itemListenerK
  936. */
  937. private void writeObject(ObjectOutputStream s)
  938. throws IOException
  939. {
  940. synchronized (this) {
  941. ListPeer peer = (ListPeer)this.peer;
  942. if (peer != null) {
  943. selected = peer.getSelectedIndexes();
  944. }
  945. }
  946. s.defaultWriteObject();
  947. AWTEventMulticaster.save(s, itemListenerK, itemListener);
  948. AWTEventMulticaster.save(s, actionListenerK, actionListener);
  949. s.writeObject(null);
  950. }
  951. /**
  952. * Read the ObjectInputStream and if it isnt null
  953. * add a listener to receive item events fired
  954. * by the List.
  955. * Unrecognised keys or values will be Ignored.
  956. * @see removeActionListener()
  957. * @see addActionListener()
  958. */
  959. private void readObject(ObjectInputStream s)
  960. throws ClassNotFoundException, IOException
  961. {
  962. s.defaultReadObject();
  963. Object keyOrNull;
  964. while(null != (keyOrNull = s.readObject())) {
  965. String key = ((String)keyOrNull).intern();
  966. if (itemListenerK == key)
  967. addItemListener((ItemListener)(s.readObject()));
  968. else if (actionListenerK == key)
  969. addActionListener((ActionListener)(s.readObject()));
  970. else // skip value for unrecognized key
  971. s.readObject();
  972. }
  973. }
  974. /////////////////
  975. // Accessibility support
  976. ////////////////
  977. /**
  978. * Gets the AccessibleContext associated with this List.
  979. * For lists, the AccessibleContext takes the form of an
  980. * AccessibleAWTList.
  981. * A new AccessibleAWTList instance is created if necessary.
  982. *
  983. * @return an AccessibleAWTList that serves as the
  984. * AccessibleContext of this List
  985. */
  986. public AccessibleContext getAccessibleContext() {
  987. if (accessibleContext == null) {
  988. accessibleContext = new AccessibleAWTList();
  989. }
  990. return accessibleContext;
  991. }
  992. /**
  993. * This class implements accessibility support for the
  994. * <code>List</code> class. It provides an implementation of the
  995. * Java Accessibility API appropriate to list user-interface elements.
  996. */
  997. protected class AccessibleAWTList extends AccessibleAWTComponent
  998. implements AccessibleSelection, ItemListener, ActionListener {
  999. public AccessibleAWTList() {
  1000. super();
  1001. List.this.addActionListener(this);
  1002. List.this.addItemListener(this);
  1003. }
  1004. public void actionPerformed(ActionEvent event) {
  1005. }
  1006. public void itemStateChanged(ItemEvent event) {
  1007. }
  1008. /**
  1009. * Get the state set of this object.
  1010. *
  1011. * @return an instance of AccessibleState containing the current state
  1012. * of the object
  1013. * @see AccessibleState
  1014. */
  1015. public AccessibleStateSet getAccessibleStateSet() {
  1016. AccessibleStateSet states = super.getAccessibleStateSet();
  1017. if (List.this.isMultipleMode()) {
  1018. states.add(AccessibleState.MULTISELECTABLE);
  1019. }
  1020. return states;
  1021. }
  1022. /**
  1023. * Get the role of this object.
  1024. *
  1025. * @return an instance of AccessibleRole describing the role of the
  1026. * object
  1027. * @see AccessibleRole
  1028. */
  1029. public AccessibleRole getAccessibleRole() {
  1030. return AccessibleRole.LIST;
  1031. }
  1032. /**
  1033. * Returns the Accessible child contained at the local coordinate
  1034. * Point, if one exists.
  1035. *
  1036. * @return the Accessible at the specified location, if it exists
  1037. */
  1038. public Accessible getAccessibleAt(Point p) {
  1039. return null; // fredxFIXME Not implemented yet
  1040. }
  1041. /**
  1042. * Returns the number of accessible children in the object. If all
  1043. * of the children of this object implement Accessible, than this
  1044. * method should return the number of children of this object.
  1045. *
  1046. * @return the number of accessible children in the object.
  1047. */
  1048. public int getAccessibleChildrenCount() {
  1049. return List.this.getItemCount();
  1050. }
  1051. /**
  1052. * Return the nth Accessible child of the object.
  1053. *
  1054. * @param i zero-based index of child
  1055. * @return the nth Accessible child of the object
  1056. */
  1057. public Accessible getAccessibleChild(int i) {
  1058. synchronized(List.this) {
  1059. if (i >= List.this.getItemCount()) {
  1060. return null;
  1061. } else {
  1062. return new AccessibleAWTListChild(List.this, i);
  1063. }
  1064. }
  1065. }
  1066. /**
  1067. * Get the AccessibleSelection associated with this object. In the
  1068. * implementation of the Java Accessibility API for this class,
  1069. * return this object, which is responsible for implementing the
  1070. * AccessibleSelection interface on behalf of itself.
  1071. *
  1072. * @return this object
  1073. */
  1074. public AccessibleSelection getAccessibleSelection() {
  1075. return this;
  1076. }
  1077. // AccessibleSelection methods
  1078. /**
  1079. * Returns the number of items currently selected.
  1080. * If no items are selected, the return value will be 0.
  1081. *
  1082. * @return the number of items currently selected.
  1083. */
  1084. public int getAccessibleSelectionCount() {
  1085. return List.this.getSelectedIndexes().length;
  1086. }
  1087. /**
  1088. * Returns an Accessible representing the specified selected item
  1089. * in the object. If there isn't a selection, or there are
  1090. * fewer items selected than the integer passed in, the return
  1091. * value will be null.
  1092. *
  1093. * @param i the zero-based index of selected items
  1094. * @return an Accessible containing the selected item
  1095. */
  1096. public Accessible getAccessibleSelection(int i) {
  1097. synchronized(List.this) {
  1098. int len = getAccessibleSelectionCount();
  1099. if (i <= 0 || i >= len) {
  1100. return null;
  1101. } else {
  1102. return getAccessibleChild(List.this.getSelectedIndexes()[i]);
  1103. }
  1104. }
  1105. }
  1106. /**
  1107. * Returns true if the current child of this object is selected.
  1108. *
  1109. * @param i the zero-based index of the child in this Accessible
  1110. * object.
  1111. * @see AccessibleContext#getAccessibleChild
  1112. */
  1113. public boolean isAccessibleChildSelected(int i) {
  1114. return List.this.isIndexSelected(i);
  1115. }
  1116. /**
  1117. * Adds the specified selected item in the object to the object's
  1118. * selection. If the object supports multiple selections,
  1119. * the specified item is added to any existing selection, otherwise
  1120. * it replaces any existing selection in the object. If the
  1121. * specified item is already selected, this method has no effect.
  1122. *
  1123. * @param i the zero-based index of selectable items
  1124. */
  1125. public void addAccessibleSelection(int i) {
  1126. List.this.select(i);
  1127. }
  1128. /**
  1129. * Removes the specified selected item in the object from the object's
  1130. * selection. If the specified item isn't currently selected, this
  1131. * method has no effect.
  1132. *
  1133. * @param i the zero-based index of selectable items
  1134. */
  1135. public void removeAccessibleSelection(int i) {
  1136. List.this.deselect(i);
  1137. }
  1138. /**
  1139. * Clears the selection in the object, so that nothing in the
  1140. * object is selected.
  1141. */
  1142. public void clearAccessibleSelection() {
  1143. synchronized(List.this) {
  1144. int selectedIndexes[] = List.this.getSelectedIndexes();
  1145. if (selectedIndexes == null)
  1146. return;
  1147. for (int i = selectedIndexes.length; i >= 0; i--) {
  1148. List.this.deselect(selectedIndexes[i]);
  1149. }
  1150. }
  1151. }
  1152. /**
  1153. * Causes every selected item in the object to be selected
  1154. * if the object supports multiple selections.
  1155. */
  1156. public void selectAllAccessibleSelection() {
  1157. synchronized(List.this) {
  1158. for (int i = List.this.getItemCount() - 1; i >= 0; i--) {
  1159. List.this.select(i);
  1160. }
  1161. }
  1162. }
  1163. /**
  1164. * This class implements accessibility support for
  1165. * List children. It provides an implementation of the
  1166. * Java Accessibility API appropriate to list children
  1167. * user-interface elements.
  1168. */
  1169. protected class AccessibleAWTListChild extends AccessibleAWTComponent
  1170. implements Accessible {
  1171. // [[[FIXME]]] need to finish implementing this!!!
  1172. private List parent;
  1173. private int indexInParent;
  1174. public AccessibleAWTListChild(List parent, int indexInParent) {
  1175. this.parent = parent;
  1176. this.setAccessibleParent(parent);
  1177. this.indexInParent = indexInParent;
  1178. }
  1179. //
  1180. // required Accessible methods
  1181. //
  1182. /**
  1183. * Gets the AccessibleContext for this object. In the
  1184. * implementation of the Java Accessibility API for this class,
  1185. * return this object, which acts as its own AccessibleContext.
  1186. *
  1187. * @return this object
  1188. */
  1189. public AccessibleContext getAccessibleContext() {
  1190. return this;
  1191. }
  1192. //
  1193. // required AccessibleContext methods
  1194. //
  1195. /**
  1196. * Get the role of this object.
  1197. *
  1198. * @return an instance of AccessibleRole describing the role of
  1199. * the object
  1200. * @see AccessibleRole
  1201. */
  1202. public AccessibleRole getAccessibleRole() {
  1203. return AccessibleRole.LIST_ITEM;
  1204. }
  1205. /**
  1206. * Get the state set of this object. The AccessibleStateSet of an
  1207. * object is composed of a set of unique AccessibleState's. A
  1208. * change in the AccessibleStateSet of an object will cause a
  1209. * PropertyChangeEvent to be fired for the
  1210. * ACCESSIBLE_STATE_PROPERTY property.
  1211. *
  1212. * @return an instance of AccessibleStateSet containing the
  1213. * current state set of the object
  1214. * @see AccessibleStateSet
  1215. * @see AccessibleState
  1216. * @see #addPropertyChangeListener
  1217. */
  1218. public AccessibleStateSet getAccessibleStateSet() {
  1219. AccessibleStateSet states = super.getAccessibleStateSet();
  1220. if (parent.isIndexSelected(indexInParent)) {
  1221. states.add(AccessibleState.SELECTED);
  1222. }
  1223. return states;
  1224. }
  1225. /**
  1226. * Gets the locale of the component. If the component does not
  1227. * have a locale, then the locale of its parent is returned.
  1228. *
  1229. * @return This component's locale. If this component does not have
  1230. * a locale, the locale of its parent is returned.
  1231. *
  1232. * @exception IllegalComponentStateException
  1233. * If the Component does not have its own locale and has not yet
  1234. * been added to a containment hierarchy such that the locale can
  1235. * be determined from the containing parent.
  1236. */
  1237. public Locale getLocale() {
  1238. return parent.getLocale();
  1239. }
  1240. /**
  1241. * Get the 0-based index of this object in its accessible parent.
  1242. *
  1243. * @return the 0-based index of this object in its parent; -1 if
  1244. * this object does not have an accessible parent.
  1245. *
  1246. * @see #getAccessibleParent
  1247. * @see #getAccessibleChildrenCount
  1248. * @see #getAccessibleChild
  1249. */
  1250. public int getAccessibleIndexInParent() {
  1251. return indexInParent;
  1252. }
  1253. /**
  1254. * Returns the number of accessible children of the object.
  1255. *
  1256. * @return the number of accessible children of the object.
  1257. */
  1258. public int getAccessibleChildrenCount() {
  1259. return 0; // list elements can't have children
  1260. }
  1261. /**
  1262. * Return the specified Accessible child of the object. The
  1263. * Accessible children of an Accessible object are zero-based,
  1264. * so the first child of an Accessible child is at index 0, the
  1265. * second child is at index 1, and so on.
  1266. *
  1267. * @param i zero-based index of child
  1268. * @return the Accessible child of the object
  1269. * @see #getAccessibleChildrenCount
  1270. */
  1271. public Accessible getAccessibleChild(int i) {
  1272. return null; // list elements can't have children
  1273. }
  1274. //
  1275. // AccessibleComponent delegatation to parent List
  1276. //
  1277. /**
  1278. * Get the background color of this object.
  1279. *
  1280. * @return the background color, if supported, of the object;
  1281. * otherwise, null
  1282. * @see #setBackground
  1283. */
  1284. public Color getBackground() {
  1285. return parent.getBackground();
  1286. }
  1287. /**
  1288. * Set the background color of this object.
  1289. *
  1290. * @param c the new Color for the background
  1291. * @see #setBackground
  1292. */
  1293. public void setBackground(Color c) {
  1294. parent.setBackground(c);
  1295. }
  1296. /**
  1297. * Get the foreground color of this object.
  1298. *
  1299. * @return the foreground color, if supported, of the object;
  1300. * otherwise, null
  1301. * @see #setForeground
  1302. */
  1303. public Color getForeground() {
  1304. return parent.getForeground();
  1305. }
  1306. /**
  1307. * Set the foreground color of this object.
  1308. *
  1309. * @param c the new Color for the foreground
  1310. * @see #getForeground
  1311. */
  1312. public void setForeground(Color c) {
  1313. parent.setForeground(c);
  1314. }
  1315. /**
  1316. * Get the Cursor of this object.
  1317. *
  1318. * @return the Cursor, if supported, of the object; otherwise, null
  1319. * @see #setCursor
  1320. */
  1321. public Cursor getCursor() {
  1322. return parent.getCursor();
  1323. }
  1324. /**
  1325. * Set the Cursor of this object.
  1326. *
  1327. * @param c the new Cursor for the object
  1328. * @see #getCursor
  1329. */
  1330. public void setCursor(Cursor cursor) {
  1331. parent.setCursor(cursor);
  1332. }
  1333. /**
  1334. * Get the Font of this object.
  1335. *
  1336. * @return the Font,if supported, for the object; otherwise, null
  1337. * @see #setFont
  1338. */
  1339. public Font getFont() {
  1340. return parent.getFont();
  1341. }
  1342. /**
  1343. * Set the Font of this object.
  1344. *
  1345. * @param f the new Font for the object
  1346. * @see #getFont
  1347. */
  1348. public void setFont(Font f) {
  1349. parent.setFont(f);
  1350. }
  1351. /**
  1352. * Get the FontMetrics of this object.
  1353. *
  1354. * @param f the Font
  1355. * @return the FontMetrics, if supported, the object; otherwise, null
  1356. * @see #getFont
  1357. */
  1358. public FontMetrics getFontMetrics(Font f) {
  1359. return parent.getFontMetrics(f);
  1360. }
  1361. /**
  1362. * Determine if the object is enabled. Objects that are enabled
  1363. * will also have the AccessibleState.ENABLED state set in their
  1364. * AccessibleStateSet.
  1365. *
  1366. * @return true if object is enabled; otherwise, false
  1367. * @see #setEnabled
  1368. * @see AccessibleContext#getAccessibleStateSet
  1369. * @see AccessibleState#ENABLED
  1370. * @see AccessibleStateSet
  1371. */
  1372. public boolean isEnabled() {
  1373. return parent.isEnabled();
  1374. }
  1375. /**
  1376. * Set the enabled state of the object.
  1377. *
  1378. * @param b if true, enables this object; otherwise, disables it
  1379. * @see #isEnabled
  1380. */
  1381. public void setEnabled(boolean b) {
  1382. parent.setEnabled(b);
  1383. }
  1384. /**
  1385. * Determine if the object is visible. Note: this means that the
  1386. * object intends to be visible; however, it may not be
  1387. * showing on the screen because one of the objects that this object
  1388. * is contained by is currently not visible. To determine if an
  1389. * object is showing on the screen, use isShowing().
  1390. * <p>Objects that are visible will also have the
  1391. * AccessibleState.VISIBLE state set in their AccessibleStateSet.
  1392. *
  1393. * @return true if object is visible; otherwise, false
  1394. * @see #setVisible
  1395. * @see AccessibleContext#getAccessibleStateSet
  1396. * @see AccessibleState#VISIBLE
  1397. * @see AccessibleStateSet
  1398. */
  1399. public boolean isVisible() {
  1400. // [[[FIXME]]] needs to work like isShowing() below
  1401. return false;
  1402. // return parent.isVisible();
  1403. }
  1404. /**
  1405. * Set the visible state of the object.
  1406. *
  1407. * @param b if true, shows this object; otherwise, hides it
  1408. * @see #isVisible
  1409. */
  1410. public void setVisible(boolean b) {
  1411. // [[[FIXME]]] should scroll to item to make it show!
  1412. parent.setVisible(b);
  1413. }
  1414. /**
  1415. * Determine if the object is showing. This is determined by
  1416. * checking the visibility of the object and visibility of the
  1417. * object ancestors.
  1418. * Note: this will return true even if the object is obscured
  1419. * by another (for example, it to object is underneath a menu
  1420. * that was pulled down).
  1421. *
  1422. * @return true if object is showing; otherwise, false
  1423. */
  1424. public boolean isShowing() {
  1425. // [[[FIXME]]] only if it's showing!!!
  1426. return false;
  1427. // return parent.isShowing();
  1428. }
  1429. /**
  1430. * Checks whether the specified point is within this object's
  1431. * bounds, where the point's x and y coordinates are defined to
  1432. * be relative to the coordinate system of the object.
  1433. *
  1434. * @param p the Point relative to the coordinate system of the
  1435. * object
  1436. * @return true if object contains Point; otherwise false
  1437. * @see #getBounds
  1438. */
  1439. public boolean contains(Point p) {
  1440. // [[[FIXME]]] - only if p is within the list element!!!
  1441. return false;
  1442. // return parent.contains(p);
  1443. }
  1444. /**
  1445. * Returns the location of the object on the screen.
  1446. *
  1447. * @return location of object on screen; null if this object
  1448. * is not on the screen
  1449. * @see #getBounds
  1450. * @see #getLocation
  1451. */
  1452. public Point getLocationOnScreen() {
  1453. // [[[FIXME]]] sigh
  1454. return null;
  1455. }
  1456. /**
  1457. * Gets the location of the object relative to the parent in the
  1458. * form of a point specifying the object's top-left corner in the
  1459. * screen's coordinate space.
  1460. *
  1461. * @return An instance of Point representing the top-left corner of
  1462. * the objects's bounds in the coordinate space of the screen; null
  1463. * if this object or its parent are not on the screen
  1464. * @see #getBounds
  1465. * @see #getLocationOnScreen
  1466. */
  1467. public Point getLocation() {
  1468. // [[[FIXME]]]
  1469. return null;
  1470. }
  1471. /**
  1472. * Sets the location of the object relative to the parent.
  1473. * @param p the new position for the top-left corner
  1474. * @see #getLocation
  1475. */
  1476. public void setLocation(Point p) {
  1477. // [[[FIXME]]] maybe - can simply return as no-op
  1478. }
  1479. /**
  1480. * Gets the bounds of this object in the form of a Rectangle object.
  1481. * The bounds specify this object's width, height, and location
  1482. * relative to its parent.
  1483. *
  1484. * @return A rectangle indicating this component's bounds; null if
  1485. * this object is not on the screen.
  1486. * @see #contains
  1487. */
  1488. public Rectangle getBounds() {
  1489. // [[[FIXME]]]
  1490. return null;
  1491. }
  1492. /**
  1493. * Sets the bounds of this object in the form of a Rectangle
  1494. * object. The bounds specify this object's width, height, and
  1495. * location relative to its parent.
  1496. *
  1497. * @param r rectangle indicating this component's bounds
  1498. * @see #getBounds
  1499. */
  1500. public void setBounds(Rectangle r) {
  1501. // no-op; not supported
  1502. }
  1503. /**
  1504. * Returns the size of this object in the form of a Dimension
  1505. * object. The height field of the Dimension object contains this
  1506. * objects's height, and the width field of the Dimension object
  1507. * contains this object's width.
  1508. *
  1509. * @return A Dimension object that indicates the size of this
  1510. * component; null if this object is not on the screen
  1511. * @see #setSize
  1512. */
  1513. public Dimension getSize() {
  1514. // [[[FIXME]]]
  1515. return null;
  1516. }
  1517. /**
  1518. * Resizes this object so that it has width and height.
  1519. *
  1520. * @param d - The dimension specifying the new size of the object.
  1521. * @see #getSize
  1522. */
  1523. public void setSize(Dimension d) {
  1524. // not supported; no-op
  1525. }
  1526. /**
  1527. * Returns the Accessible child, if one exists, contained at the
  1528. * local coordinate Point.
  1529. *
  1530. * @param p The point relative to the coordinate system of this
  1531. * object.
  1532. * @return the Accessible, if it exists, at the specified location;
  1533. * otherwise null
  1534. */
  1535. public Accessible getAccessibleAt(Point p) {
  1536. return null; // object cannot have children!
  1537. }
  1538. /**
  1539. * Returns whether this object can accept focus or not. Objects
  1540. * that can accept focus will also have the
  1541. * AccessibleState.FOCUSABLE state set in their AccessibleStateSet.
  1542. *
  1543. * @return true if object can accept focus; otherwise false
  1544. * @see AccessibleContext#getAccessibleStateSet
  1545. * @see AccessibleState#FOCUSABLE
  1546. * @see AccessibleState#FOCUSED
  1547. * @see AccessibleStateSet
  1548. */
  1549. public boolean isFocusTraversable() {
  1550. return false; // list element cannot receive focus!
  1551. }
  1552. /**
  1553. * Requests focus for this object. If this object cannot accept
  1554. * focus, nothing will happen. Otherwise, the object will attempt
  1555. * to take focus.
  1556. * @see #isFocusTraversable
  1557. */
  1558. public void requestFocus() {
  1559. // nothing to do; a no-op
  1560. }
  1561. /**
  1562. * Adds the specified focus listener to receive focus events from
  1563. * this component.
  1564. *
  1565. * @param l the focus listener
  1566. * @see #removeFocusListener
  1567. */
  1568. public void addFocusListener(FocusListener l) {
  1569. // nothing to do; a no-op
  1570. }
  1571. /**
  1572. * Removes the specified focus listener so it no longer receives
  1573. * focus events from this component.
  1574. *
  1575. * @param l the focus listener
  1576. * @see #addFocusListener
  1577. */
  1578. public void removeFocusListener(FocusListener l) {
  1579. // nothing to do; a no-op
  1580. }
  1581. } // inner class AccessibleAWTListChild
  1582. } // inner class AccessibleAWTList
  1583. }