KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > List


1 /*
2  * @(#)List.java 1.106 04/05/18
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package java.awt;
8
9 import java.util.Vector JavaDoc;
10 import java.util.Locale JavaDoc;
11 import java.util.EventListener JavaDoc;
12 import java.awt.peer.ListPeer;
13 import java.awt.event.*;
14 import java.io.ObjectOutputStream JavaDoc;
15 import java.io.ObjectInputStream JavaDoc;
16 import java.io.IOException JavaDoc;
17 import javax.accessibility.*;
18
19
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&nbsp;.&nbsp;.&nbsp;.
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  * alt="Shows a list containing: Venus, Earth, JavaSoft, and Mars. Javasoft is selected." ALIGN=center HSPACE=10 VSPACE=7>
47  * <p>
48  * If the List allows multiple selections, then 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>. If the List does not allow multiple
53  * selections, selecting an item causes any other selected item
54  * to be deselected.
55  * <p>
56  * Note that the list in the example shown was created with four visible
57  * rows. Once the list has been created, the number of visible rows
58  * cannot be changed. A default <code>List</code> is created with
59  * four rows, so that <code>lst = new List()</code> is equivalent to
60  * <code>list = new List(4, false)</code>.
61  * <p>
62  * Beginning with Java&nbsp;1.1, the Abstract Window Toolkit
63  * sends the <code>List</code> object all mouse, keyboard, and focus events
64  * that occur over it. (The old AWT event model is being maintained
65  * only for backwards compatibility, and its use is discouraged.)
66  * <p>
67  * When an item is selected or deselected by the user, AWT sends an instance
68  * of <code>ItemEvent</code> to the list.
69  * When the user double-clicks on an item in a scrolling list,
70  * AWT sends an instance of <code>ActionEvent</code> to the
71  * list following the item event. AWT also generates an action event
72  * when the user presses the return key while an item in the
73  * list is selected.
74  * <p>
75  * If an application wants to perform some action based on an item
76  * in this list being selected or activated by the user, it should implement
77  * <code>ItemListener</code> or <code>ActionListener</code>
78  * as appropriate and register the new listener to receive
79  * events from this list.
80  * <p>
81  * For multiple-selection scrolling lists, it is considered a better
82  * user interface to use an external gesture (such as clicking on a
83  * button) to trigger the action.
84  * @version 1.106, 05/18/04
85  * @author Sami Shaio
86  * @see java.awt.event.ItemEvent
87  * @see java.awt.event.ItemListener
88  * @see java.awt.event.ActionEvent
89  * @see java.awt.event.ActionListener
90  * @since JDK1.0
91  */

