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