jdk/src/java.desktop/share/classes/java/awt/MenuBar.java
author serb
Tue, 13 Jan 2015 17:10:28 +0300
changeset 28982 5155c7ab896a
parent 25859 3317bb8137f4
child 30471 c1568a2416a8
permissions -rw-r--r--
6475361: Attempting to remove help menu from java.awt.MenuBar throws NullPointerException Reviewed-by: azvegint, ant
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
28982
5155c7ab896a 6475361: Attempting to remove help menu from java.awt.MenuBar throws NullPointerException
serb
parents: 25859
diff changeset
     2
 * Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Enumeration;
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
    31
import sun.awt.AWTAccessor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.peer.MenuBarPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.event.KeyEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * The <code>MenuBar</code> class encapsulates the platform's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * concept of a menu bar bound to a frame. In order to associate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * the menu bar with a <code>Frame</code> object, call the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * frame's <code>setMenuBar</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <A NAME="mbexample"></A><!-- target for cross references -->
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * This is what a menu bar might look like:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <img src="doc-files/MenuBar-1.gif"
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 15994
diff changeset
    46
 * alt="Diagram of MenuBar containing 2 menus: Examples and Options.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * Examples menu is expanded showing items: Basic, Simple, Check, and More Examples."
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 20172
diff changeset
    48
 * style="float:center; margin: 7px 10px;">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * A menu bar handles keyboard shortcuts for menu items, passing them
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * along to its child menus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * (Keyboard shortcuts, which are optional, provide the user with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * an alternative to the mouse for invoking a menu item and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * action that is associated with it.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * Each menu item can maintain an instance of <code>MenuShortcut</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * The <code>MenuBar</code> class defines several methods,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * {@link MenuBar#shortcuts} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * {@link MenuBar#getShortcutMenuItem}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * that retrieve information about the shortcuts a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * menu bar is managing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * @author Sami Shaio
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * @see        java.awt.Frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * @see        java.awt.Frame#setMenuBar(java.awt.MenuBar)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * @see        java.awt.Menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * @see        java.awt.MenuItem
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @see        java.awt.MenuShortcut
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23010
diff changeset
    68
 * @since      1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
public class MenuBar extends MenuComponent implements MenuContainer, Accessible {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        /* ensure that the necessary native libraries are loaded */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        Toolkit.loadLibraries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        if (!GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        }
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
    78
        AWTAccessor.setMenuBarAccessor(
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
    79
            new AWTAccessor.MenuBarAccessor() {
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
    80
                public Menu getHelpMenu(MenuBar menuBar) {
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
    81
                    return menuBar.helpMenu;
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
    82
                }
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
    83
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 13604
diff changeset
    84
                public Vector<Menu> getMenus(MenuBar menuBar) {
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
    85
                    return menuBar.menus;
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
    86
                }
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 5506
diff changeset
    87
            });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * This field represents a vector of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * actual menus that will be part of the MenuBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @see #countMenus()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 13604
diff changeset
    97
    Vector<Menu> menus = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * This menu is a special menu dedicated to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * help.  The one thing to note about this menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * is that on some platforms it appears at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * right edge of the menubar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @see #getHelpMenu()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @see #setHelpMenu(Menu)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    Menu helpMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private static final String base = "menubar";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    private static int nameCounter = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     private static final long serialVersionUID = -4930327919388951260L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Creates a new menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public MenuBar() throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Construct a name for this MenuComponent.  Called by getName() when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * the name is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    String constructComponentName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        synchronized (MenuBar.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            return base + nameCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * Creates the menu bar's peer.  The peer allows us to change the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * appearance of the menu bar without changing any of the menu bar's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * functionality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public void addNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            if (peer == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                peer = Toolkit.getDefaultToolkit().createMenuBar(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            int nmenus = getMenuCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            for (int i = 0 ; i < nmenus ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                getMenu(i).addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * Removes the menu bar's peer.  The peer allows us to change the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * appearance of the menu bar without changing any of the menu bar's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * functionality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public void removeNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            int nmenus = getMenuCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            for (int i = 0 ; i < nmenus ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                getMenu(i).removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            super.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * Gets the help menu on the menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @return    the help menu on this menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public Menu getHelpMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        return helpMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * Sets the specified menu to be this menu bar's help menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * If this menu bar has an existing help menu, the old help menu is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * removed from the menu bar, and replaced with the specified menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @param m    the menu to be set as the help menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
28982
5155c7ab896a 6475361: Attempting to remove help menu from java.awt.MenuBar throws NullPointerException
serb
parents: 25859
diff changeset
   184
    public void setHelpMenu(final Menu m) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            if (helpMenu == m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            if (helpMenu != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                remove(helpMenu);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            helpMenu = m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            if (m != null) {
28982
5155c7ab896a 6475361: Attempting to remove help menu from java.awt.MenuBar throws NullPointerException
serb
parents: 25859
diff changeset
   194
                if (m.parent != this) {
5155c7ab896a 6475361: Attempting to remove help menu from java.awt.MenuBar throws NullPointerException
serb
parents: 25859
diff changeset
   195
                    add(m);
5155c7ab896a 6475361: Attempting to remove help menu from java.awt.MenuBar throws NullPointerException
serb
parents: 25859
diff changeset
   196
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                m.isHelpMenu = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                m.parent = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                MenuBarPeer peer = (MenuBarPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                    if (m.peer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                        m.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    peer.addHelpMenu(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * Adds the specified menu to the menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * If the menu has been part of another menu bar,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * removes it from that menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @param        m   the menu to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @return       the menu added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @see          java.awt.MenuBar#remove(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @see          java.awt.MenuBar#remove(java.awt.MenuComponent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    public Menu add(Menu m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            if (m.parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                m.parent.remove(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            menus.addElement(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            m.parent = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            MenuBarPeer peer = (MenuBarPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                if (m.peer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                    m.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                peer.addMenu(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            return m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * Removes the menu located at the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * index from this menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @param        index   the position of the menu to be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @see          java.awt.MenuBar#add(java.awt.Menu)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
28982
5155c7ab896a 6475361: Attempting to remove help menu from java.awt.MenuBar throws NullPointerException
serb
parents: 25859
diff changeset
   245
    public void remove(final int index) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            Menu m = getMenu(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            menus.removeElementAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            MenuBarPeer peer = (MenuBarPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                m.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                m.parent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                peer.delMenu(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            }
28982
5155c7ab896a 6475361: Attempting to remove help menu from java.awt.MenuBar throws NullPointerException
serb
parents: 25859
diff changeset
   255
            if (helpMenu == m) {
5155c7ab896a 6475361: Attempting to remove help menu from java.awt.MenuBar throws NullPointerException
serb
parents: 25859
diff changeset
   256
                helpMenu = null;
5155c7ab896a 6475361: Attempting to remove help menu from java.awt.MenuBar throws NullPointerException
serb
parents: 25859
diff changeset
   257
                m.isHelpMenu = false;
5155c7ab896a 6475361: Attempting to remove help menu from java.awt.MenuBar throws NullPointerException
serb
parents: 25859
diff changeset
   258
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * Removes the specified menu component from this menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @param        m the menu component to be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @see          java.awt.MenuBar#add(java.awt.Menu)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public void remove(MenuComponent m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            int index = menus.indexOf(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            if (index >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                remove(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * Gets the number of menus on the menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @return     the number of menus on the menu bar.
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23010
diff changeset
   279
     * @since      1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    public int getMenuCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        return countMenus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
   286
     * Gets the number of menus on the menu bar.
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
   287
     *
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
   288
     * @return the number of menus on the menu bar.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * replaced by <code>getMenuCount()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    public int countMenus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        return getMenuCountImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * This is called by the native code, so client code can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * be called on the toolkit thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    final int getMenuCountImpl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        return menus.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * Gets the specified menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @param      i the index position of the menu to be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @return     the menu at the specified index of this menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    public Menu getMenu(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        return getMenuImpl(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * This is called by the native code, so client code can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * be called on the toolkit thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    final Menu getMenuImpl(int i) {
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 13604
diff changeset
   319
        return menus.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * Gets an enumeration of all menu shortcuts this menu bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * is managing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @return      an enumeration of menu shortcuts that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *                      menu bar is managing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * @see         java.awt.MenuShortcut
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23010
diff changeset
   328
     * @since       1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    public synchronized Enumeration<MenuShortcut> shortcuts() {
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 13604
diff changeset
   331
        Vector<MenuShortcut> shortcuts = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        int nmenus = getMenuCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        for (int i = 0 ; i < nmenus ; i++) {
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 13604
diff changeset
   334
            Enumeration<MenuShortcut> e = getMenu(i).shortcuts();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            while (e.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                shortcuts.addElement(e.nextElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        return shortcuts.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * Gets the instance of <code>MenuItem</code> associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * with the specified <code>MenuShortcut</code> object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * or <code>null</code> if none of the menu items being managed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * by this menu bar is associated with the specified menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * shortcut.
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
   348
     * @param  s the specified menu shortcut.
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
   349
     * @return the menu item for the specified shortcut.
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
   350
     * @see java.awt.MenuItem
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
   351
     * @see java.awt.MenuShortcut
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
   352
     * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     public MenuItem getShortcutMenuItem(MenuShortcut s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        int nmenus = getMenuCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        for (int i = 0 ; i < nmenus ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            MenuItem mi = getMenu(i).getShortcutMenuItem(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            if (mi != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                return mi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        return null;  // MenuShortcut wasn't found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * Post an ACTION_EVENT to the target of the MenuPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * associated with the specified keyboard event (on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * keydown).  Returns true if there is an associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * keyboard event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    boolean handleShortcut(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        // Is it a key event?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        if (id != KeyEvent.KEY_PRESSED && id != KeyEvent.KEY_RELEASED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        // Is the accelerator modifier key pressed?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        int accelKey = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        if ((e.getModifiers() & accelKey) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        // Pass MenuShortcut on to child menus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        int nmenus = getMenuCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        for (int i = 0 ; i < nmenus ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            Menu m = getMenu(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            if (m.handleShortcut(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * Deletes the specified menu shortcut.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * @param     s the menu shortcut to delete.
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23010
diff changeset
   398
     * @since     1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    public void deleteShortcut(MenuShortcut s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        int nmenus = getMenuCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        for (int i = 0 ; i < nmenus ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            getMenu(i).deleteShortcut(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    /* Serialization support.  Restore the (transient) parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * fields of Menubar menus here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * The MenuBar's serialized data version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    private int menuBarSerializedDataVersion = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * Writes default serializable fields to stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @param s the <code>ObjectOutputStream</code> to write
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * @see #readObject(java.io.ObjectInputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    private void writeObject(java.io.ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
      throws java.lang.ClassNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
             java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
      s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * Reads the <code>ObjectInputStream</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * Unrecognized keys or values will be ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @param s the <code>ObjectInputStream</code> to read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     *   <code>GraphicsEnvironment.isHeadless</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     *   <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * @see #writeObject(java.io.ObjectOutputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
      throws ClassNotFoundException, IOException, HeadlessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
      // HeadlessException will be thrown from MenuComponent's readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
      s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
      for (int i = 0; i < menus.size(); i++) {
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 13604
diff changeset
   449
        Menu m = menus.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        m.parent = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * Initialize JNI field and method IDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * Gets the AccessibleContext associated with this MenuBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * For menu bars, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * AccessibleAWTMenuBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * A new AccessibleAWTMenuBar instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @return an AccessibleAWTMenuBar that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     *         AccessibleContext of this MenuBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            accessibleContext = new AccessibleAWTMenuBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * Defined in MenuComponent. Overridden here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    int getAccessibleChildIndex(MenuComponent child) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        return menus.indexOf(child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * Inner class of MenuBar used to provide default support for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * accessibility.  This class is not meant to be used directly by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * application developers, but is instead meant only to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * subclassed by menu component developers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * <code>MenuBar</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * Java Accessibility API appropriate to menu bar user-interface elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    protected class AccessibleAWTMenuBar extends AccessibleAWTMenuComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
         * JDK 1.3 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        private static final long serialVersionUID = -8577604491830083815L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
         * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            return AccessibleRole.MENU_BAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    } // class AccessibleAWTMenuBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
}