| 1 | /* Menu.java -- A Java AWT Menu
|
|---|
| 2 | Copyright (C) 1999, 2002 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 4 | This file is part of GNU Classpath.
|
|---|
| 5 |
|
|---|
| 6 | GNU Classpath is free software; you can redistribute it and/or modify
|
|---|
| 7 | it under the terms of the GNU General Public License as published by
|
|---|
| 8 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 9 | any later version.
|
|---|
| 10 |
|
|---|
| 11 | GNU Classpath is distributed in the hope that it will be useful, but
|
|---|
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 14 | General Public License for more details.
|
|---|
| 15 |
|
|---|
| 16 | You should have received a copy of the GNU General Public License
|
|---|
| 17 | along with GNU Classpath; see the file COPYING. If not, write to the
|
|---|
| 18 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|---|
| 19 | 02111-1307 USA.
|
|---|
| 20 |
|
|---|
| 21 | Linking this library statically or dynamically with other modules is
|
|---|
| 22 | making a combined work based on this library. Thus, the terms and
|
|---|
| 23 | conditions of the GNU General Public License cover the whole
|
|---|
| 24 | combination.
|
|---|
| 25 |
|
|---|
| 26 | As a special exception, the copyright holders of this library give you
|
|---|
| 27 | permission to link this library with independent modules to produce an
|
|---|
| 28 | executable, regardless of the license terms of these independent
|
|---|
| 29 | modules, and to copy and distribute the resulting executable under
|
|---|
| 30 | terms of your choice, provided that you also meet, for each linked
|
|---|
| 31 | independent module, the terms and conditions of the license of that
|
|---|
| 32 | module. An independent module is a module which is not derived from
|
|---|
| 33 | or based on this library. If you modify this library, you may extend
|
|---|
| 34 | this exception to your version of the library, but you are not
|
|---|
| 35 | obligated to do so. If you do not wish to do so, delete this
|
|---|
| 36 | exception statement from your version. */
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | package java.awt;
|
|---|
| 40 |
|
|---|
| 41 | import java.awt.peer.MenuPeer;
|
|---|
| 42 | import java.awt.peer.MenuItemPeer;
|
|---|
| 43 | import java.awt.peer.MenuComponentPeer;
|
|---|
| 44 | import java.io.Serializable;
|
|---|
| 45 | import java.util.Vector;
|
|---|
| 46 | import java.util.Enumeration;
|
|---|
| 47 |
|
|---|
| 48 | /**
|
|---|
| 49 | * This class represents a pull down or tear off menu in Java's AWT.
|
|---|
| 50 | *
|
|---|
| 51 | * @author Aaron M. Renn ([email protected])
|
|---|
| 52 | */
|
|---|
| 53 | public class Menu extends MenuItem implements MenuContainer, Serializable
|
|---|
| 54 | {
|
|---|
| 55 |
|
|---|
| 56 | /*
|
|---|
| 57 | * Static Variables
|
|---|
| 58 | */
|
|---|
| 59 |
|
|---|
| 60 | // Serialization Constant
|
|---|
| 61 | private static final long serialVersionUID = -8809584163345499784L;
|
|---|
| 62 |
|
|---|
| 63 | /*************************************************************************/
|
|---|
| 64 |
|
|---|
| 65 | /*
|
|---|
| 66 | * Instance Variables
|
|---|
| 67 | */
|
|---|
| 68 |
|
|---|
| 69 | /**
|
|---|
| 70 | * @serial The actual items in the menu
|
|---|
| 71 | */
|
|---|
| 72 | private Vector items = new Vector();
|
|---|
| 73 |
|
|---|
| 74 | /**
|
|---|
| 75 | * @serial Flag indicating whether or not this menu is a tear off
|
|---|
| 76 | */
|
|---|
| 77 | private boolean isTearOff;
|
|---|
| 78 |
|
|---|
| 79 | /**
|
|---|
| 80 | * @serial Indicates whether or not this is a help menu.
|
|---|
| 81 | */
|
|---|
| 82 | private boolean isHelpMenu;
|
|---|
| 83 |
|
|---|
| 84 | // From the serialization spec. FIXME: what should it be?
|
|---|
| 85 | private int menuSerializedDataVersion;
|
|---|
| 86 |
|
|---|
| 87 | static final MenuItem separator = new MenuItem("-");
|
|---|
| 88 |
|
|---|
| 89 | /*************************************************************************/
|
|---|
| 90 |
|
|---|
| 91 | /*
|
|---|
| 92 | * Constructors
|
|---|
| 93 | */
|
|---|
| 94 |
|
|---|
| 95 | /**
|
|---|
| 96 | * Initializes a new instance of <code>Menu</code> with no label and that
|
|---|
| 97 | * is not a tearoff;
|
|---|
| 98 | *
|
|---|
| 99 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 100 | */
|
|---|
| 101 | public
|
|---|
| 102 | Menu()
|
|---|
| 103 | {
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | /*************************************************************************/
|
|---|
| 107 |
|
|---|
| 108 | /**
|
|---|
| 109 | * Initializes a new instance of <code>Menu</code> that is not a tearoff and
|
|---|
| 110 | * that has the specified label.
|
|---|
| 111 | *
|
|---|
| 112 | * @param label The menu label.
|
|---|
| 113 | *
|
|---|
| 114 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 115 | */
|
|---|
| 116 | public
|
|---|
| 117 | Menu(String label)
|
|---|
| 118 | {
|
|---|
| 119 | this(label, false);
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | /*************************************************************************/
|
|---|
| 123 |
|
|---|
| 124 | /**
|
|---|
| 125 | * Initializes a new instance of <code>Menu</code> with the specified
|
|---|
| 126 | * label and tearoff status.
|
|---|
| 127 | *
|
|---|
| 128 | * @param label The label for this menu
|
|---|
| 129 | * @param isTearOff <code>true</code> if this menu is a tear off menu,
|
|---|
| 130 | * <code>false</code> otherwise.
|
|---|
| 131 | *
|
|---|
| 132 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 133 | */
|
|---|
| 134 | public
|
|---|
| 135 | Menu(String label, boolean isTearOff)
|
|---|
| 136 | {
|
|---|
| 137 | super(label);
|
|---|
| 138 |
|
|---|
| 139 | this.isTearOff = isTearOff;
|
|---|
| 140 |
|
|---|
| 141 | if (label.equals("Help"))
|
|---|
| 142 | isHelpMenu = true;
|
|---|
| 143 |
|
|---|
| 144 | if (GraphicsEnvironment.isHeadless())
|
|---|
| 145 | throw new HeadlessException ();
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | /*************************************************************************/
|
|---|
| 149 |
|
|---|
| 150 | /*
|
|---|
| 151 | * Instance Methods
|
|---|
| 152 | */
|
|---|
| 153 |
|
|---|
| 154 | /**
|
|---|
| 155 | * Tests whether or not this menu is a tearoff.
|
|---|
| 156 | *
|
|---|
| 157 | * @return <code>true</code> if this menu is a tearoff, <code>false</code>
|
|---|
| 158 | * otherwise.
|
|---|
| 159 | */
|
|---|
| 160 | public boolean
|
|---|
| 161 | isTearOff()
|
|---|
| 162 | {
|
|---|
| 163 | return(isTearOff);
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | /*************************************************************************/
|
|---|
| 167 |
|
|---|
| 168 | /**
|
|---|
| 169 | * Returns the number of items in this menu.
|
|---|
| 170 | *
|
|---|
| 171 | * @return The number of items in this menu.
|
|---|
| 172 | */
|
|---|
|
|---|