Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / java / awt / List.java
blob00636a0224ff2a76fce2d937c04a19168e4367b6
1 /* List.java -- A listbox widget
2 Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package java.awt;
41 import java.awt.event.ActionEvent;
42 import java.awt.event.ActionListener;
43 import java.awt.event.ItemEvent;
44 import java.awt.event.ItemListener;
45 import java.awt.peer.ListPeer;
46 import java.util.EventListener;
47 import java.util.Vector;
49 import javax.accessibility.Accessible;
50 import javax.accessibility.AccessibleContext;
51 import javax.accessibility.AccessibleRole;
52 import javax.accessibility.AccessibleSelection;
53 import javax.accessibility.AccessibleState;
54 import javax.accessibility.AccessibleStateSet;
56 /**
57 * Class that implements a listbox widget
59 * @author Aaron M. Renn (arenn@urbanophile.com)
61 public class List extends Component
62 implements ItemSelectable, Accessible
66 * Static Variables
69 // Serialization constant
70 private static final long serialVersionUID = -3304312411574666869L;
72 /*************************************************************************/
75 * Instance Variables
78 // FIXME: Need read/writeObject
80 /**
81 * @serial The items in the list.
83 private Vector items = new Vector();
85 /**
86 * @serial Indicates whether or not multiple items can be selected
87 * simultaneously.
89 private boolean multipleMode;
91 /**
92 * @serial The number of rows in the list. This is set on creation
93 * only and cannot be modified.
95 private int rows;
97 /**
98 * @serial An array of the item indices that are selected.
100 private int[] selected;
103 * @serial An index value used by <code>makeVisible()</code> and
104 * <code>getVisibleIndex</code>.
106 private int visibleIndex;
108 // The list of ItemListeners for this object.
109 private ItemListener item_listeners;
111 // The list of ActionListeners for this object.
112 private ActionListener action_listeners;
115 /*************************************************************************/
118 * Constructors
122 * Initializes a new instance of <code>List</code> with no visible lines
123 * and multi-select disabled.
125 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
127 public
128 List()
130 this(4, false);
133 /*************************************************************************/
136 * Initializes a new instance of <code>List</code> with the specified
137 * number of visible lines and multi-select disabled.
139 * @param rows The number of visible rows in the list.
141 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
143 public
144 List(int rows)
146 this(rows, false);
149 /*************************************************************************/
152 * Initializes a new instance of <code>List</code> with the specified
153 * number of lines and the specified multi-select setting.
155 * @param rows The number of visible rows in the list.
156 * @param multipleMode <code>true</code> if multiple lines can be selected
157 * simultaneously, <code>false</code> otherwise.
159 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
161 public
162 List(int rows, boolean multipleMode)
164 this.rows = rows;
165 this.multipleMode = multipleMode;
166 selected = new int[0];
168 if (GraphicsEnvironment.isHeadless())
169 throw new HeadlessException ();
172 /*************************************************************************/
175 * Instance Variables
179 * Returns the number of items in this list.
181 * @return The number of items in this list.
183 public int
184 getItemCount()
186 return countItems ();
189 /*************************************************************************/
192 * Returns the number of items in this list.
194 * @return The number of items in this list.
196 * @deprecated This method is deprecated in favor of
197 * <code>getItemCount()</code>
199 public int
200 countItems()
202 return items.size ();
205 /*************************************************************************/
208 * Returns the complete list of items.
210 * @return The complete list of items in the list.
212 public synchronized String[]
213 getItems()
215 String[] l_items = new String[getItemCount()];
217 items.copyInto(l_items);
218 return(l_items);
221 /*************************************************************************/
224 * Returns the item at the specified index.
226 * @param index The index of the item to retrieve.
228 * @exception IndexOutOfBoundsException If the index value is not valid.
230 public String
231 getItem(int index)
233 return((String)items.elementAt(index));
236 /*************************************************************************/
239 * Returns the number of visible rows in the list.
241 * @return The number of visible rows in the list.
243 public int
244 getRows()
246 return(rows);
249 /*************************************************************************/
252 * Tests whether or not multi-select mode is enabled.
254 * @return <code>true</code> if multi-select mode is enabled,
255 * <code>false</code> otherwise.
257 public boolean
258 isMultipleMode()
260 return allowsMultipleSelections ();
263 /*************************************************************************/
266 * Tests whether or not multi-select mode is enabled.
268 * @return <code>true</code> if multi-select mode is enabled,
269 * <code>false</code> otherwise.
271 * @deprecated This method is deprecated in favor of
272 * <code>isMultipleMode()</code>.
274 public boolean
275 allowsMultipleSelections()
277 return multipleMode;
280 /*************************************************************************/
283 * This method enables or disables multiple selection mode for this
284 * list.
286 * @param multipleMode <code>true</code> to enable multiple mode,
287 * <code>false</code> otherwise.
289 public void
290 setMultipleMode(boolean multipleMode)
292 setMultipleSelections (multipleMode);
295 /*************************************************************************/
298 * This method enables or disables multiple selection mode for this
299 * list.
301 * @param multipleMode <code>true</code> to enable multiple mode,
302 * <code>false</code> otherwise.
304 * @deprecated
306 public void
307 setMultipleSelections(boolean multipleMode)
309 this.multipleMode = multipleMode;
311 ListPeer peer = (ListPeer) getPeer ();
312 if (peer != null)
313 peer.setMultipleMode (multipleMode);
316 /*************************************************************************/
319 * Returns the minimum size of this component.
321 * @return The minimum size of this component.
323 public Dimension
324 getMinimumSize()
326 return getMinimumSize (getRows ());
329 /*************************************************************************/
332 * Returns the minimum size of this component.
334 * @return The minimum size of this component.
336 * @deprecated This method is deprecated in favor of
337 * <code>getMinimumSize</code>.
339 public Dimension
340 minimumSize()
342 return minimumSize (getRows ());
345 /*************************************************************************/
348 * Returns the minimum size of this component assuming it had the specified
349 * number of rows.
351 * @param rows The number of rows to size for.
353 * @return The minimum size of this component.
355 public Dimension
356 getMinimumSize(int rows)
358 return minimumSize (rows);
361 /*************************************************************************/
364 * Returns the minimum size of this component assuming it had the specified
365 * number of rows.
367 * @param rows The number of rows to size for.
369 * @return The minimum size of this component.
371 * @deprecated This method is deprecated in favor of
372 * <code>getMinimumSize(int)</code>>
374 public Dimension
375 minimumSize(int rows)
377 ListPeer peer = (ListPeer) getPeer ();
378 if (peer != null)
379 return peer.minimumSize (rows);
380 else
381 return new Dimension (0, 0);
384 /*************************************************************************/
387 * Returns the preferred size of this component.
389 * @return The preferred size of this component.
391 public Dimension
392 getPreferredSize()
394 return getPreferredSize (getRows ());
397 /*************************************************************************/
400 * Returns the preferred size of this component.
402 * @return The preferred size of this component.
404 * @deprecated This method is deprecated in favor of
405 * <code>getPreferredSize</code>.
407 public Dimension
408 preferredSize()
410 return preferredSize (getRows ());
413 /*************************************************************************/
416 * Returns the preferred size of this component assuming it had the specified
417 * number of rows.
419 * @param rows The number of rows to size for.
421 * @return The preferred size of this component.
423 public Dimension
424 getPreferredSize(int rows)
426 return preferredSize (rows);
429 /*************************************************************************/
432 * Returns the preferred size of this component assuming it had the specified
433 * number of rows.
435 * @param rows The number of rows to size for.
437 * @return The preferred size of this component.
439 * @deprecated This method is deprecated in favor of
440 * <code>getPreferredSize(int)</code>>
442 public Dimension
443 preferredSize(int rows)
445 ListPeer peer = (ListPeer) getPeer ();
446 if (peer != null)
447 return peer.preferredSize (rows);
448 else
449 return new Dimension (0, 0);
452 /*************************************************************************/
455 * This method adds the specified item to the end of the list.
457 * @param item The item to add to the list.
459 public void
460 add(String item)
462 add (item, -1);
465 /*************************************************************************/
468 * This method adds the specified item to the end of the list.
470 * @param item The item to add to the list.
472 * @deprecated Use add() instead.
474 public void
475 addItem(String item)
477 addItem (item, -1);
480 /*************************************************************************/
483 * Adds the specified item to the specified location in the list.
484 * If the desired index is -1 or greater than the number of rows
485 * in the list, then the item is added to the end.
487 * @param item The item to add to the list.
488 * @param index The location in the list to add the item, or -1 to add
489 * to the end.
491 public void
492 add(String item, int index)
494 addItem (item, index);
497 /*************************************************************************/
500 * Adds the specified item to the specified location in the list.
501 * If the desired index is -1 or greater than the number of rows
502 * in the list, then the item is added to the end.
504 * @param item The item to add to the list.
505 * @param index The location in the list to add the item, or -1 to add
506 * to the end.
508 * @deprecated Use add() instead.
510 public void
511 addItem(String item, int index)
513 if ((index == -1) || (index >= items.size ()))
514 items.addElement (item);
515 else
516 items.insertElementAt (item, index);
518 ListPeer peer = (ListPeer) getPeer ();
519 if (peer != null)
520 peer.add (item, index);
523 /*************************************************************************/
526 * Deletes the item at the specified index.
528 * @param index The index of the item to delete.
530 * @exception IllegalArgumentException If the index is not valid
532 * @deprecated
534 public void
535 delItem(int index) throws IllegalArgumentException
537 items.removeElementAt (index);
539 ListPeer peer = (ListPeer) getPeer ();
540 if (peer != null)
541 peer.delItems (index, index);
544 /*************************************************************************/
547 * Deletes the item at the specified index.
549 * @param index The index of the item to delete.
551 * @exception IllegalArgumentException If the index is not valid
553 public void
554 remove(int index) throws IllegalArgumentException
556 delItem (index);
559 /*************************************************************************/
562 * Deletes all items in the specified index range.
564 * @param start The beginning index of the range to delete.
565 * @param end The ending index of the range to delete.
567 * @exception IllegalArgumentException If the indexes are not valid
569 * @deprecated This method is deprecated for some unknown reason.
571 public synchronized void
572 delItems(int start, int end) throws IllegalArgumentException
574 if ((start < 0) || (start >= items.size()))
575 throw new IllegalArgumentException("Bad list start index value: " + start);
577 if ((start < 0) || (start >= items.size()))
578 throw new IllegalArgumentException("Bad list start index value: " + start);
580 if (start > end)
581 throw new IllegalArgumentException("Start is greater than end!");
583 // We must run the loop in reverse direction.
584 for (int i = end; i >= start; --i)
585 items.removeElementAt (i);
586 if (peer != null)
588 ListPeer l = (ListPeer) peer;
589 l.delItems (start, end);
593 /*************************************************************************/
596 * Deletes the first occurrence of the specified item from the list.
598 * @param item The item to delete.
600 * @exception IllegalArgumentException If the specified item does not exist.
602 public synchronized void
603 remove(String item) throws IllegalArgumentException
605 int index = items.indexOf(item);
606 if (index == -1)
607 throw new IllegalArgumentException("List element to delete not found");
609 remove(index);
612 /*************************************************************************/
615 * Deletes all of the items from the list.
617 public synchronized void
618 removeAll()
620 clear ();
623 /*************************************************************************/
626 * Deletes all of the items from the list.
628 * @deprecated This method is deprecated in favor of <code>removeAll()</code>.
630 public void
631 clear()
633 items.clear();
635 ListPeer peer = (ListPeer) getPeer ();
636 if (peer != null)
637 peer.removeAll ();
640 /*************************************************************************/
643 * Replaces the item at the specified index with the specified item.
645 * @param item The new item value.
646 * @param index The index of the item to replace.
648 * @exception IllegalArgumentException If the index is not valid.
650 public synchronized void
651 replaceItem(String item, int index) throws IllegalArgumentException
653 if ((index < 0) || (index >= items.size()))
654 throw new IllegalArgumentException("Bad list index: " + index);
656 items.insertElementAt(item, index + 1);
657 items.removeElementAt (index);
659 if (peer != null)
661 ListPeer l = (ListPeer) peer;
663 /* We add first and then remove so that the selected
664 item remains the same */
665 l.add (item, index + 1);
666 l.delItems (index, index);
670 /*************************************************************************/
673 * Returns the index of the currently selected item. -1 will be returned
674 * if there are no selected rows or if there are multiple selected rows.
676 * @return The index of the selected row.
678 public synchronized int
679 getSelectedIndex()
681 if (peer != null)
683 ListPeer l = (ListPeer) peer;
684 selected = l.getSelectedIndexes ();
687 if (selected == null || selected.length != 1)
688 return -1;
689 return selected[0];
692 /*************************************************************************/
695 * Returns an array containing the indexes of the rows that are
696 * currently selected.
698 * @return A list of indexes of selected rows.
700 public synchronized int[]
701 getSelectedIndexes()
703 if (peer != null)
705 ListPeer l = (ListPeer) peer;
706 selected = l.getSelectedIndexes ();
708 return selected;
711 /*************************************************************************/
714 * Returns the item that is currently selected, or <code>null</code> if there
715 * is no item selected. FIXME: What happens if multiple items selected?
717 * @return The selected item, or <code>null</code> if there is no
718 * selected item.
720 public synchronized String
721 getSelectedItem()
723 int index = getSelectedIndex();
724 if (index == -1)
725 return(null);
727 return((String)items.elementAt(index));
730 /*************************************************************************/
733 * Returns the list of items that are currently selected in this list.
735 * @return The list of currently selected items.
737 public synchronized String[]
738 getSelectedItems()
740 int[] indexes = getSelectedIndexes();
741 if (indexes == null)
742 return(new String[0]);
744 String[] retvals = new String[indexes.length];
745 if (retvals.length > 0)
746 for (int i = 0 ; i < retvals.length; i++)
747 retvals[i] = (String)items.elementAt(indexes[i]);
749 return(retvals);
752 /*************************************************************************/
755 * Returns the list of items that are currently selected in this list as
756 * an array of type <code>Object[]</code> instead of <code>String[]</code>.
758 * @return The list of currently selected items.
760 public synchronized Object[]
761 getSelectedObjects()
763 int[] indexes = getSelectedIndexes();
764 if (indexes == null)
765 return(new Object[0]);
767 Object[] retvals = new Object[indexes.length];
768 if (retvals.length > 0)
769 for (int i = 0 ; i < retvals.length; i++)
770 retvals[i] = items.elementAt(indexes[i]);
772 return(retvals);
775 /*************************************************************************/
778 * Tests whether or not the specified index is selected.
780 * @param index The index to test.
782 * @return <code>true</code> if the index is selected, <code>false</code>
783 * otherwise.
785 public boolean
786 isIndexSelected(int index)
788 return isSelected (index);
791 /*************************************************************************/
794 * Tests whether or not the specified index is selected.
796 * @param index The index to test.
798 * @return <code>true</code> if the index is selected, <code>false</code>
799 * otherwise.
801 * @deprecated This method is deprecated in favor of
802 * <code>isIndexSelected(int)</code>.
804 public boolean
805 isSelected(int index)
807 int[] indexes = getSelectedIndexes ();
809 for (int i = 0; i < indexes.length; i++)
810 if (indexes[i] == index)
811 return true;
813 return false;
816 /*************************************************************************/
819 * This method ensures that the item at the specified index is visible.
821 * @exception IllegalArgumentException If the specified index is out of
822 * range.
824 public synchronized void
825 makeVisible(int index) throws IllegalArgumentException
827 if ((index < 0) || (index >= items.size()))
828 throw new IllegalArgumentException("Bad list index: " + index);
830 visibleIndex = index;
831 if (peer != null)
833 ListPeer l = (ListPeer) peer;
834 l.makeVisible (index);
838 /*************************************************************************/
841 * Returns the index of the last item that was made visible via the
842 * <code>makeVisible()</code> method.
844 * @return The index of the last item made visible via the
845 * <code>makeVisible()</code> method.
847 public int
848 getVisibleIndex()
850 return(visibleIndex);
853 /*************************************************************************/
856 * Makes the item at the specified index selected.
858 * @param index The index of the item to select.
860 public synchronized void
861 select(int index)
863 ListPeer lp = (ListPeer)getPeer();
864 if (lp != null)
865 lp.select(index);
868 /*************************************************************************/
871 * Makes the item at the specified index not selected.
873 * @param index The index of the item to unselect.
875 public synchronized void
876 deselect(int index)
878 ListPeer lp = (ListPeer)getPeer();
879 if (lp != null)
880 lp.deselect(index);
883 /*************************************************************************/
886 * Notifies this object to create its native peer.
888 public void
889 addNotify()
891 if (peer == null)
892 peer = getToolkit ().createList (this);
893 super.addNotify ();
896 /*************************************************************************/
899 * Notifies this object to destroy its native peer.
901 public void
902 removeNotify()
904 super.removeNotify();
907 /*************************************************************************/
910 * Adds the specified <code>ActionListener</code> to the list of
911 * registered listeners for this object.
913 * @param listener The listener to add.
915 public synchronized void
916 addActionListener(ActionListener listener)
918 action_listeners = AWTEventMulticaster.add(action_listeners, listener);
921 /*************************************************************************/
924 * Removes the specified <code>ActionListener</code> from the list of
925 * registers listeners for this object.
927 * @param listener The listener to remove.
929 public synchronized void
930 removeActionListener(ActionListener listener)
932 action_listeners = AWTEventMulticaster.remove(action_listeners, listener);
935 /*************************************************************************/
938 * Adds the specified <code>ItemListener</code> to the list of
939 * registered listeners for this object.
941 * @param listener The listener to add.
943 public synchronized void
944 addItemListener(ItemListener listener)
946 item_listeners = AWTEventMulticaster.add(item_listeners, listener);
949 /*************************************************************************/
952 * Removes the specified <code>ItemListener</code> from the list of
953 * registers listeners for this object.
955 * @param listener The listener to remove.
957 public synchronized void
958 removeItemListener(ItemListener listener)
960 item_listeners = AWTEventMulticaster.remove(item_listeners, listener);
963 /*************************************************************************/
966 * Processes the specified event for this object. If the event is an
967 * instance of <code>ActionEvent</code> then the
968 * <code>processActionEvent()</code> method is called. Similarly, if the
969 * even is an instance of <code>ItemEvent</code> then the
970 * <code>processItemEvent()</code> method is called. Otherwise the
971 * superclass method is called to process this event.
973 * @param event The event to process.
975 protected void
976 processEvent(AWTEvent event)
978 if (event instanceof ActionEvent)
979 processActionEvent((ActionEvent)event);
980 else if (event instanceof ItemEvent)
981 processItemEvent((ItemEvent)event);
982 else
983 super.processEvent(event);
986 /*************************************************************************/
989 * This method processes the specified event by dispatching it to any
990 * registered listeners. Note that this method will only get called if
991 * action events are enabled. This will happen automatically if any
992 * listeners are added, or it can be done "manually" by calling
993 * the <code>enableEvents()</code> method.
995 * @param event The event to process.
997 protected void
998 processActionEvent(ActionEvent event)
1000 if (action_listeners != null)
1001 action_listeners.actionPerformed(event);
1004 /*************************************************************************/
1007 * This method processes the specified event by dispatching it to any
1008 * registered listeners. Note that this method will only get called if
1009 * item events are enabled. This will happen automatically if any
1010 * listeners are added, or it can be done "manually" by calling
1011 * the <code>enableEvents()</code> method.
1013 * @param event The event to process.
1015 protected void
1016 processItemEvent(ItemEvent event)
1018 if (item_listeners != null)
1019 item_listeners.itemStateChanged(event);
1022 void
1023 dispatchEventImpl(AWTEvent e)
1025 if (e.id <= ItemEvent.ITEM_LAST
1026 && e.id >= ItemEvent.ITEM_FIRST
1027 && (item_listeners != null
1028 || (eventMask & AWTEvent.ITEM_EVENT_MASK) != 0))
1029 processEvent(e);
1030 else if (e.id <= ActionEvent.ACTION_LAST
1031 && e.id >= ActionEvent.ACTION_FIRST
1032 && (action_listeners != null
1033 || (eventMask & AWTEvent.ACTION_EVENT_MASK) != 0))
1034 processEvent(e);
1035 else
1036 super.dispatchEventImpl(e);
1039 /*************************************************************************/
1042 * Returns a debugging string for this object.
1044 * @return A debugging string for this object.
1046 protected String
1047 paramString()
1049 return "multiple=" + multipleMode + ",rows=" + rows + super.paramString();
1053 * Returns an array of all the objects currently registered as FooListeners
1054 * upon this <code>List</code>. FooListeners are registered using the
1055 * addFooListener method.
1057 * @exception ClassCastException If listenerType doesn't specify a class or
1058 * interface that implements java.util.EventListener.
1060 public EventListener[] getListeners (Class listenerType)
1062 if (listenerType == ActionListener.class)
1063 return AWTEventMulticaster.getListeners (action_listeners, listenerType);
1065 if (listenerType == ItemListener.class)
1066 return AWTEventMulticaster.getListeners (item_listeners, listenerType);
1068 return super.getListeners (listenerType);
1072 * Returns all action listeners registered to this object.
1074 public ActionListener[] getActionListeners ()
1076 return (ActionListener[]) getListeners (ActionListener.class);
1080 * Returns all action listeners registered to this object.
1082 public ItemListener[] getItemListeners ()
1084 return (ItemListener[]) getListeners (ItemListener.class);
1087 // Accessibility internal class
1088 protected class AccessibleAWTList extends AccessibleAWTComponent
1089 implements AccessibleSelection, ItemListener, ActionListener
1091 private static final long serialVersionUID = 7924617370136012829L;
1093 protected class AccessibleAWTListChild extends AccessibleAWTComponent
1094 implements Accessible
1096 private static final long serialVersionUID = 4412022926028300317L;
1098 // Field names are fixed by serialization spec.
1099 private List parent;
1100 private int indexInParent;
1102 public AccessibleAWTListChild(List parent, int indexInParent)
1104 this.parent = parent;
1105 this.indexInParent = indexInParent;
1106 if (parent == null)
1107 this.indexInParent = -1;
1110 /* (non-Javadoc)
1111 * @see javax.accessibility.Accessible#getAccessibleContext()
1113 public AccessibleContext getAccessibleContext()
1115 return this;
1118 public AccessibleRole getAccessibleRole()
1120 return AccessibleRole.LIST_ITEM;
1123 public AccessibleStateSet getAccessibleStateSet()
1125 AccessibleStateSet states = super.getAccessibleStateSet();
1126 if (parent.isIndexSelected(indexInParent))
1127 states.add(AccessibleState.SELECTED);
1128 return states;
1131 public int getAccessibleIndexInParent()
1133 return indexInParent;
1138 public AccessibleAWTList()
1140 addItemListener(this);
1141 addActionListener(this);
1144 public AccessibleRole getAccessibleRole()
1146 return AccessibleRole.LIST;
1149 public AccessibleStateSet getAccessibleStateSet()
1151 AccessibleStateSet states = super.getAccessibleStateSet();
1152 states.add(AccessibleState.SELECTABLE);
1153 if (isMultipleMode())
1154 states.add(AccessibleState.MULTISELECTABLE);
1155 return states;
1158 public int getAccessibleChildrenCount()
1160 return getItemCount();
1163 public Accessible getAccessibleChild(int i)
1165 if (i >= getItemCount())
1166 return null;
1167 return new AccessibleAWTListChild(List.this, i);
1170 /* (non-Javadoc)
1171 * @see javax.accessibility.AccessibleSelection#getAccessibleSelectionCount()
1173 public int getAccessibleSelectionCount()
1175 return getSelectedIndexes().length;
1178 /* (non-Javadoc)
1179 * @see javax.accessibility.AccessibleSelection#getAccessibleSelection()
1181 public AccessibleSelection getAccessibleSelection()
1183 return this;
1186 /* (non-Javadoc)
1187 * @see javax.accessibility.AccessibleSelection#getAccessibleSelection(int)
1189 public Accessible getAccessibleSelection(int i)
1191 int[] items = getSelectedIndexes();
1192 if (i >= items.length)
1193 return null;
1194 return new AccessibleAWTListChild(List.this, items[i]);
1197 /* (non-Javadoc)
1198 * @see javax.accessibility.AccessibleSelection#isAccessibleChildSelected(int)
1200 public boolean isAccessibleChildSelected(int i)
1202 return isIndexSelected(i);
1205 /* (non-Javadoc)
1206 * @see javax.accessibility.AccessibleSelection#addAccessibleSelection(int)
1208 public void addAccessibleSelection(int i)
1210 select(i);
1213 /* (non-Javadoc)
1214 * @see javax.accessibility.AccessibleSelection#removeAccessibleSelection(int)
1216 public void removeAccessibleSelection(int i)
1218 deselect(i);
1221 /* (non-Javadoc)
1222 * @see javax.accessibility.AccessibleSelection#clearAccessibleSelection()
1224 public void clearAccessibleSelection()
1226 for (int i = 0; i < getItemCount(); i++)
1227 deselect(i);
1230 /* (non-Javadoc)
1231 * @see javax.accessibility.AccessibleSelection#selectAllAccessibleSelection()
1233 public void selectAllAccessibleSelection()
1235 if (isMultipleMode())
1236 for (int i = 0; i < getItemCount(); i++)
1237 select(i);
1240 /* (non-Javadoc)
1241 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
1243 public void itemStateChanged(ItemEvent event)
1247 /* (non-Javadoc)
1248 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
1250 public void actionPerformed(ActionEvent event)
1257 * Gets the AccessibleContext associated with this <code>List</code>.
1258 * The context is created, if necessary.
1260 * @return the associated context
1262 public AccessibleContext getAccessibleContext()
1264 /* Create the context if this is the first request */
1265 if (accessibleContext == null)
1266 accessibleContext = new AccessibleAWTList();
1267 return accessibleContext;
1269 } // class List