aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/awt/Menu.java
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2002-01-22 22:03:04 +0000
committerTom Tromey <tromey@gcc.gnu.org>2002-01-22 22:03:04 +0000
commitbda145054363dfa5eef640d526542bc6130a56d0 (patch)
tree317e29ad09d5c7d11f21d6999c1e4c2d70eb6650 /libjava/java/awt/Menu.java
parente3b0efd1eeea460b091c1b9b9038605a672b1cb9 (diff)
downloadgcc-bda145054363dfa5eef640d526542bc6130a56d0.zip
gcc-bda145054363dfa5eef640d526542bc6130a56d0.tar.gz
gcc-bda145054363dfa5eef640d526542bc6130a56d0.tar.bz2
ButtonPeer.java: Replace with Classpath version.
* java/awt/peer/ButtonPeer.java: Replace with Classpath version. * java/awt/peer/CanvasPeer.java: Replace with Classpath version. * java/awt/peer/CheckboxMenuItemPeer.java: Replace with Classpath version. * java/awt/peer/CheckboxPeer.java: Replace with Classpath version. * java/awt/peer/ChoicePeer.java: Replace with Classpath version. * java/awt/peer/ComponentPeer.java: Replace with Classpath version. * java/awt/peer/ContainerPeer.java: Replace with Classpath version. * java/awt/peer/DialogPeer.java: Replace with Classpath version. * java/awt/peer/FileDialogPeer.java: Replace with Classpath version. * java/awt/peer/FontPeer.java: Replace with Classpath version. * java/awt/peer/FramePeer.java: Replace with Classpath version. * java/awt/peer/LabelPeer.java: Replace with Classpath version. * java/awt/peer/LightweightPeer.java: Replace with Classpath version. * java/awt/peer/ListPeer.java: Replace with Classpath version. * java/awt/peer/MenuBarPeer.java: Replace with Classpath version. * java/awt/peer/MenuComponentPeer.java: Replace with Classpath version. * java/awt/peer/MenuItemPeer.java: Replace with Classpath version. * java/awt/peer/MenuPeer.java: Replace with Classpath version. * java/awt/peer/PanelPeer.java: Replace with Classpath version. * java/awt/peer/PopupMenuPeer.java: Replace with Classpath version. * java/awt/peer/ScrollPanePeer.java: Replace with Classpath version. * java/awt/peer/ScrollbarPeer.java: Replace with Classpath version. * java/awt/peer/TextAreaPeer.java: Replace with Classpath version. * java/awt/peer/TextComponentPeer.java: Replace with Classpath version. * java/awt/peer/TextFieldPeer.java: Replace with Classpath version. * java/awt/peer/WindowPeer.java: Replace with Classpath version. * gnu/awt/xlib/XPanelPeer.java (insets): New method. * gnu/awt/xlib/XCanvasPeer.java (show, hide): New methods. (minimumSize, preferredSize, reshape): Likewise. * gnu/awt/xlib/XFramePeer.java (insets, enable, disable, getColorModel): New methods. * java/awt/PopupMenu.java: Merged with Classpath. * java/awt/MenuBar.java: Merged with Classpath. * java/awt/SystemColor.java: Replace with Classpath version. * java/awt/Panel.java: Merged with Classpath. * java/awt/PaintContext.java: Updated copyright. * java/awt/MenuShortcut.java: Merged with Classpath. * java/awt/MenuContainer.java: Merged with Classpath. * java/awt/Menu.java: Merged with Classpath. * java/awt/MediaEntry.java: New file from Classpath. * java/awt/MediaTracker.java: New file from Classpath. * java/awt/List.java: Merged with Classpath version. * java/awt/Insets.java: Merged with Classpath version. * java/awt/ImageMediaEntry.java: New file from Classpath. * java/awt/Image.java: Replaced with Classpath version. * java/awt/FontMetrics.java: Merged with Classpath version. * java/awt/Cursor.java (getDefaultCursor): Use DEFAULT_CURSOR constant. * java/awt/Font.java: Merged with Classpath version. * java/awt/Dialog.java: Merged with Classpath version. * java/awt/Color.java: Merged with Classpath version. * java/awt/Choice.java: Merged with Classpath version. * java/awt/CheckboxMenuItem.java: Merged with Classpath version. * java/awt/Adjustable.java: Replace with Classpath version. * java/awt/MenuItem.java (paramString): Don't include class name or brackets. Call superclass paramString. * java/awt/MenuComponent.java (toString): Call paramString. (paramString): Compute string; don't call toString. * java/awt/Label.java (paramString): Don't include class name or brackets. Call superclass paramString. * java/awt/Checkbox.java (paramString): Don't include class name or brackets. Call superclass paramString. * java/awt/Button.java (paramString): Don't include class name or brackets. Call superclass paramString. * java/awt/MenuComponent.java (getTreeLock): Now protected. From-SVN: r49099
Diffstat (limited to 'libjava/java/awt/Menu.java')
-rw-r--r--libjava/java/awt/Menu.java523
1 files changed, 390 insertions, 133 deletions
diff --git a/libjava/java/awt/Menu.java b/libjava/java/awt/Menu.java
index 6d52d05..ab73a23 100644
--- a/libjava/java/awt/Menu.java
+++ b/libjava/java/awt/Menu.java
@@ -1,141 +1,398 @@
-/* Copyright (C) 1999, 2000, 2001 Free Software Foundation
+/* Menu.java -- A Java AWT Menu
+ Copyright (C) 1999, 2002 Free Software Foundation, Inc.
- This file is part of libjava.
+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.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License. */
-This software is copyrighted work licensed under the terms of the
-Libjava License. Please consult the file "LIBJAVA_LICENSE" for
-details. */
package java.awt;
+import java.awt.peer.MenuPeer;
+import java.awt.peer.MenuItemPeer;
+import java.awt.peer.MenuComponentPeer;
+import java.io.Serializable;
import java.util.Vector;
+import java.util.Enumeration;
+
+/**
+ * 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;
+ */
+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.
+ */
+public
+Menu(String label)
+{
+ this(label, false);
+}
+
+/*************************************************************************/
-/* Status: Incomplete. */
-
-public class Menu extends MenuItem implements MenuContainer
-{
- // Fields from the serialization spec. Decalare others "transient".
- Vector items = new Vector();
- boolean tearOff;
- boolean isHelpMenu;
- int menuSerializedDataVersion;
-
- static final MenuItem separator = new MenuItem("-");
-
- public Menu()
- {
- this(null, false);
- }
-
- public Menu(String label)
- {
- this(label, false);
- }
-
- public Menu(String label, boolean tearOff)
- {
- super(label);
- this.tearOff = tearOff;
- }
-
- public void addNotify()
- {
- if (peer != null)
- {
- // This choice of toolkit seems unsatisfying, but I'm not sure
- // what else to do.
- peer = Toolkit.getDefaultToolkit ().createMenu (this);
- }
- super.addNotify ();
- }
-
- public void removeNotify()
- {
- // FIXME
- }
-
- public boolean isTearOff()
- {
- return tearOff;
- }
-
- public int getItemCount()
- {
- return items.size();
- }
-
- /** @deprecated Use getItemCount() instead. */
- public int countItems()
- {
- return getItemCount();
- }
-
- public MenuItem getItem(int index)
- {
- return (MenuItem) items.elementAt(index);
- }
-
- public synchronized MenuItem add(MenuItem mi)
- {
- items.addElement(mi);
- if (mi.parent != null)
- {
- mi.parent.remove(mi);
- }
- mi.parent = this;
- return mi;
- }
-
- public void add(String label)
- {
- MenuItem mi = new MenuItem(label);
- this.add(mi);
- }
-
- public synchronized void insert(MenuItem menuitem, int index)
- {
- if (index < 0)
- throw new IllegalArgumentException();
- items.insertElementAt(menuitem, index);
- }
-
- public void insert(String label, int index)
- {
- MenuItem mi = new MenuItem(label);
- this.insert(mi, index);
- }
-
- public void addSeparator()
- {
- this.add(separator);
- }
-
- public void insertSeparator(int index)
- {
- this.insert(separator, index);
- }
-
- public synchronized void remove(int index)
- {
- items.removeElementAt(index);
- }
-
- public synchronized void remove(MenuComponent item)
- {
- items.removeElement(item);
- }
-
- public synchronized void removeAll()
- {
- items.removeAllElements();
- }
-
- public String paramString()
- {
- return getName() + ",label" + label + ",tearOff=" + tearOff +
- ",isHelpMenu=" + isHelpMenu;
- }
-
- // Accessibility API not yet implemented.
- // public AccessibleContext getAccessibleContext()
+/**
+ * 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.
+ */
+public
+Menu(String label, boolean isTearOff)
+{
+ super(label);
+
+ this.isTearOff = isTearOff;
+
+ if (label.equals("Help"))
+ isHelpMenu = true;
}
+
+/*************************************************************************/
+
+/*
+ * 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());
+}
+
+/*************************************************************************/
+
+/**
+ * Returns the number of items in this menu.
+ *
+ * @return The number of items in this menu.
+ *
+ * @deprecated This method is deprecated in favor of <code>getItemCount()</code>.
+ */
+public int
+count()
+{
+ return(items.size());
+}
+
+/*************************************************************************/
+
+/**
+ * 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