Source Code Cross Referenced for List.java in  » 6.0-JDK-Core » AWT » java » awt » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » AWT » java.awt 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001        /*
0002         * Copyright 1995-2007 Sun Microsystems, Inc.  All Rights Reserved.
0003         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0004         *
0005         * This code is free software; you can redistribute it and/or modify it
0006         * under the terms of the GNU General Public License version 2 only, as
0007         * published by the Free Software Foundation.  Sun designates this
0008         * particular file as subject to the "Classpath" exception as provided
0009         * by Sun in the LICENSE file that accompanied this code.
0010         *
0011         * This code is distributed in the hope that it will be useful, but WITHOUT
0012         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0013         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0014         * version 2 for more details (a copy is included in the LICENSE file that
0015         * accompanied this code).
0016         *
0017         * You should have received a copy of the GNU General Public License version
0018         * 2 along with this work; if not, write to the Free Software Foundation,
0019         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0020         *
0021         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0022         * CA 95054 USA or visit www.sun.com if you need additional information or
0023         * have any questions.
0024         */
0025        package java.awt;
0026
0027        import java.util.Vector;
0028        import java.util.Locale;
0029        import java.util.EventListener;
0030        import java.awt.peer.ListPeer;
0031        import java.awt.event.*;
0032        import java.io.ObjectOutputStream;
0033        import java.io.ObjectInputStream;
0034        import java.io.IOException;
0035        import javax.accessibility.*;
0036
0037        /**
0038         * The <code>List</code> component presents the user with a
0039         * scrolling list of text items. The list can be set up so that
0040         * the user can choose either one item or multiple items.
0041         * <p>
0042         * For example, the code&nbsp;.&nbsp;.&nbsp;.
0043         * <p>
0044         * <hr><blockquote><pre>
0045         * List lst = new List(4, false);
0046         * lst.add("Mercury");
0047         * lst.add("Venus");
0048         * lst.add("Earth");
0049         * lst.add("JavaSoft");
0050         * lst.add("Mars");
0051         * lst.add("Jupiter");
0052         * lst.add("Saturn");
0053         * lst.add("Uranus");
0054         * lst.add("Neptune");
0055         * lst.add("Pluto");
0056         * cnt.add(lst);
0057         * </pre></blockquote><hr>
0058         * <p>
0059         * where <code>cnt</code> is a container, produces the following
0060         * scrolling list:
0061         * <p>
0062         * <img src="doc-files/List-1.gif"
0063         * alt="Shows a list containing: Venus, Earth, JavaSoft, and Mars. Javasoft is selected." ALIGN=center HSPACE=10 VSPACE=7>
0064         * <p>
0065         * If the List allows multiple selections, then clicking on
0066         * an item that is already selected deselects it. In the preceding
0067         * example, only one item from the scrolling list can be selected
0068         * at a time, since the second argument when creating the new scrolling
0069         * list is <code>false</code>. If the List does not allow multiple
0070         * selections, selecting an item causes any other selected item
0071         * to be deselected.
0072         * <p>
0073         * Note that the list in the example shown was created with four visible
0074         * rows.  Once the list has been created, the number of visible rows
0075         * cannot be changed.  A default <code>List</code> is created with
0076         * four rows, so that <code>lst = new List()</code> is equivalent to
0077         * <code>list = new List(4, false)</code>.
0078         * <p>
0079         * Beginning with Java&nbsp;1.1, the Abstract Window Toolkit
0080         * sends the <code>List</code> object all mouse, keyboard, and focus events
0081         * that occur over it. (The old AWT event model is being maintained
0082         * only for backwards compatibility, and its use is discouraged.)
0083         * <p>
0084         * When an item is selected or deselected by the user, AWT sends an instance
0085         * of <code>ItemEvent</code> to the list.
0086         * When the user double-clicks on an item in a scrolling list,
0087         * AWT sends an instance of <code>ActionEvent</code> to the
0088         * list following the item event. AWT also generates an action event
0089         * when the user presses the return key while an item in the
0090         * list is selected.
0091         * <p>
0092         * If an application wants to perform some action based on an item
0093         * in this list being selected or activated by the user, it should implement
0094         * <code>ItemListener</code> or <code>ActionListener</code>
0095         * as appropriate and register the new listener to receive
0096         * events from this list.
0097         * <p>
0098         * For multiple-selection scrolling lists, it is considered a better
0099         * user interface to use an external gesture (such as clicking on a
0100         * button) to trigger the action.
0101         * @version 	1.118, 05/15/07
0102         * @author 	Sami Shaio
0103         * @see         java.awt.event.ItemEvent
0104         * @see         java.awt.event.ItemListener
0105         * @see         java.awt.event.ActionEvent
0106         * @see         java.awt.event.ActionListener
0107         * @since       JDK1.0
0108         */
0109        public class List extends Component implements  ItemSelectable,
0110                Accessible {
0111            /**
0112             * A vector created to contain items which will become
0113             * part of the List Component.
0114             *
0115             * @serial
0116             * @see #addItem(String)
0117             * @see #getItem(int)
0118             */
0119            Vector items = new Vector();
0120
0121            /**
0122             * This field will represent the number of visible rows in the
0123             * <code>List</code> Component.  It is specified only once, and
0124             * that is when the list component is actually
0125             * created.  It will never change.
0126             *
0127             * @serial
0128             * @see #getRows()
0129             */
0130            int rows = 0;
0131
0132            /**
0133             * <code>multipleMode</code> is a variable that will
0134             * be set to <code>true</code> if a list component is to be set to
0135             * multiple selection mode, that is where the user can
0136             * select more than one item in a list at one time.
0137             * <code>multipleMode</code> will be set to false if the
0138             * list component is set to single selection, that is where
0139             * the user can only select one item on the list at any
0140             * one time.
0141             *
0142             * @serial
0143             * @see #isMultipleMode()
0144             * @see #setMultipleMode(boolean)
0145             */
0146            boolean multipleMode = false;
0147
0148            /**
0149             * <code>selected</code> is an array that will contain
0150             * the indices of items that have been selected.
0151             *
0152             * @serial
0153             * @see #getSelectedIndexes()
0154             * @see #getSelectedIndex()
0155             */
0156            int selected[] = new int[0];
0157
0158            /**
0159             * This variable contains the value that will be used
0160             * when trying to make a particular list item visible.
0161             *
0162             * @serial
0163             * @see #makeVisible(int)
0164             */
0165            int visibleIndex = -1;
0166
0167            transient ActionListener actionListener;
0168            transient ItemListener itemListener;
0169
0170            private static final String base = "list";
0171            private static int nameCounter = 0;
0172
0173            /*
0174             * JDK 1.1 serialVersionUID
0175             */
0176            private static final long serialVersionUID = -3304312411574666869L;
0177
0178            /**
0179             * Creates a new scrolling list.
0180             * By default, there are four visible lines and multiple selections are
0181             * not allowed.  Note that this is a convenience method for
0182             * <code>List(0, false)</code>.  Also note that the number of visible
0183             * lines in the list cannot be changed after it has been created.
0184             * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0185             * returns true.
0186             * @see java.awt.GraphicsEnvironment#isHeadless
0187             */
0188            public List() throws HeadlessException {
0189                this (0, false);
0190            }
0191
0192            /**
0193             * Creates a new scrolling list initialized with the specified
0194             * number of visible lines. By default, multiple selections are
0195             * not allowed.  Note that this is a convenience method for
0196             * <code>List(rows, false)</code>.  Also note that the number
0197             * of visible rows in the list cannot be changed after it has
0198             * been created.
0199             * @param       rows the number of items to show.
0200             * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0201             * returns true.
0202             * @see java.awt.GraphicsEnvironment#isHeadless
0203             * @since       JDK1.1
0204             */
0205            public List(int rows) throws HeadlessException {
0206                this (rows, false);
0207            }
0208
0209            /**
0210             * The default number of visible rows is 4.  A list with
0211             * zero rows is unusable and unsightly.
0212             */
0213            final static int DEFAULT_VISIBLE_ROWS = 4;
0214
0215            /**
0216             * Creates a new scrolling list initialized to display the specified
0217             * number of rows. Note that if zero rows are specified, then
0218             * the list will be created with a default of four rows.
0219             * Also note that the number of visible rows in the list cannot
0220             * be changed after it has been created.
0221             * If the value of <code>multipleMode</code> is
0222             * <code>true</code>, then the user can select multiple items from
0223             * the list. If it is <code>false</code>, only one item at a time
0224             * can be selected.
0225             * @param       rows   the number of items to show.
0226             * @param       multipleMode   if <code>true</code>,
0227             *                     then multiple selections are allowed;
0228             *                     otherwise, only one item can be selected at a time.
0229             * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0230             * returns true.
0231             * @see java.awt.GraphicsEnvironment#isHeadless
0232             */
0233            public List(int rows, boolean multipleMode)
0234                    throws HeadlessException {
0235                GraphicsEnvironment.checkHeadless();
0236                this .rows = (rows != 0) ? rows : DEFAULT_VISIBLE_ROWS;
0237                this .multipleMode = multipleMode;
0238            }
0239
0240            /**
0241             * Construct a name for this component.  Called by
0242             * <code>getName</code> when the name is <code>null</code>.
0243             */
0244            String constructComponentName() {
0245                synchronized (List.class) {
0246                    return base + nameCounter++;
0247                }
0248            }
0249
0250            /**
0251             * Creates the peer for the list.  The peer allows us to modify the
0252             * list's appearance without changing its functionality.
0253             */
0254            public void addNotify() {
0255                synchronized (getTreeLock()) {
0256                    if (peer == null)
0257                        peer = getToolkit().createList(this );
0258                    super .addNotify();
0259                }
0260            }
0261
0262            /**
0263             * Removes the peer for this list.  The peer allows us to modify the
0264             * list's appearance without changing its functionality.
0265             */
0266            public void removeNotify() {
0267                synchronized (getTreeLock()) {
0268                    ListPeer peer = (ListPeer) this .peer;
0269                    if (peer != null) {
0270                        selected = peer.getSelectedIndexes();
0271                    }
0272                    super .removeNotify();
0273                }
0274            }
0275
0276            /**
0277             * Gets the number of items in the list.
0278             * @return     the number of items in the list
0279             * @see        #getItem
0280             * @since      JDK1.1
0281             */
0282            public int getItemCount() {
0283                return countItems();
0284            }
0285
0286            /**
0287             * @deprecated As of JDK version 1.1,
0288             * replaced by <code>getItemCount()</code>.
0289             */
0290            @Deprecated
0291            public int countItems() {
0292                return items.size();
0293            }
0294
0295            /**
0296             * Gets the item associated with the specified index.
0297             * @return       an item that is associated with
0298             *                    the specified index
0299             * @param        index the position of the item
0300             * @see          #getItemCount
0301             */
0302            public String getItem(int index) {
0303                return getItemImpl(index);
0304            }
0305
0306            // NOTE: This method may be called by privileged threads.
0307            //       We implement this functionality in a package-private method 
0308            //       to insure that it cannot be overridden by client subclasses. 
0309            //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
0310            final String getItemImpl(int index) {
0311                return (String) items.elementAt(index);
0312            }
0313
0314            /**
0315             * Gets the items in the list.
0316             * @return       a string array containing items of the list
0317             * @see          #select
0318             * @see          #deselect
0319             * @see          #isIndexSelected
0320             * @since        JDK1.1
0321             */
0322            public synchronized String[] getItems() {
0323                String itemCopies[] = new String[items.size()];
0324                items.copyInto(itemCopies);
0325                return itemCopies;
0326            }
0327
0328            /**
0329             * Adds the specified item to the end of scrolling list.
0330             * @param item the item to be added
0331             * @since JDK1.1
0332             */
0333            public void add(String item) {
0334                addItem(item);
0335            }
0336
0337            /**
0338             * @deprecated      replaced by <code>add(String)</code>.
0339             */
0340            @Deprecated
0341            public void addItem(String item) {
0342                addItem(item, -1);
0343            }
0344
0345            /**
0346             * Adds the specified item to the the scrolling list
0347             * at the position indicated by the index.  The index is 
0348             * zero-based.  If the value of the index is less than zero, 
0349             * or if the value of the index is greater than or equal to 
0350             * the number of items in the list, then the item is added 
0351             * to the end of the list.
0352             * @param       item   the item to be added;
0353             *              if this parameter is <code>null</code> then the item is
0354             *              treated as an empty string, <code>""</code>
0355             * @param       index  the position at which to add the item
0356             * @since       JDK1.1
0357             */
0358            public void add(String item, int index) {
0359                addItem(item, index);
0360            }
0361
0362            /**
0363             * @deprecated      replaced by <code>add(String, int)</code>.
0364             */
0365            @Deprecated
0366            public synchronized void addItem(String item, int index) {
0367                if (index < -1 || index >= items.size()) {
0368                    index = -1;
0369                }
0370
0371                if (item == null) {
0372                    item = "";
0373                }
0374
0375                if (index == -1) {
0376                    items.addElement(item);
0377                } else {
0378                    items.insertElementAt(item, index);
0379                }
0380
0381                ListPeer peer = (ListPeer) this .peer;
0382                if (peer != null) {
0383                    peer.addItem(item, index);
0384                }
0385            }
0386
0387            /**
0388             * Replaces the item at the specified index in the scrolling list
0389             * with the new string.
0390             * @param       newValue   a new string to replace an existing item
0391             * @param       index      the position of the item to replace
0392             * @exception ArrayIndexOutOfBoundsException if <code>index</code>
0393             *		is out of range
0394             */
0395            public synchronized void replaceItem(String newValue, int index) {
0396                remove(index);
0397                add(newValue, index);
0398            }
0399
0400            /**
0401             * Removes all items from this list.
0402             * @see #remove
0403             * @see #delItems
0404             * @since JDK1.1
0405             */
0406            public void removeAll() {
0407                clear();
0408            }
0409
0410            /**
0411             * @deprecated As of JDK version 1.1,
0412             * replaced by <code>removeAll()</code>.
0413             */
0414            @Deprecated
0415            public synchronized void clear() {
0416                ListPeer peer = (ListPeer) this .peer;
0417                if (peer != null) {
0418                    peer.clear();
0419                }
0420                items = new Vector();
0421                selected = new int[0];
0422            }
0423
0424            /**
0425             * Removes the first occurrence of an item from the list.
0426             * If the specified item is selected, and is the only selected 
0427             * item in the list, the list is set to have no selection.
0428             * @param        item  the item to remove from the list
0429             * @exception    IllegalArgumentException
0430             *                     if the item doesn't exist in the list
0431             * @since        JDK1.1
0432             */
0433            public synchronized void remove(String item) {
0434                int index = items.indexOf(item);
0435                if (index < 0) {
0436                    throw new IllegalArgumentException("item " + item
0437                            + " not found in list");
0438                } else {
0439                    remove(index);
0440                }
0441            }
0442
0443            /**
0444             * Removes the item at the specified position
0445             * from this scrolling list.
0446             * If the item with the specified position is selected, and is the 
0447             * only selected item in the list, the list is set to have no selection.
0448             * @param      position   the index of the item to delete
0449             * @see        #add(String, int)
0450             * @since      JDK1.1
0451             * @exception    ArrayIndexOutOfBoundsException
0452             *               if the <code>position</code> is less than 0 or
0453             *               greater than <code>getItemCount()-1</code>
0454             */
0455            public void remove(int position) {
0456                delItem(position);
0457            }
0458
0459            /**
0460             * @deprecated     replaced by <code>remove(String)</code>
0461             *                         and <code>remove(int)</code>.
0462             */
0463            @Deprecated
0464            public void delItem(int position) {
0465                delItems(position, position);
0466            }
0467
0468            /**
0469             * Gets the index of the selected item on the list,
0470             * 
0471             * @return        the index of the selected item; 
0472             *                if no item is selected, or if multiple items are 
0473             *                selected, <code>-1</code> is returned.  
0474             * @see           #select
0475             * @see           #deselect
0476             * @see           #isIndexSelected
0477             */
0478            public synchronized int getSelectedIndex() {
0479                int sel[] = getSelectedIndexes();
0480                return (sel.length == 1) ? sel[0] : -1;
0481            }
0482
0483            /**
0484             * Gets the selected indexes on the list.
0485             * 
0486             * @return        an array of the selected indexes on this scrolling list; 
0487             *                if no item is selected, a zero-length array is returned. 
0488             * @see           #select
0489             * @see           #deselect
0490             * @see           #isIndexSelected
0491             */
0492            public synchronized int[] getSelectedIndexes() {
0493                ListPeer peer = (ListPeer) this .peer;
0494                if (peer != null) {
0495                    selected = ((ListPeer) peer).getSelectedIndexes();
0496                }
0497                return (int[]) selected.clone();
0498            }
0499
0500            /**
0501             * Gets the selected item on this scrolling list.
0502             * 
0503             * @return        the selected item on the list; 
0504             *                if no item is selected, or if multiple items are 
0505             *                selected, <code>null</code> is returned.  
0506             * @see           #select
0507             * @see           #deselect
0508             * @see           #isIndexSelected
0509             */
0510            public synchronized String getSelectedItem() {
0511                int index = getSelectedIndex();
0512                return (index < 0) ? null : getItem(index);
0513            }
0514
0515            /**
0516             * Gets the selected items on this scrolling list.
0517             * 
0518             * @return        an array of the selected items on this scrolling list;
0519             *                if no item is selected, a zero-length array is returned. 
0520             * @see           #select
0521             * @see           #deselect
0522             * @see           #isIndexSelected
0523             */
0524            public synchronized String[] getSelectedItems() {
0525                int sel[] = getSelectedIndexes();
0526                String str[] = new String[sel.length];
0527                for (int i = 0; i < sel.length; i++) {
0528                    str[i] = getItem(sel[i]);
0529                }
0530                return str;
0531            }
0532
0533            /**
0534             * Gets the selected items on this scrolling list in an array of Objects.
0535             * @return        an array of <code>Object</code>s representing the 
0536             *                selected items on this scrolling list;
0537             *                if no item is selected, a zero-length array is returned.
0538             * @see #getSelectedItems
0539             * @see ItemSelectable
0540             */
0541            public Object[] getSelectedObjects() {
0542                return getSelectedItems();
0543            }
0544
0545            /**
0546             * Selects the item at the specified index in the scrolling list.
0547             *<p>
0548             * Note that passing out of range parameters is invalid, 
0549             * and will result in unspecified behavior.  
0550             *
0551             * <p>Note that this method should be primarily used to
0552             * initially select an item in this component.  
0553             * Programmatically calling this method will <i>not</i> trigger
0554             * an <code>ItemEvent</code>.  The only way to trigger an
0555             * <code>ItemEvent</code> is by user interaction.
0556             *
0557             * @param        index the position of the item to select
0558             * @see          #getSelectedItem
0559             * @see          #deselect
0560             * @see          #isIndexSelected
0561             */
0562            public void select(int index) {
0563                // Bug #4059614: select can't be synchronized while calling the peer, 
0564                // because it is called from the Window Thread.  It is sufficient to 
0565                // synchronize the code that manipulates 'selected' except for the 
0566                // case where the peer changes.  To handle this case, we simply 
0567                // repeat the selection process. 
0568
0569                ListPeer peer;
0570                do {
0571                    peer = (ListPeer) this .peer;
0572                    if (peer != null) {
0573                        peer.select(index);
0574                        return;
0575                    }
0576
0577                    synchronized (this ) {
0578                        boolean alreadySelected = false;
0579
0580                        for (int i = 0; i < selected.length; i++) {
0581                            if (selected[i] == index) {
0582                                alreadySelected = true;
0583                                break;
0584                            }
0585                        }
0586
0587                        if (!alreadySelected) {
0588                            if (!multipleMode) {
0589                                selected = new int[1];
0590                                selected[0] = index;
0591                            } else {
0592                                int newsel[] = new int[selected.length + 1];
0593                                System.arraycopy(selected, 0, newsel, 0,
0594                                        selected.length);
0595                                newsel[selected.length] = index;
0596                                selected = newsel;
0597                            }
0598                        }
0599                    }
0600                } while (peer != this .peer);
0601            }
0602
0603            /**
0604             * Deselects the item at the specified index.
0605             * <p>
0606             * Note that passing out of range parameters is invalid, 
0607             * and will result in unspecified behavior.  
0608             * <p>
0609             * If the item at the specified index is not selected,
0610             * then the operation is ignored.
0611             * @param        index the position of the item to deselect
0612             * @see          #select
0613             * @see          #getSelectedItem
0614             * @see          #isIndexSelected
0615             */
0616            public synchronized void deselect(int index) {
0617                ListPeer peer = (ListPeer) this .peer;
0618                if (peer != null) {
0619                    if (isMultipleMode() || (getSelectedIndex() == index)) {
0620                        peer.deselect(index);
0621                    }
0622                }
0623
0624                for (int i = 0; i < selected.length; i++) {
0625                    if (selected[i] == index) {
0626                        int newsel[] = new int[selected.length - 1];
0627                        System.arraycopy(selected, 0, newsel, 0, i);
0628                        System.arraycopy(selected, i + 1, newsel, i,
0629                                selected.length - (i + 1));
0630                        selected = newsel;
0631                        return;
0632                    }
0633                }
0634            }
0635
0636            /**
0637             * Determines if the specified item in this scrolling list is
0638             * selected.
0639             * @param      index   the item to be checked
0640             * @return     <code>true</code> if the specified item has been
0641             *                       selected; <code>false</code> otherwise
0642             * @see        #select
0643             * @see        #deselect
0644             * @since      JDK1.1
0645             */
0646            public boolean isIndexSelected(int index) {
0647                return isSelected(index);
0648            }
0649
0650            /**
0651             * @deprecated As of JDK version 1.1,
0652             * replaced by <code>isIndexSelected(int)</code>.
0653             */
0654            @Deprecated
0655            public boolean isSelected(int index) {
0656                int sel[] = getSelectedIndexes();
0657                for (int i = 0; i < sel.length; i++) {
0658                    if (sel[i] == index) {
0659                        return true;
0660                    }
0661                }
0662                return false;
0663            }
0664
0665            /**
0666             * Gets the number of visible lines in this list.  Note that
0667             * once the <code>List</code> has been created, this number
0668             * will never change.
0669             * @return     the number of visible lines in this scrolling list
0670             */
0671            public int getRows() {
0672                return rows;
0673            }
0674
0675            /**
0676             * Determines whether this list allows multiple selections.
0677             * @return     <code>true</code> if this list allows multiple
0678             *                 selections; otherwise, <code>false</code>
0679             * @see        #setMultipleMode
0680             * @since      JDK1.1
0681             */
0682            public boolean isMultipleMode() {
0683                return allowsMultipleSelections();
0684            }
0685
0686            /**
0687             * @deprecated As of JDK version 1.1,
0688             * replaced by <code>isMultipleMode()</code>.
0689             */
0690            @Deprecated
0691            public boolean allowsMultipleSelections() {
0692                return multipleMode;
0693            }
0694
0695            /**
0696             * Sets the flag that determines whether this list
0697             * allows multiple selections.
0698             * When the selection mode is changed from multiple-selection to
0699             * single-selection, the selected items change as follows:
0700             * If a selected item has the location cursor, only that 
0701             * item will remain selected.  If no selected item has the 
0702             * location cursor, all items will be deselected.  
0703             * @param       b   if <code>true</code> then multiple selections
0704             *                      are allowed; otherwise, only one item from
0705             *                      the list can be selected at once
0706             * @see         #isMultipleMode
0707             * @since       JDK1.1
0708             */
0709            public void setMultipleMode(boolean b) {
0710                setMultipleSelections(b);
0711            }
0712
0713            /**
0714             * @deprecated As of JDK version 1.1,
0715             * replaced by <code>setMultipleMode(boolean)</code>.
0716             */
0717            @Deprecated
0718            public synchronized void setMultipleSelections(boolean b) {
0719                if (b != multipleMode) {
0720                    multipleMode = b;
0721                    ListPeer peer = (ListPeer) this .peer;
0722                    if (peer != null) {
0723                        peer.setMultipleSelections(b);
0724                    }
0725                }
0726            }
0727
0728            /**
0729             * Gets the index of the item that was last made visible by
0730             * the method <code>makeVisible</code>.
0731             * @return      the index of the item that was last made visible
0732             * @see         #makeVisible
0733             */
0734            public int getVisibleIndex() {
0735                return visibleIndex;
0736            }
0737
0738            /**
0739             * Makes the item at the specified index visible.
0740             * @param       index    the position of the item
0741             * @see         #getVisibleIndex
0742             */
0743            public synchronized void makeVisible(int index) {
0744                visibleIndex = index;
0745                ListPeer peer = (ListPeer) this .peer;
0746                if (peer != null) {
0747                    peer.makeVisible(index);
0748                }
0749            }
0750
0751            /**
0752             * Gets the preferred dimensions for a list with the specified
0753             * number of rows.
0754             * @param      rows    number of rows in the list
0755             * @return     the preferred dimensions for displaying this scrolling list
0756             *             given that the specified number of rows must be visible
0757             * @see        java.awt.Component#getPreferredSize
0758             * @since      JDK1.1
0759             */
0760            public Dimension getPreferredSize(int rows) {
0761                return preferredSize(rows);
0762            }
0763
0764            /**
0765             * @deprecated As of JDK version 1.1,
0766             * replaced by <code>getPreferredSize(int)</code>.
0767             */
0768            @Deprecated
0769            public Dimension preferredSize(int rows) {
0770                synchronized (getTreeLock()) {
0771                    ListPeer peer = (ListPeer) this .peer;
0772                    return (peer != null) ? peer.preferredSize(rows) : super 
0773                            .preferredSize();
0774                }
0775            }
0776
0777            /**
0778             * Gets the preferred size of this scrolling list.
0779             * @return     the preferred dimensions for displaying this scrolling list
0780             * @see        java.awt.Component#getPreferredSize
0781             * @since      JDK1.1
0782             */
0783            public Dimension getPreferredSize() {
0784                return preferredSize();
0785            }
0786
0787            /**
0788             * @deprecated As of JDK version 1.1,
0789             * replaced by <code>getPreferredSize()</code>.
0790             */
0791            @Deprecated
0792            public Dimension preferredSize() {
0793                synchronized (getTreeLock()) {
0794                    return (rows > 0) ? preferredSize(rows) : super 
0795                            .preferredSize();
0796                }
0797            }
0798
0799            /**
0800             * Gets the minumum dimensions for a list with the specified
0801             * number of rows.
0802             * @param      rows    number of rows in the list
0803             * @return     the minimum dimensions for displaying this scrolling list
0804             *             given that the specified number of rows must be visible
0805             * @see        java.awt.Component#getMinimumSize
0806             * @since      JDK1.1
0807             */
0808            public Dimension getMinimumSize(int rows) {
0809                return minimumSize(rows);
0810            }
0811
0812            /**
0813             * @deprecated As of JDK version 1.1,
0814             * replaced by <code>getMinimumSize(int)</code>.
0815             */
0816            @Deprecated
0817            public Dimension minimumSize(int rows) {
0818                synchronized (getTreeLock()) {
0819                    ListPeer peer = (ListPeer) this .peer;
0820                    return (peer != null) ? peer.minimumSize(rows) : super 
0821                            .minimumSize();
0822                }
0823            }
0824
0825            /**
0826             * Determines the minimum size of this scrolling list.
0827             * @return       the minimum dimensions needed
0828             *                        to display this scrolling list
0829             * @see          java.awt.Component#getMinimumSize()
0830             * @since        JDK1.1
0831             */
0832            public Dimension getMinimumSize() {
0833                return minimumSize();
0834            }
0835
0836            /**
0837             * @deprecated As of JDK version 1.1,
0838             * replaced by <code>getMinimumSize()</code>.
0839             */
0840            @Deprecated
0841            public Dimension minimumSize() {
0842                synchronized (getTreeLock()) {
0843                    return (rows > 0) ? minimumSize(rows) : super .minimumSize();
0844                }
0845            }
0846
0847            /**
0848             * Adds the specified item listener to receive item events from
0849             * this list.  Item events are sent in response to user input, but not
0850             * in response to calls to <code>select</code> or <code>deselect</code>.
0851             * If listener <code>l</code> is <code>null</code>,
0852             * no exception is thrown and no action is performed.
0853             * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0854             * >AWT Threading Issues</a> for details on AWT's threading model.
0855             *
0856             * @param         l the item listener
0857             * @see           #removeItemListener
0858             * @see           #getItemListeners
0859             * @see           #select
0860             * @see           #deselect
0861             * @see           java.awt.event.ItemEvent
0862             * @see           java.awt.event.ItemListener
0863             * @since         JDK1.1
0864             */
0865            public synchronized void addItemListener(ItemListener l) {
0866                if (l == null) {
0867                    return;
0868                }
0869                itemListener = AWTEventMulticaster.add(itemListener, l);
0870                newEventsOnly = true;
0871            }
0872
0873            /**
0874             * Removes the specified item listener so that it no longer
0875             * receives item events from this list.
0876             * If listener <code>l</code> is <code>null</code>,
0877             * no exception is thrown and no action is performed.
0878             * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0879             * >AWT Threading Issues</a> for details on AWT's threading model.
0880             *
0881             * @param         	l the item listener
0882             * @see           	#addItemListener
0883             * @see           	#getItemListeners
0884             * @see           	java.awt.event.ItemEvent
0885             * @see           	java.awt.event.ItemListener
0886             * @since         	JDK1.1
0887             */
0888            public synchronized void removeItemListener(ItemListener l) {
0889                if (l == null) {
0890                    return;
0891                }
0892                itemListener = AWTEventMulticaster.remove(itemListener, l);
0893            }
0894
0895            /**
0896             * Returns an array of all the item listeners
0897             * registered on this list.
0898             *
0899             * @return all of this list's <code>ItemListener</code>s
0900             *         or an empty array if no item
0901             *         listeners are currently registered
0902             *
0903             * @see           	#addItemListener
0904             * @see           	#removeItemListener
0905             * @see           	java.awt.event.ItemEvent
0906             * @see           	java.awt.event.ItemListener
0907             * @since 1.4
0908             */
0909            public synchronized ItemListener[] getItemListeners() {
0910                return (ItemListener[]) (getListeners(ItemListener.class));
0911            }
0912
0913            /**
0914             * Adds the specified action listener to receive action events from
0915             * this list. Action events occur when a user double-clicks
0916             * on a list item or types Enter when the list has the keyboard
0917             * focus.
0918             * <p>
0919             * If listener <code>l</code> is <code>null</code>,
0920             * no exception is thrown and no action is performed.
0921             * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0922             * >AWT Threading Issues</a> for details on AWT's threading model.
0923             *
0924             * @param         l the action listener
0925             * @see           #removeActionListener
0926             * @see           #getActionListeners
0927             * @see           java.awt.event.ActionEvent
0928             * @see           java.awt.event.ActionListener
0929             * @since         JDK1.1
0930             */
0931            public synchronized void addActionListener(ActionListener l) {
0932                if (l == null) {
0933                    return;
0934                }
0935                actionListener = AWTEventMulticaster.add(actionListener, l);
0936                newEventsOnly = true;
0937            }
0938
0939            /**
0940             * Removes the specified action listener so that it no longer
0941             * receives action events from this list. Action events
0942             * occur when a user double-clicks on a list item.
0943             * If listener <code>l</code> is <code>null</code>,
0944             * no exception is thrown and no action is performed.
0945             * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0946             * >AWT Threading Issues</a> for details on AWT's threading model.
0947             *
0948             * @param         	l     the action listener
0949             * @see           	#addActionListener
0950             * @see           	#getActionListeners
0951             * @see           	java.awt.event.ActionEvent
0952             * @see           	java.awt.event.ActionListener
0953             * @since         	JDK1.1
0954             */
0955            public synchronized void removeActionListener(ActionListener l) {
0956                if (l == null) {
0957                    return;
0958                }
0959                actionListener = AWTEventMulticaster.remove(actionListener, l);
0960            }
0961
0962            /**
0963             * Returns an array of all the action listeners
0964             * registered on this list.
0965             *
0966             * @return all of this list's <code>ActionListener</code>s
0967             *         or an empty array if no action
0968             *         listeners are currently registered
0969             *
0970             * @see           	#addActionListener
0971             * @see           	#removeActionListener
0972             * @see           	java.awt.event.ActionEvent
0973             * @see           	java.awt.event.ActionListener
0974             * @since 1.4
0975             */
0976            public synchronized ActionListener[] getActionListeners() {
0977                return (ActionListener[]) (getListeners(ActionListener.class));
0978            }
0979
0980            /**
0981             * Returns an array of all the objects currently registered
0982             * as <code><em>Foo</em>Listener</code>s
0983             * upon this <code>List</code>.
0984             * <code><em>Foo</em>Listener</code>s are registered using the
0985             * <code>add<em>Foo</em>Listener</code> method.
0986             *
0987             * <p>
0988             * You can specify the <code>listenerType</code> argument
0989             * with a class literal, such as
0990             * <code><em>Foo</em>Listener.class</code>.
0991             * For example, you can query a
0992             * <code>List</code> <code>l</code>
0993             * for its item listeners with the following code:
0994             *
0995             * <pre>ItemListener[] ils = (ItemListener[])(l.getListeners(ItemListener.class));</pre>
0996             *
0997             * If no such listeners exist, this method returns an empty array.
0998             *
0999             * @param listenerType the type of listeners requested; this parameter
1000             *          should specify an interface that descends from
1001             *          <code>java.util.EventListener</code>
1002             * @return an array of all objects registered as
1003             *          <code><em>Foo</em>Listener</code>s on this list,
1004             *          or an empty array if no such
1005             *          listeners have been added
1006             * @exception ClassCastException if <code>listenerType</code>
1007             *          doesn't specify a class or interface that implements
1008             *          <code>java.util.EventListener</code>
1009             *
1010             * @see #getItemListeners
1011             * @since 1.3
1012             */
1013            public <T extends EventListener> T[] getListeners(
1014                    Class<T> listenerType) {
1015                EventListener l = null;
1016                if (listenerType == ActionListener.class) {
1017                    l = actionListener;
1018                } else if (listenerType == ItemListener.class) {
1019                    l = itemListener;
1020                } else {
1021                    return super .getListeners(listenerType);
1022                }
1023                return AWTEventMulticaster.getListeners(l, listenerType);
1024            }
1025
1026            // REMIND: remove when filtering is done at lower level
1027            boolean eventEnabled(AWTEvent e) {
1028                switch (e.id) {
1029                case ActionEvent.ACTION_PERFORMED:
1030                    if ((eventMask & AWTEvent.ACTION_EVENT_MASK) != 0
1031                            || actionListener != null) {
1032                        return true;
1033                    }
1034                    return false;
1035                case ItemEvent.ITEM_STATE_CHANGED:
1036                    if ((eventMask & AWTEvent.ITEM_EVENT_MASK) != 0
1037                            || itemListener != null) {
1038                        return true;
1039                    }
1040                    return false;
1041                default:
1042                    break;
1043                }
1044                return super .eventEnabled(e);
1045            }
1046
1047            /**
1048             * Processes events on this scrolling list. If an event is
1049             * an instance of <code>ItemEvent</code>, it invokes the
1050             * <code>processItemEvent</code> method. Else, if the
1051             * event is an instance of <code>ActionEvent</code>,
1052             * it invokes <code>processActionEvent</code>.
1053             * If the event is not an item event or an action event,
1054             * it invokes <code>processEvent</code> on the superclass.
1055             * <p>Note that if the event parameter is <code>null</code>
1056             * the behavior is unspecified and may result in an
1057             * exception.
1058             *
1059             * @param        e the event
1060             * @see          java.awt.event.ActionEvent
1061             * @see          java.awt.event.ItemEvent
1062             * @see          #processActionEvent
1063             * @see          #processItemEvent
1064             * @since        JDK1.1
1065             */
1066            protected void processEvent(AWTEvent e) {
1067                if (e instanceof  ItemEvent) {
1068                    processItemEvent((ItemEvent) e);
1069                    return;
1070                } else if (e instanceof  ActionEvent) {
1071                    processActionEvent((ActionEvent) e);
1072                    return;
1073                }
1074                super .processEvent(e);
1075            }
1076
1077            /**
1078             * Processes item events occurring on this list by
1079             * dispatching them to any registered
1080             * <code>ItemListener</code> objects.
1081             * <p>
1082             * This method is not called unless item events are
1083             * enabled for this component. Item events are enabled
1084             * when one of the following occurs:
1085             * <p><ul>
1086             * <li>An <code>ItemListener</code> object is registered
1087             * via <code>addItemListener</code>.
1088             * <li>Item events are enabled via <code>enableEvents</code>.
1089             * </ul>
1090             * <p>Note that if the event parameter is <code>null</code>
1091             * the behavior is unspecified and may result in an
1092             * exception.
1093             *
1094             * @param       e the item event
1095             * @see         java.awt.event.ItemEvent
1096             * @see         java.awt.event.ItemListener
1097             * @see         #addItemListener
1098             * @see         java.awt.Component#enableEvents
1099             * @since       JDK1.1
1100             */
1101            protected void processItemEvent(ItemEvent e) {
1102                ItemListener listener = itemListener;
1103                if (listener != null) {
1104                    listener.itemStateChanged(e);
1105                }
1106            }
1107
1108            /**
1109             * Processes action events occurring on this component
1110             * by dispatching them to any registered
1111             * <code>ActionListener</code> objects.
1112             * <p>
1113             * This method is not called unless action events are
1114             * enabled for this component. Action events are enabled
1115             * when one of the following occurs:
1116             * <p><ul>
1117             * <li>An <code>ActionListener</code> object is registered
1118             * via <code>addActionListener</code>.
1119             * <li>Action events are enabled via <code>enableEvents</code>.
1120             * </ul>
1121             * <p>Note that if the event parameter is <code>null</code>
1122             * the behavior is unspecified and may result in an
1123             * exception.
1124             *
1125             * @param       e the action event
1126             * @see         java.awt.event.ActionEvent
1127             * @see         java.awt.event.ActionListener
1128             * @see         #addActionListener
1129             * @see         java.awt.Component#enableEvents
1130             * @since       JDK1.1
1131             */
1132            protected void processActionEvent(ActionEvent e) {
1133                ActionListener listener = actionListener;
1134                if (listener != null) {
1135                    listener.actionPerformed(e);
1136                }
1137            }
1138
1139            /**
1140             * Returns the parameter string representing the state of this
1141             * scrolling list. This string is useful for debugging.
1142             * @return    the parameter string of this scrolling list
1143             */
1144            protected String paramString() {
1145                return super .paramString() + ",selected=" + getSelectedItem();
1146            }
1147
1148            /**
1149             * @deprecated As of JDK version 1.1,
1150             * Not for public use in the future.
1151             * This method is expected to be retained only as a package
1152             * private method.
1153             */
1154            @Deprecated
1155            public synchronized void delItems(int start, int end) {
1156                for (int i = end; i >= start; i--) {
1157                    items.removeElementAt(i);
1158                }
1159                ListPeer peer = (ListPeer) this .peer;
1160                if (peer != null) {
1161                    peer.delItems(start, end);
1162                }
1163            }
1164
1165            /*
1166             * Serialization support.  Since the value of the selected
1167             * field isn't neccessarily up to date we sync it up with the
1168             * peer before serializing.
1169             */
1170
1171            /**
1172             * The <code>List</code> component's
1173             * Serialized Data Version.
1174             *
1175             * @serial
1176             */
1177            private int listSerializedDataVersion = 1;
1178
1179            /**
1180             * Writes default serializable fields to stream.  Writes
1181             * a list of serializable <code>ItemListeners</code>
1182             * and <code>ActionListeners</code> as optional data.
1183             * The non-serializable listeners are detected and
1184             * no attempt is made to serialize them.
1185             *
1186             * @serialData <code>null</code> terminated sequence of 0
1187             *  or more pairs; the pair consists of a <code>String</code>
1188             *  and an <code>Object</code>; the <code>String</code>
1189             *  indicates the type of object and is one of the
1190             *  following:
1191             *  <code>itemListenerK</code> indicating an
1192             *    <code>ItemListener</code> object;
1193             *  <code>actionListenerK</code> indicating an
1194             *    <code>ActionListener</code> object
1195             *
1196             * @param s the <code>ObjectOutputStream</code> to write
1197             * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
1198             * @see java.awt.Component#itemListenerK
1199             * @see java.awt.Component#actionListenerK
1200             * @see #readObject(ObjectInputStream)
1201             */
1202            private void writeObject(ObjectOutputStream s) throws IOException {
1203                synchronized (this ) {
1204                    ListPeer peer = (ListPeer) this .peer;
1205                    if (peer != null) {
1206                        selected = peer.getSelectedIndexes();
1207                    }
1208                }
1209                s.defaultWriteObject();
1210
1211                AWTEventMulticaster.save(s, itemListenerK, itemListener);
1212                AWTEventMulticaster.save(s, actionListenerK, actionListener);
1213                s.writeObject(null);
1214            }
1215
1216            /**
1217             * Reads the <code>ObjectInputStream</code> and if it
1218             * isn't <code>null</code> adds a listener to receive
1219             * both item events and action events (as specified
1220             * by the key stored in the stream) fired by the
1221             * <code>List</code>.
1222             * Unrecognized keys or values will be ignored.
1223             *
1224             * @param s the <code>ObjectInputStream</code> to write
1225             * @exception HeadlessException if
1226             *   <code>GraphicsEnvironment.isHeadless</code> returns
1227             *   <code>true</code>
1228             * @see #removeItemListener(ItemListener)
1229             * @see #addItemListener(ItemListener)
1230             * @see java.awt.GraphicsEnvironment#isHeadless
1231             * @see #writeObject(ObjectOutputStream)
1232             */
1233            private void readObject(ObjectInputStream s)
1234                    throws ClassNotFoundException, IOException,
1235                    HeadlessException {
1236                GraphicsEnvironment.checkHeadless();
1237                s.defaultReadObject();
1238
1239                Object keyOrNull;
1240                while (null != (keyOrNull = s.readObject())) {
1241                    String key = ((String) keyOrNull).intern();
1242
1243                    if (itemListenerK == key)
1244                        addItemListener((ItemListener) (s.readObject()));
1245
1246                    else if (actionListenerK == key)
1247                        addActionListener((ActionListener) (s.readObject()));
1248
1249                    else
1250                        // skip value for unrecognized key
1251                        s.readObject();
1252                }
1253            }
1254
1255            /////////////////
1256            // Accessibility support
1257            ////////////////
1258
1259            /**
1260             * Gets the <code>AccessibleContext</code> associated with this 
1261             * <code>List</code>. For lists, the <code>AccessibleContext</code>
1262             * takes the form of an <code>AccessibleAWTList</code>. 
1263             * A new <code>AccessibleAWTList</code> instance is created, if necessary.
1264             *
1265             * @return an <code>AccessibleAWTList</code> that serves as the 
1266             *         <code>AccessibleContext</code> of this <code>List</code>
1267             * @since 1.3
1268             */
1269            public AccessibleContext getAccessibleContext() {
1270                if (accessibleContext == null) {
1271                    accessibleContext = new AccessibleAWTList();
1272                }
1273                return accessibleContext;
1274            }
1275
1276            /**
1277             * This class implements accessibility support for the 
1278             * <code>List</code> class.  It provides an implementation of the 
1279             * Java Accessibility API appropriate to list user-interface elements.
1280             * @since 1.3
1281             */
1282            protected class AccessibleAWTList extends AccessibleAWTComponent
1283                    implements  AccessibleSelection, ItemListener,
1284                    ActionListener {
1285                /*
1286                 * JDK 1.3 serialVersionUID
1287                 */
1288                private static final long serialVersionUID = 7924617370136012829L;
1289
1290                public AccessibleAWTList() {
1291                    super ();
1292                    List.this .addActionListener(this );
1293                    List.this .addItemListener(this );
1294                }
1295
1296                public void actionPerformed(ActionEvent event) {
1297                }
1298
1299                public void itemStateChanged(ItemEvent event) {
1300                }
1301
1302                /**
1303                 * Get the state set of this object.
1304                 *
1305                 * @return an instance of AccessibleState containing the current state
1306                 * of the object
1307                 * @see AccessibleState
1308                 */
1309                public AccessibleStateSet getAccessibleStateSet() {
1310                    AccessibleStateSet states = super .getAccessibleStateSet();
1311                    if (List.this .isMultipleMode()) {
1312                        states.add(AccessibleState.MULTISELECTABLE);
1313                    }
1314                    return states;
1315                }
1316
1317                /**
1318                 * Get the role of this object.
1319                 *
1320                 * @return an instance of AccessibleRole describing the role of the 
1321                 * object
1322                 * @see AccessibleRole
1323                 */
1324                public AccessibleRole getAccessibleRole() {
1325                    return AccessibleRole.LIST;
1326                }
1327
1328                /**
1329                 * Returns the Accessible child contained at the local coordinate
1330                 * Point, if one exists.
1331                 *
1332                 * @return the Accessible at the specified location, if it exists
1333                 */
1334                public Accessible getAccessibleAt(Point p) {
1335                    return null; // fredxFIXME Not implemented yet
1336                }
1337
1338                /**
1339                 * Returns the number of accessible children in the object.  If all
1340                 * of the children of this object implement Accessible, than this
1341                 * method should return the number of children of this object.
1342                 *
1343                 * @return the number of accessible children in the object.
1344                 */
1345                public int getAccessibleChildrenCount() {
1346                    return List.this .getItemCount();
1347                }
1348
1349                /**
1350                 * Return the nth Accessible child of the object.
1351                 *
1352                 * @param i zero-based index of child
1353                 * @return the nth Accessible child of the object
1354                 */
1355                public Accessible getAccessibleChild(int i) {
1356                    synchronized (List.this ) {
1357                        if (i >= List.this .getItemCount()) {
1358                            return null;
1359                        } else {
1360                            return new AccessibleAWTListChild(List.this , i);
1361                        }
1362                    }
1363                }
1364
1365                /**
1366                 * Get the AccessibleSelection associated with this object.  In the
1367                 * implementation of the Java Accessibility API for this class, 
1368                 * return this object, which is responsible for implementing the
1369                 * AccessibleSelection interface on behalf of itself.
1370                 * 
1371                 * @return this object
1372                 */
1373                public AccessibleSelection getAccessibleSelection() {
1374                    return this ;
1375                }
1376
1377                // AccessibleSelection methods
1378
1379                /**
1380                 * Returns the number of items currently selected.
1381                 * If no items are selected, the return value will be 0.
1382                 *
1383                 * @return the number of items currently selected.
1384                 */
1385                public int getAccessibleSelectionCount() {
1386                    return List.this .getSelectedIndexes().length;
1387                }
1388
1389                /**
1390                 * Returns an Accessible representing the specified selected item
1391                 * in the object.  If there isn't a selection, or there are
1392                 * fewer items selected than the integer passed in, the return
1393                 * value will be null.
1394                 *
1395                 * @param i the zero-based index of selected items
1396                 * @return an Accessible containing the selected item
1397                 */
1398                public Accessible getAccessibleSelection(int i) {
1399                    synchronized (List.this ) {
1400                        int len = getAccessibleSelectionCount();
1401                        if (i < 0 || i >= len) {
1402                            return null;
1403                        } else {
1404                            return getAccessibleChild(List.this 
1405                                    .getSelectedIndexes()[i]);
1406                        }
1407                    }
1408                }
1409
1410                /**
1411                 * Returns true if the current child of this object is selected.
1412                 *
1413                 * @param i the zero-based index of the child in this Accessible
1414                 * object.
1415                 * @see AccessibleContext#getAccessibleChild
1416                 */
1417                public boolean isAccessibleChildSelected(int i) {
1418                    return List.this .isIndexSelected(i);
1419                }
1420
1421                /**
1422                 * Adds the specified selected item in the object to the object's
1423                 * selection.  If the object supports multiple selections,
1424                 * the specified item is added to any existing selection, otherwise
1425                 * it replaces any existing selection in the object.  If the
1426                 * specified item is already selected, this method has no effect.
1427                 *
1428                 * @param i the zero-based index of selectable items
1429                 */
1430                public void addAccessibleSelection(int i) {
1431                    List.this .select(i);
1432                }
1433
1434                /**
1435                 * Removes the specified selected item in the object from the object's
1436                 * selection.  If the specified item isn't currently selected, this
1437                 * method has no effect.
1438                 *
1439                 * @param i the zero-based index of selectable items
1440                 */
1441                public void removeAccessibleSelection(int i) {
1442                    List.this .deselect(i);
1443                }
1444
1445                /**
1446                 * Clears the selection in the object, so that nothing in the
1447                 * object is selected.
1448                 */
1449                public void clearAccessibleSelection() {
1450                    synchronized (List.this ) {
1451                        int selectedIndexes[] = List.this .getSelectedIndexes();
1452                        if (selectedIndexes == null)
1453                            return;
1454                        for (int i = selectedIndexes.length - 1; i >= 0; i--) {
1455                            List.this .deselect(selectedIndexes[i]);
1456                        }
1457                    }
1458                }
1459
1460                /**
1461                 * Causes every selected item in the object to be selected
1462                 * if the object supports multiple selections.
1463                 */
1464                public void selectAllAccessibleSelection() {
1465                    synchronized (List.this ) {
1466                        for (int i = List.this .getItemCount() - 1; i >= 0; i--) {
1467                            List.this .select(i);
1468                        }
1469                    }
1470                }
1471
1472                /**
1473                 * This class implements accessibility support for 
1474                 * List children.  It provides an implementation of the 
1475                 * Java Accessibility API appropriate to list children 
1476                 * user-interface elements.
1477                 * @since 1.3
1478                 */
1479                protected class AccessibleAWTListChild extends
1480                        AccessibleAWTComponent implements  Accessible {
1481                    /*
1482                     * JDK 1.3 serialVersionUID
1483                     */
1484                    private static final long serialVersionUID = 4412022926028300317L;
1485
1486                    // [[[FIXME]]] need to finish implementing this!!!
1487
1488                    private List parent;
1489                    private int indexInParent;
1490
1491                    public AccessibleAWTListChild(List parent, int indexInParent) {
1492                        this .parent = parent;
1493                        this .setAccessibleParent(parent);
1494                        this .indexInParent = indexInParent;
1495                    }
1496
1497                    //
1498                    // required Accessible methods
1499                    //
1500                    /**
1501                     * Gets the AccessibleContext for this object.  In the
1502                     * implementation of the Java Accessibility API for this class, 
1503                     * return this object, which acts as its own AccessibleContext.
1504                     * 
1505                     * @return this object
1506                     */
1507                    public AccessibleContext getAccessibleContext() {
1508                        return this ;
1509                    }
1510
1511                    //
1512                    // required AccessibleContext methods
1513                    //
1514
1515                    /**
1516                     * Get the role of this object.  
1517                     *
1518                     * @return an instance of AccessibleRole describing the role of 
1519                     * the object
1520                     * @see AccessibleRole
1521                     */
1522                    public AccessibleRole getAccessibleRole() {
1523                        return AccessibleRole.LIST_ITEM;
1524                    }
1525
1526                    /**
1527                     * Get the state set of this object.  The AccessibleStateSet of an 
1528                     * object is composed of a set of unique AccessibleState's.  A 
1529                     * change in the AccessibleStateSet of an object will cause a 
1530                     * PropertyChangeEvent to be fired for the 
1531                     * ACCESSIBLE_STATE_PROPERTY property.
1532                     *
1533                     * @return an instance of AccessibleStateSet containing the
1534                     * current state set of the object
1535                     * @see AccessibleStateSet
1536                     * @see AccessibleState
1537                     * @see #addPropertyChangeListener
1538                     */
1539                    public AccessibleStateSet getAccessibleStateSet() {
1540                        AccessibleStateSet states = super 
1541                                .getAccessibleStateSet();
1542                        if (parent.isIndexSelected(indexInParent)) {
1543                            states.add(AccessibleState.SELECTED);
1544                        }
1545                        return states;
1546                    }
1547
1548                    /**
1549                     * Gets the locale of the component. If the component does not 
1550                     * have a locale, then the locale of its parent is returned.
1551                     *
1552                     * @return This component's locale.  If this component does not have
1553                     * a locale, the locale of its parent is returned.
1554                     *
1555                     * @exception IllegalComponentStateException
1556                     * If the Component does not have its own locale and has not yet 
1557                     * been added to a containment hierarchy such that the locale can
1558                     * be determined from the containing parent.
1559                     */
1560                    public Locale getLocale() {
1561                        return parent.getLocale();
1562                    }
1563
1564                    /**
1565                     * Get the 0-based index of this object in its accessible parent.
1566                     *
1567                     * @return the 0-based index of this object in its parent; -1 if 
1568                     * this object does not have an accessible parent.
1569                     *
1570                     * @see #getAccessibleParent
1571                     * @see #getAccessibleChildrenCount
1572                     * @see #getAccessibleChild
1573                     */
1574                    public int getAccessibleIndexInParent() {
1575                        return indexInParent;
1576                    }
1577
1578                    /**
1579                     * Returns the number of accessible children of the object.
1580                     *
1581                     * @return the number of accessible children of the object.
1582                     */
1583                    public int getAccessibleChildrenCount() {
1584                        return 0; // list elements can't have children
1585                    }
1586
1587                    /**
1588                     * Return the specified Accessible child of the object.  The 
1589                     * Accessible children of an Accessible object are zero-based, 
1590                     * so the first child of an Accessible child is at index 0, the 
1591                     * second child is at index 1, and so on.
1592                     *
1593                     * @param i zero-based index of child
1594                     * @return the Accessible child of the object
1595                     * @see #getAccessibleChildrenCount
1596                     */
1597                    public Accessible getAccessibleChild(int i) {
1598                        return null; // list elements can't have children
1599                    }
1600
1601                    //
1602                    // AccessibleComponent delegatation to parent List
1603                    //
1604
1605                    /**
1606                     * Get the background color of this object.
1607                     *
1608                     * @return the background color, if supported, of the object; 
1609                     * otherwise, null
1610                     * @see #setBackground
1611                     */
1612                    public Color getBackground() {
1613                        return parent.getBackground();
1614                    }
1615
1616                    /**
1617                     * Set the background color of this object.
1618                     *
1619                     * @param c the new Color for the background
1620                     * @see #setBackground
1621                     */
1622                    public void setBackground(Color c) {
1623                        parent.setBackground(c);
1624                    }
1625
1626                    /**
1627                     * Get the foreground color of this object.
1628                     *
1629                     * @return the foreground color, if supported, of the object; 
1630                     * otherwise, null
1631                     * @see #setForeground
1632                     */
1633                    public Color getForeground() {
1634                        return parent.getForeground();
1635                    }
1636
1637                    /**
1638                     * Set the foreground color of this object.
1639                     *
1640                     * @param c the new Color for the foreground
1641                     * @see #getForeground
1642                     */
1643                    public void setForeground(Color c) {
1644                        parent.setForeground(c);
1645                    }
1646
1647                    /**
1648                     * Get the Cursor of this object.
1649                     *
1650                     * @return the Cursor, if supported, of the object; otherwise, null
1651                     * @see #setCursor
1652                     */
1653                    public Cursor getCursor() {
1654                        return parent.getCursor();
1655                    }
1656
1657                    /**
1658                     * Set the Cursor of this object.
1659                     * <p>
1660                     * The method may have no visual effect if the Java platform
1661                     * implementation and/or the native system do not support
1662                     * changing the mouse cursor shape.
1663                     * @param cursor the new Cursor for the object
1664                     * @see #getCursor
1665                     */
1666                    public void setCursor(Cursor cursor) {
1667                        parent.setCursor(cursor);
1668                    }
1669
1670                    /**
1671                     * Get the Font of this object.
1672                     *
1673                     * @return the Font,if supported, for the object; otherwise, null
1674                     * @see #setFont
1675                     */
1676                    public Font getFont() {
1677                        return parent.getFont();
1678                    }
1679
1680                    /**
1681                     * Set the Font of this object.
1682                     *
1683                     * @param f the new Font for the object
1684                     * @see #getFont
1685                     */
1686                    public void setFont(Font f) {
1687                        parent.setFont(f);
1688                    }
1689
1690                    /**
1691                     * Get the FontMetrics of this object.
1692                     *
1693                     * @param f the Font
1694                     * @return the FontMetrics, if supported, the object; otherwise, null
1695                     * @see #getFont
1696                     */
1697                    public FontMetrics getFontMetrics(Font f) {
1698                        return parent.getFontMetrics(f);
1699                    }
1700
1701                    /**
1702                     * Determine if the object is enabled.  Objects that are enabled
1703                     * will also have the AccessibleState.ENABLED state set in their
1704                     * AccessibleStateSet.
1705                     *
1706                     * @return true if object is enabled; otherwise, false
1707                     * @see #setEnabled
1708                     * @see AccessibleContext#getAccessibleStateSet
1709                     * @see AccessibleState#ENABLED
1710                     * @see AccessibleStateSet
1711                     */
1712                    public boolean isEnabled() {
1713                        return parent.isEnabled();
1714                    }
1715
1716                    /**
1717                     * Set the enabled state of the object.
1718                     *
1719                     * @param b if true, enables this object; otherwise, disables it 
1720                     * @see #isEnabled
1721                     */
1722                    public void setEnabled(boolean b) {
1723                        parent.setEnabled(b);
1724                    }
1725
1726                    /**
1727                     * Determine if the object is visible.  Note: this means that the
1728                     * object intends to be visible; however, it may not be
1729                     * showing on the screen because one of the objects that this object
1730                     * is contained by is currently not visible.  To determine if an 
1731                     * object is showing on the screen, use isShowing().
1732                     * <p>Objects that are visible will also have the 
1733                     * AccessibleState.VISIBLE state set in their AccessibleStateSet.
1734                     *
1735                     * @return true if object is visible; otherwise, false
1736                     * @see #setVisible
1737                     * @see AccessibleContext#getAccessibleStateSet
1738                     * @see AccessibleState#VISIBLE
1739                     * @see AccessibleStateSet
1740                     */
1741                    public boolean isVisible() {
1742                        // [[[FIXME]]] needs to work like isShowing() below
1743                        return false;
1744                        // return parent.isVisible();
1745                    }
1746
1747                    /**
1748                     * Set the visible state of the object.
1749                     *
1750                     * @param b if true, shows this object; otherwise, hides it 
1751                     * @see #isVisible
1752                     */
1753                    public void setVisible(boolean b) {
1754                        // [[[FIXME]]] should scroll to item to make it show!
1755                        parent.setVisible(b);
1756                    }
1757
1758                    /**
1759                     * Determine if the object is showing.  This is determined by 
1760                     * checking the visibility of the object and visibility of the 
1761                     * object ancestors.
1762                     * Note: this will return true even if the object is obscured 
1763                     * by another (for example, it to object is underneath a menu 
1764                     * that was pulled down).
1765                     *
1766                     * @return true if object is showing; otherwise, false
1767                     */
1768                    public boolean isShowing() {
1769                        // [[[FIXME]]] only if it's showing!!!
1770                        return false;
1771                        // return parent.isShowing();
1772                    }
1773
1774                    /** 
1775                     * Checks whether the specified point is within this object's 
1776                     * bounds, where the point's x and y coordinates are defined to 
1777                     * be relative to the coordinate system of the object. 
1778                     *
1779                     * @param p the Point relative to the coordinate system of the 
1780                     * object
1781                     * @return true if object contains Point; otherwise false
1782                     * @see #getBounds
1783                     */
1784                    public boolean contains(Point p) {
1785                        // [[[FIXME]]] - only if p is within the list element!!!
1786                        return false;
1787                        // return parent.contains(p);
1788                    }
1789
1790                    /** 
1791                     * Returns the location of the object on the screen.
1792                     *
1793                     * @return location of object on screen; null if this object
1794                     * is not on the screen
1795                     * @see #getBounds
1796                     * @see #getLocation
1797                     */
1798                    public Point getLocationOnScreen() {
1799                        // [[[FIXME]]] sigh
1800                        return null;
1801                    }
1802
1803                    /** 
1804                     * Gets the location of the object relative to the parent in the 
1805                     * form of a point specifying the object's top-left corner in the 
1806                     * screen's coordinate space.
1807                     *
1808                     * @return An instance of Point representing the top-left corner of
1809                     * the objects's bounds in the coordinate space of the screen; null
1810                     * if this object or its parent are not on the screen
1811                     * @see #getBounds
1812                     * @see #getLocationOnScreen
1813                     */
1814                    public Point getLocation() {
1815                        // [[[FIXME]]]
1816                        return null;
1817                    }
1818
1819                    /** 
1820                     * Sets the location of the object relative to the parent.
1821                     * @param p the new position for the top-left corner
1822                     * @see #getLocation
1823                     */
1824                    public void setLocation(Point p) {
1825                        // [[[FIXME]]] maybe - can simply return as no-op
1826                    }
1827
1828                    /** 
1829                     * Gets the bounds of this object in the form of a Rectangle object. 
1830                     * The bounds specify this object's width, height, and location
1831                     * relative to its parent. 
1832                     *
1833                     * @return A rectangle indicating this component's bounds; null if 
1834                     * this object is not on the screen.
1835                     * @see #contains
1836                     */
1837                    public Rectangle getBounds() {
1838                        // [[[FIXME]]]
1839                        return null;
1840                    }
1841
1842                    /** 
1843                     * Sets the bounds of this object in the form of a Rectangle 
1844                     * object.  The bounds specify this object's width, height, and 
1845                     * location relative to its parent.
1846                     *	
1847                     * @param r rectangle indicating this component's bounds
1848                     * @see #getBounds
1849                     */
1850                    public void setBounds(Rectangle r) {
1851                        // no-op; not supported
1852                    }
1853
1854                    /** 
1855                     * Returns the size of this object in the form of a Dimension 
1856                     * object.  The height field of the Dimension object contains this 
1857                     * objects's height, and the width field of the Dimension object 
1858                     * contains this object's width. 
1859                     *
1860                     * @return A Dimension object that indicates the size of this 
1861                     * component; null if this object is not on the screen
1862                     * @see #setSize
1863                     */
1864                    public Dimension getSize() {
1865                        // [[[FIXME]]]
1866                        return null;
1867                    }
1868
1869                    /** 
1870                     * Resizes this object so that it has width and height. 
1871                     *	
1872                     * @param d - The dimension specifying the new size of the object. 
1873                     * @see #getSize
1874                     */
1875                    public void setSize(Dimension d) {
1876                        // not supported; no-op
1877                    }
1878
1879                    /**
1880                     * Returns the <code>Accessible</code> child, if one exists,
1881                     * contained at the local coordinate <code>Point</code>.
1882                     *
1883                     * @param p the point relative to the coordinate system of this 
1884                     *     object
1885                     * @return the <code>Accessible</code>, if it exists,
1886                     *     at the specified location; otherwise <code>null</code>
1887                     */
1888                    public Accessible getAccessibleAt(Point p) {
1889                        return null; // object cannot have children!
1890                    }
1891
1892                    /**
1893                     * Returns whether this object can accept focus or not.   Objects 
1894                     * that can accept focus will also have the 
1895                     * <code>AccessibleState.FOCUSABLE</code> state set in their 
1896                     * <code>AccessibleStateSet</code>.
1897                     *
1898                     * @return true if object can accept focus; otherwise false
1899                     * @see AccessibleContext#getAccessibleStateSet
1900                     * @see AccessibleState#FOCUSABLE
1901                     * @see AccessibleState#FOCUSED
1902                     * @see AccessibleStateSet
1903                     */
1904                    public boolean isFocusTraversable() {
1905                        return false; // list element cannot receive focus!
1906                    }
1907
1908                    /**
1909                     * Requests focus for this object.  If this object cannot accept 
1910                     * focus, nothing will happen.  Otherwise, the object will attempt 
1911                     * to take focus.
1912                     * @see #isFocusTraversable
1913                     */
1914                    public void requestFocus() {
1915                        // nothing to do; a no-op
1916                    }
1917
1918                    /**
1919                     * Adds the specified focus listener to receive focus events from 
1920                     * this component. 
1921                     *
1922                     * @param l the focus listener
1923                     * @see #removeFocusListener
1924                     */
1925                    public void addFocusListener(FocusListener l) {
1926                        // nothing to do; a no-op
1927                    }
1928
1929                    /**
1930                     * Removes the specified focus listener so it no longer receives 
1931                     * focus events from this component.
1932                     *
1933                     * @param l the focus listener
1934                     * @see #addFocusListener
1935                     */
1936                    public void removeFocusListener(FocusListener l) {
1937                        // nothing to do; a no-op
1938                    }
1939
1940                } // inner class AccessibleAWTListChild
1941
1942            } // inner class AccessibleAWTList
1943
1944        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.