jdk/src/share/classes/javax/swing/JMenuBar.java
author rupashka
Tue, 26 Aug 2008 15:12:54 +0400
changeset 1301 15e81207e1f2
parent 466 6acd5ec503a8
child 5506 202f599c92aa
permissions -rw-r--r--
6727662: Code improvement and warnings removing from swing packages Summary: Removed unnecessary castings and other warnings Reviewed-by: malenkov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
     2
 * Copyright 1997-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 href="http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html">How to Use Menus</a>,
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
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}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *   attribute: isContainer true
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * description: A container for holding and displaying menus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * @author Georges Saab
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * @author David Karlton
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * @author Arnaud Weber
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * @see JMenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * @see JPopupMenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * @see JMenuItem
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
public class JMenuBar extends JComponent implements Accessible,MenuElement
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @see #getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @see #readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private static final String uiClassID = "MenuBarUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * Model for the selected subcontrol.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private transient SingleSelectionModel selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private boolean paintBorder           = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private Insets     margin             = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /* diagnostic aids -- should be false for production builds. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private static final boolean TRACE =   false; // trace creates and disposes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private static final boolean VERBOSE = false; // show reuse hits/misses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private static final boolean DEBUG =   false;  // show bad params, misc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Creates a new menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public JMenuBar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        setFocusTraversalKeysEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        setSelectionModel(new DefaultSingleSelectionModel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * Returns the menubar's current UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @see #setUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public MenuBarUI getUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        return (MenuBarUI)ui;
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
     * Sets the L&F object that renders this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @param ui the new MenuBarUI L&F object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *       hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *  description: The UI object that implements the Component's LookAndFeel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public void setUI(MenuBarUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        super.setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Resets the UI property with a value from the current look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @see JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        setUI((MenuBarUI)UIManager.getUI(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Returns the name of the L&F class that renders this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @return the string "MenuBarUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        return uiClassID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * Returns the model object that handles single selections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @return the <code>SingleSelectionModel</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @see SingleSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public SingleSelectionModel getSelectionModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        return selectionModel;
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
     * Sets the model object to handle single selections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @param model the <code>SingleSelectionModel</code> to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @see SingleSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * description: The selection model, recording which child is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public void setSelectionModel(SingleSelectionModel model) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        SingleSelectionModel oldValue = selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        this.selectionModel = model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        firePropertyChange("selectionModel", oldValue, selectionModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * Appends the specified menu to the end of the menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @param c the <code>JMenu</code> component to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @return the menu component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public JMenu add(JMenu c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        super.add(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * Returns the menu at the specified position in the menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @param index  an integer giving the position in the menu bar, where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *               0 is the first position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @return the <code>JMenu</code> at that position, or <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *          if there is no <code>JMenu</code> at that position (ie. if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *          it is a <code>JMenuItem</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public JMenu getMenu(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        Component c = getComponentAtIndex(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        if (c instanceof JMenu)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            return (JMenu) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * Returns the number of items in the menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @return the number of items in the menu bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    public int getMenuCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        return getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * Sets the help menu that appears when the user selects the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * "help" option in the menu bar. This method is not yet implemented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * and will throw an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @param menu the JMenu that delivers help to the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public void setHelpMenu(JMenu menu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        throw new Error("setHelpMenu() not yet implemented.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * Gets the help menu for the menu bar.  This method is not yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * implemented and will throw an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @return the <code>JMenu</code> that delivers help to the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     */
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   240
    @Transient
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public JMenu getHelpMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        throw new Error("getHelpMenu() not yet implemented.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * Returns the component at the specified index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @param i an integer specifying the position, where 0 is first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @return the <code>Component</code> at the position,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *          or <code>null</code> for an invalid index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @deprecated replaced by <code>getComponent(int i)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    public Component getComponentAtIndex(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        if(i < 0 || i >= getComponentCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        return getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * Returns the index of the specified component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @param c  the <code>Component</code> to find
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @return an integer giving the component's position, where 0 is first;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *          or -1 if it can't be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public int getComponentIndex(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        int ncomponents = this.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        Component[] component = this.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        for (int i = 0 ; i < ncomponents ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            Component comp = component[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            if (comp == c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * Sets the currently selected component, producing a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * a change to the selection model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @param sel the <code>Component</code> to select
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public void setSelected(Component sel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        SingleSelectionModel model = getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        int index = getComponentIndex(sel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        model.setSelectedIndex(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * Returns true if the menu bar currently has a component selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @return true if a selection has been made, else false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    public boolean isSelected() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        return selectionModel.isSelected();
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 bars border should be painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @return  true if the border should be painted, else false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    public boolean isBorderPainted() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        return paintBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * Sets whether the border should be painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @param b if true and border property is not <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     *          the border is painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @see #isBorderPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *  description: Whether the border should be painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    public void setBorderPainted(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        boolean oldValue = paintBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        paintBorder = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        firePropertyChange("borderPainted", oldValue, paintBorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        if (b != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * Paints the menubar's border if <code>BorderPainted</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * property is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @param g the <code>Graphics</code> context to use for painting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @see JComponent#paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @see JComponent#setBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    protected void paintBorder(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        if (isBorderPainted()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            super.paintBorder(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * Sets the margin between the menubar's border and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * its menus. Setting to <code>null</code> will cause the menubar to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * use the default margins.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * @param m an Insets object containing the margin values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * @see Insets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     *  description: The space between the menubar's border and its contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    public void setMargin(Insets m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        Insets old = margin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        this.margin = m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        firePropertyChange("margin", old, m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        if (old == null || !old.equals(m)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * Returns the margin between the menubar's border and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * its menus.  If there is no previous margin, it will create
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * a default margin with zero size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @return an <code>Insets</code> object containing the margin values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @see Insets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    public Insets getMargin() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        if(margin == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            return new Insets(0,0,0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            return margin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * Implemented to be a <code>MenuElement</code> -- does nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * @see #getSubElements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    public void processMouseEvent(MouseEvent event,MenuElement path[],MenuSelectionManager manager) {
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 processKeyEvent(KeyEvent e,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 menuSelectionChanged(boolean isIncluded) {
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> -- returns the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * menus in this menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * This is the reason for implementing the <code>MenuElement</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * interface -- so that the menu bar can be treated the same as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * other menu elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @return an array of menu items in the menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    public MenuElement[] getSubElements() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        MenuElement result[];
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
   417
        Vector<MenuElement> tmp = new Vector<MenuElement>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        int c = getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        Component m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        for(i=0 ; i < c ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            m = getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            if(m instanceof MenuElement)
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
   425
                tmp.addElement((MenuElement) m);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        result = new MenuElement[tmp.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        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
   430
            result[i] = tmp.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * Implemented to be a <code>MenuElement</code>. Returns this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @return the current <code>Component</code> (this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @see #getSubElements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    public Component getComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * Returns a string representation of this <code>JMenuBar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * @return  a string representation of this <code>JMenuBar</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        String paintBorderString = (paintBorder ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                                    "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        String marginString = (margin != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                               margin.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        ",margin=" + marginString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        ",paintBorder=" + paintBorderString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * Gets the AccessibleContext associated with this JMenuBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * For JMenuBars, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * AccessibleJMenuBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * A new AccessibleJMenuBar instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * @return an AccessibleJMenuBar that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     *         AccessibleContext of this JMenuBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            accessibleContext = new AccessibleJMenuBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * <code>JMenuBar</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * Java Accessibility API appropriate to menu bar user-interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    protected class AccessibleJMenuBar extends AccessibleJComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        implements AccessibleSelection {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
         * Get the accessible state set of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
         * @return an instance of AccessibleState containing the current state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
         *         of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            AccessibleStateSet states = super.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            return states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            return AccessibleRole.MENU_BAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
         * Get the AccessibleSelection associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
         * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
         * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
         * AccessibleSelection interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        public AccessibleSelection getAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
         * Returns 1 if a menu is currently selected in this menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
         * @return 1 if a menu is currently selected, else 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
         public int getAccessibleSelectionCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            if (isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
         * Returns the currently selected menu if one is selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
         * otherwise null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
         public Accessible getAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            if (isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                if (i != 0) {   // single selection model for JMenuBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                int j = getSelectionModel().getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                if (getComponentAtIndex(j) instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                    return (Accessible) getComponentAtIndex(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
         * Returns true if the current child of this object is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
         * @param i the zero-based index of the child in this Accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
         * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
         * @see AccessibleContext#getAccessibleChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        public boolean isAccessibleChildSelected(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            return (i == getSelectionModel().getSelectedIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
         * Selects the nth menu in the menu bar, forcing it to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
         * pop up.  If another menu is popped up, this will force
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
         * it to close.  If the nth menu is already selected, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
         * method has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
         * @param i the zero-based index of selectable items
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
         * @see #getAccessibleStateSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        public void addAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            // first close up any open menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            int j = getSelectionModel().getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            if (i == j) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            if (j >= 0 && j < getMenuCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                JMenu menu = getMenu(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                if (menu != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                    MenuSelectionManager.defaultManager().setSelectedPath(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
//                  menu.setPopupMenuVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            // now popup the new menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            getSelectionModel().setSelectedIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            JMenu menu = getMenu(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            if (menu != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                MenuElement me[] = new MenuElement[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                me[0] = JMenuBar.this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                me[1] = menu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                me[2] = menu.getPopupMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                MenuSelectionManager.defaultManager().setSelectedPath(me);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
//              menu.setPopupMenuVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
         * Removes the nth selected item in the object from the object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
         * selection.  If the nth item isn't currently selected, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
         * method has no effect.  Otherwise, it closes the popup menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
         * @param i the zero-based index of selectable items
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        public void removeAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            if (i >= 0 && i < getMenuCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                JMenu menu = getMenu(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                if (menu != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                    MenuSelectionManager.defaultManager().setSelectedPath(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
//                  menu.setPopupMenuVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                getSelectionModel().setSelectedIndex(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
         * Clears the selection in the object, so that nothing in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
         * object is selected.  This will close any open menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        public void clearAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            int i = getSelectionModel().getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            if (i >= 0 && i < getMenuCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                JMenu menu = getMenu(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                if (menu != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                    MenuSelectionManager.defaultManager().setSelectedPath(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
//                  menu.setPopupMenuVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            getSelectionModel().setSelectedIndex(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
         * Normally causes every selected item in the object to be selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
         * if the object supports multiple selections.  This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
         * makes no sense in a menu bar, and so does nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        public void selectAllAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    } // internal class AccessibleJMenuBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * Subclassed to check all the child menus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                                        int condition, boolean pressed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        // See if we have a local binding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        boolean retValue = super.processKeyBinding(ks, e, condition, pressed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        if (!retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            MenuElement[] subElements = getSubElements();
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
   667
            for (MenuElement subElement : subElements) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                if (processBindingForKeyStrokeRecursive(
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
   669
                        subElement, ks, e, condition, pressed)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        return retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    static boolean processBindingForKeyStrokeRecursive(MenuElement elem,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                                                       KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        if (elem == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        Component c = elem.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        if ( !(c.isVisible() || (c instanceof JPopupMenu)) || !c.isEnabled() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        if (c != null && c instanceof JComponent &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            ((JComponent)c).processKeyBinding(ks, e, condition, pressed)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        MenuElement[] subElements = elem.getSubElements();
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
   696
        for (MenuElement subElement : subElements) {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
   697
            if (processBindingForKeyStrokeRecursive(subElement, ks, e, condition, pressed)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                // We don't, pass along to children JMenu's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * Overrides <code>JComponent.addNotify</code> to register this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * menu bar with the current keyboard manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    public void addNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        super.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        KeyboardManager.getCurrentManager().registerMenuBar(this);
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.removeNotify</code> to unregister 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 removeNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        super.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        KeyboardManager.getCurrentManager().unregisterMenuBar(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
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        Object[] kvData = new Object[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        int n = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        if (selectionModel instanceof Serializable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            kvData[n++] = "selectionModel";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            kvData[n++] = selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        s.writeObject(kvData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * See JComponent.readObject() for information about serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        Object[] kvData = (Object[])(s.readObject());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        for(int i = 0; i < kvData.length; i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            if (kvData[i] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            else if (kvData[i].equals("selectionModel")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                selectionModel = (SingleSelectionModel)kvData[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
}