0N/A/*
2362N/A * Copyright (c) 1995, 2008, 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.*;
0N/Aimport java.awt.peer.ChoicePeer;
0N/Aimport java.awt.event.*;
0N/Aimport java.util.EventListener;
0N/Aimport java.io.ObjectOutputStream;
0N/Aimport java.io.ObjectInputStream;
0N/Aimport java.io.IOException;
0N/A
0N/Aimport javax.accessibility.*;
0N/A
0N/A/**
0N/A * The <code>Choice</code> class presents a pop-up menu of choices.
0N/A * The current choice is displayed as the title of the menu.
0N/A * <p>
0N/A * The following code example produces a pop-up menu:
0N/A * <p>
0N/A * <hr><blockquote><pre>
0N/A * Choice ColorChooser = new Choice();
0N/A * ColorChooser.add("Green");
0N/A * ColorChooser.add("Red");
0N/A * ColorChooser.add("Blue");
0N/A * </pre></blockquote><hr>
0N/A * <p>
0N/A * After this choice menu has been added to a panel,
0N/A * it appears as follows in its normal state:
0N/A * <p>
0N/A * <img src="doc-files/Choice-1.gif" alt="The following text describes the graphic"
0N/A * ALIGN=center HSPACE=10 VSPACE=7>
0N/A * <p>
0N/A * In the picture, <code>"Green"</code> is the current choice.
0N/A * Pushing the mouse button down on the object causes a menu to
0N/A * appear with the current choice highlighted.
0N/A * <p>
0N/A * Some native platforms do not support arbitrary resizing of
0N/A * <code>Choice</code> components and the behavior of
0N/A * <code>setSize()/getSize()</code> is bound by
0N/A * such limitations.
0N/A * Native GUI <code>Choice</code> components' size are often bound by such
0N/A * attributes as font size and length of items contained within
0N/A * the <code>Choice</code>.
0N/A * <p>
0N/A * @author Sami Shaio
0N/A * @author Arthur van Hoff
0N/A * @since JDK1.0
0N/A */
0N/Apublic class Choice extends Component implements ItemSelectable, Accessible {
0N/A /**
0N/A * The items for the <code>Choice</code>.
0N/A * This can be a <code>null</code> value.
0N/A * @serial
0N/A * @see #add(String)
0N/A * @see #addItem(String)
0N/A * @see #getItem(int)
0N/A * @see #getItemCount()
0N/A * @see #insert(String, int)
0N/A * @see #remove(String)
0N/A */
0N/A Vector pItems;
0N/A
0N/A /**
0N/A * The index of the current choice for this <code>Choice</code>
0N/A * or -1 if nothing is selected.
0N/A * @serial
0N/A * @see #getSelectedItem()
0N/A * @see #select(int)
0N/A */
0N/A int selectedIndex = -1;
0N/A
0N/A transient ItemListener itemListener;
0N/A
0N/A private static final String base = "choice";
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 = -4075310674757313071L;
0N/A
0N/A /**
0N/A * Creates a new choice menu. The menu initially has no items in it.
0N/A * <p>
0N/A * By default, the first item added to the choice menu becomes the
0N/A * selected item, until a different selection is made by the user
0N/A * by calling one of the <code>select</code> methods.
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see #select(int)
0N/A * @see #select(java.lang.String)
0N/A */
0N/A public Choice() throws HeadlessException {
0N/A GraphicsEnvironment.checkHeadless();
0N/A pItems = new Vector();
0N/A }
0N/A
0N/A /**
0N/A * Constructs 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 (Choice.class) {
0N/A return base + nameCounter++;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Creates the <code>Choice</code>'s peer. This peer allows us
0N/A * to change the look
0N/A * of the <code>Choice</code> without changing its functionality.
0N/A * @see java.awt.Toolkit#createChoice(java.awt.Choice)
0N/A * @see java.awt.Component#getToolkit()
0N/A */
0N/A public void addNotify() {
0N/A synchronized (getTreeLock()) {
0N/A if (peer == null)
0N/A peer = getToolkit().createChoice(this);
0N/A super.addNotify();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the number of items in this <code>Choice</code> menu.
0N/A * @return the number of items in this <code>Choice</code> menu
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 pItems.size();
0N/A }
0N/A
0N/A /**
0N/A * Gets the string at the specified index in this
0N/A * <code>Choice</code> menu.
0N/A * @param index the index at which to begin
0N/A * @see #getItemCount
0N/A */
0N/A public String getItem(int index) {
0N/A return getItemImpl(index);
0N/A }
0N/A
0N/A /*
0N/A * This is called by the native code, so client code can't
0N/A * be called on the toolkit thread.
0N/A */
0N/A final String getItemImpl(int index) {
0N/A return (String)pItems.elementAt(index);
0N/A }
0N/A
0N/A /**
0N/A * Adds an item to this <code>Choice</code> menu.
0N/A * @param item the item to be added
0N/A * @exception NullPointerException if the item's value is
0N/A * <code>null</code>
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 * Obsolete as of Java 2 platform v1.1. Please use the
0N/A * <code>add</code> method instead.
0N/A * <p>
0N/A * Adds an item to this <code>Choice</code> menu.
0N/A * @param item the item to be added
0N/A * @exception NullPointerException if the item's value is equal to
0N/A * <code>null</code>
0N/A */
0N/A public void addItem(String item) {
0N/A synchronized (this) {
0N/A insertNoInvalidate(item, pItems.size());
0N/A }
0N/A
0N/A // This could change the preferred size of the Component.
555N/A invalidateIfValid();
0N/A }
0N/A
0N/A /**
0N/A * Inserts an item to this <code>Choice</code>,
0N/A * but does not invalidate the <code>Choice</code>.
0N/A * Client methods must provide their own synchronization before
0N/A * invoking this method.
0N/A * @param item the item to be added
0N/A * @param index the new item position
0N/A * @exception NullPointerException if the item's value is equal to
0N/A * <code>null</code>
0N/A */
0N/A private void insertNoInvalidate(String item, int index) {
0N/A if (item == null) {
0N/A throw new
0N/A NullPointerException("cannot add null item to Choice");
0N/A }
0N/A pItems.insertElementAt(item, index);
0N/A ChoicePeer peer = (ChoicePeer)this.peer;
0N/A if (peer != null) {
872N/A peer.add(item, index);
0N/A }
0N/A // no selection or selection shifted up
0N/A if (selectedIndex < 0 || selectedIndex >= index) {
0N/A select(0);
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Inserts the item into this choice at the specified position.
0N/A * Existing items at an index greater than or equal to
0N/A * <code>index</code> are shifted up by one to accommodate
0N/A * the new item. If <code>index</code> is greater than or
0N/A * equal to the number of items in this choice,
0N/A * <code>item</code> is added to the end of this choice.
0N/A * <p>
0N/A * If the item is the first one being added to the choice,
0N/A * then the item becomes selected. Otherwise, if the
0N/A * selected item was one of the items shifted, the first
0N/A * item in the choice becomes the selected item. If the
0N/A * selected item was no among those shifted, it remains
0N/A * the selected item.
0N/A * @param item the non-<code>null</code> item to be inserted
0N/A * @param index the position at which the item should be inserted
0N/A * @exception IllegalArgumentException if index is less than 0
0N/A */
0N/A public void insert(String item, int index) {
0N/A synchronized (this) {
0N/A if (index < 0) {
0N/A throw new IllegalArgumentException("index less than zero.");
0N/A }
0N/A /* if the index greater than item count, add item to the end */
0N/A index = Math.min(index, pItems.size());
0N/A
0N/A insertNoInvalidate(item, index);
0N/A }
0N/A
0N/A // This could change the preferred size of the Component.
555N/A invalidateIfValid();
0N/A }
0N/A
0N/A /**
0N/A * Removes the first occurrence of <code>item</code>
0N/A * from the <code>Choice</code> menu. If the item
0N/A * being removed is the currently selected item,
0N/A * then the first item in the choice becomes the
0N/A * selected item. Otherwise, the currently selected
0N/A * item remains selected (and the selected index is
0N/A * updated accordingly).
0N/A * @param item the item to remove from this <code>Choice</code> menu
0N/A * @exception IllegalArgumentException if the item doesn't
0N/A * exist in the choice menu
0N/A * @since JDK1.1
0N/A */
0N/A public void remove(String item) {
0N/A synchronized (this) {
0N/A int index = pItems.indexOf(item);
0N/A if (index < 0) {
0N/A throw new IllegalArgumentException("item " + item +
0N/A " not found in choice");
0N/A } else {
0N/A removeNoInvalidate(index);
0N/A }
0N/A }
0N/A
0N/A // This could change the preferred size of the Component.
555N/A invalidateIfValid();
0N/A }
0N/A
0N/A /**
0N/A * Removes an item from the choice menu
0N/A * at the specified position. If the item
0N/A * being removed is the currently selected item,
0N/A * then the first item in the choice becomes the
0N/A * selected item. Otherwise, the currently selected
0N/A * item remains selected (and the selected index is
0N/A * updated accordingly).
0N/A * @param position the position of the item
0N/A * @throws IndexOutOfBoundsException if the specified
0N/A * position is out of bounds
0N/A * @since JDK1.1
0N/A */
0N/A public void remove(int position) {
0N/A synchronized (this) {
0N/A removeNoInvalidate(position);
0N/A }
0N/A
0N/A // This could change the preferred size of the Component.
555N/A invalidateIfValid();
0N/A }
0N/A
0N/A /**
0N/A * Removes an item from the <code>Choice</code> at the
0N/A * specified position, but does not invalidate the <code>Choice</code>.
0N/A * Client methods must provide their
0N/A * own synchronization before invoking this method.
0N/A * @param position the position of the item
0N/A */
0N/A private void removeNoInvalidate(int position) {
0N/A pItems.removeElementAt(position);
0N/A ChoicePeer peer = (ChoicePeer)this.peer;
0N/A if (peer != null) {
0N/A peer.remove(position);
0N/A }
0N/A /* Adjust selectedIndex if selected item was removed. */
0N/A if (pItems.size() == 0) {
0N/A selectedIndex = -1;
0N/A } else if (selectedIndex == position) {
0N/A select(0);
0N/A } else if (selectedIndex > position) {
0N/A select(selectedIndex-1);
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Removes all items from the choice menu.
0N/A * @see #remove
0N/A * @since JDK1.1
0N/A */
0N/A public void removeAll() {
0N/A synchronized (this) {
0N/A if (peer != null) {
0N/A ((ChoicePeer)peer).removeAll();
0N/A }
0N/A pItems.removeAllElements();
0N/A selectedIndex = -1;
0N/A }
0N/A
0N/A // This could change the preferred size of the Component.
555N/A invalidateIfValid();
0N/A }
0N/A
0N/A /**
0N/A * Gets a representation of the current choice as a string.
0N/A * @return a string representation of the currently
0N/A * selected item in this choice menu
0N/A * @see #getSelectedIndex
0N/A */
0N/A public synchronized String getSelectedItem() {
0N/A return (selectedIndex >= 0) ? getItem(selectedIndex) : null;
0N/A }
0N/A
0N/A /**
0N/A * Returns an array (length 1) containing the currently selected
0N/A * item. If this choice has no items, returns <code>null</code>.
0N/A * @see ItemSelectable
0N/A */
0N/A public synchronized Object[] getSelectedObjects() {
0N/A if (selectedIndex >= 0) {
0N/A Object[] items = new Object[1];
0N/A items[0] = getItem(selectedIndex);
0N/A return items;
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Returns the index of the currently selected item.
0N/A * If nothing is selected, returns -1.
0N/A *
0N/A * @return the index of the currently selected item, or -1 if nothing
0N/A * is currently selected
0N/A * @see #getSelectedItem
0N/A */
0N/A public int getSelectedIndex() {
0N/A return selectedIndex;
0N/A }
0N/A
0N/A /**
0N/A * Sets the selected item in this <code>Choice</code> menu to be the
0N/A * item at the specified position.
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 pos the positon of the selected item
0N/A * @exception IllegalArgumentException if the specified
0N/A * position is greater than the
0N/A * number of items or less than zero
0N/A * @see #getSelectedItem
0N/A * @see #getSelectedIndex
0N/A */
0N/A public synchronized void select(int pos) {
0N/A if ((pos >= pItems.size()) || (pos < 0)) {
0N/A throw new IllegalArgumentException("illegal Choice item position: " + pos);
0N/A }
0N/A if (pItems.size() > 0) {
0N/A selectedIndex = pos;
0N/A ChoicePeer peer = (ChoicePeer)this.peer;
0N/A if (peer != null) {
0N/A peer.select(pos);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the selected item in this <code>Choice</code> menu
0N/A * to be the item whose name is equal to the specified string.
0N/A * If more than one item matches (is equal to) the specified string,
0N/A * the one with the smallest index is selected.
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 str the specified string
0N/A * @see #getSelectedItem
0N/A * @see #getSelectedIndex
0N/A */
0N/A public synchronized void select(String str) {
0N/A int index = pItems.indexOf(str);
0N/A if (index >= 0) {
0N/A select(index);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Adds the specified item listener to receive item events from
0N/A * this <code>Choice</code> menu. Item events are sent in response
0N/A * to user input, but not in response to calls to <code>select</code>.
0N/A * If l is <code>null</code>, no exception is thrown and no action
0N/A * 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 * @param l the item listener
0N/A * @see #removeItemListener
0N/A * @see #getItemListeners
0N/A * @see #select
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 receives
0N/A * item events from this <code>Choice</code> menu.
0N/A * If l is <code>null</code>, no exception is thrown and no
0N/A * 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 * @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 choice.
0N/A *
0N/A * @return all of this choice'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 * Returns an array of all the objects currently registered
0N/A * as <code><em>Foo</em>Listener</code>s
0N/A * upon this <code>Choice</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>Choice</code> <code>c</code>
0N/A * for its item listeners with the following code:
0N/A *
0N/A * <pre>ItemListener[] ils = (ItemListener[])(c.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 choice,
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 == 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 if (e.id == 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 }
0N/A return super.eventEnabled(e);
0N/A }
0N/A
0N/A /**
0N/A * Processes events on this choice. If the event is an
0N/A * instance of <code>ItemEvent</code>, it invokes the
0N/A * <code>processItemEvent</code> method. Otherwise, it calls its
0N/A * superclass's <code>processEvent</code> method.
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.ItemEvent
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 }
0N/A super.processEvent(e);
0N/A }
0N/A
0N/A /**
0N/A * Processes item events occurring on this <code>Choice</code>
0N/A * menu by 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(ItemListener)
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 * Returns a string representing the state of this <code>Choice</code>
0N/A * menu. This method is intended to be used only for debugging purposes,
0N/A * and the content and format of the returned string may vary between
0N/A * implementations. The returned string may be empty but may not be
0N/A * <code>null</code>.
0N/A *
0N/A * @return the parameter string of this <code>Choice</code> menu
0N/A */
0N/A protected String paramString() {
0N/A return super.paramString() + ",current=" + getSelectedItem();
0N/A }
0N/A
0N/A
0N/A /* Serialization support.
0N/A */
0N/A
0N/A /*
0N/A * Choice Serial Data Version.
0N/A * @serial
0N/A */
0N/A private int choiceSerializedDataVersion = 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 * as optional data. The non-serializable
0N/A * <code>ItemListeners</code> are detected and
0N/A * no attempt is made to serialize them.
0N/A *
0N/A * @param s the <code>ObjectOutputStream</code> to write
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> indicates
0N/A * the type of object and is one of the following:
0N/A * <code>itemListenerK</code> indicating an
0N/A * <code>ItemListener</code> object
0N/A *
0N/A * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
0N/A * @see java.awt.Component#itemListenerK
0N/A * @see #readObject(ObjectInputStream)
0N/A */
0N/A private void writeObject(ObjectOutputStream s)
0N/A throws java.io.IOException
0N/A {
0N/A s.defaultWriteObject();
0N/A
0N/A AWTEventMulticaster.save(s, itemListenerK, itemListener);
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 * item events fired by the <code>Choice</code> item.
0N/A * Unrecognized keys or values will be ignored.
0N/A *
0N/A * @param s the <code>ObjectInputStream</code> to read
0N/A * @exception HeadlessException if
0N/A * <code>GraphicsEnvironment.isHeadless</code> returns
0N/A * <code>true</code>
0N/A * @serial
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 // 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>Choice</code>. For <code>Choice</code> components,
0N/A * the <code>AccessibleContext</code> takes the form of an
0N/A * <code>AccessibleAWTChoice</code>. A new <code>AccessibleAWTChoice</code>
0N/A * instance is created if necessary.
0N/A *
0N/A * @return an <code>AccessibleAWTChoice</code> that serves as the
0N/A * <code>AccessibleContext</code> of this <code>Choice</code>
0N/A * @since 1.3
0N/A */
0N/A public AccessibleContext getAccessibleContext() {
0N/A if (accessibleContext == null) {
0N/A accessibleContext = new AccessibleAWTChoice();
0N/A }
0N/A return accessibleContext;
0N/A }
0N/A
0N/A /**
0N/A * This class implements accessibility support for the
0N/A * <code>Choice</code> class. It provides an implementation of the
0N/A * Java Accessibility API appropriate to choice user-interface elements.
0N/A * @since 1.3
0N/A */
0N/A protected class AccessibleAWTChoice extends AccessibleAWTComponent
0N/A implements AccessibleAction
0N/A {
0N/A /*
0N/A * JDK 1.3 serialVersionUID
0N/A */
0N/A private static final long serialVersionUID = 7175603582428509322L;
0N/A
0N/A public AccessibleAWTChoice() {
0N/A super();
0N/A }
0N/A
0N/A /**
0N/A * Get the AccessibleAction 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 * AccessibleAction interface on behalf of itself.
0N/A *
0N/A * @return this object
0N/A * @see AccessibleAction
0N/A */
0N/A public AccessibleAction getAccessibleAction() {
0N/A return this;
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.COMBO_BOX;
0N/A }
0N/A
0N/A /**
0N/A * Returns the number of accessible actions available in this object
0N/A * If there are more than one, the first one is considered the "default"
0N/A * action of the object.
0N/A *
0N/A * @return the zero-based number of Actions in this object
0N/A */
0N/A public int getAccessibleActionCount() {
0N/A return 0; // To be fully implemented in a future release
0N/A }
0N/A
0N/A /**
0N/A * Returns a description of the specified action of the object.
0N/A *
0N/A * @param i zero-based index of the actions
0N/A * @return a String description of the action
0N/A * @see #getAccessibleActionCount
0N/A */
0N/A public String getAccessibleActionDescription(int i) {
0N/A return null; // To be fully implemented in a future release
0N/A }
0N/A
0N/A /**
0N/A * Perform the specified Action on the object
0N/A *
0N/A * @param i zero-based index of actions
0N/A * @return true if the action was performed; otherwise false.
0N/A * @see #getAccessibleActionCount
0N/A */
0N/A public boolean doAccessibleAction(int i) {
0N/A return false; // To be fully implemented in a future release
0N/A }
0N/A
0N/A } // inner class AccessibleAWTChoice
0N/A
0N/A}