92 public class List extends Component JavaDoc implements ItemSelectable JavaDoc, Accessible {
93     /**
94      * A vector created to contain items which will become
95      * part of the List Component.
96      *
97      * @serial
98      * @see #addItem(String)
99      * @see #getItem(int)
100      */

101     Vector JavaDoc items = new Vector JavaDoc();
102     
103     /**
104      * This field will represent the number of visible rows in the
105      * <code>List</code> Component. It is specified only once, and
106      * that is when the list component is actually
107      * created. It will never change.
108      *
109      * @serial
110      * @see #getRows()
111      */

112     int rows = 0;
113
114     /**
115      * <code>multipleMode</code> is a variable that will
116      * be set to <code>true</code> if a list component is to be set to
117      * multiple selection mode, that is where the user can
118      * select more than one item in a list at one time.
119      * <code>multipleMode</code> will be set to false if the
120      * list component is set to single selection, that is where
121      * the user can only select one item on the list at any
122      * one time.
123      *
124      * @serial
125      * @see #isMultipleMode()
126      * @see #setMultipleMode(boolean)
127      */

128     boolean multipleMode = false;
129
130     /**
131      * <code>selected</code> is an array that will contain
132      * the indices of items that have been selected.
133      *
134      * @serial
135      * @see #getSelectedIndexes()
136      * @see #getSelectedIndex()
137      */

138     int selected[] = new int[0];
139
140     /**
141      * This variable contains the value that will be used
142      * when trying to make a particular list item visible.
143      *
144      * @serial
145      * @see #makeVisible(int)
146      */

147     int visibleIndex = -1;
148
149     transient ActionListener actionListener;
150     transient ItemListener itemListener;
151
152     private static final String JavaDoc base = "list";
153     private static int nameCounter = 0;
154
155     /*
156      * JDK 1.1 serialVersionUID
157      */

158      private static final long serialVersionUID = -3304312411574666869L;
159
160     /**
161      * Creates a new scrolling list.
162      * By default, there are four visible lines and multiple selections are
163      * not allowed. Note that this is a convenience method for
164      * <code>List(0, false)</code>. Also note that the number of visible
165      * lines in the list cannot be changed after it has been created.
166      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
167      * returns true.
168      * @see java.awt.GraphicsEnvironment#isHeadless
169      */

170     public List() throws HeadlessException JavaDoc {
171     this(0, false);
172     }
173
174     /**
175      * Creates a new scrolling list initialized with the specified
176      * number of visible lines. By default, multiple selections are
177      * not allowed. Note that this is a convenience method for
178      * <code>List(rows, false)</code>. Also note that the number
179      * of visible rows in the list cannot be changed after it has
180      * been created.
181      * @param rows the number of items to show.
182      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
183      * returns true.
184      * @see java.awt.GraphicsEnvironment#isHeadless
185      * @since JDK1.1
186      */

187     public List(int rows) throws HeadlessException JavaDoc {
188         this(rows, false);
189     }
190
191     /**
192      * The default number of visible rows is 4. A list with
193      * zero rows is unusable and unsightly.
194      */

195     final static int DEFAULT_VISIBLE_ROWS = 4;
196
197     /**
198      * Creates a new scrolling list initialized to display the specified
199      * number of rows. Note that if zero rows are specified, then
200      * the list will be created with a default of four rows.
201      * Also note that the number of visible rows in the list cannot
202      * be changed after it has been created.
203      * If the value of <code>multipleMode</code> is
204      * <code>true</code>, then the user can select multiple items from
205      * the list. If it is <code>false</code>, only one item at a time
206      * can be selected.
207      * @param rows the number of items to show.
208      * @param multipleMode if <code>true</code>,
209      * then multiple selections are allowed;
210      * otherwise, only one item can be selected at a time.
211      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
212      * returns true.
213      * @see java.awt.GraphicsEnvironment#isHeadless
214      */

215     public List(int rows, boolean multipleMode) throws HeadlessException JavaDoc {
216         GraphicsEnvironment.checkHeadless();
217     this.rows = (rows != 0) ? rows : DEFAULT_VISIBLE_ROWS;
218     this.multipleMode = multipleMode;
219     }
220
221     /**
222      * Construct a name for this component. Called by
223      * <code>getName</code> when the name is <code>null</code>.
224      */

225     String JavaDoc constructComponentName() {
226         synchronized (getClass()) {
227         return base + nameCounter++;
228     }
229     }
230
231     /**
232      * Creates the peer for the list. The peer allows us to modify the
233      * list's appearance without changing its functionality.
234      */

235     public void addNotify() {
236         synchronized (getTreeLock()) {
237         if (peer == null)
238             peer = getToolkit().createList(this);
239         super.addNotify();
240     }
241     }
242
243     /**
244      * Removes the peer for this list. The peer allows us to modify the
245      * list's appearance without changing its functionality.
246      */

247     public void removeNotify() {
248         synchronized (getTreeLock()) {
249         ListPeer peer = (ListPeer)this.peer;
250         if (peer != null) {
251         selected = peer.getSelectedIndexes();
252         }
253         super.removeNotify();
254     }
255     }
256
257     /**
258      * Gets the number of items in the list.
259      * @return the number of items in the list
260      * @see #getItem
261      * @since JDK1.1
262      */

263     public int getItemCount() {
264     return countItems();
265     }
266
267     /**
268      * @deprecated As of JDK version 1.1,
269      * replaced by <code>getItemCount()</code>.
270      */

271     @Deprecated JavaDoc
272     public int countItems() {
273     return items.size();
274     }
275
276     /**
277      * Gets the item associated with the specified index.
278      * @return an item that is associated with
279      * the specified index
280      * @param index the position of the item
281      * @see #getItemCount
282      */

283     public String JavaDoc getItem(int index) {
284     return getItemImpl(index);
285     }
286
287     // NOTE: This method may be called by privileged threads.
288
// We implement this functionality in a package-private method
289
// to insure that it cannot be overridden by client subclasses.
290
// DO NOT INVOKE CLIENT CODE ON THIS THREAD!
291
final String JavaDoc getItemImpl(int index) {
292     return (String JavaDoc)items.elementAt(index);
293     }
294
295     /**
296      * Gets the items in the list.
297      * @return a string array containing items of the list
298      * @see #select
299      * @see #deselect
300      * @see #isIndexSelected
301      * @since JDK1.1
302      */

303     public synchronized String JavaDoc[] getItems() {
304     String JavaDoc itemCopies[] = new String JavaDoc[items.size()];
305         items.copyInto(itemCopies);
306     return itemCopies;
307     }
308
309     /**
310      * Adds the specified item to the end of scrolling list.
311      * @param item the item to be added
312      * @since JDK1.1
313      */

314     public void add(String JavaDoc item) {
315     addItem(item);
316     }
317
318     /**
319      * @deprecated replaced by <code>add(String)</code>.
320      */

321     @Deprecated JavaDoc
322     public void addItem(String JavaDoc item) {
323     addItem(item, -1);
324     }
325
326     /**
327      * Adds the specified item to the the scrolling list
328      * at the position indicated by the index. The index is
329      * zero-based. If the value of the index is less than zero,
330      * or if the value of the index is greater than or equal to
331      * the number of items in the list, then the item is added
332      * to the end of the list.
333      * @param item the item to be added;
334      * if this parameter is <code>null</code> then the item is
335      * treated as an empty string, <code>""</code>
336      * @param index the position at which to add the item
337      * @since JDK1.1
338      */

339     public void add(String JavaDoc item, int index) {
340     addItem(item, index);
341     }
342
343     /**
344      * @deprecated replaced by <code>add(String, int)</code>.
345      */

346     @Deprecated JavaDoc
347     public synchronized void addItem(String JavaDoc item, int index) {
348     if (index < -1 || index >= items.size()) {
349         index = -1;
350     }
351
352         if (item == null) {
353             item = "";
354         }
355
356     if (index == -1) {
357         items.addElement(item);
358     } else {
359         items.insertElementAt(item, index);
360     }
361
362     ListPeer peer = (ListPeer)this.peer;
363     if (peer != null) {
364         peer.addItem(item, index);
365     }
366     }
367
368     /**
369      * Replaces the item at the specified index in the scrolling list
370      * with the new string.
371      * @param newValue a new string to replace an existing item
372      * @param index the position of the item to replace
373      * @exception ArrayIndexOutOfBoundsException if <code>index</code>
374      * is out of range
375      */

376     public synchronized void replaceItem(String JavaDoc newValue, int index) {
377     remove(index);
378     add(newValue, index);
379     }
380
381     /**
382      * Removes all items from this list.
383      * @see #remove
384      * @see #delItems
385      * @since JDK1.1
386      */

387     public void removeAll() {
388     clear();
389     }
390
391     /**
392      * @deprecated As of JDK version 1.1,
393      * replaced by <code>removeAll()</code>.
394      */

395     @Deprecated JavaDoc
396     public synchronized void clear() {
397     ListPeer peer = (ListPeer)this.peer;
398     if (peer != null) {
399         peer.clear();
400     }
401     items = new Vector JavaDoc();
402     selected = new int[0];
403     }
404
405     /**
406      * Removes the first occurrence of an item from the list.
407      * If the specified item is selected, and is the only selected
408      * item in the list, the list is set to have no selection.
409      * @param item the item to remove from the list
410      * @exception IllegalArgumentException
411      * if the item doesn't exist in the list
412      * @since JDK1.1
413      */

414     public synchronized void remove(String JavaDoc item) {
415         int index = items.indexOf(item);
416         if (index < 0) {
417         throw new IllegalArgumentException JavaDoc("item " + item +
418                            " not found in list");
419     } else {
420         remove(index);
421     }
422     }
423
424     /**
425      * Removes the item at the specified position
426      * from this scrolling list.
427      * If the item with the specified position is selected, and is the
428      * only selected item in the list, the list is set to have no selection.
429      * @param position the index of the item to delete
430      * @see #add(String, int)
431      * @since JDK1.1
432      * @exception ArrayIndexOutOfBoundsException
433      * if the <code>position</code> is less than 0 or
434      * greater than <code>getItemCount()-1</code>
435      */

436     public void remove(int position) {
437     delItem(position);
438     }
439
440     /**
441      * @deprecated replaced by <code>remove(String)</code>
442      * and <code>remove(int)</code>.
443      */

444     @Deprecated JavaDoc
445     public void delItem(int position) {
446     delItems(position, position);
447     }
448
449     /**
450      * Gets the index of the selected item on the list,
451      *
452      * @return the index of the selected item;
453      * if no item is selected, or if multiple items are
454      * selected, <code>-1</code> is returned.
455      * @see #select
456      * @see #deselect
457      * @see #isIndexSelected
458      */

459     public synchronized int getSelectedIndex() {
460     int sel[] = getSelectedIndexes();
461     return (sel.length == 1) ? sel[0] : -1;
462     }
463
464     /**
465      * Gets the selected indexes on the list.
466      *
467      * @return an array of the selected indexes on this scrolling list;
468      * if no item is selected, a zero-length array is returned.
469      * @see #select
470      * @see #deselect
471      * @see #isIndexSelected
472      */

473     public synchronized int[] getSelectedIndexes() {
474     ListPeer peer = (ListPeer)this.peer;
475     if (peer != null) {
476         selected = ((ListPeer)peer).getSelectedIndexes();
477     }
478     return (int[])selected.clone();
479     }
480
481     /**
482      * Gets the selected item on this scrolling list.
483      *
484      * @return the selected item on the list;
485      * if no item is selected, or if multiple items are
486      * selected, <code>null</code> is returned.
487      * @see #select
488      * @see #deselect
489      * @see #isIndexSelected
490      */

491     public synchronized String JavaDoc getSelectedItem() {
492     int index = getSelectedIndex();
493     return (index < 0) ? null : getItem(index);
494     }
495
496     /**
497      * Gets the selected items on this scrolling list.
498      *
499      * @return an array of the selected items on this scrolling list;
500      * if no item is selected, a zero-length array is returned.
501      * @see #select
502      * @see #deselect
503      * @see #isIndexSelected
504      */

505     public synchronized String JavaDoc[] getSelectedItems() {
506     int sel[] = getSelectedIndexes();
507     String JavaDoc str[] = new String JavaDoc[sel.length];
508     for (int i = 0 ; i < sel.length ; i++) {
509         str[i] = getItem(sel[i]);
510     }
511     return str;
512     }
513
514     /**
515      * Gets the selected items on this scrolling list in an array of Objects.
516      * @return an array of <code>Object</code>s representing the
517      * selected items on this scrolling list;
518      * if no item is selected, a zero-length array is returned.
519      * @see #getSelectedItems
520      * @see ItemSelectable
521      */

522     public Object JavaDoc[] getSelectedObjects() {
523         return getSelectedItems();
524     }
525
526     /**
527      * Selects the item at the specified index in the scrolling list.
528      *<p>
529      * Note that passing out of range parameters is invalid,
530      * and will result in unspecified behavior.
531      *
532      * <p>Note that this method should be primarily used to
533      * initially select an item in this component.
534      * Programmatically calling this method will <i>not</i> trigger
535      * an <code>ItemEvent</code>. The only way to trigger an
536      * <code>ItemEvent</code> is by user interaction.
537      *
538      * @param index the position of the item to select
539      * @see #getSelectedItem
540      * @see #deselect
541      * @see #isIndexSelected
542      */

543     public void select(int index) {
544         // Bug #4059614: select can't be synchronized while calling the peer,
545
// because it is called from the Window Thread. It is sufficient to
546
// synchronize the code that manipulates 'selected' except for the
547
// case where the peer changes. To handle this case, we simply
548
// repeat the selection process.
549

550         ListPeer peer;
551         do {
552             peer = (ListPeer)this.peer;
553             if (peer != null) {
554                 peer.select(index);
555                 return;
556             }
557              
558             synchronized(this)
559             {
560                 boolean alreadySelected = false;
561  
562                 for (int i = 0 ; i < selected.length ; i++) {
563                     if (selected[i] == index) {
564                         alreadySelected = true;
565                         break;
566                     }
567                 }
568  
569                 if (!alreadySelected) {
570                     if (!multipleMode) {
571                         selected = new int[1];
572                         selected[0] = index;
573                     } else {
574                         int newsel[] = new int[selected.length + 1];
575                         System.arraycopy(selected, 0, newsel, 0,
576                                          selected.length);
577                         newsel[selected.length] = index;
578                         selected = newsel;
579                     }
580                 }
581             }
582         } while (peer != this.peer);
583     }
584
585     /**
586      * Deselects the item at the specified index.
587      * <p>
588      * Note that passing out of range parameters is invalid,
589      * and will result in unspecified behavior.
590      * <p>
591      * If the item at the specified index is not selected,
592      * then the operation is ignored.
593      * @param index the position of the item to deselect
594      * @see #select
595      * @see #getSelectedItem
596      * @see #isIndexSelected
597      */

598     public synchronized void deselect(int index) {
599     ListPeer peer = (ListPeer)this.peer;
600     if (peer != null) {
601         peer.deselect(index);
602     }
603
604     for (int i = 0 ; i < selected.length ; i++) {
605         if (selected[i] == index) {
606         int newsel[] = new int[selected.length - 1];
607         System.arraycopy(selected, 0, newsel, 0, i);
608         System.arraycopy(selected, i+1, newsel, i, selected.length - (i+1));
609         selected = newsel;
610         return;
611         }
612     }
613     }
614
615     /**
616      * Determines if the specified item in this scrolling list is
617      * selected.
618      * @param index the item to be checked
619      * @return <code>true</code> if the specified item has been
620      * selected; <code>false</code> otherwise
621      * @see #select
622      * @see #deselect
623      * @since JDK1.1
624      */

625     public boolean isIndexSelected(int index) {
626     return isSelected(index);
627     }
628
629     /**
630      * @deprecated As of JDK version 1.1,
631      * replaced by <code>isIndexSelected(int)</code>.
632      */

633     @Deprecated JavaDoc
634     public boolean isSelected(int index) {
635     int sel[] = getSelectedIndexes();
636     for (int i = 0 ; i < sel.length ; i++) {
637         if (sel[i] == index) {
638         return true;
639         }
640     }
641     return false;
642     }
643
644     /**
645      * Gets the number of visible lines in this list. Note that
646      * once the <code>List</code> has been created, this number
647      * will never change.
648      * @return the number of visible lines in this scrolling list
649      */

650     public int getRows() {
651     return rows;
652     }
653
654     /**
655      * Determines whether this list allows multiple selections.
656      * @return <code>true</code> if this list allows multiple
657      * selections; otherwise, <code>false</code>
658      * @see #setMultipleMode
659      * @since JDK1.1
660      */

661     public boolean isMultipleMode() {
662     return allowsMultipleSelections();
663     }
664
665     /**
666      * @deprecated As of JDK version 1.1,
667      * replaced by <code>isMultipleMode()</code>.
668      */

669     @Deprecated JavaDoc
670     public boolean allowsMultipleSelections() {
671     return multipleMode;
672     }
673
674     /**
675      * Sets the flag that determines whether this list
676      * allows multiple selections.
677      * When the selection mode is changed from multiple-selection to
678      * single-selection, the selected items change as follows:
679      * If a selected item has the location cursor, only that
680      * item will remain selected. If no selected item has the
681      * location cursor, all items will be deselected.
682      * @param b if <code>true</code> then multiple selections
683      * are allowed; otherwise, only one item from
684      * the list can be selected at once
685      * @see #isMultipleMode
686      * @since JDK1.1
687      */

688     public void setMultipleMode(boolean b) {
689         setMultipleSelections(b);
690     }
691
692     /**
693      * @deprecated As of JDK version 1.1,
694      * replaced by <code>setMultipleMode(boolean)</code>.
695      */

696     @Deprecated JavaDoc
697     public synchronized void setMultipleSelections(boolean b) {
698     if (b != multipleMode) {
699         multipleMode = b;
700         ListPeer peer = (ListPeer)this.peer;
701         if (peer != null) {
702         peer.setMultipleSelections(b);
703         }
704     }
705     }
706
707     /**
708      * Gets the index of the item that was last made visible by
709      * the method <code>makeVisible</code>.
710      * @return the index of the item that was last made visible
711      * @see #makeVisible
712      */

713     public int getVisibleIndex() {
714     return visibleIndex;
715     }
716
717     /**
718      * Makes the item at the specified index visible.
719      * @param index the position of the item
720      * @see #getVisibleIndex
721      */

722     public synchronized void makeVisible(int index) {
723     visibleIndex = index;
724     ListPeer peer = (ListPeer)this.peer;
725     if (peer != null) {
726         peer.makeVisible(index);
727     }
728     }
729
730     /**
731      * Gets the preferred dimensions for a list with the specified
732      * number of rows.
733      * @param rows number of rows in the list
734      * @return the preferred dimensions for displaying this scrolling list
735      * given that the specified number of rows must be visible
736      * @see java.awt.Component#getPreferredSize
737      * @since JDK1.1
738      */

739     public Dimension JavaDoc getPreferredSize(int rows) {
740     return preferredSize(rows);
741     }
742
743     /**
744      * @deprecated As of JDK version 1.1,
745      * replaced by <code>getPreferredSize(int)</code>.
746      */

747     @Deprecated JavaDoc
748     public Dimension JavaDoc preferredSize(int rows) {
749         synchronized (getTreeLock()) {
750         ListPeer peer = (ListPeer)this.peer;
751         return (peer != null) ?
752                peer.preferredSize(rows) :
753                super.preferredSize();
754         }
755     }
756
757     /**
758      * Gets the preferred size of this scrolling list.
759      * @return the preferred dimensions for displaying this scrolling list
760      * @see java.awt.Component#getPreferredSize
761      * @since JDK1.1
762      */

763     public Dimension JavaDoc getPreferredSize() {
764     return preferredSize();
765     }
766
767     /**
768      * @deprecated As of JDK version 1.1,
769      * replaced by <code>getPreferredSize()</code>.
770      */

771     @Deprecated JavaDoc
772     public Dimension JavaDoc preferredSize() {
773         synchronized (getTreeLock()) {
774         return (rows > 0) ?
775                preferredSize(rows) :
776                super.preferredSize();
777         }
778     }
779
780     /**
781      * Gets the minumum dimensions for a list with the specified
782      * number of rows.
783      * @param rows number of rows in the list
784      * @return the minimum dimensions for displaying this scrolling list
785      * given that the specified number of rows must be visible
786      * @see java.awt.Component#getMinimumSize
787      * @since JDK1.1
788      */

789     public Dimension JavaDoc getMinimumSize(int rows) {
790     return minimumSize(rows);
791     }
792
793     /**
794      * @deprecated As of JDK version 1.1,
795      * replaced by <code>getMinimumSize(int)</code>.
796      */

797     @Deprecated JavaDoc
798     public Dimension JavaDoc minimumSize(int rows) {
799         synchronized (getTreeLock()) {
800         ListPeer peer = (ListPeer)this.peer;
801         return (peer != null) ?
802                peer.minimumSize(rows) :
803                super.minimumSize();
804         }
805     }
806
807     /**
808      * Determines the minimum size of this scrolling list.
809      * @return the minimum dimensions needed
810      * to display this scrolling list
811      * @see java.awt.Component#getMinimumSize()
812      * @since JDK1.1
813      */

814     public Dimension JavaDoc getMinimumSize() {
815     return minimumSize();
816     }
817
818     /**
819      * @deprecated As of JDK version 1.1,
820      * replaced by <code>getMinimumSize()</code>.
821      */

822     @Deprecated JavaDoc
823     public Dimension JavaDoc minimumSize() {
824         synchronized (getTreeLock()) {
825         return (rows > 0) ? minimumSize(rows) : super.minimumSize();
826         }
827     }
828
829     /**
830      * Adds the specified item listener to receive item events from
831      * this list. Item events are sent in response to user input, but not
832      * in response to calls to <code>select</code> or <code>deselect</code>.
833      * If listener <code>l</code> is <code>null</code>,
834      * no exception is thrown and no action is performed.
835      *
836      * @param l the item listener
837      * @see #removeItemListener
838      * @see #getItemListeners
839      * @see #select
840      * @see #deselect
841      * @see java.awt.event.ItemEvent
842      * @see java.awt.event.ItemListener
843      * @since JDK1.1
844      */

845     public synchronized void addItemListener(ItemListener l) {
846     if (l == null) {
847         return;
848     }
849         itemListener = AWTEventMulticaster.add(itemListener, l);
850         newEventsOnly = true;
851     }
852
853     /**
854      * Removes the specified item listener so that it no longer
855      * receives item events from this list.
856      * If listener <code>l</code> is <code>null</code>,
857      * no exception is thrown and no action is performed.
858      *
859      * @param l the item listener
860      * @see #addItemListener
861      * @see #getItemListeners
862      * @see java.awt.event.ItemEvent
863      * @see java.awt.event.ItemListener
864      * @since JDK1.1
865      */

866     public synchronized void removeItemListener(ItemListener l) {
867     if (l == null) {
868         return;
869     }
870         itemListener = AWTEventMulticaster.remove(itemListener, l);
871     }
872
873     /**
874      * Returns an array of all the item listeners
875      * registered on this list.
876      *
877      * @return all of this list's <code>ItemListener</code>s
878      * or an empty array if no item
879      * listeners are currently registered
880      *
881      * @see #addItemListener
882      * @see #removeItemListener
883      * @see java.awt.event.ItemEvent
884      * @see java.awt.event.ItemListener
885      * @since 1.4
886      */

887     public synchronized ItemListener[] getItemListeners() {
888         return (ItemListener[])(getListeners(ItemListener.class));
889     }
890
891     /**
892      * Adds the specified action listener to receive action events from
893      * this list. Action events occur when a user double-clicks
894      * on a list item or types Enter when the list has the keyboard
895      * focus.
896      * <p>
897      * If listener <code>l</code> is <code>null</code>,
898      * no exception is thrown and no action is performed.
899      *
900      * @param l the action listener
901      * @see #removeActionListener
902      * @see #getActionListeners
903      * @see java.awt.event.ActionEvent
904      * @see java.awt.event.ActionListener
905      * @since JDK1.1
906      */

907     public synchronized void addActionListener(ActionListener l) {
908     if (l == null) {
909         return;
910     }
911     actionListener = AWTEventMulticaster.add(actionListener, l);
912         newEventsOnly = true;
913     }
914
915     /**
916      * Removes the specified action listener so that it no longer
917      * receives action events from this list. Action events
918      * occur when a user double-clicks on a list item.
919      * If listener <code>l</code> is <code>null</code>,
920      * no exception is thrown and no action is performed.
921      *
922      * @param l the action listener
923      * @see #addActionListener
924      * @see #getActionListeners
925      * @see java.awt.event.ActionEvent
926      * @see java.awt.event.ActionListener
927      * @since JDK1.1
928      */

929     public synchronized void removeActionListener(ActionListener l) {
930     if (l == null) {
931         return;
932     }
933     actionListener = AWTEventMulticaster.remove(actionListener, l);
934     }
935
936     /**
937      * Returns an array of all the action listeners
938      * registered on this list.
939      *
940      * @return all of this list's <code>ActionListener</code>s
941      * or an empty array if no action
942      * listeners are currently registered
943      *
944      * @see #addActionListener
945      * @see #removeActionListener
946      * @see java.awt.event.ActionEvent
947      * @see java.awt.event.ActionListener
948      * @since 1.4
949      */

950     public synchronized ActionListener[] getActionListeners() {
951         return (ActionListener[])(getListeners(ActionListener.class));
952     }
953
954     /**
955      * Returns an array of all the objects currently registered
956      * as <code><em>Foo</em>Listener</code>s
957      * upon this <code>List</code>.
958      * <code><em>Foo</em>Listener</code>s are registered using the
959      * <code>add<em>Foo</em>Listener</code> method.
960      *
961      * <p>
962      * You can specify the <code>listenerType</code> argument
963      * with a class literal, such as
964      * <code><em>Foo</em>Listener.class</code>.
965      * For example, you can query a
966      * <code>List</code> <code>l</code>
967      * for its item listeners with the following code:
968      *
969      * <pre>ItemListener[] ils = (ItemListener[])(l.getListeners(ItemListener.class));</pre>
970      *
971      * If no such listeners exist, this method returns an empty array.
972      *
973      * @param listenerType the type of listeners requested; this parameter
974      * should specify an interface that descends from
975      * <code>java.util.EventListener</code>
976      * @return an array of all objects registered as
977      * <code><em>Foo</em>Listener</code>s on this list,
978      * or an empty array if no such
979      * listeners have been added
980      * @exception ClassCastException if <code>listenerType</code>
981      * doesn't specify a class or interface that implements
982      * <code>java.util.EventListener</code>
983      *
984      * @see #getItemListeners
985      * @since 1.3
986      */

987     public <T extends EventListener JavaDoc> T[] getListeners(Class JavaDoc<T> listenerType) {
988     EventListener JavaDoc l = null;
989     if (listenerType == ActionListener.class) {
990         l = actionListener;
991     } else if (listenerType == ItemListener.class) {
992         l = itemListener;
993     } else {
994         return super.getListeners(listenerType);
995     }
996     return AWTEventMulticaster.getListeners(l, listenerType);
997     }
998
999     // REMIND: remove when filtering is done at lower level
1000
boolean eventEnabled(AWTEvent JavaDoc e) {
1001        switch(e.id) {
1002          case ActionEvent.ACTION_PERFORMED:
1003            if ((eventMask & AWTEvent.ACTION_EVENT_MASK) != 0 ||
1004                actionListener != null) {
1005                return true;
1006            }
1007            return false;
1008          case ItemEvent.ITEM_STATE_CHANGED:
1009            if ((eventMask & AWTEvent.ITEM_EVENT_MASK) != 0 ||
1010                itemListener != null) {
1011                return true;
1012            }
1013            return false;
1014          default: