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:
1015            break;
1016        }
1017        return super.eventEnabled(e);
1018    }
1019
1020    /**
1021     * Processes events on this scrolling list. If an event is
1022     * an instance of <code>ItemEvent</code>, it invokes the
1023     * <code>processItemEvent</code> method. Else, if the
1024     * event is an instance of <code>ActionEvent</code>,
1025     * it invokes <code>processActionEvent</code>.
1026     * If the event is not an item event or an action event,
1027     * it invokes <code>processEvent</code> on the superclass.
1028     * <p>Note that if the event parameter is <code>null</code>
1029     * the behavior is unspecified and may result in an
1030     * exception.
1031     *
1032     * @param e the event
1033     * @see java.awt.event.ActionEvent
1034     * @see java.awt.event.ItemEvent
1035     * @see #processActionEvent
1036     * @see #processItemEvent
1037     * @since JDK1.1
1038     */

1039    protected void processEvent(AWTEvent JavaDoc e) {
1040        if (e instanceof ItemEvent) {
1041            processItemEvent((ItemEvent)e);
1042            return;
1043        } else if (e instanceof ActionEvent) {
1044            processActionEvent((ActionEvent)e);
1045            return;
1046        }
1047    super.processEvent(e);
1048    }
1049
1050    /**
1051     * Processes item events occurring on this list by
1052     * dispatching them to any registered
1053     * <code>ItemListener</code> objects.
1054     * <p>
1055     * This method is not called unless item events are
1056     * enabled for this component. Item events are enabled
1057     * when one of the following occurs:
1058     * <p><ul>
1059     * <li>An <code>ItemListener</code> object is registered
1060     * via <code>addItemListener</code>.
1061     * <li>Item events are enabled via <code>enableEvents</code>.
1062     * </ul>
1063     * <p>Note that if the event parameter is <code>null</code>
1064     * the behavior is unspecified and may result in an
1065     * exception.
1066     *
1067     * @param e the item event
1068     * @see java.awt.event.ItemEvent
1069     * @see java.awt.event.ItemListener
1070     * @see #addItemListener
1071     * @see java.awt.Component#enableEvents
1072     * @since JDK1.1
1073     */

1074    protected void processItemEvent(ItemEvent e) {
1075        ItemListener listener = itemListener;
1076        if (listener != null) {
1077            listener.itemStateChanged(e);
1078        }
1079    }
1080
1081    /**
1082     * Processes action events occurring on this component
1083     * by dispatching them to any registered
1084     * <code>ActionListener</code> objects.
1085     * <p>
1086     * This method is not called unless action events are
1087     * enabled for this component. Action events are enabled
1088     * when one of the following occurs:
1089     * <p><ul>
1090     * <li>An <code>ActionListener</code> object is registered
1091     * via <code>addActionListener</code>.
1092     * <li>Action events are enabled via <code>enableEvents</code>.
1093     * </ul>
1094     * <p>Note that if the event parameter is <code>null</code>
1095     * the behavior is unspecified and may result in an
1096     * exception.
1097     *
1098     * @param e the action event
1099     * @see java.awt.event.ActionEvent
1100     * @see java.awt.event.ActionListener
1101     * @see #addActionListener
1102     * @see java.awt.Component#enableEvents
1103     * @since JDK1.1
1104     */

1105    protected void processActionEvent(ActionEvent e) {
1106        ActionListener listener = actionListener;
1107        if (listener != null) {
1108            listener.actionPerformed(e);
1109        }
1110    }
1111
1112    /**
1113     * Returns the parameter string representing the state of this
1114     * scrolling list. This string is useful for debugging.
1115     * @return the parameter string of this scrolling list
1116     */

1117    protected String JavaDoc paramString() {
1118    return super.paramString() + ",selected=" + getSelectedItem();
1119    }
1120
1121    /**
1122     * @deprecated As of JDK version 1.1,
1123     * Not for public use in the future.
1124     * This method is expected to be retained only as a package
1125     * private method.
1126     */

1127    @Deprecated JavaDoc
1128    public synchronized void delItems(int start, int end) {
1129    for (int i = end; i >= start; i--) {
1130        items.removeElementAt(i);
1131    }
1132    ListPeer peer = (ListPeer)this.peer;
1133    if (peer != null) {
1134        peer.delItems(start, end);
1135    }
1136    }
1137
1138    /*
1139     * Serialization support. Since the value of the selected
1140     * field isn't neccessarily up to date we sync it up with the
1141     * peer before serializing.
1142     */

1143
1144    /**
1145     * The <code>List</code> component's
1146     * Serialized Data Version.
1147     *
1148     * @serial
1149     */

1150    private int listSerializedDataVersion = 1;
1151
1152    /**
1153     * Writes default serializable fields to stream. Writes
1154     * a list of serializable <code>ItemListeners</code>
1155     * and <code>ActionListeners</code> as optional data.
1156     * The non-serializable listeners are detected and
1157     * no attempt is made to serialize them.
1158     *
1159     * @serialData <code>null</code> terminated sequence of 0
1160     * or more pairs; the pair consists of a <code>String</code>
1161     * and an <code>Object</code>; the <code>String</code>
1162     * indicates the type of object and is one of the
1163     * following:
1164     * <code>itemListenerK</code> indicating an
1165     * <code>ItemListener</code> object;
1166     * <code>actionListenerK</code> indicating an
1167     * <code>ActionListener</code> object
1168     *
1169     * @param s the <code>ObjectOutputStream</code> to write
1170     * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
1171     * @see java.awt.Component#itemListenerK
1172     * @see java.awt.Component#actionListenerK
1173     * @see #readObject(ObjectInputStream)
1174     */

1175    private void writeObject(ObjectOutputStream JavaDoc s)
1176      throws IOException JavaDoc
1177    {
1178      synchronized (this) {
1179    ListPeer peer = (ListPeer)this.peer;
1180    if (peer != null) {
1181      selected = peer.getSelectedIndexes();
1182    }
1183      }
1184      s.defaultWriteObject();
1185
1186      AWTEventMulticaster.save(s, itemListenerK, itemListener);
1187      AWTEventMulticaster.save(s, actionListenerK, actionListener);
1188      s.writeObject(null);
1189    }
1190
1191    /**
1192     * Reads the <code>ObjectInputStream</code> and if it
1193     * isn't <code>null</code> adds a listener to receive
1194     * both item events and action events (as specified
1195     * by the key stored in the stream) fired by the
1196     * <code>List</code>.
1197     * Unrecognized keys or values will be ignored.
1198     *
1199     * @param s the <code>ObjectInputStream</code> to write
1200     * @exception HeadlessException if
1201     * <code>GraphicsEnvironment.isHeadless</code> returns
1202     * <code>true</code>
1203     * @see #removeItemListener(ItemListener)
1204     * @see #addItemListener(ItemListener)
1205     * @see java.awt.GraphicsEnvironment#isHeadless
1206     * @see #writeObject(ObjectOutputStream)
1207     */

1208    private void readObject(ObjectInputStream JavaDoc s)
1209      throws ClassNotFoundException JavaDoc, IOException JavaDoc, HeadlessException JavaDoc
1210    {
1211      GraphicsEnvironment.checkHeadless();
1212      s.defaultReadObject();
1213
1214      Object JavaDoc keyOrNull;
1215      while(null != (keyOrNull = s.readObject())) {
1216    String JavaDoc key = ((String JavaDoc)keyOrNull).intern();
1217
1218    if (itemListenerK == key)
1219      addItemListener((ItemListener)(s.readObject()));
1220
1221    else if (actionListenerK == key)
1222      addActionListener((ActionListener)(s.readObject()));
1223
1224    else // skip value for unrecognized key
1225
s.readObject();
1226      }
1227    }
1228
1229
1230/////////////////
1231
// Accessibility support
1232
////////////////
1233

1234
1235    /**
1236     * Gets the <code>AccessibleContext</code> associated with this
1237     * <code>List</code>. For lists, the <code>AccessibleContext</code>
1238     * takes the form of an <code>AccessibleAWTList</code>.
1239     * A new <code>AccessibleAWTList</code> instance is created, if necessary.
1240     *
1241     * @return an <code>AccessibleAWTList</code> that serves as the
1242     * <code>AccessibleContext</code> of this <code>List</code>
1243     */

1244    public AccessibleContext getAccessibleContext() {
1245        if (accessibleContext == null) {
1246            accessibleContext = new AccessibleAWTList();
1247        }
1248        return accessibleContext;
1249    }
1250
1251    /**
1252     * This class implements accessibility support for the
1253     * <code>List</code> class. It provides an implementation of the
1254     * Java Accessibility API appropriate to list user-interface elements.
1255     */

1256    protected class AccessibleAWTList extends AccessibleAWTComponent
1257        implements AccessibleSelection, ItemListener, ActionListener
1258    {
1259        /*
1260         * JDK 1.3 serialVersionUID
1261         */

1262        private static final long serialVersionUID = 7924617370136012829L;
1263
1264    public AccessibleAWTList() {
1265        super();
1266            List.this.addActionListener(this);
1267            List.this.addItemListener(this);
1268    }
1269
1270        public void actionPerformed(ActionEvent event) {
1271        }
1272
1273        public void itemStateChanged(ItemEvent event) {
1274        }
1275
1276        /**
1277         * Get the state set of this object.
1278         *
1279         * @return an instance of AccessibleState containing the current state
1280         * of the object
1281         * @see AccessibleState
1282         */

1283        public AccessibleStateSet getAccessibleStateSet() {
1284            AccessibleStateSet states = super.getAccessibleStateSet();
1285            if (List.this.isMultipleMode()) {
1286                states.add(AccessibleState.MULTISELECTABLE);
1287            }
1288            return states;
1289        }
1290
1291        /**
1292         * Get the role of this object.
1293         *
1294         * @return an instance of AccessibleRole describing the role of the
1295     * object
1296         * @see AccessibleRole
1297         */

1298        public AccessibleRole getAccessibleRole() {
1299            return AccessibleRole.LIST;
1300        }
1301
1302        /**
1303         * Returns the Accessible child contained at the local coordinate
1304         * Point, if one exists.
1305         *
1306         * @return the Accessible at the specified location, if it exists
1307         */

1308        public Accessible getAccessibleAt(Point JavaDoc p) {
1309            return null; // fredxFIXME Not implemented yet
1310
}
1311
1312        /**
1313         * Returns the number of accessible children in the object. If all
1314         * of the children of this object implement Accessible, than this
1315         * method should return the number of children of this object.
1316         *
1317         * @return the number of accessible children in the object.
1318         */

1319        public int getAccessibleChildrenCount() {
1320            return List.this.getItemCount();
1321        }
1322
1323        /**
1324         * Return the nth Accessible child of the object.
1325         *
1326         * @param i zero-based index of child
1327         * @return the nth Accessible child of the object
1328         */

1329        public Accessible getAccessibleChild(int i) {
1330            synchronized(List.this) {
1331                if (i >= List.this.getItemCount()) {
1332                    return null;
1333                } else {
1334                    return new AccessibleAWTListChild(List.this, i);
1335                }
1336            }
1337        }
1338
1339        /**
1340         * Get the AccessibleSelection associated with this object. In the
1341         * implementation of the Java Accessibility API for this class,
1342     * return this object, which is responsible for implementing the
1343         * AccessibleSelection interface on behalf of itself.
1344     *
1345     * @return this object
1346         */

1347        public AccessibleSelection getAccessibleSelection() {
1348            return this;
1349        }
1350
1351    // AccessibleSelection methods
1352

1353        /**
1354         * Returns the number of items currently selected.
1355         * If no items are selected, the return value will be 0.
1356         *
1357         * @return the number of items currently selected.
1358         */

1359         public int getAccessibleSelectionCount() {
1360             return List.this.getSelectedIndexes().length;
1361         }
1362
1363        /**
1364         * Returns an Accessible representing the specified selected item
1365         * in the object. If there isn't a selection, or there are
1366         * fewer items selected than the integer passed in, the return
1367         * value will be null.
1368         *
1369         * @param i the zero-based index of selected items
1370         * @return an Accessible containing the selected item
1371         */

1372         public Accessible getAccessibleSelection(int i) {
1373             synchronized(List.this) {
1374                 int len = getAccessibleSelectionCount();
1375                 if (i < 0 || i >= len) {
1376                     return null;
1377                 } else {
1378                     return getAccessibleChild(List.this.getSelectedIndexes()[i]);
1379                 }
1380             }
1381         }
1382
1383        /**
1384         * Returns true if the current child of this object is selected.
1385         *
1386         * @param i the zero-based index of the child in this Accessible
1387         * object.
1388         * @see AccessibleContext#getAccessibleChild
1389         */

1390        public boolean isAccessibleChildSelected(int i) {
1391            return List.this.isIndexSelected(i);
1392        }
1393
1394        /**
1395         * Adds the specified selected item in the object to the object's
1396         * selection. If the object supports multiple selections,
1397         * the specified item is added to any existing selection, otherwise
1398         * it replaces any existing selection in the object. If the
1399         * specified item is already selected, this method has no effect.
1400         *
1401         * @param i the zero-based index of selectable items
1402         */

1403         public void addAccessibleSelection(int i) {
1404             List.this.select(i);
1405         }
1406
1407        /**
1408         * Removes the specified selected item in the object from the object's
1409         * selection. If the specified item isn't currently selected, this
1410         * method has no effect.
1411         *
1412         * @param i the zero-based index of selectable items
1413         */

1414         public void removeAccessibleSelection(int i) {
1415             List.this.deselect(i);
1416         }
1417
1418        /**
1419         * Clears the selection in the object, so that nothing in the
1420         * object is selected.
1421         */

1422         public void clearAccessibleSelection() {
1423             synchronized(List.this) {
1424                 int selectedIndexes[] = List.this.getSelectedIndexes();
1425                 if (selectedIndexes == null)
1426                     return;
1427                 for (int i = selectedIndexes.length - 1; i >= 0; i--) {
1428                     List.this.deselect(selectedIndexes[i]);
1429                 }
1430             }
1431         }
1432
1433        /**
1434         * Causes every selected item in the object to be selected
1435         * if the object supports multiple selections.
1436         */

1437         public void selectAllAccessibleSelection() {
1438             synchronized(List.this) {
1439                 for (int i = List.this.getItemCount() - 1; i >= 0; i--) {
1440                     List.this.select(i);
1441                 }
1442             }
1443         }
1444
1445       /**
1446        * This class implements accessibility support for
1447        * List children. It provides an implementation of the
1448        * Java Accessibility API appropriate to list children
1449    * user-interface elements.
1450        */

1451        protected class AccessibleAWTListChild extends AccessibleAWTComponent
1452            implements Accessible
1453        {
1454            /*
1455             * JDK 1.3 serialVersionUID
1456             */

1457            private static final long serialVersionUID = 4412022926028300317L;
1458    
1459    // [[[FIXME]]] need to finish implementing this!!!
1460

1461            private List JavaDoc parent;
1462            private int indexInParent;
1463
1464            public AccessibleAWTListChild(List JavaDoc parent, int indexInParent) {
1465                this.parent = parent;
1466        this.setAccessibleParent(parent);
1467                this.indexInParent = indexInParent;
1468            }
1469
1470        //
1471
// required Accessible methods
1472
//
1473
/**
1474       * Gets the AccessibleContext for this object. In the
1475           * implementation of the Java Accessibility API for this class,
1476       * return this object, which acts as its own AccessibleContext.
1477       *
1478       * @return this object
1479       */

1480        public AccessibleContext getAccessibleContext() {
1481        return this;
1482        }
1483
1484        //
1485
// required AccessibleContext methods
1486
//
1487

1488        /**
1489         * Get the role of this object.
1490         *
1491         * @return an instance of AccessibleRole describing the role of
1492         * the object
1493         * @see AccessibleRole
1494         */

1495        public AccessibleRole getAccessibleRole() {
1496        return AccessibleRole.LIST_ITEM;
1497        }
1498
1499        /**
1500         * Get the state set of this object. The AccessibleStateSet of an
1501         * object is composed of a set of unique AccessibleState's. A
1502         * change in the AccessibleStateSet of an object will cause a
1503         * PropertyChangeEvent to be fired for the
1504         * ACCESSIBLE_STATE_PROPERTY property.
1505         *
1506         * @return an instance of AccessibleStateSet containing the
1507         * current state set of the object
1508         * @see AccessibleStateSet
1509         * @see AccessibleState
1510         * @see #addPropertyChangeListener
1511         */

1512        public AccessibleStateSet getAccessibleStateSet() {
1513        AccessibleStateSet states = super.getAccessibleStateSet();
1514        if (parent.isIndexSelected(indexInParent)) {
1515            states.add(AccessibleState.SELECTED);
1516        }
1517        return states;
1518        }
1519
1520        /**
1521         * Gets the locale of the component. If the component does not
1522         * have a locale, then the locale of its parent is returned.
1523         *
1524         * @return This component's locale. If this component does not have
1525         * a locale, the locale of its parent is returned.
1526         *
1527         * @exception IllegalComponentStateException
1528         * If the Component does not have its own locale and has not yet
1529         * been added to a containment hierarchy such that the locale can
1530         * be determined from the containing parent.
1531         */

1532        public Locale JavaDoc getLocale() {
1533        return parent.getLocale();
1534        }
1535
1536        /**
1537         * Get the 0-based index of this object in its accessible parent.
1538         *
1539         * @return the 0-based index of this object in its parent; -1 if
1540         * this object does not have an accessible parent.
1541         *
1542         * @see #getAccessibleParent
1543         * @see #getAccessibleChildrenCount
1544         * @see #getAccessibleChild
1545         */

1546        public int getAccessibleIndexInParent() {
1547        return indexInParent;
1548        }
1549
1550        /**
1551         * Returns the number of accessible children of the object.
1552         *
1553         * @return the number of accessible children of the object.
1554         */

1555        public int getAccessibleChildrenCount() {
1556        return 0; // list elements can't have children
1557
}
1558
1559        /**
1560         * Return the specified Accessible child of the object. The
1561         * Accessible children of an Accessible object are zero-based,
1562         * so the first child of an Accessible child is at index 0, the
1563         * second child is at index 1, and so on.
1564         *
1565         * @param i zero-based index of child
1566         * @return the Accessible child of the object
1567         * @see #getAccessibleChildrenCount
1568         */

1569        public Accessible getAccessibleChild(int i) {
1570        return null; // list elements can't have children
1571
}
1572
1573
1574        //
1575
// AccessibleComponent delegatation to parent List
1576
//
1577

1578        /**
1579         * Get the background color of this object.
1580         *
1581         * @return the background color, if supported, of the object;
1582         * otherwise, null
1583         * @see #setBackground
1584         */

1585        public Color JavaDoc getBackground() {
1586        return parent.getBackground();
1587        }
1588
1589        /**
1590         * Set the background color of this object.
1591         *
1592         * @param c the new Color for the background
1593         * @see #setBackground
1594         */

1595        public void setBackground(Color JavaDoc c) {
1596        parent.setBackground(c);
1597        }
1598
1599        /**
1600         * Get the foreground color of this object.
1601         *
1602         * @return the foreground color, if supported, of the object;
1603         * otherwise, null
1604         * @see #setForeground
1605         */

1606        public Color JavaDoc getForeground() {
1607        return parent.getForeground();
1608        }
1609
1610        /**
1611         * Set the foreground color of this object.
1612         *
1613         * @param c the new Color for the foreground
1614         * @see #getForeground
1615         */

1616        public void setForeground(Color JavaDoc c) {
1617        parent.setForeground(c);
1618        }
1619
1620        /**
1621         * Get the Cursor of this object.
1622         *
1623         * @return the Cursor, if supported, of the object; otherwise, null
1624         * @see #setCursor
1625         */

1626        public Cursor JavaDoc getCursor() {
1627        return parent.getCursor();
1628        }
1629
1630        /**
1631         * Set the Cursor of this object.
1632         *
1633         * @param cursor the new Cursor for the object
1634         * @see #getCursor
1635         */

1636        public void setCursor(Cursor JavaDoc cursor) {
1637        parent.setCursor(cursor);
1638        }
1639
1640        /**
1641         * Get the Font of this object.
1642         *
1643         * @return the Font,if supported, for the object; otherwise, null
1644         * @see #setFont
1645         */

1646        public Font JavaDoc getFont() {
1647        return parent.getFont();
1648        }
1649
1650        /**
1651         * Set the Font of this object.
1652         *
1653         * @param f the new Font for the object
1654         * @see #getFont
1655         */

1656        public void setFont(Font JavaDoc f) {
1657        parent.setFont(f);
1658        }
1659
1660        /**
1661         * Get the FontMetrics of this object.
1662         *
1663         * @param f the Font
1664         * @return the FontMetrics, if supported, the object; otherwise, null
1665         * @see #getFont
1666         */

1667        public FontMetrics JavaDoc getFontMetrics(Font JavaDoc f) {
1668        return parent.getFontMetrics(f);
1669        }
1670
1671        /**
1672         * Determine if the object is enabled. Objects that are enabled
1673         * will also have the AccessibleState.ENABLED state set in their
1674         * AccessibleStateSet.
1675         *
1676         * @return true if object is enabled; otherwise, false
1677         * @see #setEnabled
1678         * @see AccessibleContext#getAccessibleStateSet
1679         * @see AccessibleState#ENABLED
1680         * @see AccessibleStateSet
1681         */

1682        public boolean isEnabled() {
1683        return parent.isEnabled();
1684        }
1685
1686        /**
1687         * Set the enabled state of the object.
1688         *
1689         * @param b if true, enables this object; otherwise, disables it
1690         * @see #isEnabled
1691         */

1692        public void setEnabled(boolean b) {
1693        parent.setEnabled(b);
1694        }
1695
1696        /**
1697         * Determine if the object is visible. Note: this means that the
1698         * object intends to be visible; however, it may not be
1699         * showing on the screen because one of the objects that this object
1700         * is contained by is currently not visible. To determine if an
1701         * object is showing on the screen, use isShowing().
1702         * <p>Objects that are visible will also have the
1703         * AccessibleState.VISIBLE state set in their AccessibleStateSet.
1704         *
1705         * @return true if object is visible; otherwise, false
1706         * @see #setVisible
1707         * @see AccessibleContext#getAccessibleStateSet
1708         * @see AccessibleState#VISIBLE
1709         * @see AccessibleStateSet
1710         */

1711        public boolean isVisible() {
1712        // [[[FIXME]]] needs to work like isShowing() below
1713
return false;
1714        // return parent.isVisible();
1715
}
1716
1717        /**
1718         * Set the visible state of the object.
1719         *
1720         * @param b if true, shows this object; otherwise, hides it
1721         * @see #isVisible
1722         */

1723        public void setVisible(boolean b) {
1724        // [[[FIXME]]] should scroll to item to make it show!
1725
parent.setVisible(b);
1726        }
1727
1728        /**
1729         * Determine if the object is showing. This is determined by
1730         * checking the visibility of the object and visibility of the
1731         * object ancestors.
1732         * Note: this will return true even if the object is obscured
1733         * by another (for example, it to object is underneath a menu
1734         * that was pulled down).
1735         *
1736         * @return true if object is showing; otherwise, false
1737         */

1738        public boolean isShowing() {
1739        // [[[FIXME]]] only if it's showing!!!
1740
return false;
1741        // return parent.isShowing();
1742
}
1743
1744        /**
1745         * Checks whether the specified point is within this object's
1746         * bounds, where the point's x and y coordinates are defined to
1747         * be relative to the coordinate system of the object.
1748         *
1749         * @param p the Point relative to the coordinate system of the
1750         * object
1751         * @return true if object contains Point; otherwise false
1752         * @see #getBounds
1753         */

1754        public boolean contains(Point JavaDoc p) {
1755        // [[[FIXME]]] - only if p is within the list element!!!
1756
return false;
1757        // return parent.contains(p);
1758
}
1759
1760        /**
1761         * Returns the location of the object on the screen.
1762         *
1763         * @return location of object on screen; null if this object
1764         * is not on the screen
1765         * @see #getBounds
1766         * @see #getLocation
1767         */

1768        public Point JavaDoc getLocationOnScreen() {
1769        // [[[FIXME]]] sigh
1770
return null;
1771        }
1772
1773        /**
1774         * Gets the location of the object relative to the parent in the
1775         * form of a point specifying the object's top-left corner in the
1776         * screen's coordinate space.
1777         *
1778         * @return An instance of Point representing the top-left corner of
1779         * the objects's bounds in the coordinate space of the screen; null
1780         * if this object or its parent are not on the screen
1781         * @see #getBounds
1782         * @see #getLocationOnScreen
1783         */

1784        public Point JavaDoc getLocation() {
1785        // [[[FIXME]]]
1786
return null;
1787        }
1788
1789        /**
1790         * Sets the location of the object relative to the parent.
1791         * @param p the new position for the top-left corner
1792         * @see #getLocation
1793         */

1794        public void setLocation(Point JavaDoc p) {
1795        // [[[FIXME]]] maybe - can simply return as no-op
1796
}
1797
1798        /**
1799         * Gets the bounds of this object in the form of a Rectangle object.
1800         * The bounds specify this object's width, height, and location
1801         * relative to its parent.
1802         *
1803         * @return A rectangle indicating this component's bounds; null if
1804         * this object is not on the screen.
1805         * @see #contains
1806         */

1807        public Rectangle JavaDoc getBounds() {
1808        // [[[FIXME]]]
1809
return null;
1810        }
1811
1812        /**
1813         * Sets the bounds of this object in the form of a Rectangle
1814         * object. The bounds specify this object's width, height, and
1815         * location relative to its parent.
1816         *
1817         * @param r rectangle indicating this component's bounds
1818         * @see #getBounds
1819         */

1820        public void setBounds(Rectangle JavaDoc r) {
1821        // no-op; not supported
1822
}
1823
1824        /**
1825         * Returns the size of this object in the form of a Dimension
1826         * object. The height field of the Dimension object contains this
1827         * objects's height, and the width field of the Dimension object
1828         * contains this object's width.
1829         *
1830         * @return A Dimension object that indicates the size of this
1831         * component; null if this object is not on the screen
1832         * @see #setSize
1833         */

1834        public Dimension JavaDoc getSize() {
1835        // [[[FIXME]]]
1836
return null;
1837        }
1838
1839        /**
1840         * Resizes this object so that it has width and height.
1841         *
1842         * @param d - The dimension specifying the new size of the object.
1843         * @see #getSize
1844         */

1845        public void setSize(Dimension JavaDoc d) {
1846        // not supported; no-op
1847
}
1848
1849        /**
1850         * Returns the <code>Accessible</code> child, if one exists,
1851             * contained at the local coordinate <code>Point</code>.
1852         *
1853         * @param p the point relative to the coordinate system of this
1854         * object
1855         * @return the <code>Accessible</code>, if it exists,
1856             * at the specified location; otherwise <code>null</code>
1857         */

1858        public Accessible getAccessibleAt(Point JavaDoc p) {
1859        return null; // object cannot have children!
1860
}
1861
1862        /**
1863         * Returns whether this object can accept focus or not. Objects
1864         * that can accept focus will also have the
1865         * <code>AccessibleState.FOCUSABLE</code> state set in their
1866             * <code>AccessibleStateSet</code>.
1867         *
1868         * @return true if object can accept focus; otherwise false
1869         * @see AccessibleContext#getAccessibleStateSet
1870         * @see AccessibleState#FOCUSABLE
1871         * @see AccessibleState#FOCUSED
1872         * @see AccessibleStateSet
1873         */

1874        public boolean isFocusTraversable() {
1875        return false; // list element cannot receive focus!
1876
}
1877
1878        /**
1879         * Requests focus for this object. If this object cannot accept
1880         * focus, nothing will happen. Otherwise, the object will attempt
1881         * to take focus.
1882         * @see #isFocusTraversable
1883         */

1884        public void requestFocus() {
1885        // nothing to do; a no-op
1886
}
1887
1888        /**
1889         * Adds the specified focus listener to receive focus events from
1890         * this component.
1891         *
1892         * @param l the focus listener
1893         * @see #removeFocusListener
1894         */

1895        public void addFocusListener(FocusListener l) {
1896        // nothing to do; a no-op
1897
}
1898
1899        /**
1900         * Removes the specified focus listener so it no longer receives
1901         * focus events from this component.
1902         *
1903         * @param l the focus listener
1904         * @see #addFocusListener
1905         */

1906        public void removeFocusListener(FocusListener l) {
1907        // nothing to do; a no-op
1908
}
1909
1910
1911
1912        } // inner class AccessibleAWTListChild
1913

1914    } // inner class AccessibleAWTList
1915

1916}
1917
Popular Tags