0N/A/*
2362N/A * Copyright (c) 1995, 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage java.awt;
0N/A
0N/Aimport java.util.Vector;
0N/Aimport java.util.Locale;
0N/Aimport java.util.EventListener;
0N/Aimport java.awt.peer.ListPeer;
0N/Aimport java.awt.event.*;
0N/Aimport java.io.ObjectOutputStream;
0N/Aimport java.io.ObjectInputStream;
0N/Aimport java.io.IOException;
0N/Aimport javax.accessibility.*;
0N/A
0N/A
0N/A/**
0N/A * The <code>List</code> component presents the user with a
0N/A * scrolling list of text items. The list can be set up so that
0N/A * the user can choose either one item or multiple items.
0N/A * <p>
0N/A * For example, the code&nbsp;.&nbsp;.&nbsp;.
0N/A * <p>
0N/A * <hr><blockquote><pre>
0N/A * List lst = new List(4, false);
0N/A * lst.add("Mercury");
0N/A * lst.add("Venus");
0N/A * lst.add("Earth");
0N/A * lst.add("JavaSoft");
0N/A * lst.add("Mars");
0N/A * lst.add("Jupiter");
0N/A * lst.add("Saturn");
0N/A * lst.add("Uranus");
0N/A * lst.add("Neptune");
0N/A * lst.add("Pluto");
0N/A * cnt.add(lst);
0N/A * </pre></blockquote><hr>
0N/A * <p>
0N/A * where <code>cnt</code> is a container, produces the following
0N/A * scrolling list:
0N/A * <p>
0N/A * <img src="doc-files/List-1.gif"
0N/A * alt="Shows a list containing: Venus, Earth, JavaSoft, and Mars. Javasoft is selected." ALIGN=center HSPACE=10 VSPACE=7>
0N/A * <p>
0N/A * If the List allows multiple selections, then clicking on
0N/A * an item that is already selected deselects it. In the preceding
0N/A * example, only one item from the scrolling list can be selected
0N/A * at a time, since the second argument when creating the new scrolling
0N/A * list is <code>false</code>. If the List does not allow multiple
0N/A * selections, selecting an item causes any other selected item
0N/A * to be deselected.
0N/A * <p>
0N/A * Note that the list in the example shown was created with four visible
0N/A * rows. Once the list has been created, the number of visible rows
0N/A * cannot be changed. A default <code>List</code> is created with
0N/A * four rows, so that <code>lst = new List()</code> is equivalent to
0N/A * <code>list = new List(4, false)</code>.
0N/A * <p>
0N/A * Beginning with Java&nbsp;1.1, the Abstract Window Toolkit
0N/A * sends the <code>List</code> object all mouse, keyboard, and focus events
0N/A * that occur over it. (The old AWT event model is being maintained
0N/A * only for backwards compatibility, and its use is discouraged.)
0N/A * <p>
0N/A * When an item is selected or deselected by the user, AWT sends an instance
0N/A * of <code>ItemEvent</code> to the list.
0N/A * When the user double-clicks on an item in a scrolling list,
0N/A * AWT sends an instance of <code>ActionEvent</code> to the
0N/A * list following the item event. AWT also generates an action event
0N/A * when the user presses the return key while an item in the
0N/A * list is selected.
0N/A * <p>
0N/A * If an application wants to perform some action based on an item
0N/A * in this list being selected or activated by the user, it should implement
0N/A * <code>ItemListener</code> or <code>ActionListener</code>
0N/A * as appropriate and register the new listener to receive
0N/A * events from this list.
0N/A * <p>
0N/A * For multiple-selection scrolling lists, it is considered a better
0N/A * user interface to use an external gesture (such as clicking on a
0N/A * button) to trigger the action.
0N/A * @author Sami Shaio
0N/A * @see java.awt.event.ItemEvent
0N/A * @see java.awt.event.ItemListener
0N/A * @see java.awt.event.ActionEvent
0N/A * @see java.awt.event.ActionListener
0N/A * @since JDK1.0
0N/A */
0N/Apublic class List extends Component implements ItemSelectable, Accessible {
0N/A /**
0N/A * A vector created to contain items which will become
0N/A * part of the List Component.
0N/A *
0N/A * @serial
0N/A * @see #addItem(String)
0N/A * @see #getItem(int)
0N/A */
0N/A Vector items = new Vector();
0N/A
0N/A /**
0N/A * This field will represent the number of visible rows in the
0N/A * <code>List</code> Component. It is specified only once, and
0N/A * that is when the list component is actually
0N/A * created. It will never change.
0N/A *
0N/A * @serial
0N/A * @see #getRows()
0N/A */
0N/A int rows = 0;
0N/A
0N/A /**
0N/A * <code>multipleMode</code> is a variable that will
0N/A * be set to <code>true</code> if a list component is to be set to
0N/A * multiple selection mode, that is where the user can
0N/A * select more than one item in a list at one time.
0N/A * <code>multipleMode</code> will be set to false if the
0N/A * list component is set to single selection, that is where
0N/A * the user can only select one item on the list at any
0N/A * one time.
0N/A *
0N/A * @serial
0N/A * @see #isMultipleMode()
0N/A * @see #setMultipleMode(boolean)
0N/A */
0N/A boolean multipleMode = false;
0N/A
0N/A /**
0N/A * <code>selected</code> is an array that will contain
0N/A * the indices of items that have been selected.
0N/A *
0N/A * @serial
0N/A * @see #getSelectedIndexes()
0N/A * @see #getSelectedIndex()
0N/A */
0N/A int selected[] = new int[0];
0N/A
0N/A /**
0N/A * This variable contains the value that will be used
0N/A * when trying to make a particular list item visible.
0N/A *
0N/A * @serial
0N/A * @see #makeVisible(int)
0N/A */
0N/A int visibleIndex = -1;
0N/A
0N/A transient ActionListener actionListener;
0N/A transient ItemListener itemListener;
0N/A
0N/A private static final String base = "list";
0N/A private static int nameCounter = 0;
0N/A
0N/A /*
0N/A * JDK 1.1 serialVersionUID
0N/A */
0N/A private static final long serialVersionUID = -3304312411574666869L;
0N/A
0N/A /**
0N/A * Creates a new scrolling list.
0N/A * By default, there are four visible lines and multiple selections are
0N/A * not allowed. Note that this is a convenience method for
0N/A * <code>List(0, false)</code>. Also note that the number of visible
0N/A * lines in the list cannot be changed after it has been created.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true.
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A */
0N/A public List() throws HeadlessException {
0N/A this(0, false);
0N/A }
0N/A
0N/A /**
0N/A * Creates a new scrolling list initialized with the specified
0N/A * number of visible lines. By default, multiple selections are
0N/A * not allowed. Note that this is a convenience method for
0N/A * <code>List(rows, false)</code>. Also note that the number
0N/A * of visible rows in the list cannot be changed after it has
0N/A * been created.
0N/A * @param rows the number of items to show.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true.
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @since JDK1.1
0N/A */
0N/A public List(int rows) throws HeadlessException {
0N/A this(rows, false);
0N/A }
0N/A
0N/A /**
0N/A * The default number of visible rows is 4. A list with
0N/A * zero rows is unusable and unsightly.
0N/A */
0N/A final static int DEFAULT_VISIBLE_ROWS = 4;
0N/A
0N/A /**
0N/A * Creates a new scrolling list initialized to display the specified
0N/A * number of rows. Note that if zero rows are specified, then
0N/A * the list will be created with a default of four rows.
0N/A * Also note that the number of visible rows in the list cannot
0N/A * be changed after it has been created.
0N/A * If the value of <code>multipleMode</code> is
0N/A * <code>true</code>, then the user can select multiple items from
0N/A * the list. If it is <code>false</code>, only one item at a time
0N/A * can be selected.
0N/A * @param rows the number of items to show.
0N/A * @param multipleMode if <code>true</code>,
0N/A * then multiple selections are allowed;
0N/A * otherwise, only one item can be selected at a time.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true.
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A */
0N/A public List(int rows, boolean multipleMode) throws HeadlessException {
0N/A GraphicsEnvironment.checkHeadless();
0N/A this.rows = (rows != 0) ? rows : DEFAULT_VISIBLE_ROWS;
0N/A this.multipleMode = multipleMode;
0N/A }
0N/A
0N/A /**
0N/A * Construct a name for this component. Called by
0N/A * <code>getName</code> when the name is <code>null</code>.
0N/A */
0N/A String constructComponentName() {
0N/A synchronized (List.class) {
0N/A return base + nameCounter++;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Creates the peer for the list. The peer allows us to modify the
0N/A * list's appearance without changing its functionality.
0N/A */
0N/A public void addNotify() {
0N/A synchronized (getTreeLock()) {
0N/A if (peer == null)
0N/A peer = getToolkit().createList(this);
0N/A super.addNotify();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Removes the peer for this list. The peer allows us to modify the
0N/A * list's appearance without changing its functionality.
0N/A */
0N/A public void removeNotify() {
0N/A synchronized (getTreeLock()) {
0N/A ListPeer peer = (ListPeer)this.peer;
0N/A if (peer != null) {
0N/A selected = peer.getSelectedIndexes();
0N/A }
0N/A super.removeNotify();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gets the number of items in the list.
0N/A * @return the number of items in the list
0N/A * @see #getItem
0N/A * @since JDK1.1
0N/A */
0N/A public int getItemCount() {
0N/A return countItems();
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>getItemCount()</code>.
0N/A */
0N/A @Deprecated
0N/A public int countItems() {
0N/A return items.size();
0N/A }
0N/A
0N/A /**
0N/A * Gets the item associated with the specified index.
0N/A * @return an item that is associated with
0N/A * the specified index
0N/A * @param index the position of the item
0N/A * @see #getItemCount
0N/A */
0N/A public String getItem(int index) {
0N/A return getItemImpl(index);
0N/A }
0N/A
0N/A // NOTE: This method may be called by privileged threads.
0N/A // We implement this functionality in a package-private method
0N/A // to insure that it cannot be overridden by client subclasses.
0N/A // DO NOT INVOKE CLIENT CODE ON THIS THREAD!
0N/A final String getItemImpl(int index) {
0N/A return (String)items.elementAt(index);
0N/A }
0N/A
0N/A /**
0N/A * Gets the items in the list.
0N/A * @return a string array containing items of the list
0N/A * @see #select
0N/A * @see #deselect
0N/A * @see #isIndexSelected
0N/A * @since JDK1.1
0N/A */
0N/A public synchronized String[] getItems() {
0N/A String itemCopies[] = new String[items.size()];
0N/A items.copyInto(itemCopies);
0N/A return itemCopies;
0N/A }
0N/A
0N/A /**
0N/A * Adds the specified item to the end of scrolling list.
0N/A * @param item the item to be added
0N/A * @since JDK1.1
0N/A */
0N/A public void add(String item) {
0N/A addItem(item);
0N/A }
0N/A
0N/A /**
0N/A * @deprecated replaced by <code>add(String)</code>.
0N/A */
0N/A @Deprecated
0N/A public void addItem(String item) {
0N/A addItem(item, -1);
0N/A }
0N/A
0N/A /**
0N/A * Adds the specified item to the the scrolling list
0N/A * at the position indicated by the index. The index is
0N/A * zero-based. If the value of the index is less than zero,
0N/A * or if the value of the index is greater than or equal to
0N/A * the number of items in the list, then the item is added
0N/A * to the end of the list.
0N/A * @param item the item to be added;
0N/A * if this parameter is <code>null</code> then the item is
0N/A * treated as an empty string, <code>""</code>
0N/A * @param index the position at which to add the item
0N/A * @since JDK1.1
0N/A */
0N/A public void add(String item, int index) {
0N/A addItem(item, index);
0N/A }
0N/A
0N/A /**
0N/A * @deprecated replaced by <code>add(String, int)</code>.
0N/A */
0N/A @Deprecated
0N/A public synchronized void addItem(String item, int index) {
0N/A if (index < -1 || index >= items.size()) {
0N/A index = -1;
0N/A }
0N/A
0N/A if (item == null) {
0N/A item = "";
0N/A }
0N/A
0N/A if (index == -1) {
0N/A items.addElement(item);
0N/A } else {
0N/A items.insertElementAt(item, index);
0N/A }
0N/A
0N/A ListPeer peer = (ListPeer)this.peer;
0N/A if (peer != null) {
872N/A peer.add(item, index);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Replaces the item at the specified index in the scrolling list
0N/A * with the new string.
0N/A * @param newValue a new string to replace an existing item
0N/A * @param index the position of the item to replace
0N/A * @exception ArrayIndexOutOfBoundsException if <code>index</code>
0N/A * is out of range
0N/A */
0N/A public synchronized void replaceItem(String newValue, int index) {
0N/A remove(index);
0N/A add(newValue, index);
0N/A }
0N/A
0N/A /**
0N/A * Removes all items from this list.
0N/A * @see #remove
0N/A * @see #delItems
0N/A * @since JDK1.1
0N/A */
0N/A public void removeAll() {
0N/A clear();
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>removeAll()</code>.
0N/A */
0N/A @Deprecated
0N/A public synchronized void clear() {
0N/A ListPeer peer = (ListPeer)this.peer;
0N/A if (peer != null) {
872N/A peer.removeAll();
0N/A }
0N/A items = new Vector();
0N/A selected = new int[0];
0N/A }
0N/A
0N/A /**
0N/A * Removes the first occurrence of an item from the list.
0N/A * If the specified item is selected, and is the only selected
0N/A * item in the list, the list is set to have no selection.
0N/A * @param item the item to remove from the list
0N/A * @exception IllegalArgumentException
0N/A * if the item doesn't exist in the list
0N/A * @since JDK1.1
0N/A */
0N/A public synchronized void remove(String item) {
0N/A int index = items.indexOf(item);
0N/A if (index < 0) {
0N/A throw new IllegalArgumentException("item " + item +
0N/A " not found in list");
0N/A } else {
0N/A remove(index);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Removes the item at the specified position
0N/A * from this scrolling list.
0N/A * If the item with the specified position is selected, and is the
0N/A * only selected item in the list, the list is set to have no selection.
0N/A * @param position the index of the item to delete
0N/A * @see #add(String, int)
0N/A * @since JDK1.1
0N/A * @exception ArrayIndexOutOfBoundsException
0N/A * if the <code>position</code> is less than 0 or
0N/A * greater than <code>getItemCount()-1</code>
0N/A */
0N/A public void remove(int position) {
0N/A delItem(position);
0N/A }
0N/A
0N/A /**
0N/A * @deprecated replaced by <code>remove(String)</code>
0N/A * and <code>remove(int)</code>.
0N/A */
0N/A @Deprecated
0N/A public void delItem(int position) {
0N/A delItems(position, position);
0N/A }
0N/A
0N/A /**
0N/A * Gets the index of the selected item on the list,
0N/A *
0N/A * @return the index of the selected item;
0N/A * if no item is selected, or if multiple items are
0N/A * selected, <code>-1</code> is returned.
0N/A * @see #select
0N/A * @see #deselect
0N/A * @see #isIndexSelected
0N/A */
0N/A public synchronized int getSelectedIndex() {
0N/A int sel[] = getSelectedIndexes();
0N/A return (sel.length == 1) ? sel[0] : -1;
0N/A }
0N/A
0N/A /**
0N/A * Gets the selected indexes on the list.
0N/A *
0N/A * @return an array of the selected indexes on this scrolling list;
0N/A * if no item is selected, a zero-length array is returned.
0N/A * @see #select
0N/A * @see #deselect
0N/A * @see #isIndexSelected
0N/A */
0N/A public synchronized int[] getSelectedIndexes() {
0N/A ListPeer peer = (ListPeer)this.peer;
0N/A if (peer != null) {
0N/A selected = ((ListPeer)peer).getSelectedIndexes();
0N/A }
0N/A return (int[])selected.clone();
0N/A }
0N/A
0N/A /**
0N/A * Gets the selected item on this scrolling list.
0N/A *
0N/A * @return the selected item on the list;
0N/A * if no item is selected, or if multiple items are
0N/A * selected, <code>null</code> is returned.
0N/A * @see #select
0N/A * @see #deselect
0N/A * @see #isIndexSelected
0N/A */
0N/A public synchronized String getSelectedItem() {
0N/A int index = getSelectedIndex();
0N/A return (index < 0) ? null : getItem(index);
0N/A }
0N/A
0N/A /**
0N/A * Gets the selected items on this scrolling list.
0N/A *
0N/A * @return an array of the selected items on this scrolling list;
0N/A * if no item is selected, a zero-length array is returned.
0N/A * @see #select
0N/A * @see #deselect
0N/A * @see #isIndexSelected
0N/A */
0N/A public synchronized String[] getSelectedItems() {
0N/A int sel[] = getSelectedIndexes();
0N/A String str[] = new String[sel.length];
0N/A for (int i = 0 ; i < sel.length ; i++) {
0N/A str[i] = getItem(sel[i]);
0N/A }
0N/A return str;
0N/A }
0N/A
0N/A /**
0N/A * Gets the selected items on this scrolling list in an array of Objects.
0N/A * @return an array of <code>Object</code>s representing the
0N/A * selected items on this scrolling list;
0N/A * if no item is selected, a zero-length array is returned.
0N/A * @see #getSelectedItems
0N/A * @see ItemSelectable
0N/A */
0N/A public Object[] getSelectedObjects() {
0N/A return getSelectedItems();
0N/A }
0N/A
0N/A /**
0N/A * Selects the item at the specified index in the scrolling list.
0N/A *<p>
0N/A * Note that passing out of range parameters is invalid,
0N/A * and will result in unspecified behavior.
0N/A *
0N/A * <p>Note that this method should be primarily used to
0N/A * initially select an item in this component.
0N/A * Programmatically calling this method will <i>not</i> trigger
0N/A * an <code>ItemEvent</code>. The only way to trigger an
0N/A * <code>ItemEvent</code> is by user interaction.
0N/A *
0N/A * @param index the position of the item to select
0N/A * @see #getSelectedItem
0N/A * @see #deselect
0N/A * @see #isIndexSelected
0N/A */
0N/A public void select(int index) {
0N/A // Bug #4059614: select can't be synchronized while calling the peer,
0N/A // because it is called from the Window Thread. It is sufficient to
0N/A // synchronize the code that manipulates 'selected' except for the
0N/A // case where the peer changes. To handle this case, we simply
0N/A // repeat the selection process.
0N/A
0N/A ListPeer peer;
0N/A do {
0N/A peer = (ListPeer)this.peer;
0N/A if (peer != null) {
0N/A peer.select(index);
0N/A return;
0N/A }
0N/A
0N/A synchronized(this)
0N/A {
0N/A boolean alreadySelected = false;
0N/A
0N/A for (int i = 0 ; i < selected.length ; i++) {
0N/A if (selected[i] == index) {
0N/A alreadySelected = true;
0N/A break;
0N/A }
0N/A }
0N/A
0N/A if (!alreadySelected) {
0N/A if (!multipleMode) {
0N/A selected = new int[1];
0N/A selected[0] = index;
0N/A } else {
0N/A int newsel[] = new int[selected.length + 1];
0N/A System.arraycopy(selected, 0, newsel, 0,
0N/A selected.length);
0N/A newsel[selected.length] = index;
0N/A selected = newsel;
0N/A }
0N/A }
0N/A }
0N/A } while (peer != this.peer);
0N/A }
0N/A
0N/A /**
0N/A * Deselects the item at the specified index.
0N/A * <p>
0N/A * Note that passing out of range parameters is invalid,
0N/A * and will result in unspecified behavior.
0N/A * <p>
0N/A * If the item at the specified index is not selected,
0N/A * then the operation is ignored.
0N/A * @param index the position of the item to deselect
0N/A * @see #select
0N/A * @see #getSelectedItem
0N/A * @see #isIndexSelected
0N/A */
0N/A public synchronized void deselect(int index) {
0N/A ListPeer peer = (ListPeer)this.peer;
0N/A if (peer != null) {
0N/A if (isMultipleMode() || (getSelectedIndex() == index)) {
0N/A peer.deselect(index);
0N/A }
0N/A }
0N/A
0N/A for (int i = 0 ; i < selected.length ; i++) {
0N/A if (selected[i] == index) {
0N/A int newsel[] = new int[selected.length - 1];
0N/A System.arraycopy(selected, 0, newsel, 0, i);
0N/A System.arraycopy(selected, i+1, newsel, i, selected.length - (i+1));
0N/A selected = newsel;
0N/A return;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Determines if the specified item in this scrolling list is
0N/A * selected.
0N/A * @param index the item to be checked
0N/A * @return <code>true</code> if the specified item has been
0N/A * selected; <code>false</code> otherwise
0N/A * @see #select
0N/A * @see #deselect
0N/A * @since JDK1.1
0N/A */
0N/A public boolean isIndexSelected(int index) {
0N/A return isSelected(index);
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>isIndexSelected(int)</code>.
0N/A */
0N/A @Deprecated
0N/A public boolean isSelected(int index) {
0N/A int sel[] = getSelectedIndexes();
0N/A for (int i = 0 ; i < sel.length ; i++) {
0N/A if (sel[i] == index) {
0N/A return true;
0N/A }
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * Gets the number of visible lines in this list. Note that
0N/A * once the <code>List</code> has been created, this number
0N/A * will never change.
0N/A * @return the number of visible lines in this scrolling list
0N/A */
0N/A public int getRows() {
0N/A return rows;
0N/A }
0N/A
0N/A /**
0N/A * Determines whether this list allows multiple selections.
0N/A * @return <code>true</code> if this list allows multiple
0N/A * selections; otherwise, <code>false</code>
0N/A * @see #setMultipleMode
0N/A * @since JDK1.1
0N/A */
0N/A public boolean isMultipleMode() {
0N/A return allowsMultipleSelections();
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>isMultipleMode()</code>.
0N/A */
0N/A @Deprecated
0N/A public boolean allowsMultipleSelections() {
0N/A return multipleMode;
0N/A }
0N/A
0N/A /**
0N/A * Sets the flag that determines whether this list
0N/A * allows multiple selections.
0N/A * When the selection mode is changed from multiple-selection to
0N/A * single-selection, the selected items change as follows:
0N/A * If a selected item has the location cursor, only that
0N/A * item will remain selected. If no selected item has the
0N/A * location cursor, all items will be deselected.
0N/A * @param b if <code>true</code> then multiple selections
0N/A * are allowed; otherwise, only one item from
0N/A * the list can be selected at once
0N/A * @see #isMultipleMode
0N/A * @since JDK1.1
0N/A */
0N/A public void setMultipleMode(boolean b) {
0N/A setMultipleSelections(b);
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>setMultipleMode(boolean)</code>.
0N/A */
0N/A @Deprecated
0N/A public synchronized void setMultipleSelections(boolean b) {
0N/A if (b != multipleMode) {
0N/A multipleMode = b;
0N/A ListPeer peer = (ListPeer)this.peer;
0N/A if (peer != null) {
872N/A peer.setMultipleMode(b);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gets the index of the item that was last made visible by
0N/A * the method <code>makeVisible</code>.
0N/A * @return the index of the item that was last made visible
0N/A * @see #makeVisible
0N/A */
0N/A public int getVisibleIndex() {
0N/A return visibleIndex;
0N/A }
0N/A
0N/A /**
0N/A * Makes the item at the specified index visible.
0N/A * @param index the position of the item
0N/A * @see #getVisibleIndex
0N/A */
0N/A public synchronized void makeVisible(int index) {
0N/A visibleIndex = index;
0N/A ListPeer peer = (ListPeer)this.peer;
0N/A if (peer != null) {
0N/A peer.makeVisible(index);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gets the preferred dimensions for a list with the specified
0N/A * number of rows.
0N/A * @param rows number of rows in the list
0N/A * @return the preferred dimensions for displaying this scrolling list
0N/A * given that the specified number of rows must be visible
0N/A * @see java.awt.Component#getPreferredSize
0N/A * @since JDK1.1
0N/A */
0N/A public Dimension getPreferredSize(int rows) {
0N/A return preferredSize(rows);
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>getPreferredSize(int)</code>.
0N/A */
0N/A @Deprecated
0N/A public Dimension preferredSize(int rows) {
0N/A synchronized (getTreeLock()) {
0N/A ListPeer peer = (ListPeer)this.peer;
0N/A return (peer != null) ?
872N/A peer.getPreferredSize(rows) :
0N/A super.preferredSize();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gets the preferred size of this scrolling list.
0N/A * @return the preferred dimensions for displaying this scrolling list
0N/A * @see java.awt.Component#getPreferredSize
0N/A * @since JDK1.1
0N/A */
0N/A public Dimension getPreferredSize() {
0N/A return preferredSize();
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>getPreferredSize()</code>.
0N/A */
0N/A @Deprecated
0N/A public Dimension preferredSize() {
0N/A synchronized (getTreeLock()) {
0N/A return (rows > 0) ?
0N/A preferredSize(rows) :
0N/A super.preferredSize();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gets the minumum dimensions for a list with the specified
0N/A * number of rows.
0N/A * @param rows number of rows in the list
0N/A * @return the minimum dimensions for displaying this scrolling list
0N/A * given that the specified number of rows must be visible
0N/A * @see java.awt.Component#getMinimumSize
0N/A * @since JDK1.1
0N/A */
0N/A public Dimension getMinimumSize(int rows) {
0N/A return minimumSize(rows);
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>getMinimumSize(int)</code>.
0N/A */
0N/A @Deprecated
0N/A public Dimension minimumSize(int rows) {
0N/A synchronized (getTreeLock()) {
0N/A ListPeer peer = (ListPeer)this.peer;
0N/A return (peer != null) ?
872N/A peer.getMinimumSize(rows) :
0N/A super.minimumSize();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Determines the minimum size of this scrolling list.
0N/A * @return the minimum dimensions needed
0N/A * to display this scrolling list
0N/A * @see java.awt.Component#getMinimumSize()
0N/A * @since JDK1.1
0N/A */
0N/A public Dimension getMinimumSize() {
0N/A return minimumSize();
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>getMinimumSize()</code>.
0N/A */
0N/A @Deprecated
0N/A public Dimension minimumSize() {
0N/A synchronized (getTreeLock()) {
0N/A return (rows > 0) ? minimumSize(rows) : super.minimumSize();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Adds the specified item listener to receive item events from
0N/A * this list. Item events are sent in response to user input, but not
0N/A * in response to calls to <code>select</code> or <code>deselect</code>.
0N/A * If listener <code>l</code> is <code>null</code>,
0N/A * no exception is thrown and no action is performed.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A *
0N/A * @param l the item listener
0N/A * @see #removeItemListener
0N/A * @see #getItemListeners
0N/A * @see #select
0N/A * @see #deselect
0N/A * @see java.awt.event.ItemEvent
0N/A * @see java.awt.event.ItemListener
0N/A * @since JDK1.1
0N/A */
0N/A public synchronized void addItemListener(ItemListener l) {
0N/A if (l == null) {
0N/A return;
0N/A }
0N/A itemListener = AWTEventMulticaster.add(itemListener, l);
0N/A newEventsOnly = true;
0N/A }
0N/A
0N/A /**
0N/A * Removes the specified item listener so that it no longer
0N/A * receives item events from this list.
0N/A * If listener <code>l</code> is <code>null</code>,
0N/A * no exception is thrown and no action is performed.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A *
0N/A * @param l the item listener
0N/A * @see #addItemListener
0N/A * @see #getItemListeners
0N/A * @see java.awt.event.ItemEvent
0N/A * @see java.awt.event.ItemListener
0N/A * @since JDK1.1
0N/A */
0N/A public synchronized void removeItemListener(ItemListener l) {
0N/A if (l == null) {
0N/A return;
0N/A }
0N/A itemListener = AWTEventMulticaster.remove(itemListener, l);
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the item listeners
0N/A * registered on this list.
0N/A *
0N/A * @return all of this list's <code>ItemListener</code>s
0N/A * or an empty array if no item
0N/A * listeners are currently registered
0N/A *
0N/A * @see #addItemListener
0N/A * @see #removeItemListener
0N/A * @see java.awt.event.ItemEvent
0N/A * @see java.awt.event.ItemListener
0N/A * @since 1.4
0N/A */
0N/A public synchronized ItemListener[] getItemListeners() {
0N/A return (ItemListener[])(getListeners(ItemListener.class));
0N/A }
0N/A
0N/A /**
0N/A * Adds the specified action listener to receive action events from
0N/A * this list. Action events occur when a user double-clicks
0N/A * on a list item or types Enter when the list has the keyboard
0N/A * focus.
0N/A * <p>
0N/A * If listener <code>l</code> is <code>null</code>,
0N/A * no exception is thrown and no action is performed.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A *
0N/A * @param l the action listener
0N/A * @see #removeActionListener
0N/A * @see #getActionListeners
0N/A * @see java.awt.event.ActionEvent
0N/A * @see java.awt.event.ActionListener
0N/A * @since JDK1.1
0N/A */
0N/A public synchronized void addActionListener(ActionListener l) {
0N/A if (l == null) {
0N/A return;
0N/A }
0N/A actionListener = AWTEventMulticaster.add(actionListener, l);
0N/A newEventsOnly = true;
0N/A }
0N/A
0N/A /**
0N/A * Removes the specified action listener so that it no longer
0N/A * receives action events from this list. Action events
0N/A * occur when a user double-clicks on a list item.
0N/A * If listener <code>l</code> is <code>null</code>,
0N/A * no exception is thrown and no action is performed.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A *
0N/A * @param l the action listener
0N/A * @see #addActionListener
0N/A * @see #getActionListeners
0N/A * @see java.awt.event.ActionEvent
0N/A * @see java.awt.event.ActionListener
0N/A * @since JDK1.1
0N/A */
0N/A public synchronized void removeActionListener(ActionListener l) {
0N/A if (l == null) {
0N/A return;
0N/A }
0N/A actionListener = AWTEventMulticaster.remove(actionListener, l);
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the action listeners
0N/A * registered on this list.
0N/A *
0N/A * @return all of this list's <code>ActionListener</code>s
0N/A * or an empty array if no action
0N/A * listeners are currently registered
0N/A *
0N/A * @see #addActionListener
0N/A * @see #removeActionListener
0N/A * @see java.awt.event.ActionEvent
0N/A * @see java.awt.event.ActionListener
0N/A * @since 1.4
0N/A */
0N/A public synchronized ActionListener[] getActionListeners() {
0N/A return (ActionListener[])(getListeners(ActionListener.class));
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the objects currently registered
0N/A * as <code><em>Foo</em>Listener</code>s
0N/A * upon this <code>List</code>.
0N/A * <code><em>Foo</em>Listener</code>s are registered using the
0N/A * <code>add<em>Foo</em>Listener</code> method.
0N/A *
0N/A * <p>
0N/A * You can specify the <code>listenerType</code> argument
0N/A * with a class literal, such as
0N/A * <code><em>Foo</em>Listener.class</code>.
0N/A * For example, you can query a
0N/A * <code>List</code> <code>l</code>
0N/A * for its item listeners with the following code:
0N/A *
0N/A * <pre>ItemListener[] ils = (ItemListener[])(l.getListeners(ItemListener.class));</pre>
0N/A *
0N/A * If no such listeners exist, this method returns an empty array.
0N/A *
0N/A * @param listenerType the type of listeners requested; this parameter
0N/A * should specify an interface that descends from
0N/A * <code>java.util.EventListener</code>
0N/A * @return an array of all objects registered as
0N/A * <code><em>Foo</em>Listener</code>s on this list,
0N/A * or an empty array if no such
0N/A * listeners have been added
0N/A * @exception ClassCastException if <code>listenerType</code>
0N/A * doesn't specify a class or interface that implements
0N/A * <code>java.util.EventListener</code>
0N/A *
0N/A * @see #getItemListeners
0N/A * @since 1.3
0N/A */
0N/A public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
0N/A EventListener l = null;
0N/A if (listenerType == ActionListener.class) {
0N/A l = actionListener;
0N/A } else if (listenerType == ItemListener.class) {
0N/A l = itemListener;
0N/A } else {
0N/A return super.getListeners(listenerType);
0N/A }
0N/A return AWTEventMulticaster.getListeners(l, listenerType);
0N/A }
0N/A
0N/A // REMIND: remove when filtering is done at lower level
0N/A boolean eventEnabled(AWTEvent e) {
0N/A switch(e.id) {
0N/A case ActionEvent.ACTION_PERFORMED:
0N/A if ((eventMask & AWTEvent.ACTION_EVENT_MASK) != 0 ||
0N/A actionListener != null) {
0N/A return true;
0N/A }
0N/A return false;
0N/A case ItemEvent.ITEM_STATE_CHANGED:
0N/A if ((eventMask & AWTEvent.ITEM_EVENT_MASK) != 0 ||
0N/A itemListener != null) {
0N/A return true;
0N/A }
0N/A return false;
0N/A default:
0N/A break;
0N/A }
0N/A return super.eventEnabled(e);
0N/A }
0N/A
0N/A /**
0N/A * Processes events on this scrolling list. If an event is
0N/A * an instance of <code>ItemEvent</code>, it invokes the
0N/A * <code>processItemEvent</code> method. Else, if the
0N/A * event is an instance of <code>ActionEvent</code>,
0N/A * it invokes <code>processActionEvent</code>.
0N/A * If the event is not an item event or an action event,
0N/A * it invokes <code>processEvent</code> on the superclass.
0N/A * <p>Note that if the event parameter is <code>null</code>
0N/A * the behavior is unspecified and may result in an
0N/A * exception.
0N/A *
0N/A * @param e the event
0N/A * @see java.awt.event.ActionEvent
0N/A * @see java.awt.event.ItemEvent
0N/A * @see #processActionEvent
0N/A * @see #processItemEvent
0N/A * @since JDK1.1
0N/A */
0N/A protected void processEvent(AWTEvent e) {
0N/A if (e instanceof ItemEvent) {
0N/A processItemEvent((ItemEvent)e);
0N/A return;
0N/A } else if (e instanceof ActionEvent) {
0N/A processActionEvent((ActionEvent)e);
0N/A return;
0N/A }
0N/A super.processEvent(e);
0N/A }
0N/A
0N/A /**
0N/A * Processes item events occurring on this list by
0N/A * dispatching them to any registered
0N/A * <code>ItemListener</code> objects.
0N/A * <p>
0N/A * This method is not called unless item events are
0N/A * enabled for this component. Item events are enabled
0N/A * when one of the following occurs:
0N/A * <p><ul>
0N/A * <li>An <code>ItemListener</code> object is registered
0N/A * via <code>addItemListener</code>.
0N/A * <li>Item events are enabled via <code>enableEvents</code>.
0N/A * </ul>
0N/A * <p>Note that if the event parameter is <code>null</code>
0N/A * the behavior is unspecified and may result in an
0N/A * exception.
0N/A *
0N/A * @param e the item event
0N/A * @see java.awt.event.ItemEvent
0N/A * @see java.awt.event.ItemListener
0N/A * @see #addItemListener
0N/A * @see java.awt.Component#enableEvents
0N/A * @since JDK1.1
0N/A */
0N/A protected void processItemEvent(ItemEvent e) {
0N/A ItemListener listener = itemListener;
0N/A if (listener != null) {
0N/A listener.itemStateChanged(e);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Processes action events occurring on this component
0N/A * by dispatching them to any registered
0N/A * <code>ActionListener</code> objects.
0N/A * <p>
0N/A * This method is not called unless action events are
0N/A * enabled for this component. Action events are enabled
0N/A * when one of the following occurs:
0N/A * <p><ul>
0N/A * <li>An <code>ActionListener</code> object is registered
0N/A * via <code>addActionListener</code>.
0N/A * <li>Action events are enabled via <code>enableEvents</code>.
0N/A * </ul>
0N/A * <p>Note that if the event parameter is <code>null</code>
0N/A * the behavior is unspecified and may result in an
0N/A * exception.
0N/A *
0N/A * @param e the action event
0N/A * @see java.awt.event.ActionEvent
0N/A * @see java.awt.event.ActionListener
0N/A * @see #addActionListener
0N/A * @see java.awt.Component#enableEvents
0N/A * @since JDK1.1
0N/A */
0N/A protected void processActionEvent(ActionEvent e) {
0N/A ActionListener listener = actionListener;
0N/A if (listener != null) {
0N/A listener.actionPerformed(e);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the parameter string representing the state of this
0N/A * scrolling list. This string is useful for debugging.
0N/A * @return the parameter string of this scrolling list
0N/A */
0N/A protected String paramString() {
0N/A return super.paramString() + ",selected=" + getSelectedItem();
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * Not for public use in the future.
0N/A * This method is expected to be retained only as a package
0N/A * private method.
0N/A */
0N/A @Deprecated
0N/A public synchronized void delItems(int start, int end) {
0N/A for (int i = end; i >= start; i--) {
0N/A items.removeElementAt(i);
0N/A }
0N/A ListPeer peer = (ListPeer)this.peer;
0N/A if (peer != null) {
0N/A peer.delItems(start, end);
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * Serialization support. Since the value of the selected
0N/A * field isn't neccessarily up to date we sync it up with the
0N/A * peer before serializing.
0N/A */
0N/A
0N/A /**
0N/A * The <code>List</code> component's
0N/A * Serialized Data Version.
0N/A *
0N/A * @serial
0N/A */
0N/A private int listSerializedDataVersion = 1;
0N/A
0N/A /**
0N/A * Writes default serializable fields to stream. Writes
0N/A * a list of serializable <code>ItemListeners</code>
0N/A * and <code>ActionListeners</code> as optional data.
0N/A * The non-serializable listeners are detected and
0N/A * no attempt is made to serialize them.
0N/A *
0N/A * @serialData <code>null</code> terminated sequence of 0
0N/A * or more pairs; the pair consists of a <code>String</code>
0N/A * and an <code>Object</code>; the <code>String</code>
0N/A * indicates the type of object and is one of the
0N/A * following:
0N/A * <code>itemListenerK</code> indicating an
0N/A * <code>ItemListener</code> object;
0N/A * <code>actionListenerK</code> indicating an
0N/A * <code>ActionListener</code> object
0N/A *
0N/A * @param s the <code>ObjectOutputStream</code> to write
0N/A * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
0N/A * @see java.awt.Component#itemListenerK
0N/A * @see java.awt.Component#actionListenerK
0N/A * @see #readObject(ObjectInputStream)
0N/A */
0N/A private void writeObject(ObjectOutputStream s)
0N/A throws IOException
0N/A {
0N/A synchronized (this) {
0N/A ListPeer peer = (ListPeer)this.peer;
0N/A if (peer != null) {
0N/A selected = peer.getSelectedIndexes();
0N/A }
0N/A }
0N/A s.defaultWriteObject();
0N/A
0N/A AWTEventMulticaster.save(s, itemListenerK, itemListener);
0N/A AWTEventMulticaster.save(s, actionListenerK, actionListener);
0N/A s.writeObject(null);
0N/A }
0N/A
0N/A /**
0N/A * Reads the <code>ObjectInputStream</code> and if it
0N/A * isn't <code>null</code> adds a listener to receive
0N/A * both item events and action events (as specified
0N/A * by the key stored in the stream) fired by the
0N/A * <code>List</code>.
0N/A * Unrecognized keys or values will be ignored.
0N/A *
0N/A * @param s the <code>ObjectInputStream</code> to write
0N/A * @exception HeadlessException if
0N/A * <code>GraphicsEnvironment.isHeadless</code> returns
0N/A * <code>true</code>
0N/A * @see #removeItemListener(ItemListener)
0N/A * @see #addItemListener(ItemListener)
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see #writeObject(ObjectOutputStream)
0N/A */
0N/A private void readObject(ObjectInputStream s)
0N/A throws ClassNotFoundException, IOException, HeadlessException
0N/A {
0N/A GraphicsEnvironment.checkHeadless();
0N/A s.defaultReadObject();
0N/A
0N/A Object keyOrNull;
0N/A while(null != (keyOrNull = s.readObject())) {
0N/A String key = ((String)keyOrNull).intern();
0N/A
0N/A if (itemListenerK == key)
0N/A addItemListener((ItemListener)(s.readObject()));
0N/A
0N/A else if (actionListenerK == key)
0N/A addActionListener((ActionListener)(s.readObject()));
0N/A
0N/A else // skip value for unrecognized key
0N/A s.readObject();
0N/A }
0N/A }
0N/A
0N/A
0N/A/////////////////
0N/A// Accessibility support
0N/A////////////////
0N/A
0N/A
0N/A /**
0N/A * Gets the <code>AccessibleContext</code> associated with this
0N/A * <code>List</code>. For lists, the <code>AccessibleContext</code>
0N/A * takes the form of an <code>AccessibleAWTList</code>.
0N/A * A new <code>AccessibleAWTList</code> instance is created, if necessary.
0N/A *
0N/A * @return an <code>AccessibleAWTList</code> that serves as the
0N/A * <code>AccessibleContext</code> of this <code>List</code>
0N/A * @since 1.3
0N/A */
0N/A public AccessibleContext getAccessibleContext() {
0N/A if (accessibleContext == null) {
0N/A accessibleContext = new AccessibleAWTList();
0N/A }
0N/A return accessibleContext;
0N/A }
0N/A
0N/A /**
0N/A * This class implements accessibility support for the
0N/A * <code>List</code> class. It provides an implementation of the
0N/A * Java Accessibility API appropriate to list user-interface elements.
0N/A * @since 1.3
0N/A */
0N/A protected class AccessibleAWTList extends AccessibleAWTComponent
0N/A implements AccessibleSelection, ItemListener, ActionListener
0N/A {
0N/A /*
0N/A * JDK 1.3 serialVersionUID
0N/A */
0N/A private static final long serialVersionUID = 7924617370136012829L;
0N/A
0N/A public AccessibleAWTList() {
0N/A super();
0N/A List.this.addActionListener(this);
0N/A List.this.addItemListener(this);
0N/A }
0N/A
0N/A public void actionPerformed(ActionEvent event) {
0N/A }
0N/A
0N/A public void itemStateChanged(ItemEvent event) {
0N/A }
0N/A
0N/A /**
0N/A * Get the state set of this object.
0N/A *
0N/A * @return an instance of AccessibleState containing the current state
0N/A * of the object
0N/A * @see AccessibleState
0N/A */
0N/A public AccessibleStateSet getAccessibleStateSet() {
0N/A AccessibleStateSet states = super.getAccessibleStateSet();
0N/A if (List.this.isMultipleMode()) {
0N/A states.add(AccessibleState.MULTISELECTABLE);
0N/A }
0N/A return states;
0N/A }
0N/A
0N/A /**
0N/A * Get the role of this object.
0N/A *
0N/A * @return an instance of AccessibleRole describing the role of the
0N/A * object
0N/A * @see AccessibleRole
0N/A */
0N/A public AccessibleRole getAccessibleRole() {
0N/A return AccessibleRole.LIST;
0N/A }
0N/A
0N/A /**
0N/A * Returns the Accessible child contained at the local coordinate
0N/A * Point, if one exists.
0N/A *
0N/A * @return the Accessible at the specified location, if it exists
0N/A */
0N/A public Accessible getAccessibleAt(Point p) {
0N/A return null; // fredxFIXME Not implemented yet
0N/A }
0N/A
0N/A /**
0N/A * Returns the number of accessible children in the object. If all
0N/A * of the children of this object implement Accessible, than this
0N/A * method should return the number of children of this object.
0N/A *
0N/A * @return the number of accessible children in the object.
0N/A */
0N/A public int getAccessibleChildrenCount() {
0N/A return List.this.getItemCount();
0N/A }
0N/A
0N/A /**
0N/A * Return the nth Accessible child of the object.
0N/A *
0N/A * @param i zero-based index of child
0N/A * @return the nth Accessible child of the object
0N/A */
0N/A public Accessible getAccessibleChild(int i) {
0N/A synchronized(List.this) {
0N/A if (i >= List.this.getItemCount()) {
0N/A return null;
0N/A } else {
0N/A return new AccessibleAWTListChild(List.this, i);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Get the AccessibleSelection associated with this object. In the
0N/A * implementation of the Java Accessibility API for this class,
0N/A * return this object, which is responsible for implementing the
0N/A * AccessibleSelection interface on behalf of itself.
0N/A *
0N/A * @return this object
0N/A */
0N/A public AccessibleSelection getAccessibleSelection() {
0N/A return this;
0N/A }
0N/A
0N/A // AccessibleSelection methods
0N/A
0N/A /**
0N/A * Returns the number of items currently selected.
0N/A * If no items are selected, the return value will be 0.
0N/A *
0N/A * @return the number of items currently selected.
0N/A */
0N/A public int getAccessibleSelectionCount() {
0N/A return List.this.getSelectedIndexes().length;
0N/A }
0N/A
0N/A /**
0N/A * Returns an Accessible representing the specified selected item
0N/A * in the object. If there isn't a selection, or there are
0N/A * fewer items selected than the integer passed in, the return
0N/A * value will be null.
0N/A *
0N/A * @param i the zero-based index of selected items
0N/A * @return an Accessible containing the selected item
0N/A */
0N/A public Accessible getAccessibleSelection(int i) {
0N/A synchronized(List.this) {
0N/A int len = getAccessibleSelectionCount();
0N/A if (i < 0 || i >= len) {
0N/A return null;
0N/A } else {
0N/A return getAccessibleChild(List.this.getSelectedIndexes()[i]);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns true if the current child of this object is selected.
0N/A *
0N/A * @param i the zero-based index of the child in this Accessible
0N/A * object.
0N/A * @see AccessibleContext#getAccessibleChild
0N/A */
0N/A public boolean isAccessibleChildSelected(int i) {
0N/A return List.this.isIndexSelected(i);
0N/A }
0N/A
0N/A /**
0N/A * Adds the specified selected item in the object to the object's
0N/A * selection. If the object supports multiple selections,
0N/A * the specified item is added to any existing selection, otherwise
0N/A * it replaces any existing selection in the object. If the
0N/A * specified item is already selected, this method has no effect.
0N/A *
0N/A * @param i the zero-based index of selectable items
0N/A */
0N/A public void addAccessibleSelection(int i) {
0N/A List.this.select(i);
0N/A }
0N/A
0N/A /**
0N/A * Removes the specified selected item in the object from the object's
0N/A * selection. If the specified item isn't currently selected, this
0N/A * method has no effect.
0N/A *
0N/A * @param i the zero-based index of selectable items
0N/A */
0N/A public void removeAccessibleSelection(int i) {
0N/A List.this.deselect(i);
0N/A }
0N/A
0N/A /**
0N/A * Clears the selection in the object, so that nothing in the
0N/A * object is selected.
0N/A */
0N/A public void clearAccessibleSelection() {
0N/A synchronized(List.this) {
0N/A int selectedIndexes[] = List.this.getSelectedIndexes();
0N/A if (selectedIndexes == null)
0N/A return;
0N/A for (int i = selectedIndexes.length - 1; i >= 0; i--) {
0N/A List.this.deselect(selectedIndexes[i]);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Causes every selected item in the object to be selected
0N/A * if the object supports multiple selections.
0N/A */
0N/A public void selectAllAccessibleSelection() {
0N/A synchronized(List.this) {
0N/A for (int i = List.this.getItemCount() - 1; i >= 0; i--) {
0N/A List.this.select(i);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * This class implements accessibility support for
0N/A * List children. It provides an implementation of the
0N/A * Java Accessibility API appropriate to list children
0N/A * user-interface elements.
0N/A * @since 1.3
0N/A */
0N/A protected class AccessibleAWTListChild extends AccessibleAWTComponent
0N/A implements Accessible
0N/A {
0N/A /*
0N/A * JDK 1.3 serialVersionUID
0N/A */
0N/A private static final long serialVersionUID = 4412022926028300317L;
0N/A
0N/A // [[[FIXME]]] need to finish implementing this!!!
0N/A
0N/A private List parent;
0N/A private int indexInParent;
0N/A
0N/A public AccessibleAWTListChild(List parent, int indexInParent) {
0N/A this.parent = parent;
0N/A this.setAccessibleParent(parent);
0N/A this.indexInParent = indexInParent;
0N/A }
0N/A
0N/A //
0N/A // required Accessible methods
0N/A //
0N/A /**
0N/A * Gets the AccessibleContext for this object. In the
0N/A * implementation of the Java Accessibility API for this class,
0N/A * return this object, which acts as its own AccessibleContext.
0N/A *
0N/A * @return this object
0N/A */
0N/A public AccessibleContext getAccessibleContext() {
0N/A return this;
0N/A }
0N/A
0N/A //
0N/A // required AccessibleContext methods
0N/A //
0N/A
0N/A /**
0N/A * Get the role of this object.
0N/A *
0N/A * @return an instance of AccessibleRole describing the role of
0N/A * the object
0N/A * @see AccessibleRole
0N/A */
0N/A public AccessibleRole getAccessibleRole() {
0N/A return AccessibleRole.LIST_ITEM;
0N/A }
0N/A
0N/A /**
0N/A * Get the state set of this object. The AccessibleStateSet of an
0N/A * object is composed of a set of unique AccessibleState's. A
0N/A * change in the AccessibleStateSet of an object will cause a
0N/A * PropertyChangeEvent to be fired for the
0N/A * ACCESSIBLE_STATE_PROPERTY property.
0N/A *
0N/A * @return an instance of AccessibleStateSet containing the
0N/A * current state set of the object
0N/A * @see AccessibleStateSet
0N/A * @see AccessibleState
0N/A * @see #addPropertyChangeListener
0N/A */
0N/A public AccessibleStateSet getAccessibleStateSet() {
0N/A AccessibleStateSet states = super.getAccessibleStateSet();
0N/A if (parent.isIndexSelected(indexInParent)) {
0N/A states.add(AccessibleState.SELECTED);
0N/A }
0N/A return states;
0N/A }
0N/A
0N/A /**
0N/A * Gets the locale of the component. If the component does not
0N/A * have a locale, then the locale of its parent is returned.
0N/A *
0N/A * @return This component's locale. If this component does not have
0N/A * a locale, the locale of its parent is returned.
0N/A *
0N/A * @exception IllegalComponentStateException
0N/A * If the Component does not have its own locale and has not yet
0N/A * been added to a containment hierarchy such that the locale can
0N/A * be determined from the containing parent.
0N/A */
0N/A public Locale getLocale() {
0N/A return parent.getLocale();
0N/A }
0N/A
0N/A /**
0N/A * Get the 0-based index of this object in its accessible parent.
0N/A *
0N/A * @return the 0-based index of this object in its parent; -1 if
0N/A * this object does not have an accessible parent.
0N/A *
0N/A * @see #getAccessibleParent
0N/A * @see #getAccessibleChildrenCount
0N/A * @see #getAccessibleChild
0N/A */
0N/A public int getAccessibleIndexInParent() {
0N/A return indexInParent;
0N/A }
0N/A
0N/A /**
0N/A * Returns the number of accessible children of the object.
0N/A *
0N/A * @return the number of accessible children of the object.
0N/A */
0N/A public int getAccessibleChildrenCount() {
0N/A return 0; // list elements can't have children
0N/A }
0N/A
0N/A /**
0N/A * Return the specified Accessible child of the object. The
0N/A * Accessible children of an Accessible object are zero-based,
0N/A * so the first child of an Accessible child is at index 0, the
0N/A * second child is at index 1, and so on.
0N/A *
0N/A * @param i zero-based index of child
0N/A * @return the Accessible child of the object
0N/A * @see #getAccessibleChildrenCount
0N/A */
0N/A public Accessible getAccessibleChild(int i) {
0N/A return null; // list elements can't have children
0N/A }
0N/A
0N/A
0N/A //
0N/A // AccessibleComponent delegatation to parent List
0N/A //
0N/A
0N/A /**
0N/A * Get the background color of this object.
0N/A *
0N/A * @return the background color, if supported, of the object;
0N/A * otherwise, null
0N/A * @see #setBackground
0N/A */
0N/A public Color getBackground() {
0N/A return parent.getBackground();
0N/A }
0N/A
0N/A /**
0N/A * Set the background color of this object.
0N/A *
0N/A * @param c the new Color for the background
0N/A * @see #setBackground
0N/A */
0N/A public void setBackground(Color c) {
0N/A parent.setBackground(c);
0N/A }
0N/A
0N/A /**
0N/A * Get the foreground color of this object.
0N/A *
0N/A * @return the foreground color, if supported, of the object;
0N/A * otherwise, null
0N/A * @see #setForeground
0N/A */
0N/A public Color getForeground() {
0N/A return parent.getForeground();
0N/A }
0N/A
0N/A /**
0N/A * Set the foreground color of this object.
0N/A *
0N/A * @param c the new Color for the foreground
0N/A * @see #getForeground
0N/A */
0N/A public void setForeground(Color c) {
0N/A parent.setForeground(c);
0N/A }
0N/A
0N/A /**
0N/A * Get the Cursor of this object.
0N/A *
0N/A * @return the Cursor, if supported, of the object; otherwise, null
0N/A * @see #setCursor
0N/A */
0N/A public Cursor getCursor() {
0N/A return parent.getCursor();
0N/A }
0N/A
0N/A /**
0N/A * Set the Cursor of this object.
0N/A * <p>
0N/A * The method may have no visual effect if the Java platform
0N/A * implementation and/or the native system do not support
0N/A * changing the mouse cursor shape.
0N/A * @param cursor the new Cursor for the object
0N/A * @see #getCursor
0N/A */
0N/A public void setCursor(Cursor cursor) {
0N/A parent.setCursor(cursor);
0N/A }
0N/A
0N/A /**
0N/A * Get the Font of this object.
0N/A *
0N/A * @return the Font,if supported, for the object; otherwise, null
0N/A * @see #setFont
0N/A */
0N/A public Font getFont() {
0N/A return parent.getFont();
0N/A }
0N/A
0N/A /**
0N/A * Set the Font of this object.
0N/A *
0N/A * @param f the new Font for the object
0N/A * @see #getFont
0N/A */
0N/A public void setFont(Font f) {
0N/A parent.setFont(f);
0N/A }
0N/A
0N/A /**
0N/A * Get the FontMetrics of this object.
0N/A *
0N/A * @param f the Font
0N/A * @return the FontMetrics, if supported, the object; otherwise, null
0N/A * @see #getFont
0N/A */
0N/A public FontMetrics getFontMetrics(Font f) {
0N/A return parent.getFontMetrics(f);
0N/A }
0N/A
0N/A /**
0N/A * Determine if the object is enabled. Objects that are enabled
0N/A * will also have the AccessibleState.ENABLED state set in their
0N/A * AccessibleStateSet.
0N/A *
0N/A * @return true if object is enabled; otherwise, false
0N/A * @see #setEnabled
0N/A * @see AccessibleContext#getAccessibleStateSet
0N/A * @see AccessibleState#ENABLED
0N/A * @see AccessibleStateSet
0N/A */
0N/A public boolean isEnabled() {
0N/A return parent.isEnabled();
0N/A }
0N/A
0N/A /**
0N/A * Set the enabled state of the object.
0N/A *
0N/A * @param b if true, enables this object; otherwise, disables it
0N/A * @see #isEnabled
0N/A */
0N/A public void setEnabled(boolean b) {
0N/A parent.setEnabled(b);
0N/A }
0N/A
0N/A /**
0N/A * Determine if the object is visible. Note: this means that the
0N/A * object intends to be visible; however, it may not be
0N/A * showing on the screen because one of the objects that this object
0N/A * is contained by is currently not visible. To determine if an
0N/A * object is showing on the screen, use isShowing().
0N/A * <p>Objects that are visible will also have the
0N/A * AccessibleState.VISIBLE state set in their AccessibleStateSet.
0N/A *
0N/A * @return true if object is visible; otherwise, false
0N/A * @see #setVisible
0N/A * @see AccessibleContext#getAccessibleStateSet
0N/A * @see AccessibleState#VISIBLE
0N/A * @see AccessibleStateSet
0N/A */
0N/A public boolean isVisible() {
0N/A // [[[FIXME]]] needs to work like isShowing() below
0N/A return false;
0N/A // return parent.isVisible();
0N/A }
0N/A
0N/A /**
0N/A * Set the visible state of the object.
0N/A *
0N/A * @param b if true, shows this object; otherwise, hides it
0N/A * @see #isVisible
0N/A */
0N/A public void setVisible(boolean b) {
0N/A // [[[FIXME]]] should scroll to item to make it show!
0N/A parent.setVisible(b);
0N/A }
0N/A
0N/A /**
0N/A * Determine if the object is showing. This is determined by
0N/A * checking the visibility of the object and visibility of the
0N/A * object ancestors.
0N/A * Note: this will return true even if the object is obscured
0N/A * by another (for example, it to object is underneath a menu
0N/A * that was pulled down).
0N/A *
0N/A * @return true if object is showing; otherwise, false
0N/A */
0N/A public boolean isShowing() {
0N/A // [[[FIXME]]] only if it's showing!!!
0N/A return false;
0N/A // return parent.isShowing();
0N/A }
0N/A
0N/A /**
0N/A * Checks whether the specified point is within this object's
0N/A * bounds, where the point's x and y coordinates are defined to
0N/A * be relative to the coordinate system of the object.
0N/A *
0N/A * @param p the Point relative to the coordinate system of the
0N/A * object
0N/A * @return true if object contains Point; otherwise false
0N/A * @see #getBounds
0N/A */
0N/A public boolean contains(Point p) {
0N/A // [[[FIXME]]] - only if p is within the list element!!!
0N/A return false;
0N/A // return parent.contains(p);
0N/A }
0N/A
0N/A /**
0N/A * Returns the location of the object on the screen.
0N/A *
0N/A * @return location of object on screen; null if this object
0N/A * is not on the screen
0N/A * @see #getBounds
0N/A * @see #getLocation
0N/A */
0N/A public Point getLocationOnScreen() {
0N/A // [[[FIXME]]] sigh
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Gets the location of the object relative to the parent in the
0N/A * form of a point specifying the object's top-left corner in the
0N/A * screen's coordinate space.
0N/A *
0N/A * @return An instance of Point representing the top-left corner of
0N/A * the objects's bounds in the coordinate space of the screen; null
0N/A * if this object or its parent are not on the screen
0N/A * @see #getBounds
0N/A * @see #getLocationOnScreen
0N/A */
0N/A public Point getLocation() {
0N/A // [[[FIXME]]]
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Sets the location of the object relative to the parent.
0N/A * @param p the new position for the top-left corner
0N/A * @see #getLocation
0N/A */
0N/A public void setLocation(Point p) {
0N/A // [[[FIXME]]] maybe - can simply return as no-op
0N/A }
0N/A
0N/A /**
0N/A * Gets the bounds of this object in the form of a Rectangle object.
0N/A * The bounds specify this object's width, height, and location
0N/A * relative to its parent.
0N/A *
0N/A * @return A rectangle indicating this component's bounds; null if
0N/A * this object is not on the screen.
0N/A * @see #contains
0N/A */
0N/A public Rectangle getBounds() {
0N/A // [[[FIXME]]]
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Sets the bounds of this object in the form of a Rectangle
0N/A * object. The bounds specify this object's width, height, and
0N/A * location relative to its parent.
0N/A *
0N/A * @param r rectangle indicating this component's bounds
0N/A * @see #getBounds
0N/A */
0N/A public void setBounds(Rectangle r) {
0N/A // no-op; not supported
0N/A }
0N/A
0N/A /**
0N/A * Returns the size of this object in the form of a Dimension
0N/A * object. The height field of the Dimension object contains this
0N/A * objects's height, and the width field of the Dimension object
0N/A * contains this object's width.
0N/A *
0N/A * @return A Dimension object that indicates the size of this
0N/A * component; null if this object is not on the screen
0N/A * @see #setSize
0N/A */
0N/A public Dimension getSize() {
0N/A // [[[FIXME]]]
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Resizes this object so that it has width and height.
0N/A *
0N/A * @param d - The dimension specifying the new size of the object.
0N/A * @see #getSize
0N/A */
0N/A public void setSize(Dimension d) {
0N/A // not supported; no-op
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>Accessible</code> child, if one exists,
0N/A * contained at the local coordinate <code>Point</code>.
0N/A *
0N/A * @param p the point relative to the coordinate system of this
0N/A * object
0N/A * @return the <code>Accessible</code>, if it exists,
0N/A * at the specified location; otherwise <code>null</code>
0N/A */
0N/A public Accessible getAccessibleAt(Point p) {
0N/A return null; // object cannot have children!
0N/A }
0N/A
0N/A /**
0N/A * Returns whether this object can accept focus or not. Objects
0N/A * that can accept focus will also have the
0N/A * <code>AccessibleState.FOCUSABLE</code> state set in their
0N/A * <code>AccessibleStateSet</code>.
0N/A *
0N/A * @return true if object can accept focus; otherwise false
0N/A * @see AccessibleContext#getAccessibleStateSet
0N/A * @see AccessibleState#FOCUSABLE
0N/A * @see AccessibleState#FOCUSED
0N/A * @see AccessibleStateSet
0N/A */
0N/A public boolean isFocusTraversable() {
0N/A return false; // list element cannot receive focus!
0N/A }
0N/A
0N/A /**
0N/A * Requests focus for this object. If this object cannot accept
0N/A * focus, nothing will happen. Otherwise, the object will attempt
0N/A * to take focus.
0N/A * @see #isFocusTraversable
0N/A */
0N/A public void requestFocus() {
0N/A // nothing to do; a no-op
0N/A }
0N/A
0N/A /**
0N/A * Adds the specified focus listener to receive focus events from
0N/A * this component.
0N/A *
0N/A * @param l the focus listener
0N/A * @see #removeFocusListener
0N/A */
0N/A public void addFocusListener(FocusListener l) {
0N/A // nothing to do; a no-op
0N/A }
0N/A
0N/A /**
0N/A * Removes the specified focus listener so it no longer receives
0N/A * focus events from this component.
0N/A *
0N/A * @param l the focus listener
0N/A * @see #addFocusListener
0N/A */
0N/A public void removeFocusListener(FocusListener l) {
0N/A // nothing to do; a no-op
0N/A }
0N/A
0N/A
0N/A
0N/A } // inner class AccessibleAWTListChild
0N/A
0N/A } // inner class AccessibleAWTList
0N/A
0N/A}