jdk/src/java.desktop/share/classes/javax/swing/JMenuBar.java
author aghaisas
Mon, 10 Jul 2017 14:55:29 +0530
changeset 47151 362dcbee0613
parent 42739 36f46e978c31
permissions -rw-r--r--
6919529: NPE from MultiUIDefaults.getUIError Reviewed-by: aghaisas, psadhukhan, serb Contributed-by: shashidhara.veerabhadraiah@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
     2
 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1301
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: 1301
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: 1301
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1301
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1301
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Insets;
42739
36f46e978c31 8166683: On macOS (Mac OS X) getting a ScreenMenuBar when not running "com.apple.laf.AquaLookAndFeel"
azvegint
parents: 33253
diff changeset
    30
import java.awt.Toolkit;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.event.*;
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
    32
import java.beans.JavaBean;
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
    33
import java.beans.BeanProperty;
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
    34
import java.beans.Transient;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
42739
36f46e978c31 8166683: On macOS (Mac OS X) getting a ScreenMenuBar when not running "com.apple.laf.AquaLookAndFeel"
azvegint
parents: 33253
diff changeset
    45
import sun.awt.SunToolkit;
36f46e978c31 8166683: On macOS (Mac OS X) getting a ScreenMenuBar when not running "com.apple.laf.AquaLookAndFeel"
azvegint
parents: 33253
diff changeset
    46
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * An implementation of a menu bar. You add <code>JMenu</code> objects to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * menu bar to construct a menu. When the user selects a <code>JMenu</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * object, its associated <code>JPopupMenu</code> is displayed, allowing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * user to select one of the <code>JMenuItems</code> on it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * For information and examples of using menu bars see
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <a
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 15633
diff changeset
    55
 href="http://docs.oracle.com/javase/tutorial/uiswing/components/menu.html">How to Use Menus</a>,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * a section in <em>The Java Tutorial.</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <strong>Warning:</strong> Swing is not thread safe. For more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * information see <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * href="package-summary.html#threading">Swing's Threading
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * Policy</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
    68
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * Please see {@link java.beans.XMLEncoder}.
15633
3b73e7d1d7e5 8000326: Focus unable to traverse in the menubar
alexsch
parents: 11268
diff changeset
    71
 * <p>
3b73e7d1d7e5 8000326: Focus unable to traverse in the menubar
alexsch
parents: 11268
diff changeset
    72
 * <strong>Warning:</strong>
3b73e7d1d7e5 8000326: Focus unable to traverse in the menubar
alexsch
parents: 11268
diff changeset
    73
 * By default, pressing the Tab key does not transfer focus from a <code>
3b73e7d1d7e5 8000326: Focus unable to traverse in the menubar
alexsch
parents: 11268
diff changeset
    74
 * JMenuBar</code> which is added to a container together with other Swing
3b73e7d1d7e5 8000326: Focus unable to traverse in the menubar
alexsch
parents: 11268
diff changeset
    75
 * components, because the <code>focusTraversalKeysEnabled</code> property
3b73e7d1d7e5 8000326: Focus unable to traverse in the menubar
alexsch
parents: 11268
diff changeset
    76
 * of <code>JMenuBar</code> is set to <code>false</code>. To resolve this,
3b73e7d1d7e5 8000326: Focus unable to traverse in the menubar
alexsch
parents: 11268
diff changeset
    77
 * you should call the <code>JMenuBar.setFocusTraversalKeysEnabled(true)</code>
3b73e7d1d7e5 8000326: Focus unable to traverse in the menubar
alexsch
parents: 11268
diff changeset
    78
 * method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * @author Georges Saab
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * @author David Karlton
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * @author Arnaud Weber
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * @see JMenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * @see JPopupMenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * @see JMenuItem
25201
4adc75e0c4e5 8046485: Add missing @since tag under javax.swing.*
henryjen
parents: 23010
diff changeset
    86
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
    88
@JavaBean(defaultProperty = "UI", description = "A container for holding and displaying menus.")
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
    89
@SwingContainer
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 5506
diff changeset
    90
@SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
public class JMenuBar extends JComponent implements Accessible,MenuElement
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @see #getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @see #readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private static final String uiClassID = "MenuBarUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Model for the selected subcontrol.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private transient SingleSelectionModel selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private boolean paintBorder           = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private Insets     margin             = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /* diagnostic aids -- should be false for production builds. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private static final boolean TRACE =   false; // trace creates and disposes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private static final boolean VERBOSE = false; // show reuse hits/misses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    private static final boolean DEBUG =   false;  // show bad params, misc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Creates a new menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public JMenuBar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        setFocusTraversalKeysEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        setSelectionModel(new DefaultSingleSelectionModel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * Returns the menubar's current UI.
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   124
     *
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   125
     * @return a {@code MenuBarUI} which is the menubar's current L&amp;F object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @see #setUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public MenuBarUI getUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        return (MenuBarUI)ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 20458
