jdk/src/share/classes/java/awt/MenuBar.java
author mcherkas
Wed, 06 Mar 2013 20:10:04 +0400
changeset 15994 5c8a3d840366
parent 13604 31089af1a447
child 20172 f48935a247ec
permissions -rw-r--r--
8007295: Reduce number of warnings in awt classes Reviewed-by: bae, anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1995, 2006, 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"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <alt="Diagram of MenuBar containing 2 menus: Examples and Options.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * Examples menu is expanded showing items: Basic, Simple, Check, and More Examples."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * ALIGN=center HSPACE=10 VSPACE=7>
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * @since      JDK1.0
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
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public void setHelpMenu(Menu m) {
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
            if (m.parent != this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                add(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            helpMenu = m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            if (m != null) {
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
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    public void remove(int index) {
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
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * Removes the specified menu component from this menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @param        m the menu component to be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @see          java.awt.MenuBar#add(java.awt.Menu)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public void remove(MenuComponent m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            int index = menus.indexOf(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            if (index >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                remove(index);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * Gets the number of menus on the menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @return     the number of menus on the menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @since      JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public int getMenuCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        return countMenus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * replaced by <code>getMenuCount()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    public int countMenus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        return getMenuCountImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * This is called by the native code, so client code can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * be called on the toolkit thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    final int getMenuCountImpl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        return menus.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * Gets the specified menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @param      i the index position of the menu to be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @return     the menu at the specified index of this menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    public Menu getMenu(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        return getMenuImpl(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * This is called by the native code, so client code can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * be called on the toolkit thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    final Menu getMenuImpl(int i) {
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 13604
diff changeset
   312
        return menus.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * Gets an enumeration of all menu shortcuts this menu bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * is managing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * @return      an enumeration of menu shortcuts that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *                      menu bar is managing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @see         java.awt.MenuShortcut
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * @since       JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    public synchronized Enumeration<MenuShortcut> shortcuts() {
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 13604
diff changeset
   324
        Vector<MenuShortcut> shortcuts = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        int nmenus = getMenuCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        for (int i = 0 ; i < nmenus ; i++) {
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 13604
diff changeset
   327
            Enumeration<MenuShortcut> e = getMenu(i).shortcuts();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            while (e.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                shortcuts.addElement(e.nextElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        return shortcuts.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * Gets the instance of <code>MenuItem</code> associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * with the specified <code>MenuShortcut</code> object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * or <code>null</code> if none of the menu items being managed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * by this menu bar is associated with the specified menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * shortcut.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @param        s the specified menu shortcut.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @see          java.awt.MenuItem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @see          java.awt.MenuShortcut
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @since        JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     public MenuItem getShortcutMenuItem(MenuShortcut s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        int nmenus = getMenuCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        for (int i = 0 ; i < nmenus ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            MenuItem mi = getMenu(i).getShortcutMenuItem(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            if (mi != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                return mi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        return null;  // MenuShortcut wasn't found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * Post an ACTION_EVENT to the target of the MenuPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * associated with the specified keyboard event (on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * keydown).  Returns true if there is an associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * keyboard event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    boolean handleShortcut(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        // Is it a key event?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        if (id != KeyEvent.KEY_PRESSED && id != KeyEvent.KEY_RELEASED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        // Is the accelerator modifier key pressed?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        int accelKey = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        if ((e.getModifiers() & accelKey) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        // Pass MenuShortcut on to child menus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        int nmenus = getMenuCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        for (int i = 0 ; i < nmenus ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            Menu m = getMenu(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            if (m.handleShortcut(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        }
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * Deletes the specified menu shortcut.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * @param     s the menu shortcut to delete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @since     JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    public void deleteShortcut(MenuShortcut s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        int nmenus = getMenuCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        for (int i = 0 ; i < nmenus ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            getMenu(i).deleteShortcut(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    /* Serialization support.  Restore the (transient) parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * fields of Menubar menus here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * The MenuBar's serialized data version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    private int menuBarSerializedDataVersion = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * Writes default serializable fields to stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @param s the <code>ObjectOutputStream</code> to write
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @see #readObject(java.io.ObjectInputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    private void writeObject(java.io.ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
      throws java.lang.ClassNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
             java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
      s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * Reads the <code>ObjectInputStream</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * Unrecognized keys or values will be ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * @param s the <code>ObjectInputStream</code> to read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *   <code>GraphicsEnvironment.isHeadless</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     *   <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * @see #writeObject(java.io.ObjectOutputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
      throws ClassNotFoundException, IOException, HeadlessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
      // HeadlessException will be thrown from MenuComponent's readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
      s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
      for (int i = 0; i < menus.size(); i++) {
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 13604
diff changeset
   441
        Menu m = menus.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        m.parent = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * Initialize JNI field and method IDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * Gets the AccessibleContext associated with this MenuBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * For menu bars, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * AccessibleAWTMenuBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * A new AccessibleAWTMenuBar instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @return an AccessibleAWTMenuBar that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *         AccessibleContext of this MenuBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            accessibleContext = new AccessibleAWTMenuBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * Defined in MenuComponent. Overridden here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    int getAccessibleChildIndex(MenuComponent child) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        return menus.indexOf(child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * Inner class of MenuBar used to provide default support for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * accessibility.  This class is not meant to be used directly by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * application developers, but is instead meant only to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * subclassed by menu component developers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * <code>MenuBar</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * Java Accessibility API appropriate to menu bar user-interface elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    protected class AccessibleAWTMenuBar extends AccessibleAWTMenuComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
         * JDK 1.3 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        private static final long serialVersionUID = -8577604491830083815L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
         * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            return AccessibleRole.MENU_BAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    } // class AccessibleAWTMenuBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
}