2002-01-22 23:03:04 +01:00
|
|
|
/* Menu.java -- A Java AWT Menu
|
|
|
|
Copyright (C) 1999, 2002 Free Software Foundation, Inc.
|
1999-05-05 13:05:57 +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. */
|
1999-05-05 13:05:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
package java.awt;
|
|
|
|
|
2002-01-22 23:03:04 +01:00
|
|
|
import java.awt.peer.MenuPeer;
|
|
|
|
import java.io.Serializable;
|
2000-07-12 05:32:07 +02:00
|
|
|
import java.util.Vector;
|
2002-01-22 23:03:04 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This class represents a pull down or tear off menu in Java's AWT.
|
|
|
|
*
|
|
|
|
* @author Aaron M. Renn (arenn@urbanophile.com)
|
|
|
|
*/
|
|
|
|
public class Menu extends MenuItem implements MenuContainer, Serializable
|
|
|
|
{
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Static Variables
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Serialization Constant
|
|
|
|
private static final long serialVersionUID = -8809584163345499784L;
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Instance Variables
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @serial The actual items in the menu
|
|
|
|
*/
|
|
|
|
private Vector items = new Vector();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @serial Flag indicating whether or not this menu is a tear off
|
|
|
|
*/
|
|
|
|
private boolean isTearOff;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @serial Indicates whether or not this is a help menu.
|
|
|
|
*/
|
|
|
|
private boolean isHelpMenu;
|
|
|
|
|
|
|
|
// From the serialization spec. FIXME: what should it be?
|
|
|
|
private int menuSerializedDataVersion;
|
|
|
|
|
|
|
|
static final MenuItem separator = new MenuItem("-");
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Constructors
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes a new instance of <code>Menu</code> with no label and that
|
|
|
|
* is not a tearoff;
|
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 HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
2002-01-22 23:03:04 +01:00
|
|
|
*/
|
|
|
|
public
|
|
|
|
Menu()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes a new instance of <code>Menu</code> that is not a tearoff and
|
|
|
|
* that has the specified label.
|
|
|
|
*
|
|
|
|
* @param label The menu label.
|
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 HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
2002-01-22 23:03:04 +01:00
|
|
|
*/
|
|
|
|
public
|
|
|
|
Menu(String label)
|
|
|
|
{
|
|
|
|
this(label, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
2000-07-12 05:32:07 +02:00
|
|
|
|
2002-01-22 23:03:04 +01:00
|
|
|
/**
|
|
|
|
* Initializes a new instance of <code>Menu</code> with the specified
|
|
|
|
* label and tearoff status.
|
|
|
|
*
|
|
|
|
* @param label The label for this menu
|
|
|
|
* @param isTearOff <code>true</code> if this menu is a tear off menu,
|
|
|
|
* <code>false</code> otherwise.
|
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 HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
2002-01-22 23:03:04 +01:00
|
|
|
*/
|
|
|
|
public
|
|
|
|
Menu(String label, boolean isTearOff)
|
|
|
|
{
|
|
|
|
super(label);
|
|
|
|
|
|
|
|
this.isTearOff = isTearOff;
|
|
|
|
|
|
|
|
if (label.equals("Help"))
|
|
|
|
isHelpMenu = true;
|
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 (GraphicsEnvironment.isHeadless())
|
|
|
|
throw new HeadlessException ();
|
1999-05-05 13:05:57 +02:00
|
|
|
}
|
2002-01-22 23:03:04 +01:00
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Instance Methods
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests whether or not this menu is a tearoff.
|
|
|
|
*
|
|
|
|
* @return <code>true</code> if this menu is a tearoff, <code>false</code>
|
|
|
|
* otherwise.
|
|
|
|
*/
|
|
|
|
public boolean
|
|
|
|
isTearOff()
|
|
|
|
{
|
|
|
|
return(isTearOff);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the number of items in this menu.
|
|
|
|
*
|
|
|
|
* @return The number of items in this menu.
|
|
|
|
*/
|
|
|
|
public int
|
|
|
|
getItemCount()
|
|
|
|
{
|
|
|
|
return(items.size());
|
|
|
|
}
|
2003-02-15 10:21:55 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the number of items in this menu.
|
|
|
|
*
|
|
|
|
* @return The number of items in this menu.
|
|
|
|
*
|
|
|
|
* @deprecated As of JDK 1.1, replaced by getItemCount().
|
|
|
|
*/
|
|
|
|
public int countItems ()
|
|
|
|
{
|
|
|
|
return getItemCount ();
|
|
|
|
}
|
2002-01-22 23:03:04 +01:00
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the item at the specified index.
|
|
|
|
*
|
|
|
|
* @return The item at the specified index.
|
|
|
|
*
|
|
|
|
* @exception ArrayIndexOutOfBoundsException If the index value is not valid.
|
|
|
|
*/
|
|
|
|
public MenuItem
|
|
|
|
getItem(int index)
|
|
|
|
{
|
|
|
|
return((MenuItem)items.elementAt(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the specified item to this menu. If it was previously part of
|
|
|
|
* another menu, it is first removed from that menu.
|
|
|
|
*
|
|
|
|
* @param item The new item to add.
|
|
|
|
*
|
|
|
|
* @return The item that was added.
|
|
|
|
*/
|
|
|
|
public MenuItem
|
|
|
|
add(MenuItem item)
|
|
|
|
{
|
|
|
|
items.addElement(item);
|
|
|
|
if (item.parent != null)
|
|
|
|
{
|
|
|
|
item.parent.remove(item);
|
|
|
|
}
|
|
|
|
item.parent = this;
|
|
|
|
|
|
|
|
if (peer != null)
|
|
|
|
{
|
|
|
|
MenuPeer mp = (MenuPeer) peer;
|
|
|
|
mp.addItem(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an item with the specified label to this menu.
|
|
|
|
*
|
|
|
|
* @param label The label of the menu item to add.
|
|
|
|
*/
|
|
|
|
public void
|
|
|
|
add(String label)
|
|
|
|
{
|
|
|
|
add(new MenuItem(label));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inserts the specified menu item into this menu at the specified index.
|
|
|
|
*
|
|
|
|
* @param item The menu item to add.
|
|
|
|
* @param index The index of the menu item.
|
|
|
|
*
|
|
|
|
* XXX: FIXME
|
|
|
|
*
|
|
|
|
* @exception IllegalArgumentException If the index is less than zero.
|
|
|
|
* @exception ArrayIndexOutOfBoundsException If the index is otherwise invalid.
|
|
|
|
*/
|
|
|
|
public void
|
|
|
|
insert(MenuItem item, int index)
|
|
|
|
{
|
|
|
|
if (index < 0)
|
|
|
|
throw new IllegalArgumentException("Index is less than zero");
|
|
|
|
|
|
|
|
items.insertElementAt(item, index);
|
|
|
|
|
|
|
|
MenuPeer mp = (MenuPeer)getPeer();
|
|
|
|
// FIXME: Need to add a peer method here.
|
|
|
|
// if (mp != null)
|
|
|
|
// mp.insertItem(item, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inserts an item with the specified label into this menu at the specified index.
|
|
|
|
*
|
|
|
|
* @param label The label of the item to add.
|
|
|
|
* @param index The index of the menu item.
|
|
|
|
*
|
|
|
|
* @exception IllegalArgumentException If the index is less than zero.
|
|
|
|
* @exception ArrayIndexOutOfBoundsException If the index is otherwise invalid.
|
|
|
|
*/
|
|
|
|
public void
|
|
|
|
insert(String label, int index)
|
|
|
|
{
|
|
|
|
insert(new MenuItem(label), index);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a separator bar at the current menu location.
|
|
|
|
*/
|
|
|
|
public void
|
|
|
|
addSeparator()
|
|
|
|
{
|
|
|
|
add(separator);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inserts a separator bar at the specified index value.
|
|
|
|
*
|
|
|
|
* @param index The index at which to insert a separator bar.
|
|
|
|
*
|
|
|
|
* XXX: FIXME
|
|
|
|
*
|
|
|
|
* @exception IllegalArgumentException If the index is less than zero.
|
|
|
|
* @exception ArrayIndexOutOfBoundsException If the index is otherwise invalid.
|
|
|
|
*/
|
|
|
|
public void
|
|
|
|
insertSeparator(int index)
|
|
|
|
{
|
|
|
|
insert(separator, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes the item at the specified index from this menu.
|
|
|
|
*
|
|
|
|
* @param index The index of the item to remove.
|
|
|
|
*
|
|
|
|
* @exception ArrayIndexOutOfBoundsException If the index is otherwise invalid.
|
|
|
|
*/
|
|
|
|
public synchronized void
|
|
|
|
remove(int index)
|
|
|
|
{
|
|
|
|
items.removeElementAt(index);
|
|
|
|
|
|
|
|
MenuPeer mp = (MenuPeer)getPeer();
|
|
|
|
if (mp != null)
|
|
|
|
mp.delItem(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the specifed item from the menu. If the specified component
|
|
|
|
* does not exist, this method does nothing. // FIXME: Right?
|
|
|
|
*
|
|
|
|
* @param item The component to remove.
|
|
|
|
*/
|
|
|
|
public void
|
|
|
|
remove(MenuComponent item)
|
|
|
|
{
|
|
|
|
int index = items.indexOf(item);
|
|
|
|
if (index == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
remove(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes all the elements from this menu.
|
|
|
|
*/
|
|
|
|
public synchronized void
|
|
|
|
removeAll()
|
|
|
|
{
|
|
|
|
int count = getItemCount();
|
|
|
|
for(int i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
// We must always remove item 0.
|
|
|
|
remove(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the native peer for this object.
|
|
|
|
*/
|
|
|
|
public void
|
|
|
|
addNotify()
|
|
|
|
{
|
|
|
|
if (peer != null)
|
|
|
|
peer = getToolkit().createMenu(this);
|
|
|
|
super.addNotify ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroys the native peer for this object.
|
|
|
|
*/
|
|
|
|
public void
|
|
|
|
removeNotify()
|
|
|
|
{
|
|
|
|
super.removeNotify();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a debugging string for this menu.
|
|
|
|
*
|
|
|
|
* @return A debugging string for this menu.
|
|
|
|
*/
|
|
|
|
public String
|
|
|
|
paramString()
|
|
|
|
{
|
|
|
|
return (",isTearOff=" + isTearOff + ",isHelpMenu=" + isHelpMenu
|
|
|
|
+ super.paramString());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Accessibility API not yet implemented.
|
|
|
|
// public AccessibleContext getAccessibleContext()
|
|
|
|
|
|
|
|
} // class Menu
|