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