2002-01-22 23:03:04 +01:00
|
|
|
/* Choice.java -- Java choice button widget.
|
|
|
|
Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
2000-08-03 14:09:41 +02:00
|
|
|
|
2002-01-22 23:03:04 +01:00
|
|
|
This file is part of GNU Classpath.
|
|
|
|
|
|
|
|
GNU Classpath is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
GNU Classpath is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GNU Classpath; see the file COPYING. If not, write to the
|
|
|
|
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
|
|
02111-1307 USA.
|
|
|
|
|
2002-01-22 23:58:09 +01:00
|
|
|
Linking this library statically or dynamically with other modules is
|
|
|
|
making a combined work based on this library. Thus, the terms and
|
|
|
|
conditions of the GNU General Public License cover the whole
|
|
|
|
combination.
|
|
|
|
|
|
|
|
As a special exception, the copyright holders of this library give you
|
|
|
|
permission to link this library with independent modules to produce an
|
|
|
|
executable, regardless of the license terms of these independent
|
|
|
|
modules, and to copy and distribute the resulting executable under
|
|
|
|
terms of your choice, provided that you also meet, for each linked
|
|
|
|
independent module, the terms and conditions of the license of that
|
|
|
|
module. An independent module is a module which is not derived from
|
|
|
|
or based on this library. If you modify this library, you may extend
|
|
|
|
this exception to your version of the library, but you are not
|
|
|
|
obligated to do so. If you do not wish to do so, delete this
|
|
|
|
exception statement from your version. */
|
2000-08-03 14:09:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
package java.awt;
|
2002-01-22 23:03:04 +01:00
|
|
|
|
|
|
|
import java.awt.event.ItemEvent;
|
|
|
|
import java.awt.event.ItemListener;
|
Button.java, [...]: New versions from Classpath.
2003-06-05 Michael Koch <konqueror@gmx.de>
* java/awt/Button.java,
java/awt/Checkbox.java,
java/awt/CheckboxMenuItem.java,
java/awt/Choice.java,
java/awt/Container.java,
java/awt/Dialog.java,
java/awt/EventQueue.java,
java/awt/FileDialog.java,
java/awt/Frame.java,
java/awt/Label.java,
java/awt/List.java,
java/awt/Menu.java,
java/awt/MenuItem.java,
java/awt/Panel.java,
java/awt/PopupMenu.java,
java/awt/Rectangle.java,
java/awt/ScrollPane.java,
java/awt/Scrollbar.java,
java/awt/TextArea.java,
java/awt/TextField.java,
java/awt/Window.java,
java/awt/datatransfer/DataFlavor.java,
java/awt/dnd/DragSource.java,
java/awt/dnd/DragSourceContext.java,
java/awt/event/HierarchyEvent.java,
java/awt/event/MouseWheelEvent.java,
java/awt/im/InputContext.java,
java/awt/image/BufferedImage.java,
java/awt/image/ComponentColorModel.java,
java/awt/image/Raster.java,
java/awt/image/WritableRaster.java,
java/awt/peer/ComponentPeer.java,
java/awt/print/PageFormat.java,
java/awt/print/PrinterJob.java:
New versions from Classpath.
From-SVN: r67506
2003-06-05 21:58:40 +02:00
|
|
|
import java.awt.peer.ChoicePeer;
|
2002-01-22 23:03:04 +01:00
|
|
|
import java.io.Serializable;
|
2003-02-15 10:21:55 +01:00
|
|
|
import java.util.EventListener;
|
Button.java, [...]: New versions from Classpath.
2003-06-05 Michael Koch <konqueror@gmx.de>
* java/awt/Button.java,
java/awt/Checkbox.java,
java/awt/CheckboxMenuItem.java,
java/awt/Choice.java,
java/awt/Container.java,
java/awt/Dialog.java,
java/awt/EventQueue.java,
java/awt/FileDialog.java,
java/awt/Frame.java,
java/awt/Label.java,
java/awt/List.java,
java/awt/Menu.java,
java/awt/MenuItem.java,
java/awt/Panel.java,
java/awt/PopupMenu.java,
java/awt/Rectangle.java,
java/awt/ScrollPane.java,
java/awt/Scrollbar.java,
java/awt/TextArea.java,
java/awt/TextField.java,
java/awt/Window.java,
java/awt/datatransfer/DataFlavor.java,
java/awt/dnd/DragSource.java,
java/awt/dnd/DragSourceContext.java,
java/awt/event/HierarchyEvent.java,
java/awt/event/MouseWheelEvent.java,
java/awt/im/InputContext.java,
java/awt/image/BufferedImage.java,
java/awt/image/ComponentColorModel.java,
java/awt/image/Raster.java,
java/awt/image/WritableRaster.java,
java/awt/peer/ComponentPeer.java,
java/awt/print/PageFormat.java,
java/awt/print/PrinterJob.java:
New versions from Classpath.
From-SVN: r67506
2003-06-05 21:58:40 +02:00
|
|
|
import java.util.Vector;
|
2002-01-22 23:03:04 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This class implements a drop down choice list.
|
|
|
|
*
|
|
|
|
* @author Aaron M. Renn (arenn@urbanophile.com)
|
|
|
|
*/
|
|
|
|
public class Choice extends Component implements ItemSelectable, Serializable
|
|
|
|
{
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Static Variables
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Serialization constant
|
|
|
|
private static final long serialVersionUID = -4075310674757313071L;
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Instance Variables
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @serial A list of items for the choice box, which can be <code>null</code>.
|
|
|
|
*/
|
|
|
|
private Vector pItems = new Vector();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @serial The index of the selected item in the choice box.
|
|
|
|
*/
|
|
|
|
private int selectedIndex = -1;
|
|
|
|
|
|
|
|
// Listener chain
|
|
|
|
private ItemListener item_listeners;
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Constructors
|
|
|
|
*/
|
|
|
|
|
Makefile.in: Rebuilt.
* Makefile.in: Rebuilt.
* Makefile.am (rmi_java_source_files): Added RMIClassLoaderSpi.
* java/awt/AlphaComposite.java, java/awt/BasicStroke.java,
java/awt/BufferCapabilities.java, java/awt/Button.java,
java/awt/CheckboxMenuItem.java, java/awt/Choice.java,
java/awt/Container.java, java/awt/Cursor.java,
java/awt/EventQueue.java, java/awt/FileDialog.java,
java/awt/Graphics2D.java, java/awt/Label.java, java/awt/Menu.java,
java/awt/MenuBar.java, java/awt/MenuComponent.java,
java/awt/PopupMenu.java, java/awt/ScrollPane.java,
java/awt/Scrollbar.java, java/awt/TextArea.java,
java/awt/TextField.java, java/awt/color/CMMException.java,
java/awt/color/ColorSpace.java, java/awt/color/ICC_Profile.java,
java/awt/color/ProfileDataException.java,
java/awt/datatransfer/Clipboard.java,
java/awt/datatransfer/DataFlavor.java,
java/awt/datatransfer/FlavorMap.java,
java/awt/datatransfer/SystemFlavorMap.java,
java/awt/dnd/DragGestureEvent.java,
java/awt/dnd/DragGestureRecognizer.java,
java/awt/dnd/DragSource.java, java/awt/dnd/DropTarget.java,
java/awt/event/WindowEvent.java, java/awt/geom/PathIterator.java,
java/awt/im/InputMethodHighlight.java,
java/io/PipedOutputStream.java, java/io/PipedWriter.java,
java/rmi/server/RMIClassLoader.java: Merged from Classpath.
* gnu/awt/j2d/Graphics2DImpl.java (drawImage): Changed type of
`op' to BufferedImageOp.
From-SVN: r60768
2003-01-02 01:14:24 +01:00
|
|
|
/**
|
|
|
|
* Initializes a new instance of <code>Choice</code>.
|
|
|
|
*
|
|
|
|
* @exception HeadlessException If GraphicsEnvironment.isHeadless()
|
|
|
|
* returns true
|
|
|
|
*/
|
|
|
|
public Choice()
|
|
|
|
{
|
|
|
|
if (GraphicsEnvironment.isHeadless())
|
|
|
|
throw new HeadlessException ();
|
|
|
|
}
|
2002-01-22 23:03:04 +01:00
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Instance Methods
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the number of items in the list.
|
|
|
|
*
|
|
|
|
* @return The number of items in the list.
|
|
|
|
*/
|
|
|
|
public int
|
|
|
|
getItemCount()
|
|
|
|
{
|
GtkListPeer.java, [...]: Fix handling of alias methods...
2004-02-03 Thomas Fitzsimmons <fitzsim@redhat.com>
* gnu/java/awt/peer/gtk/GtkListPeer.java,
java/awt/BorderLayout.java, java/awt/CardLayout.java,
java/awt/CheckboxGroup.java, java/awt/Choice.java,
java/awt/Component.java, java/awt/Container.java,
java/awt/FontMetrics.java, java/awt/GridBagLayout.java,
java/awt/LayoutManager2.java, java/awt/List.java,
java/awt/Menu.java, java/awt/MenuBar.java,
java/awt/MenuItem.java, java/awt/Polygon.java,
java/awt/Rectangle.java, java/awt/ScrollPane.java,
java/awt/Scrollbar.java, java/awt/TextArea.java,
java/awt/TextField.java,
java/awt/image/renderable/RenderContext.java,
javax/swing/JApplet.java: Fix handling of alias methods, where a
method has been deprecated in favour of a new one with the same
funtion but a different name. Put the method implementation in
the deprecated method and have the new method call the
deprecated one. Make all other code call the new method.
From-SVN: r77178
2004-02-03 18:10:56 +01:00
|
|
|
return countItems ();
|
2002-01-22 23:03:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the number of items in the list.
|
|
|
|
*
|
|
|
|
* @return The number of items in the list.
|
|
|
|
*
|
|
|
|
* @deprecated This method is deprecated in favor of <code>getItemCount</code>.
|
|
|
|
*/
|
|
|
|
public int
|
|
|
|
countItems()
|
|
|
|
{
|
|
|
|
return(pItems.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the item at the specified index in the list.
|
|
|
|
*
|
|
|
|
* @param index The index into the list to return the item from.
|
|
|
|
*
|
|
|
|
* @exception ArrayIndexOutOfBoundsException If the index is invalid.
|
|
|
|
*/
|
|
|
|
public String
|
|
|
|
getItem(int index)
|
|
|
|
{
|
|
|
|
return((String)pItems.elementAt(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the specified item to this choice box.
|
|
|
|
*
|
|
|
|
* @param item The item to add.
|
Makefile.in: Rebuilt.
* Makefile.in: Rebuilt.
* Makefile.am (rmi_java_source_files): Added RMIClassLoaderSpi.
* java/awt/AlphaComposite.java, java/awt/BasicStroke.java,
java/awt/BufferCapabilities.java, java/awt/Button.java,
java/awt/CheckboxMenuItem.java, java/awt/Choice.java,
java/awt/Container.java, java/awt/Cursor.java,
java/awt/EventQueue.java, java/awt/FileDialog.java,
java/awt/Graphics2D.java, java/awt/Label.java, java/awt/Menu.java,
java/awt/MenuBar.java, java/awt/MenuComponent.java,
java/awt/PopupMenu.java, java/awt/ScrollPane.java,
java/awt/Scrollbar.java, java/awt/TextArea.java,
java/awt/TextField.java, java/awt/color/CMMException.java,
java/awt/color/ColorSpace.java, java/awt/color/ICC_Profile.java,
java/awt/color/ProfileDataException.java,
java/awt/datatransfer/Clipboard.java,
java/awt/datatransfer/DataFlavor.java,
java/awt/datatransfer/FlavorMap.java,
java/awt/datatransfer/SystemFlavorMap.java,
java/awt/dnd/DragGestureEvent.java,
java/awt/dnd/DragGestureRecognizer.java,
java/awt/dnd/DragSource.java, java/awt/dnd/DropTarget.java,
java/awt/event/WindowEvent.java, java/awt/geom/PathIterator.java,
java/awt/im/InputMethodHighlight.java,
java/io/PipedOutputStream.java, java/io/PipedWriter.java,
java/rmi/server/RMIClassLoader.java: Merged from Classpath.
* gnu/awt/j2d/Graphics2DImpl.java (drawImage): Changed type of
`op' to BufferedImageOp.
From-SVN: r60768
2003-01-02 01:14:24 +01:00
|
|
|
*
|
|
|
|
* @exception NullPointerException If the item's value is null
|
|
|
|
*
|
|
|
|
* @since 1.1
|
2002-01-22 23:03:04 +01:00
|
|
|
*/
|
|
|
|
public synchronized void
|
|
|
|
add(String item)
|
|
|
|
{
|
|
|
|
if (item == null)
|
Makefile.in: Rebuilt.
* Makefile.in: Rebuilt.
* Makefile.am (rmi_java_source_files): Added RMIClassLoaderSpi.
* java/awt/AlphaComposite.java, java/awt/BasicStroke.java,
java/awt/BufferCapabilities.java, java/awt/Button.java,
java/awt/CheckboxMenuItem.java, java/awt/Choice.java,
java/awt/Container.java, java/awt/Cursor.java,
java/awt/EventQueue.java, java/awt/FileDialog.java,
java/awt/Graphics2D.java, java/awt/Label.java, java/awt/Menu.java,
java/awt/MenuBar.java, java/awt/MenuComponent.java,
java/awt/PopupMenu.java, java/awt/ScrollPane.java,
java/awt/Scrollbar.java, java/awt/TextArea.java,
java/awt/TextField.java, java/awt/color/CMMException.java,
java/awt/color/ColorSpace.java, java/awt/color/ICC_Profile.java,
java/awt/color/ProfileDataException.java,
java/awt/datatransfer/Clipboard.java,
java/awt/datatransfer/DataFlavor.java,
java/awt/datatransfer/FlavorMap.java,
java/awt/datatransfer/SystemFlavorMap.java,
java/awt/dnd/DragGestureEvent.java,
java/awt/dnd/DragGestureRecognizer.java,
java/awt/dnd/DragSource.java, java/awt/dnd/DropTarget.java,
java/awt/event/WindowEvent.java, java/awt/geom/PathIterator.java,
java/awt/im/InputMethodHighlight.java,
java/io/PipedOutputStream.java, java/io/PipedWriter.java,
java/rmi/server/RMIClassLoader.java: Merged from Classpath.
* gnu/awt/j2d/Graphics2DImpl.java (drawImage): Changed type of
`op' to BufferedImageOp.
From-SVN: r60768
2003-01-02 01:14:24 +01:00
|
|
|
throw new NullPointerException ("item must be non-null");
|
2002-01-22 23:03:04 +01:00
|
|
|
|
|
|
|
pItems.addElement(item);
|
|
|
|
|
|
|
|
int i = pItems.size () - 1;
|
|
|
|
if (peer != null)
|
|
|
|
{
|
|
|
|
ChoicePeer cp = (ChoicePeer) peer;
|
|
|
|
cp.add (item, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
2000-08-03 14:09:41 +02:00
|
|
|
|
2002-01-22 23:03:04 +01:00
|
|
|
/**
|
|
|
|
* Adds the specified item to this choice box.
|
|
|
|
*
|
Makefile.in: Rebuilt.
* Makefile.in: Rebuilt.
* Makefile.am (rmi_java_source_files): Added RMIClassLoaderSpi.
* java/awt/AlphaComposite.java, java/awt/BasicStroke.java,
java/awt/BufferCapabilities.java, java/awt/Button.java,
java/awt/CheckboxMenuItem.java, java/awt/Choice.java,
java/awt/Container.java, java/awt/Cursor.java,
java/awt/EventQueue.java, java/awt/FileDialog.java,
java/awt/Graphics2D.java, java/awt/Label.java, java/awt/Menu.java,
java/awt/MenuBar.java, java/awt/MenuComponent.java,
java/awt/PopupMenu.java, java/awt/ScrollPane.java,
java/awt/Scrollbar.java, java/awt/TextArea.java,
java/awt/TextField.java, java/awt/color/CMMException.java,
java/awt/color/ColorSpace.java, java/awt/color/ICC_Profile.java,
java/awt/color/ProfileDataException.java,
java/awt/datatransfer/Clipboard.java,
java/awt/datatransfer/DataFlavor.java,
java/awt/datatransfer/FlavorMap.java,
java/awt/datatransfer/SystemFlavorMap.java,
java/awt/dnd/DragGestureEvent.java,
java/awt/dnd/DragGestureRecognizer.java,
java/awt/dnd/DragSource.java, java/awt/dnd/DropTarget.java,
java/awt/event/WindowEvent.java, java/awt/geom/PathIterator.java,
java/awt/im/InputMethodHighlight.java,
java/io/PipedOutputStream.java, java/io/PipedWriter.java,
java/rmi/server/RMIClassLoader.java: Merged from Classpath.
* gnu/awt/j2d/Graphics2DImpl.java (drawImage): Changed type of
`op' to BufferedImageOp.
From-SVN: r60768
2003-01-02 01:14:24 +01:00
|
|
|
* This method is oboslete since Java 2 platform 1.1. Please use @see add
|
|
|
|
* instead.
|
|
|
|
*
|
2002-01-22 23:03:04 +01:00
|
|
|
* @param item The item to add.
|
Makefile.in: Rebuilt.
* Makefile.in: Rebuilt.
* Makefile.am (rmi_java_source_files): Added RMIClassLoaderSpi.
* java/awt/AlphaComposite.java, java/awt/BasicStroke.java,
java/awt/BufferCapabilities.java, java/awt/Button.java,
java/awt/CheckboxMenuItem.java, java/awt/Choice.java,
java/awt/Container.java, java/awt/Cursor.java,
java/awt/EventQueue.java, java/awt/FileDialog.java,
java/awt/Graphics2D.java, java/awt/Label.java, java/awt/Menu.java,
java/awt/MenuBar.java, java/awt/MenuComponent.java,
java/awt/PopupMenu.java, java/awt/ScrollPane.java,
java/awt/Scrollbar.java, java/awt/TextArea.java,
java/awt/TextField.java, java/awt/color/CMMException.java,
java/awt/color/ColorSpace.java, java/awt/color/ICC_Profile.java,
java/awt/color/ProfileDataException.java,
java/awt/datatransfer/Clipboard.java,
java/awt/datatransfer/DataFlavor.java,
java/awt/datatransfer/FlavorMap.java,
java/awt/datatransfer/SystemFlavorMap.java,
java/awt/dnd/DragGestureEvent.java,
java/awt/dnd/DragGestureRecognizer.java,
java/awt/dnd/DragSource.java, java/awt/dnd/DropTarget.java,
java/awt/event/WindowEvent.java, java/awt/geom/PathIterator.java,
java/awt/im/InputMethodHighlight.java,
java/io/PipedOutputStream.java, java/io/PipedWriter.java,
java/rmi/server/RMIClassLoader.java: Merged from Classpath.
* gnu/awt/j2d/Graphics2DImpl.java (drawImage): Changed type of
`op' to BufferedImageOp.
From-SVN: r60768
2003-01-02 01:14:24 +01:00
|
|
|
*
|
|
|
|
* @exception NullPointerException If the item's value is equal to null
|
2002-01-22 23:03:04 +01:00
|
|
|
*/
|
|
|
|
public synchronized void
|
|
|
|
addItem(String item)
|
|
|
|
{
|
|
|
|
add(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/** Inserts an item into this Choice. Existing items are shifted
|
|
|
|
* upwards. If the new item is the only item, then it is selected.
|
|
|
|
* If the currently selected item is shifted, then the first item is
|
|
|
|
* selected. If the currently selected item is not shifted, then it
|
|
|
|
* remains selected.
|
|
|
|
*
|
|
|
|
* @param item The item to add.
|
|
|
|
* @param index The index at which the item should be inserted.
|
Makefile.in: Rebuilt.
* Makefile.in: Rebuilt.
* Makefile.am (rmi_java_source_files): Added RMIClassLoaderSpi.
* java/awt/AlphaComposite.java, java/awt/BasicStroke.java,
java/awt/BufferCapabilities.java, java/awt/Button.java,
java/awt/CheckboxMenuItem.java, java/awt/Choice.java,
java/awt/Container.java, java/awt/Cursor.java,
java/awt/EventQueue.java, java/awt/FileDialog.java,
java/awt/Graphics2D.java, java/awt/Label.java, java/awt/Menu.java,
java/awt/MenuBar.java, java/awt/MenuComponent.java,
java/awt/PopupMenu.java, java/awt/ScrollPane.java,
java/awt/Scrollbar.java, java/awt/TextArea.java,
java/awt/TextField.java, java/awt/color/CMMException.java,
java/awt/color/ColorSpace.java, java/awt/color/ICC_Profile.java,
java/awt/color/ProfileDataException.java,
java/awt/datatransfer/Clipboard.java,
java/awt/datatransfer/DataFlavor.java,
java/awt/datatransfer/FlavorMap.java,
java/awt/datatransfer/SystemFlavorMap.java,
java/awt/dnd/DragGestureEvent.java,
java/awt/dnd/DragGestureRecognizer.java,
java/awt/dnd/DragSource.java, java/awt/dnd/DropTarget.java,
java/awt/event/WindowEvent.java, java/awt/geom/PathIterator.java,
java/awt/im/InputMethodHighlight.java,
java/io/PipedOutputStream.java, java/io/PipedWriter.java,
java/rmi/server/RMIClassLoader.java: Merged from Classpath.
* gnu/awt/j2d/Graphics2DImpl.java (drawImage): Changed type of
`op' to BufferedImageOp.
From-SVN: r60768
2003-01-02 01:14:24 +01:00
|
|
|
*
|
|
|
|
* @exception IllegalArgumentException If index is less than 0
|
2000-12-26 01:25:13 +01:00
|
|
|
*/
|
2002-01-22 23:03:04 +01:00
|
|
|
public synchronized void
|
|
|
|
insert(String item, int index)
|
2000-08-03 14:09:41 +02:00
|
|
|
{
|
Makefile.in: Rebuilt.
* Makefile.in: Rebuilt.
* Makefile.am (rmi_java_source_files): Added RMIClassLoaderSpi.
* java/awt/AlphaComposite.java, java/awt/BasicStroke.java,
java/awt/BufferCapabilities.java, java/awt/Button.java,
java/awt/CheckboxMenuItem.java, java/awt/Choice.java,
java/awt/Container.java, java/awt/Cursor.java,
java/awt/EventQueue.java, java/awt/FileDialog.java,
java/awt/Graphics2D.java, java/awt/Label.java, java/awt/Menu.java,
java/awt/MenuBar.java, java/awt/MenuComponent.java,
java/awt/PopupMenu.java, java/awt/ScrollPane.java,
java/awt/Scrollbar.java, java/awt/TextArea.java,
java/awt/TextField.java, java/awt/color/CMMException.java,
java/awt/color/ColorSpace.java, java/awt/color/ICC_Profile.java,
java/awt/color/ProfileDataException.java,
java/awt/datatransfer/Clipboard.java,
java/awt/datatransfer/DataFlavor.java,
java/awt/datatransfer/FlavorMap.java,
java/awt/datatransfer/SystemFlavorMap.java,
java/awt/dnd/DragGestureEvent.java,
java/awt/dnd/DragGestureRecognizer.java,
java/awt/dnd/DragSource.java, java/awt/dnd/DropTarget.java,
java/awt/event/WindowEvent.java, java/awt/geom/PathIterator.java,
java/awt/im/InputMethodHighlight.java,
java/io/PipedOutputStream.java, java/io/PipedWriter.java,
java/rmi/server/RMIClassLoader.java: Merged from Classpath.
* gnu/awt/j2d/Graphics2DImpl.java (drawImage): Changed type of
`op' to BufferedImageOp.
From-SVN: r60768
2003-01-02 01:14:24 +01:00
|
|
|
if (index < 0)
|
|
|
|
throw new IllegalArgumentException ("index may not be less then 0");
|
|
|
|
|
2002-01-22 23:03:04 +01:00
|
|
|
if (index > getItemCount ())
|
|
|
|
index = getItemCount ();
|
|
|
|
|
|
|
|
pItems.insertElementAt(item, index);
|
|
|
|
|
|
|
|
if (peer != null)
|
|
|
|
{
|
|
|
|
ChoicePeer cp = (ChoicePeer) peer;
|
|
|
|
cp.add (item, index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the specified item from the choice box.
|
|
|
|
*
|
|
|
|
* @param item The item to remove.
|
|
|
|
*
|
2002-11-07 14:01:34 +01:00
|
|
|
* @exception IllegalArgumentException If the specified item doesn't exist.
|
2002-01-22 23:03:04 +01:00
|
|
|
*/
|
|
|
|
public synchronized void
|
|
|
|
remove(String item)
|
|
|
|
{
|
|
|
|
int index = pItems.indexOf(item);
|
|
|
|
if (index == -1)
|
|
|
|
throw new IllegalArgumentException ("item \""
|
|
|
|
+ item + "\" not found in Choice");
|
|
|
|
remove(index);
|
2000-08-03 14:09:41 +02:00
|
|
|
}
|
2002-01-22 23:03:04 +01:00
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the item at the specified index from the choice box.
|
|
|
|
*
|
|
|
|
* @param index The index of the item to remove.
|
|
|
|
*
|
2002-11-07 14:01:34 +01:00
|
|
|
* @exception IndexOutOfBoundsException If the index is not valid.
|
2002-01-22 23:03:04 +01:00
|
|
|
*/
|
|
|
|
public synchronized void
|
|
|
|
remove(int index)
|
|
|
|
{
|
2004-01-05 22:18:06 +01:00
|
|
|
if ((index < 0) || (index > getItemCount()))
|
|
|
|
throw new IllegalArgumentException("Bad index: " + index);
|
|
|
|
|
2002-01-22 23:03:04 +01:00
|
|
|
pItems.removeElementAt(index);
|
|
|
|
|
|
|
|
if (peer != null)
|
|
|
|
{
|
|
|
|
ChoicePeer cp = (ChoicePeer) peer;
|
|
|
|
cp.remove (index);
|
|
|
|
}
|
|
|
|
|
2004-01-05 22:18:06 +01:00
|
|
|
if (selectedIndex > index)
|
2002-01-22 23:03:04 +01:00
|
|
|
--selectedIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes all of the objects from this choice box.
|
|
|
|
*/
|
|
|
|
public synchronized void
|
|
|
|
removeAll()
|
|
|
|
{
|
2004-01-05 22:18:06 +01:00
|
|
|
if (getItemCount() <= 0)
|
2003-12-23 20:24:00 +01:00
|
|
|
return;
|
|
|
|
|
2004-01-05 22:18:06 +01:00
|
|
|
pItems.removeAllElements ();
|
2003-12-23 20:24:00 +01:00
|
|
|
|
2004-01-05 22:18:06 +01:00
|
|
|
if (peer != null)
|
2002-01-22 23:03:04 +01:00
|
|
|
{
|
2004-01-05 22:18:06 +01:00
|
|
|
ChoicePeer cp = (ChoicePeer) peer;
|
|
|
|
cp.removeAll ();
|
2002-01-22 23:03:04 +01:00
|
|
|
}
|
2003-12-23 20:24:00 +01:00
|
|
|
|
|
|
|
selectedIndex = -1;
|
2002-01-22 23:03:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the currently selected item, or null if no item is
|
|
|
|
* selected.
|
|
|
|
*
|
|
|
|
* @return The currently selected item.
|
|
|
|
*/
|
|
|
|
public synchronized String
|
|
|
|
getSelectedItem()
|
|
|
|
{
|
|
|
|
return (selectedIndex == -1
|
|
|
|
? null
|
|
|
|
: ((String)pItems.elementAt(selectedIndex)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array with one row containing the selected item.
|
|
|
|
*
|
|
|
|
* @return An array containing the selected item.
|
|
|
|
*/
|
|
|
|
public synchronized Object[]
|
|
|
|
getSelectedObjects()
|
|
|
|
{
|
|
|
|
if (selectedIndex == -1)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
Object[] objs = new Object[1];
|
|
|
|
objs[0] = pItems.elementAt(selectedIndex);
|
|
|
|
|
|
|
|
return(objs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the index of the selected item.
|
|
|
|
*
|
|
|
|
* @return The index of the selected item.
|
|
|
|
*/
|
|
|
|
public int
|
|
|
|
getSelectedIndex()
|
|
|
|
{
|
|
|
|
return(selectedIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Forces the item at the specified index to be selected.
|
|
|
|
*
|
|
|
|
* @param index The index of the row to make selected.
|
|
|
|
*
|
2002-11-07 14:01:34 +01:00
|
|
|
* @exception IllegalArgumentException If the specified index is invalid.
|
2002-01-22 23:03:04 +01:00
|
|
|
*/
|
|
|
|
public synchronized void
|
|
|
|
select(int index)
|
|
|
|
{
|
|
|
|
if ((index < 0) || (index > getItemCount()))
|
|
|
|
throw new IllegalArgumentException("Bad index: " + index);
|
|
|
|
|
|
|
|
this.selectedIndex = index;
|
|
|
|
if (peer != null)
|
|
|
|
{
|
|
|
|
ChoicePeer cp = (ChoicePeer) peer;
|
|
|
|
cp.select (index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Forces the named item to be selected.
|
|
|
|
*
|
|
|
|
* @param item The item to be selected.
|
|
|
|
*
|
|
|
|
* @exception IllegalArgumentException If the specified item does not exist.
|
|
|
|
*/
|
|
|
|
public synchronized void
|
|
|
|
select(String item)
|
|
|
|
{
|
|
|
|
int index = pItems.indexOf(item);
|
|
|
|
if (index >= 0)
|
|
|
|
select(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the native peer for this object.
|
|
|
|
*/
|
|
|
|
public void
|
|
|
|
addNotify()
|
|
|
|
{
|
|
|
|
if (peer == null)
|
|
|
|
peer = getToolkit ().createChoice (this);
|
|
|
|
super.addNotify ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the specified listener to the list of registered listeners for
|
|
|
|
* this object.
|
|
|
|
*
|
|
|
|
* @param listener The listener to add.
|
|
|
|
*/
|
|
|
|
public synchronized void
|
|
|
|
addItemListener(ItemListener listener)
|
|
|
|
{
|
|
|
|
item_listeners = AWTEventMulticaster.add(item_listeners, listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the specified listener from the list of registered listeners for
|
|
|
|
* this object.
|
|
|
|
*
|
|
|
|
* @param listener The listener to remove.
|
|
|
|
*/
|
|
|
|
public synchronized void
|
|
|
|
removeItemListener(ItemListener listener)
|
|
|
|
{
|
|
|
|
item_listeners = AWTEventMulticaster.remove(item_listeners, listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Processes this event by invoking <code>processItemEvent()</code> if the
|
|
|
|
* event is an instance of <code>ItemEvent</code>, otherwise the event
|
|
|
|
* is passed to the superclass.
|
|
|
|
*
|
|
|
|
* @param event The event to process.
|
|
|
|
*/
|
|
|
|
protected void
|
|
|
|
processEvent(AWTEvent event)
|
|
|
|
{
|
|
|
|
if (event instanceof ItemEvent)
|
|
|
|
processItemEvent((ItemEvent)event);
|
|
|
|
else
|
|
|
|
super.processEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Processes item event by dispatching to any registered listeners.
|
|
|
|
*
|
|
|
|
* @param event The event to process.
|
|
|
|
*/
|
|
|
|
protected void
|
|
|
|
processItemEvent(ItemEvent event)
|
|
|
|
{
|
|
|
|
if (item_listeners != null)
|
|
|
|
item_listeners.itemStateChanged(event);
|
|
|
|
}
|
|
|
|
|
2002-03-24 23:37:51 +01:00
|
|
|
void
|
|
|
|
dispatchEventImpl(AWTEvent e)
|
|
|
|
{
|
|
|
|
if (e.id <= ItemEvent.ITEM_LAST
|
|
|
|
&& e.id >= ItemEvent.ITEM_FIRST
|
|
|
|
&& (item_listeners != null
|
|
|
|
|| (eventMask & AWTEvent.ITEM_EVENT_MASK) != 0))
|
|
|
|
processEvent(e);
|
|
|
|
else
|
|
|
|
super.dispatchEventImpl(e);
|
|
|
|
}
|
|
|
|
|
2002-01-22 23:03:04 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a debugging string for this object.
|
|
|
|
*
|
|
|
|
* @return A debugging string for this object.
|
|
|
|
*/
|
|
|
|
protected String
|
|
|
|
paramString()
|
|
|
|
{
|
|
|
|
return ("selectedIndex=" + selectedIndex + "," + super.paramString());
|
|
|
|
}
|
|
|
|
|
2003-02-15 10:21:55 +01:00
|
|
|
/**
|
|
|
|
* Returns an array of all the objects currently registered as FooListeners
|
|
|
|
* upon this Choice. FooListeners are registered using the addFooListener
|
|
|
|
* method.
|
|
|
|
*
|
|
|
|
* @exception ClassCastException If listenerType doesn't specify a class or
|
|
|
|
* interface that implements java.util.EventListener.
|
|
|
|
*
|
|
|
|
* @since 1.3
|
|
|
|
*/
|
|
|
|
public EventListener[] getListeners (Class listenerType)
|
|
|
|
{
|
|
|
|
if (listenerType == ItemListener.class)
|
|
|
|
return AWTEventMulticaster.getListeners (item_listeners, listenerType);
|
|
|
|
|
|
|
|
return super.getListeners (listenerType);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns all registered item listeners.
|
|
|
|
*
|
|
|
|
* @since 1.4
|
|
|
|
*/
|
|
|
|
public ItemListener[] getItemListeners ()
|
|
|
|
{
|
|
|
|
return (ItemListener[]) getListeners (ItemListener.class);
|
|
|
|
}
|
2002-01-22 23:03:04 +01:00
|
|
|
} // class Choice
|