List.java 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034
  1. /* List.java -- A listbox widget
  2. Copyright (C) 1999, 2002 Free Software Foundation, Inc.
  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., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 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 java.awt;
  32. import java.io.Serializable;
  33. import java.awt.event.ActionEvent;
  34. import java.awt.event.ActionListener;
  35. import java.awt.event.ItemEvent;
  36. import java.awt.event.ItemListener;
  37. import java.awt.peer.ListPeer;
  38. import java.awt.peer.ComponentPeer;
  39. import java.util.Vector;
  40. import javax.accessibility.Accessible;
  41. /**
  42. * Class that implements a listbox widget
  43. *
  44. * @author Aaron M. Renn (arenn@urbanophile.com)
  45. */
  46. public class List extends Component
  47. implements ItemSelectable, Serializable, Accessible
  48. {
  49. /*
  50. * Static Variables
  51. */
  52. // Serialization constant
  53. private static final long serialVersionUID = -3304312411574666869L;
  54. /*************************************************************************/
  55. /*
  56. * Instance Variables
  57. */
  58. // FIXME: Need read/writeObject
  59. /**
  60. * @serial The items in the list.
  61. */
  62. private Vector items = new Vector();
  63. /**
  64. * @serial Indicates whether or not multiple items can be selected
  65. * simultaneously.
  66. */
  67. private boolean multipleMode;
  68. /**
  69. * @serial The number of rows in the list. This is set on creation
  70. * only and cannot be modified.
  71. */
  72. private int rows;
  73. /**
  74. * @serial An array of the item indices that are selected.
  75. */
  76. private int[] selected;
  77. /**
  78. * @serial An index value used by <code>makeVisible()</code> and
  79. * <code>getVisibleIndex</code>.
  80. */
  81. private int visibleIndex;
  82. // The list of ItemListeners for this object.
  83. private ItemListener item_listeners;
  84. // The list of ActionListeners for this object.
  85. private ActionListener action_listeners;
  86. /*************************************************************************/
  87. /*
  88. * Constructors
  89. */
  90. /**
  91. * Initializes a new instance of <code>List</code> with no visible lines
  92. * and multi-select disabled.
  93. *
  94. * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
  95. */
  96. public
  97. List()
  98. {
  99. this(4, false);
  100. }
  101. /*************************************************************************/
  102. /**
  103. * Initializes a new instance of <code>List</code> with the specified
  104. * number of visible lines and multi-select disabled.
  105. *
  106. * @param lines The number of visible lines in the list.
  107. *
  108. * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
  109. */
  110. public
  111. List(int rows)
  112. {
  113. this(rows, false);
  114. }
  115. /*************************************************************************/
  116. /**
  117. * Initializes a new instance of <code>List</code> with the specified
  118. * number of lines and the specified multi-select setting.
  119. *
  120. * @param lines The number of visible lines in the list.
  121. * @param multipleMode <code>true</code> if multiple lines can be selected
  122. * simultaneously, <code>false</code> otherwise.
  123. *
  124. * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
  125. */
  126. public
  127. List(int rows, boolean multipleMode)
  128. {
  129. this.rows = rows;
  130. this.multipleMode = multipleMode;
  131. if (GraphicsEnvironment.isHeadless())
  132. throw new HeadlessException ();
  133. }
  134. /*************************************************************************/
  135. /*
  136. * Instance Variables
  137. */
  138. /**
  139. * Returns the number of items in this list.
  140. *
  141. * @return The number of items in this list.
  142. */
  143. public int
  144. getItemCount()
  145. {
  146. return(items.size());
  147. }
  148. /*************************************************************************/
  149. /**
  150. * Returns the number of items in this list.
  151. *
  152. * @return The number of items in this list.
  153. *
  154. * @deprecated This method is deprecated in favor of
  155. * <code>getItemCount()</code>
  156. */
  157. public int
  158. countItems()
  159. {
  160. return(getItemCount());
  161. }
  162. /*************************************************************************/
  163. /**
  164. * Returns the complete list of items.
  165. *
  166. * @return The complete list of items in the list.
  167. */
  168. public synchronized String[]
  169. getItems()
  170. {
  171. String[] l_items = new String[getItemCount()];
  172. items.copyInto(l_items);
  173. return(l_items);
  174. }
  175. /*************************************************************************/
  176. /**
  177. * Returns the item at the specified index.
  178. *
  179. * @param index The index of the item to retrieve.
  180. *
  181. * @exception IndexOutOfBoundsException If the index value is not valid.
  182. */
  183. public String
  184. getItem(int index)
  185. {
  186. return((String)items.elementAt(index));
  187. }
  188. /*************************************************************************/
  189. /**
  190. * Returns the number of visible rows in the list.
  191. *
  192. * @return The number of visible rows in the list.
  193. */
  194. public int
  195. getRows()
  196. {
  197. return(rows);
  198. }
  199. /*************************************************************************/
  200. /**
  201. * Tests whether or not multi-select mode is enabled.
  202. *
  203. * @return <code>true</code> if multi-select mode is enabled,
  204. * <code>false</code> otherwise.
  205. */
  206. public boolean
  207. isMultipleMode()
  208. {
  209. return(multipleMode);
  210. }
  211. /*************************************************************************/
  212. /**
  213. * Tests whether or not multi-select mode is enabled.
  214. *
  215. * @return <code>true</code> if multi-select mode is enabled,
  216. * <code>false</code> otherwise.
  217. *
  218. * @deprecated This method is deprecated in favor of
  219. * <code>isMultipleMode()</code>.
  220. */
  221. public boolean
  222. allowsMultipleSelections()
  223. {
  224. return(multipleMode);
  225. }
  226. /*************************************************************************/
  227. /**
  228. * This method enables or disables multiple selection mode for this
  229. * list.
  230. *
  231. * @param multipleMode <code>true</code> to enable multiple mode,
  232. * <code>false</code> otherwise.
  233. */
  234. public void
  235. setMultipleMode(boolean multipleMode)
  236. {
  237. this.multipleMode = multipleMode;
  238. if (peer != null)
  239. {
  240. ListPeer l = (ListPeer) peer;
  241. l.setMultipleMode (multipleMode);
  242. }
  243. }
  244. /*************************************************************************/
  245. /**
  246. * This method enables or disables multiple selection mode for this
  247. * list.
  248. *
  249. * @param multipleMode <code>true</code> to enable multiple mode,
  250. * <code>false</code> otherwise.
  251. */
  252. public void
  253. setMultipleSelections(boolean multipleMode)
  254. {
  255. setMultipleMode(multipleMode);
  256. }
  257. /*************************************************************************/
  258. /**
  259. * Returns the minimum size of this component.
  260. *
  261. * @return The minimum size of this component.
  262. */
  263. public Dimension
  264. getMinimumSize()
  265. {
  266. return(getMinimumSize(rows));
  267. }
  268. /*************************************************************************/
  269. /**
  270. * Returns the minimum size of this component.
  271. *
  272. * @return The minimum size of this component.
  273. *
  274. * @deprecated This method is deprecated in favor of
  275. * <code>getMinimumSize</code>.
  276. */
  277. public Dimension
  278. minimumSize()
  279. {
  280. return(getMinimumSize(rows));
  281. }
  282. /*************************************************************************/
  283. /**
  284. * Returns the minimum size of this component assuming it had the specified
  285. * number of rows.
  286. *
  287. * @param rows The number of rows to size for.
  288. *
  289. * @return The minimum size of this component.
  290. */
  291. public Dimension
  292. getMinimumSize(int rows)
  293. {
  294. ListPeer lp = (ListPeer)getPeer();
  295. if (lp != null)
  296. return(lp.minimumSize(rows));
  297. else
  298. return(new Dimension(0,0));
  299. }
  300. /*************************************************************************/
  301. /**
  302. * Returns the minimum size of this component assuming it had the specified
  303. * number of rows.
  304. *
  305. * @param rows The number of rows to size for.
  306. *
  307. * @return The minimum size of this component.
  308. *
  309. * @deprecated This method is deprecated in favor of
  310. * <code>getMinimumSize(int)</code>>
  311. */
  312. public Dimension
  313. minimumSize(int rows)
  314. {
  315. return(getMinimumSize(rows));
  316. }
  317. /*************************************************************************/
  318. /**
  319. * Returns the preferred size of this component.
  320. *
  321. * @return The preferred size of this component.
  322. */
  323. public Dimension
  324. getPreferredSize()
  325. {
  326. return(getPreferredSize(rows));
  327. }
  328. /*************************************************************************/
  329. /**
  330. * Returns the preferred size of this component.
  331. *
  332. * @return The preferred size of this component.
  333. *
  334. * @deprecated This method is deprecated in favor of
  335. * <code>getPreferredSize</code>.
  336. */
  337. public Dimension
  338. preferredSize()
  339. {
  340. return(getPreferredSize(rows));
  341. }
  342. /*************************************************************************/
  343. /**
  344. * Returns the preferred size of this component assuming it had the specified
  345. * number of rows.
  346. *
  347. * @param rows The number of rows to size for.
  348. *
  349. * @return The preferred size of this component.
  350. */
  351. public Dimension
  352. getPreferredSize(int rows)
  353. {
  354. ListPeer lp = (ListPeer)getPeer();
  355. if (lp != null)
  356. return(lp.preferredSize(rows));
  357. else
  358. return(new Dimension(0,0));
  359. }
  360. /*************************************************************************/
  361. /**
  362. * Returns the preferred size of this component assuming it had the specified
  363. * number of rows.
  364. *
  365. * @param rows The number of rows to size for.
  366. *
  367. * @return The preferred size of this component.
  368. *
  369. * @deprecated This method is deprecated in favor of
  370. * <code>getPreferredSize(int)</code>>
  371. */
  372. public Dimension
  373. preferredSize(int rows)
  374. {
  375. return(getPreferredSize(rows));
  376. }
  377. /*************************************************************************/
  378. /**
  379. * This method adds the specified item to the end of the list.
  380. *
  381. * @param item The item to add to the list.
  382. */
  383. public void
  384. add(String item)
  385. {
  386. add(item, -1);
  387. }
  388. /*************************************************************************/
  389. /**
  390. * This method adds the specified item to the end of the list.
  391. *
  392. * @param item The item to add to the list.
  393. *
  394. * @deprecated Use add() instead.
  395. */
  396. public void
  397. addItem(String item)
  398. {
  399. addItem(item, -1);
  400. }
  401. /*************************************************************************/
  402. /**
  403. * Adds the specified item to the specified location in the list.
  404. * If the desired index is -1 or greater than the number of rows
  405. * in the list, then the item is added to the end.
  406. *
  407. * @param item The item to add to the list.
  408. * @param index The location in the list to add the item, or -1 to add
  409. * to the end.
  410. */
  411. public void
  412. add(String item, int index)
  413. {
  414. if ((index == -1) || (index >= items.size()))
  415. items.addElement(item);
  416. else
  417. items.insertElementAt(item, index);
  418. if (peer != null)
  419. {
  420. ListPeer l = (ListPeer) peer;
  421. l.add (item, index);
  422. }
  423. }
  424. /*************************************************************************/
  425. /**
  426. * Adds the specified item to the specified location in the list.
  427. * If the desired index is -1 or greater than the number of rows
  428. * in the list, then the item is added to the end.
  429. *
  430. * @param item The item to add to the list.
  431. * @param index The location in the list to add the item, or -1 to add
  432. * to the end.
  433. *
  434. * @deprecated Use add() instead.
  435. */
  436. public void
  437. addItem(String item, int index)
  438. {
  439. add(item, index);
  440. }
  441. /*************************************************************************/
  442. /**
  443. * Deletes the item at the specified index.
  444. *
  445. * @param index The index of the item to delete.
  446. *
  447. * @exception IllegalArgumentException If the index is not valid
  448. */
  449. public void
  450. delItem(int index) throws IllegalArgumentException
  451. {
  452. remove(index);
  453. }
  454. /*************************************************************************/
  455. /**
  456. * Deletes the item at the specified index.
  457. *
  458. * @param index The index of the item to delete.
  459. *
  460. * @exception IllegalArgumentException If the index is not valid
  461. */
  462. public void
  463. remove(int index) throws IllegalArgumentException
  464. {
  465. items.removeElementAt (index);
  466. if (peer != null)
  467. {
  468. ListPeer l = (ListPeer) peer;
  469. l.delItems (index, index);
  470. }
  471. }
  472. /*************************************************************************/
  473. /**
  474. * Deletes all items in the specified index range.
  475. *
  476. * @param start The beginning index of the range to delete.
  477. * @param end The ending index of the range to delete.
  478. *
  479. * @exception IllegalArgumentException If the indexes are not valid
  480. *
  481. * @deprecated This method is deprecated for some unknown reason.
  482. */
  483. public synchronized void
  484. delItems(int start, int end) throws IllegalArgumentException
  485. {
  486. if ((start < 0) || (start >= items.size()))
  487. throw new IllegalArgumentException("Bad list start index value: " + start);
  488. if ((start < 0) || (start >= items.size()))
  489. throw new IllegalArgumentException("Bad list start index value: " + start);
  490. if (start > end)
  491. throw new IllegalArgumentException("Start is greater than end!");
  492. // We must run the loop in reverse direction.
  493. for (int i = end; i >= start; --i)
  494. items.removeElementAt (i);
  495. if (peer != null)
  496. {
  497. ListPeer l = (ListPeer) peer;
  498. l.delItems (start, end);
  499. }
  500. }
  501. /*************************************************************************/
  502. /**
  503. * Deletes the first occurrence of the specified item from the list.
  504. *
  505. * @param item The item to delete.
  506. *
  507. * @exception IllegalArgumentException If the specified item does not exist.
  508. */
  509. public synchronized void
  510. remove(String item) throws IllegalArgumentException
  511. {
  512. int index = items.indexOf(item);
  513. if (index == -1)
  514. throw new IllegalArgumentException("List element to delete not found");
  515. remove(index);
  516. }
  517. /*************************************************************************/
  518. /**
  519. * Deletes all of the items from the list.
  520. */
  521. public synchronized void
  522. removeAll()
  523. {
  524. items.clear();
  525. if (peer != null)
  526. {
  527. ListPeer l = (ListPeer) peer;
  528. l.removeAll ();
  529. }
  530. }
  531. /*************************************************************************/
  532. /**
  533. * Deletes all of the items from the list.
  534. *
  535. * @deprecated This method is deprecated in favor of <code>removeAll()</code>.
  536. */
  537. public void
  538. clear()
  539. {
  540. removeAll();
  541. }
  542. /*************************************************************************/
  543. /**
  544. * Replaces the item at the specified index with the specified item.
  545. *
  546. * @param item The new item value.
  547. * @param index The index of the item to replace.
  548. *
  549. * @exception IllegalArgumentException If the index is not valid.
  550. */
  551. public synchronized void
  552. replaceItem(String item, int index) throws IllegalArgumentException
  553. {
  554. remove(index);
  555. addItem(item, index);
  556. }
  557. /*************************************************************************/
  558. /**
  559. * Returns the index of the currently selected item. -1 will be returned
  560. * if there are no selected rows or if there are multiple selected rows.
  561. *
  562. * @return The index of the selected row.
  563. */
  564. public synchronized int
  565. getSelectedIndex()
  566. {
  567. if (peer != null)
  568. {
  569. ListPeer l = (ListPeer) peer;
  570. selected = l.getSelectedIndexes ();
  571. }
  572. if (selected == null || selected.length > 1)
  573. return -1;
  574. return selected[0];
  575. }
  576. /*************************************************************************/
  577. /**
  578. * Returns an array containing the indexes of the rows that are
  579. * currently selected.
  580. *
  581. * @return A list of indexes of selected rows.
  582. */
  583. public synchronized int[]
  584. getSelectedIndexes()
  585. {
  586. if (peer != null)
  587. {
  588. ListPeer l = (ListPeer) peer;
  589. selected = l.getSelectedIndexes ();
  590. }
  591. return selected;
  592. }
  593. /*************************************************************************/
  594. /**
  595. * Returns the item that is currently selected, or <code>null</code> if there
  596. * is no item selected. FIXME: What happens if multiple items selected?
  597. *
  598. * @return The selected item, or <code>null</code> if there is no
  599. * selected item.
  600. */
  601. public synchronized String
  602. getSelectedItem()
  603. {
  604. int index = getSelectedIndex();
  605. if (index == -1)
  606. return(null);
  607. return((String)items.elementAt(index));
  608. }
  609. /*************************************************************************/
  610. /**
  611. * Returns the list of items that are currently selected in this list.
  612. *
  613. * @return The list of currently selected items.
  614. */
  615. public synchronized String[]
  616. getSelectedItems()
  617. {
  618. int[] indexes = getSelectedIndexes();
  619. if (indexes == null)
  620. return(new String[0]);
  621. String[] retvals = new String[indexes.length];
  622. if (retvals.length > 0)
  623. for (int i = 0 ; i < retvals.length; i++)
  624. retvals[i] = (String)items.elementAt(indexes[i]);
  625. return(retvals);
  626. }
  627. /*************************************************************************/
  628. /**
  629. * Returns the list of items that are currently selected in this list as
  630. * an array of type <code>Object[]</code> instead of <code>String[]</code>.
  631. *
  632. * @return The list of currently selected items.
  633. */
  634. public synchronized Object[]
  635. getSelectedObjects()
  636. {
  637. int[] indexes = getSelectedIndexes();
  638. if (indexes == null)
  639. return(new Object[0]);
  640. Object[] retvals = new Object[indexes.length];
  641. if (retvals.length > 0)
  642. for (int i = 0 ; i < retvals.length; i++)
  643. retvals[i] = items.elementAt(indexes[i]);
  644. return(retvals);
  645. }
  646. /*************************************************************************/
  647. /**
  648. * Tests whether or not the specified index is selected.
  649. *
  650. * @param index The index to test.
  651. *
  652. * @return <code>true</code> if the index is selected, <code>false</code>
  653. * otherwise.
  654. */
  655. public boolean
  656. isIndexSelected(int index)
  657. {
  658. int[] indexes = getSelectedIndexes();
  659. for (int i = 0; i < indexes.length; i++)
  660. if (indexes[i] == index)
  661. return(true);
  662. return(false);
  663. }
  664. /*************************************************************************/
  665. /**
  666. * Tests whether or not the specified index is selected.
  667. *
  668. * @param index The index to test.
  669. *
  670. * @return <code>true</code> if the index is selected, <code>false</code>
  671. * otherwise.
  672. *
  673. * @deprecated This method is deprecated in favor of
  674. * <code>isIndexSelected(int)</code>.
  675. */
  676. public boolean
  677. isSelected(int index)
  678. {
  679. return(isIndexSelected(index));
  680. }
  681. /*************************************************************************/
  682. /**
  683. * This method ensures that the item at the specified index is visible.
  684. *
  685. * @exception IllegalArgumentException If the specified index is out of
  686. * range.
  687. */
  688. public synchronized void
  689. makeVisible(int index) throws IllegalArgumentException
  690. {
  691. if ((index < 0) || (index >= items.size()))
  692. throw new IllegalArgumentException("Bad list index: " + index);
  693. visibleIndex = index;
  694. if (peer != null)
  695. {
  696. ListPeer l = (ListPeer) peer;
  697. l.makeVisible (index);
  698. }
  699. }
  700. /*************************************************************************/
  701. /**
  702. * Returns the index of the last item that was made visible via the
  703. * <code>makeVisible()</code> method.
  704. *
  705. * @return The index of the last item made visible via the
  706. * <code>makeVisible()</code> method.
  707. */
  708. public int
  709. getVisibleIndex()
  710. {
  711. return(visibleIndex);
  712. }
  713. /*************************************************************************/
  714. /**
  715. * Makes the item at the specified index selected.
  716. *
  717. * @param index The index of the item to select.
  718. */
  719. public synchronized void
  720. select(int index)
  721. {
  722. ListPeer lp = (ListPeer)getPeer();
  723. if (lp != null)
  724. lp.select(index);
  725. }
  726. /*************************************************************************/
  727. /**
  728. * Makes the item at the specified index not selected.
  729. *
  730. * @param index The index of the item to unselect.
  731. */
  732. public synchronized void
  733. deselect(int index)
  734. {
  735. ListPeer lp = (ListPeer)getPeer();
  736. if (lp != null)
  737. lp.deselect(index);
  738. }
  739. /*************************************************************************/
  740. /**
  741. * Notifies this object to create its native peer.
  742. */
  743. public void
  744. addNotify()
  745. {
  746. if (peer == null)
  747. peer = getToolkit ().createList (this);
  748. super.addNotify ();
  749. }
  750. /*************************************************************************/
  751. /**
  752. * Notifies this object to destroy its native peer.
  753. */
  754. public void
  755. removeNotify()
  756. {
  757. super.removeNotify();
  758. }
  759. /*************************************************************************/
  760. /**
  761. * Adds the specified <code>ActionListener</code> to the list of
  762. * registered listeners for this object.
  763. *
  764. * @param listener The listener to add.
  765. */
  766. public synchronized void
  767. addActionListener(ActionListener listener)
  768. {
  769. action_listeners = AWTEventMulticaster.add(action_listeners, listener);
  770. }
  771. /*************************************************************************/
  772. /**
  773. * Removes the specified <code>ActionListener</code> from the list of
  774. * registers listeners for this object.
  775. *
  776. * @param listener The listener to remove.
  777. */
  778. public synchronized void
  779. removeActionListener(ActionListener listener)
  780. {
  781. action_listeners = AWTEventMulticaster.remove(action_listeners, listener);
  782. }
  783. /*************************************************************************/
  784. /**
  785. * Adds the specified <code>ItemListener</code> to the list of
  786. * registered listeners for this object.
  787. *
  788. * @param listener The listener to add.
  789. */
  790. public synchronized void
  791. addItemListener(ItemListener listener)
  792. {
  793. item_listeners = AWTEventMulticaster.add(item_listeners, listener);
  794. }
  795. /*************************************************************************/
  796. /**
  797. * Removes the specified <code>ItemListener</code> from the list of
  798. * registers listeners for this object.
  799. *
  800. * @param listener The listener to remove.
  801. */
  802. public synchronized void
  803. removeItemListener(ItemListener listener)
  804. {
  805. item_listeners = AWTEventMulticaster.remove(item_listeners, listener);
  806. }
  807. /*************************************************************************/
  808. /**
  809. * Processes the specified event for this object. If the event is an
  810. * instance of <code>ActionEvent</code> then the
  811. * <code>processActionEvent()</code> method is called. Similarly, if the
  812. * even is an instance of <code>ItemEvent</code> then the
  813. * <code>processItemEvent()</code> method is called. Otherwise the
  814. * superclass method is called to process this event.
  815. *
  816. * @param event The event to process.
  817. */
  818. protected void
  819. processEvent(AWTEvent event)
  820. {
  821. if (event instanceof ActionEvent)
  822. processActionEvent((ActionEvent)event);
  823. else if (event instanceof ItemEvent)
  824. processItemEvent((ItemEvent)event);
  825. else
  826. super.processEvent(event);
  827. }
  828. /*************************************************************************/
  829. /**
  830. * This method processes the specified event by dispatching it to any
  831. * registered listeners. Note that this method will only get called if
  832. * action events are enabled. This will happen automatically if any
  833. * listeners are added, or it can be done "manually" by calling
  834. * the <code>enableEvents()</code> method.
  835. *
  836. * @param event The event to process.
  837. */
  838. protected void
  839. processActionEvent(ActionEvent event)
  840. {
  841. if (action_listeners != null)
  842. action_listeners.actionPerformed(event);
  843. }
  844. /*************************************************************************/
  845. /**
  846. * This method processes the specified event by dispatching it to any
  847. * registered listeners. Note that this method will only get called if
  848. * item events are enabled. This will happen automatically if any
  849. * listeners are added, or it can be done "manually" by calling
  850. * the <code>enableEvents()</code> method.
  851. *
  852. * @param event The event to process.
  853. */
  854. protected void
  855. processItemEvent(ItemEvent event)
  856. {
  857. if (item_listeners != null)
  858. item_listeners.itemStateChanged(event);
  859. }
  860. void
  861. dispatchEventImpl(AWTEvent e)
  862. {
  863. if (e.id <= ItemEvent.ITEM_LAST
  864. && e.id >= ItemEvent.ITEM_FIRST
  865. && (item_listeners != null
  866. || (eventMask & AWTEvent.ITEM_EVENT_MASK) != 0))
  867. processEvent(e);
  868. else if (e.id <= ActionEvent.ACTION_LAST
  869. && e.id >= ActionEvent.ACTION_FIRST
  870. && (action_listeners != null
  871. || (eventMask & AWTEvent.ACTION_EVENT_MASK) != 0))
  872. processEvent(e);
  873. else
  874. super.dispatchEventImpl(e);
  875. }
  876. /*************************************************************************/
  877. /**
  878. * Returns a debugging string for this object.
  879. *
  880. * @return A debugging string for this object.
  881. */
  882. protected String
  883. paramString()
  884. {
  885. return "multiple=" + multipleMode + ",rows=" + rows + super.paramString();
  886. }
  887. } // class List