jdk/src/share/classes/javax/swing/JMenuBar.java
author lana
Thu, 26 Dec 2013 12:04:16 -0800
changeset 23010 6dadb192ad81
parent 21592 da6abe91602a
child 25201 4adc75e0c4e5
permissions -rw-r--r--
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013 Summary: updated files with 2011, 2012 and 2013 years according to the file's last updated date Reviewed-by: tbell, lancea, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21592
diff changeset
     2
 * Copyright (c) 1997, 2013, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.event.*;
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
    35
import java.beans.Transient;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.swing.border.Border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * An implementation of a menu bar. You add <code>JMenu</code> objects to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * menu bar to construct a menu. When the user selects a <code>JMenu</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * object, its associated <code>JPopupMenu</code> is displayed, allowing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * user to select one of the <code>JMenuItems</code> on it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * For information and examples of using menu bars see
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <a
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 15633
diff changeset
    57
 href="http://docs.oracle.com/javase/tutorial/uiswing/components/menu.html">How to Use Menus</a>,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * a section in <em>The Java Tutorial.</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <strong>Warning:</strong> Swing is not thread safe. For more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * information see <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * href="package-summary.html#threading">Swing's Threading
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * Policy</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * 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
    70
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * Please see {@link java.beans.XMLEncoder}.
15633
3b73e7d1d7e5 8000326: Focus unable to traverse in the menubar
alexsch
parents: 11268
diff changeset
    73
 * <p>
3b73e7d1d7e5 8000326: Focus unable to traverse in the menubar
alexsch
parents: 11268
diff changeset
    74
 * <strong>Warning:</strong>
3b73e7d1d7e5 8000326: Focus unable to traverse in the menubar
alexsch
parents: 11268
diff changeset
    75
 * 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
    76
 * 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
    77
 * components, because the <code>focusTraversalKeysEnabled</code> property
3b73e7d1d7e5 8000326: Focus unable to traverse in the menubar
alexsch
parents: 11268
diff changeset
    78
 * 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
    79
 * you should call the <code>JMenuBar.setFocusTraversalKeysEnabled(true)</code>
3b73e7d1d7e5 8000326: Focus unable to traverse in the menubar
alexsch
parents: 11268
diff changeset
    80
 * method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *   attribute: isContainer true
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * description: A container for holding and displaying menus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * @author Georges Saab
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * @author David Karlton
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * @author Arnaud Weber
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * @see JMenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * @see JPopupMenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * @see JMenuItem
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 */
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 5506
diff changeset
    92
@SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
public class JMenuBar extends JComponent implements Accessible,MenuElement
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @see #getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @see #readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private static final String uiClassID = "MenuBarUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Model for the selected subcontrol.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private transient SingleSelectionModel selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private boolean paintBorder           = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private Insets     margin             = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /* diagnostic aids -- should be false for production builds. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    private static final boolean TRACE =   false; // trace creates and disposes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private static final boolean VERBOSE = false; // show reuse hits/misses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    private static final boolean DEBUG =   false;  // show bad params, misc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Creates a new menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public JMenuBar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        setFocusTraversalKeysEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        setSelectionModel(new DefaultSingleSelectionModel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * Returns the menubar's current UI.
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
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *       hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *  description: The UI object that implements the Component's LookAndFeel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public void setUI(MenuBarUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        super.setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * Resets the UI property with a value from the current look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @see JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        setUI((MenuBarUI)UIManager.getUI(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 20458
diff changeset
   158
     * Returns the name of the L&amp;F class that renders this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @return the string "MenuBarUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        return uiClassID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
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
     * Returns the model object that handles single selections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @return the <code>SingleSelectionModel</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @see SingleSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public SingleSelectionModel getSelectionModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        return selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * Sets the model object to handle single selections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @param model the <code>SingleSelectionModel</code> to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @see SingleSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * description: The selection model, recording which child is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
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
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public int getMenuCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        return getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * Sets the help menu that appears when the user selects the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * "help" option in the menu bar. This method is not yet implemented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * and will throw an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @param menu the JMenu that delivers help to the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public void setHelpMenu(JMenu menu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        throw new Error("setHelpMenu() not yet implemented.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * Gets the help menu for the menu bar.  This method is not yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * implemented and will throw an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @return the <code>JMenu</code> that delivers help to the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     */
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   248
    @Transient
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    public JMenu getHelpMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        throw new Error("getHelpMenu() not yet implemented.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * Returns the component at the specified index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @param i an integer specifying the position, where 0 is first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @return the <code>Component</code> at the position,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *          or <code>null</code> for an invalid index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @deprecated replaced by <code>getComponent(int i)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public Component getComponentAtIndex(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        if(i < 0 || i >= getComponentCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        return getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * Returns the index of the specified component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @param c  the <code>Component</code> to find
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @return an integer giving the component's position, where 0 is first;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *          or -1 if it can't be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    public int getComponentIndex(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        int ncomponents = this.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        Component[] component = this.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        for (int i = 0 ; i < ncomponents ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            Component comp = component[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            if (comp == c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * Sets the currently selected component, producing a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * a change to the selection model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @param sel the <code>Component</code> to select
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    public void setSelected(Component sel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        SingleSelectionModel model = getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        int index = getComponentIndex(sel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        model.setSelectedIndex(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * Returns true if the menu bar currently has a component selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @return true if a selection has been made, else false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    public boolean isSelected() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        return selectionModel.isSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * Returns true if the menu bars border should be painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @return  true if the border should be painted, else false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    public boolean isBorderPainted() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        return paintBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * Sets whether the border should be painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @param b if true and border property is not <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *          the border is painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @see #isBorderPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *  description: Whether the border should be painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     */
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
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     *  description: The space between the menubar's border and its contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    public void setMargin(Insets m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        Insets old = margin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        this.margin = m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        firePropertyChange("margin", old, m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        if (old == null || !old.equals(m)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * Returns the margin between the menubar's border and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * its menus.  If there is no previous margin, it will create
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * a default margin with zero size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * @return an <code>Insets</code> object containing the margin values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * @see Insets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    public Insets getMargin() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        if(margin == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            return new Insets(0,0,0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            return margin;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * Implemented to be a <code>MenuElement</code> -- does nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @see #getSubElements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    public void processMouseEvent(MouseEvent event,MenuElement path[],MenuSelectionManager manager) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * Implemented to be a <code>MenuElement</code> -- does nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @see #getSubElements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    public void processKeyEvent(KeyEvent e,MenuElement path[],MenuSelectionManager manager) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * Implemented to be a <code>MenuElement</code> -- does nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * @see #getSubElements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    public void menuSelectionChanged(boolean isIncluded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * Implemented to be a <code>MenuElement</code> -- returns the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * menus in this menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * This is the reason for implementing the <code>MenuElement</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * interface -- so that the menu bar can be treated the same as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * other menu elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @return an array of menu items in the menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    public MenuElement[] getSubElements() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        MenuElement result[];
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
   425
        Vector<MenuElement> tmp = new Vector<MenuElement>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        int c = getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        Component m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        for(i=0 ; i < c ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            m = getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            if(m instanceof MenuElement)
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
   433
                tmp.addElement((MenuElement) m);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        result = new MenuElement[tmp.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        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
   438
            result[i] = tmp.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * Implemented to be a <code>MenuElement</code>. Returns this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * @return the current <code>Component</code> (this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * @see #getSubElements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    public Component getComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        return this;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * Returns a string representation of this <code>JMenuBar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @return  a string representation of this <code>JMenuBar</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        String paintBorderString = (paintBorder ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                                    "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        String marginString = (margin != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                               margin.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        ",margin=" + marginString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        ",paintBorder=" + paintBorderString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * Gets the AccessibleContext associated with this JMenuBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * For JMenuBars, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * AccessibleJMenuBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * A new AccessibleJMenuBar instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * @return an AccessibleJMenuBar that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     *         AccessibleContext of this JMenuBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     */
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
}