diff changeset
   133
     * Sets the L&amp;F object that renders this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 20458
diff changeset
   135
     * @param ui the new MenuBarUI L&amp;F object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   138
    @BeanProperty(hidden = true, visualUpdate = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   139
            = "The UI object that implements the Component's LookAndFeel.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public void setUI(MenuBarUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        super.setUI(ui);
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
     * Resets the UI property with a value from the current look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @see JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public void updateUI() {
42739
36f46e978c31 8166683: On macOS (Mac OS X) getting a ScreenMenuBar when not running "com.apple.laf.AquaLookAndFeel"
azvegint
parents: 33253
diff changeset
   150
        Toolkit tk = Toolkit.getDefaultToolkit();
36f46e978c31 8166683: On macOS (Mac OS X) getting a ScreenMenuBar when not running "com.apple.laf.AquaLookAndFeel"
azvegint
parents: 33253
diff changeset
   151
        if (tk instanceof SunToolkit) {
36f46e978c31 8166683: On macOS (Mac OS X) getting a ScreenMenuBar when not running "com.apple.laf.AquaLookAndFeel"
azvegint
parents: 33253
diff changeset
   152
            ((SunToolkit)tk).updateScreenMenuBarUI();
36f46e978c31 8166683: On macOS (Mac OS X) getting a ScreenMenuBar when not running "com.apple.laf.AquaLookAndFeel"
azvegint
parents: 33253
diff changeset
   153
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        setUI((MenuBarUI)UIManager.getUI(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /**
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 20458
diff changeset
   159
     * Returns the name of the L&amp;F class that renders this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @return the string "MenuBarUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   165
    @BeanProperty(bound = false)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        return uiClassID;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * Returns the model object that handles single selections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @return the <code>SingleSelectionModel</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @see SingleSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public SingleSelectionModel getSelectionModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        return selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * Sets the model object to handle single selections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @param model the <code>SingleSelectionModel</code> to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @see SingleSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   187
    @BeanProperty(description = "The selection model, recording which child is selected.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public void setSelectionModel(SingleSelectionModel model) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        SingleSelectionModel oldValue = selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        this.selectionModel = model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        firePropertyChange("selectionModel", oldValue, selectionModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * Appends the specified menu to the end of the menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @param c the <code>JMenu</code> component to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @return the menu component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    public JMenu add(JMenu c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        super.add(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * Returns the menu at the specified position in the menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @param index  an integer giving the position in the menu bar, where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *               0 is the first position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @return the <code>JMenu</code> at that position, or <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *          if there is no <code>JMenu</code> at that position (ie. if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *          it is a <code>JMenuItem</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    public JMenu getMenu(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        Component c = getComponentAtIndex(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        if (c instanceof JMenu)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            return (JMenu) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * Returns the number of items in the menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @return the number of items in the menu bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   227
    @BeanProperty(bound = false)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public int getMenuCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        return getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * Sets the help menu that appears when the user selects the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * "help" option in the menu bar. This method is not yet implemented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * and will throw an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @param menu the JMenu that delivers help to the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public void setHelpMenu(JMenu menu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        throw new Error("setHelpMenu() not yet implemented.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * Gets the help menu for the menu bar.  This method is not yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * implemented and will throw an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @return the <code>JMenu</code> that delivers help to the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   249
    @Transient
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public JMenu getHelpMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        throw new Error("getHelpMenu() not yet implemented.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Returns the component at the specified index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @param i an integer specifying the position, where 0 is first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @return the <code>Component</code> at the position,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *          or <code>null</code> for an invalid index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @deprecated replaced by <code>getComponent(int i)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public Component getComponentAtIndex(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        if(i < 0 || i >= getComponentCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        return getComponent(i);
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
     * Returns the index of the specified component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @param c  the <code>Component</code> to find
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @return an integer giving the component's position, where 0 is first;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *          or -1 if it can't be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public int getComponentIndex(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        int ncomponents = this.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        Component[] component = this.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        for (int i = 0 ; i < ncomponents ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            Component comp = component[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            if (comp == c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * Sets the currently selected component, producing a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * a change to the selection model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @param sel the <code>Component</code> to select
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    public void setSelected(Component sel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        SingleSelectionModel model = getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        int index = getComponentIndex(sel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        model.setSelectedIndex(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * Returns true if the menu bar currently has a component selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @return true if a selection has been made, else false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   305
    @BeanProperty(bound = false)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    public boolean isSelected() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        return selectionModel.isSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * Returns true if the menu bars border should be painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @return  true if the border should be painted, else false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public boolean isBorderPainted() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        return paintBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * Sets whether the border should be painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @param b if true and border property is not <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *          the border is painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @see #isBorderPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   326
    @BeanProperty(visualUpdate = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   327
            = "Whether the border should be painted.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    public void setBorderPainted(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        boolean oldValue = paintBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        paintBorder = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        firePropertyChange("borderPainted", oldValue, paintBorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        if (b != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * Paints the menubar's border if <code>BorderPainted</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * property is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @param g the <code>Graphics</code> context to use for painting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @see JComponent#paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @see JComponent#setBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    protected void paintBorder(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        if (isBorderPainted()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            super.paintBorder(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * Sets the margin between the menubar's border and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * its menus. Setting to <code>null</code> will cause the menubar to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * use the default margins.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * @param m an Insets object containing the margin values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * @see Insets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   360
    @BeanProperty(visualUpdate = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   361
            = "The space between the menubar's border and its contents")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    public void setMargin(Insets m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        Insets old = margin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        this.margin = m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        firePropertyChange("margin", old, m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        if (old == null || !old.equals(m)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * Returns the margin between the menubar's border and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * its menus.  If there is no previous margin, it will create
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * a default margin with zero size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * @return an <code>Insets</code> object containing the margin values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * @see Insets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    public Insets getMargin() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        if(margin == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            return new Insets(0,0,0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            return margin;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * Implemented to be a <code>MenuElement</code> -- does nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @see #getSubElements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    public void processMouseEvent(MouseEvent event,MenuElement path[],MenuSelectionManager manager) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * Implemented to be a <code>MenuElement</code> -- does nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @see #getSubElements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    public void processKeyEvent(KeyEvent e,MenuElement path[],MenuSelectionManager manager) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * Implemented to be a <code>MenuElement</code> -- does nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * @see #getSubElements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    public void menuSelectionChanged(boolean isIncluded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * Implemented to be a <code>MenuElement</code> -- returns the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * menus in this menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * This is the reason for implementing the <code>MenuElement</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * interface -- so that the menu bar can be treated the same as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * other menu elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @return an array of menu items in the menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   421
    @BeanProperty(bound = false)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    public MenuElement[] getSubElements() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        MenuElement result[];
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
   424
        Vector<MenuElement> tmp = new Vector<MenuElement>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        int c = getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        Component m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        for(i=0 ; i < c ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            m = getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            if(m instanceof MenuElement)
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
   432
                tmp.addElement((MenuElement) m);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        result = new MenuElement[tmp.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        for(i=0,c=tmp.size() ; i < c ; i++)
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
   437
            result[i] = tmp.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * Implemented to be a <code>MenuElement</code>. Returns this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * @return the current <code>Component</code> (this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * @see #getSubElements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    public Component getComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    }
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
     * Returns a string representation of this <code>JMenuBar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * @return  a string representation of this <code>JMenuBar</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        String paintBorderString = (paintBorder ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                                    "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        String marginString = (margin != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                               margin.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        ",margin=" + marginString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        ",paintBorder=" + paintBorderString;
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
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * Gets the AccessibleContext associated with this JMenuBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * For JMenuBars, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * AccessibleJMenuBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * A new AccessibleJMenuBar instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * @return an AccessibleJMenuBar that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     *         AccessibleContext of this JMenuBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   486
    @BeanProperty(bound = false)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            accessibleContext = new AccessibleJMenuBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * <code>JMenuBar</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * Java Accessibility API appropriate to menu bar user-interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
   505
     * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     */
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 5506
diff changeset
   509
    @SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    protected class AccessibleJMenuBar extends AccessibleJComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        implements AccessibleSelection {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
         * Get the accessible state set of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
         * @return an instance of AccessibleState containing the current state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
         *         of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            AccessibleStateSet states = super.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            return states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            return AccessibleRole.MENU_BAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
         * Get the AccessibleSelection associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
         * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
         * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
         * AccessibleSelection interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        public AccessibleSelection getAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
         * Returns 1 if a menu is currently selected in this menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
         * @return 1 if a menu is currently selected, else 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
         public int getAccessibleSelectionCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            if (isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
         * Returns the currently selected menu if one is selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
         * otherwise null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
         public Accessible getAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            if (isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                if (i != 0) {   // single selection model for JMenuBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                int j = getSelectionModel().getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                if (getComponentAtIndex(j) instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                    return (Accessible) getComponentAtIndex(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
         * Returns true if the current child of this object is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
         * @param i the zero-based index of the child in this Accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
         * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
         * @see AccessibleContext#getAccessibleChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        public boolean isAccessibleChildSelected(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            return (i == getSelectionModel().getSelectedIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
         * Selects the nth menu in the menu bar, forcing it to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
         * pop up.  If another menu is popped up, this will force
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
         * it to close.  If the nth menu is already selected, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
         * method has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
         * @param i the zero-based index of selectable items
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
         * @see #getAccessibleStateSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        public void addAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            // first close up any open menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            int j = getSelectionModel().getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            if (i == j) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            if (j >= 0 && j < getMenuCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                JMenu menu = getMenu(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                if (menu != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                    MenuSelectionManager.defaultManager().setSelectedPath(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
//                  menu.setPopupMenuVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            // now popup the new menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            getSelectionModel().setSelectedIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            JMenu menu = getMenu(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            if (menu != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                MenuElement me[] = new MenuElement[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                me[0] = JMenuBar.this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                me[1] = menu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                me[2] = menu.getPopupMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                MenuSelectionManager.defaultManager().setSelectedPath(me);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
//              menu.setPopupMenuVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
         * Removes the nth selected item in the object from the object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
         * selection.  If the nth item isn't currently selected, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
         * method has no effect.  Otherwise, it closes the popup menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
         * @param i the zero-based index of selectable items
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        public void removeAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            if (i >= 0 && i < getMenuCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                JMenu menu = getMenu(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                if (menu != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                    MenuSelectionManager.defaultManager().setSelectedPath(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
//                  menu.setPopupMenuVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                getSelectionModel().setSelectedIndex(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
         * Clears the selection in the object, so that nothing in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
         * object is selected.  This will close any open menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        public void clearAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            int i = getSelectionModel().getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            if (i >= 0 && i < getMenuCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                JMenu menu = getMenu(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                if (menu != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                    MenuSelectionManager.defaultManager().setSelectedPath(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
//                  menu.setPopupMenuVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            getSelectionModel().setSelectedIndex(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
         * Normally causes every selected item in the object to be selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
         * if the object supports multiple selections.  This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
         * makes no sense in a menu bar, and so does nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        public void selectAllAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    } // internal class AccessibleJMenuBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * Subclassed to check all the child menus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                                        int condition, boolean pressed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        // See if we have a local binding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        boolean retValue = super.processKeyBinding(ks, e, condition, pressed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        if (!retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            MenuElement[] subElements = getSubElements();
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
   676
            for (MenuElement subElement : subElements) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                if (processBindingForKeyStrokeRecursive(
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
   678
                        subElement, ks, e, condition, pressed)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        return retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    static boolean processBindingForKeyStrokeRecursive(MenuElement elem,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                                                       KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        if (elem == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        Component c = elem.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        if ( !(c.isVisible() || (c instanceof JPopupMenu)) || !c.isEnabled() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        if (c != null && c instanceof JComponent &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            ((JComponent)c).processKeyBinding(ks, e, condition, pressed)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        MenuElement[] subElements = elem.getSubElements();
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
   705
        for (MenuElement subElement : subElements) {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
   706
            if (processBindingForKeyStrokeRecursive(subElement, ks, e, condition, pressed)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                // We don't, pass along to children JMenu's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * Overrides <code>JComponent.addNotify</code> to register this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * menu bar with the current keyboard manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    public void addNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        super.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        KeyboardManager.getCurrentManager().registerMenuBar(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * Overrides <code>JComponent.removeNotify</code> to unregister this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * menu bar with the current keyboard manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    public void removeNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        super.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        KeyboardManager.getCurrentManager().unregisterMenuBar(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        Object[] kvData = new Object[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        int n = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        if (selectionModel instanceof Serializable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            kvData[n++] = "selectionModel";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            kvData[n++] = selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        s.writeObject(kvData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * See JComponent.readObject() for information about serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        Object[] kvData = (Object[])(s.readObject());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        for(int i = 0; i < kvData.length; i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            if (kvData[i] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            else if (kvData[i].equals("selectionModel")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                selectionModel = (SingleSelectionModel)kvData[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
}