jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicMenuUI.java
author chegar
Sun, 17 Aug 2014 15:54:13 +0100
changeset 25859 3317bb8137f4
parent 25761 jdk/src/share/classes/javax/swing/plaf/basic/BasicMenuUI.java@c408b10ef757
child 35650 15f1f0ff7790
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 23010
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3974
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3974
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3974
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3974
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3974
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.plaf.basic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import sun.swing.DefaultLookup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import sun.swing.UIAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 7668
diff changeset
    42
 * A default L&F implementation of MenuUI.  This implementation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * is a "combined" view/controller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * @author Georges Saab
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @author David Karlton
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * @author Arnaud Weber
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
public class BasicMenuUI extends BasicMenuItemUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
{
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
    51
    /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
    52
     * The instance of {@code ChangeListener}.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
    53
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    protected ChangeListener         changeListener;
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
    55
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
    56
    /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
    57
     * The instance of {@code MenuListener}.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
    58
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    protected MenuListener           menuListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private int lastMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /** Uses as the parent of the windowInputMap when selected. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private InputMap selectedWindowInputMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /* diagnostic aids -- should be false for production builds. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private static final boolean TRACE =   false; // trace creates and disposes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private static final boolean VERBOSE = false; // show reuse hits/misses
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private static final boolean DEBUG =   false;  // show bad params, misc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private static boolean crossMenuMnemonic = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
    73
    /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
    74
     * Constructs a new instance of {@code BasicMenuUI}.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
    75
     *
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
    76
     * @param x a component
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
    77
     * @return a new instance of {@code BasicMenuUI}
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
    78
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public static ComponentUI createUI(JComponent x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        return new BasicMenuUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    static void loadActionMap(LazyActionMap map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        BasicMenuItemUI.loadActionMap(map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        map.put(new Actions(Actions.SELECT, null, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        super.installDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        updateDefaultBackgroundColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        ((JMenu)menuItem).setDelay(200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        crossMenuMnemonic = UIManager.getBoolean("Menu.crossMenuMnemonic");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    protected String getPropertyPrefix() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        return "Menu";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    protected void installListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        super.installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        if (changeListener == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            changeListener = createChangeListener(menuItem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        if (changeListener != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            menuItem.addChangeListener(changeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        if (menuListener == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            menuListener = createMenuListener(menuItem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        if (menuListener != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            ((JMenu)menuItem).addMenuListener(menuListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    protected void installKeyboardActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        super.installKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        updateMnemonicBinding();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    void installLazyActionMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        LazyActionMap.installLazyActionMap(menuItem, BasicMenuUI.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                                           getPropertyPrefix() + ".actionMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    void updateMnemonicBinding() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        int mnemonic = menuItem.getModel().getMnemonic();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        int[] shortcutKeys = (int[])DefaultLookup.get(menuItem, this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                                                   "Menu.shortcutKeys");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        if (shortcutKeys == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            shortcutKeys = new int[] {KeyEvent.ALT_MASK};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        if (mnemonic == lastMnemonic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        InputMap windowInputMap = SwingUtilities.getUIInputMap(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                       menuItem, JComponent.WHEN_IN_FOCUSED_WINDOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        if (lastMnemonic != 0 && windowInputMap != null) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   139
            for (int shortcutKey : shortcutKeys) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                windowInputMap.remove(KeyStroke.getKeyStroke
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   141
                        (lastMnemonic, shortcutKey, false));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        if (mnemonic != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            if (windowInputMap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                windowInputMap = createInputMap(JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                                              WHEN_IN_FOCUSED_WINDOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                SwingUtilities.replaceUIInputMap(menuItem, JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                                       WHEN_IN_FOCUSED_WINDOW, windowInputMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            }
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   151
            for (int shortcutKey : shortcutKeys) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                windowInputMap.put(KeyStroke.getKeyStroke(mnemonic,
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   153
                        shortcutKey, false), "selectMenu");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        lastMnemonic = mnemonic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    protected void uninstallKeyboardActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        super.uninstallKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        lastMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    protected MouseInputListener createMouseInputListener(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   168
    /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   169
     * Returns an instance of {@code MenuListener}.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   170
     *
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   171
     * @param c a component
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   172
     * @return an instance of {@code MenuListener}
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   173
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    protected MenuListener createMenuListener(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   178
    /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   179
     * Returns an instance of {@code ChangeListener}.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   180
     *
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   181
     * @param c a component
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   182
     * @return an instance of {@code ChangeListener}
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   183
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    protected ChangeListener createChangeListener(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    protected PropertyChangeListener createPropertyChangeListener(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    BasicMenuItemUI.Handler getHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (handler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            handler = new Handler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        return handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    protected void uninstallDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        menuItem.setArmed(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        menuItem.setSelected(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        menuItem.resetKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        super.uninstallDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        super.uninstallListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        if (changeListener != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            menuItem.removeChangeListener(changeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        if (menuListener != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            ((JMenu)menuItem).removeMenuListener(menuListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        changeListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        menuListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        handler = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    protected MenuDragMouseListener createMenuDragMouseListener(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
7246
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   224
    protected MenuKeyListener createMenuKeyListener(JComponent c) {
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   225
        return (MenuKeyListener)getHandler();
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   226
    }
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   227
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public Dimension getMaximumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        if (((JMenu)menuItem).isTopLevelMenu() == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            Dimension d = c.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            return new Dimension(d.width, Short.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   236
    /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   237
     * Sets timer to the {@code menu}.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   238
     *
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   239
     * @param menu an instance of {@code JMenu}.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   240
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    protected void setupPostTimer(JMenu menu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        Timer timer = new Timer(menu.getDelay(), new Actions(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                                    Actions.SELECT, menu,false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        timer.setRepeats(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        timer.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    private static void appendPath(MenuElement[] path, MenuElement elem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        MenuElement newPath[] = new MenuElement[path.length+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        System.arraycopy(path, 0, newPath, 0, path.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        newPath[path.length] = elem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        MenuSelectionManager.defaultManager().setSelectedPath(newPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    private static class Actions extends UIAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        private static final String SELECT = "selectMenu";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        // NOTE: This will be null if the action is registered in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        // ActionMap. For the timer use it will be non-null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        private JMenu menu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        private boolean force=false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        Actions(String key, JMenu menu, boolean shouldForce) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            super(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            this.menu = menu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            this.force = shouldForce;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        private JMenu getMenu(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            if (e.getSource() instanceof JMenu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                return (JMenu)e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            return menu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            JMenu menu = getMenu(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            if (!crossMenuMnemonic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                JPopupMenu pm = BasicPopupMenuUI.getLastPopup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                if (pm != null && pm != menu.getParent()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            final MenuSelectionManager defaultManager = MenuSelectionManager.defaultManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            if(force) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                Container cnt = menu.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                if(cnt != null && cnt instanceof JMenuBar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                    MenuElement me[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                    MenuElement subElements[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                    subElements = menu.getPopupMenu().getSubElements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                    if(subElements.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                        me = new MenuElement[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                        me[0] = (MenuElement) cnt;
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   296
                        me[1] = menu;
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   297
                        me[2] = menu.getPopupMenu();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                        me[3] = subElements[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                        me = new MenuElement[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                        me[0] = (MenuElement)cnt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                        me[1] = menu;
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   303
                        me[2] = menu.getPopupMenu();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                    defaultManager.setSelectedPath(me);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                MenuElement path[] = defaultManager.getSelectedPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                if(path.length > 0 && path[path.length-1] == menu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                    appendPath(path, menu.getPopupMenu());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        public boolean isEnabled(Object c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            if (c instanceof JMenu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                return ((JMenu)c).isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * Set the background color depending on whether this is a toplevel menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * in a menubar or a submenu of another menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    private void updateDefaultBackgroundColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        if (!UIManager.getBoolean("Menu.useMenuBarBackgroundForTopLevel")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
           return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        JMenu menu = (JMenu)menuItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        if (menu.getBackground() instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            if (menu.isTopLevelMenu()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                menu.setBackground(UIManager.getColor("MenuBar.background"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                menu.setBackground(UIManager.getColor(getPropertyPrefix() + ".background"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        }
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
     * Instantiated and used by a menu item to handle the current menu selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * from mouse events. A MouseInputHandler processes and forwards all mouse events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * to a shared instance of the MenuSelectionManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * This class is protected so that it can be subclassed by other look and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * feels to implement their own mouse handling behavior. All overridden
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * methods should call the parent methods so that the menu selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * is correct.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @see javax.swing.MenuSelectionManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    protected class MouseInputHandler implements MouseInputListener {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
   355
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        public void mouseClicked(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            getHandler().mouseClicked(e);
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
         * Invoked when the mouse has been clicked on the menu. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
         * method clears or sets the selection path of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
         * MenuSelectionManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
         * @param e the mouse event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            getHandler().mousePressed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
         * Invoked when the mouse has been released on the menu. Delegates the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
         * mouse event to the MenuSelectionManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
         * @param e the mouse event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        public void mouseReleased(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            getHandler().mouseReleased(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
         * Invoked when the cursor enters the menu. This method sets the selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
         * path for the MenuSelectionManager and handles the case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
         * in which a menu item is used to pop up an additional menu, as in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
         * hierarchical menu system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
         * @param e the mouse event; not used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        public void mouseEntered(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            getHandler().mouseEntered(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        public void mouseExited(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            getHandler().mouseExited(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
         * Invoked when a mouse button is pressed on the menu and then dragged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
         * Delegates the mouse event to the MenuSelectionManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
         * @param e the mouse event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
         * @see java.awt.event.MouseMotionListener#mouseDragged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        public void mouseDragged(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            getHandler().mouseDragged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        public void mouseMoved(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            getHandler().mouseMoved(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * As of Java 2 platform 1.4, this previously undocumented class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * is now obsolete. KeyBindings are now managed by the popup menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    public class ChangeHandler implements ChangeListener {
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   421
        /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   422
         * The instance of {@code JMenu}.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   423
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        public JMenu    menu;
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   425
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   426
        /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   427
         * The instance of {@code BasicMenuUI}.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   428
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        public BasicMenuUI ui;
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   430
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   431
        /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   432
         * {@code true} if an item of popup menu is selected.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   433
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        public boolean  isSelected = false;
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   435
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   436
        /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   437
         * The component that was focused.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   438
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        public Component wasFocused;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   441
        /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   442
         * Constructs a new instance of {@code ChangeHandler}.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   443
         *
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   444
         * @param m an instance of {@code JMenu}
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   445
         * @param ui an instance of {@code BasicMenuUI}
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   446
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        public ChangeHandler(JMenu m, BasicMenuUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            menu = m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            this.ui = ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        public void stateChanged(ChangeEvent e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
7246
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   455
    private class Handler extends BasicMenuItemUI.Handler implements MenuKeyListener {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        // PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            if (e.getPropertyName() == AbstractButton.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                             MNEMONIC_CHANGED_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                updateMnemonicBinding();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                if (e.getPropertyName().equals("ancestor")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                    updateDefaultBackgroundColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                super.propertyChange(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        // MouseInputListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        public void mouseClicked(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
         * Invoked when the mouse has been clicked on the menu. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
         * method clears or sets the selection path of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
         * MenuSelectionManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
         * @param e the mouse event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            JMenu menu = (JMenu)menuItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            if (!menu.isEnabled())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            MenuSelectionManager manager =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                MenuSelectionManager.defaultManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            if(menu.isTopLevelMenu()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                if(menu.isSelected() && menu.getPopupMenu().isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                    manager.clearSelectedPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                    Container cnt = menu.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                    if(cnt != null && cnt instanceof JMenuBar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                        MenuElement me[] = new MenuElement[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                        me[0]=(MenuElement)cnt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                        me[1]=menu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                        manager.setSelectedPath(me);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            MenuElement selectedPath[] = manager.getSelectedPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            if (selectedPath.length > 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                selectedPath[selectedPath.length-1] != menu.getPopupMenu()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                if(menu.isTopLevelMenu() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                   menu.getDelay() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                    appendPath(selectedPath, menu.getPopupMenu());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                    setupPostTimer(menu);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
         * Invoked when the mouse has been released on the menu. Delegates the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
         * mouse event to the MenuSelectionManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
         * @param e the mouse event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        public void mouseReleased(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            JMenu menu = (JMenu)menuItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            if (!menu.isEnabled())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            MenuSelectionManager manager =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                MenuSelectionManager.defaultManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            manager.processMouseEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            if (!e.isConsumed())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                manager.clearSelectedPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
         * Invoked when the cursor enters the menu. This method sets the selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
         * path for the MenuSelectionManager and handles the case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
         * in which a menu item is used to pop up an additional menu, as in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
         * hierarchical menu system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
         * @param e the mouse event; not used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        public void mouseEntered(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            JMenu menu = (JMenu)menuItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            // only disable the menu highlighting if it's disabled and the property isn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            // true. This allows disabled rollovers to work in WinL&F
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            if (!menu.isEnabled() && !UIManager.getBoolean("MenuItem.disabledAreNavigable")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            MenuSelectionManager manager =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                MenuSelectionManager.defaultManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            MenuElement selectedPath[] = manager.getSelectedPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            if (!menu.isTopLevelMenu()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                if(!(selectedPath.length > 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                     selectedPath[selectedPath.length-1] ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                     menu.getPopupMenu())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                    if(menu.getDelay() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                        appendPath(getPath(), menu.getPopupMenu());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                        manager.setSelectedPath(getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                        setupPostTimer(menu);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                if(selectedPath.length > 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                   selectedPath[0] == menu.getParent()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                    MenuElement newPath[] = new MenuElement[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                    // A top level menu's parent is by definition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                    // a JMenuBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                    newPath[0] = (MenuElement)menu.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                    newPath[1] = menu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                    if (BasicPopupMenuUI.getLastPopup() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                        newPath[2] = menu.getPopupMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                    manager.setSelectedPath(newPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        public void mouseExited(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
         * Invoked when a mouse button is pressed on the menu and then dragged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
         * Delegates the mouse event to the MenuSelectionManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
         * @param e the mouse event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
         * @see java.awt.event.MouseMotionListener#mouseDragged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        public void mouseDragged(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            JMenu menu = (JMenu)menuItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            if (!menu.isEnabled())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            MenuSelectionManager.defaultManager().processMouseEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        public void mouseMoved(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        // MenuDragHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        public void menuDragMouseEntered(MenuDragMouseEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        public void menuDragMouseDragged(MenuDragMouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            if (menuItem.isEnabled() == false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            MenuSelectionManager manager = e.getMenuSelectionManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            MenuElement path[] = e.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            Point p = e.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            if(p.x >= 0 && p.x < menuItem.getWidth() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
               p.y >= 0 && p.y < menuItem.getHeight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                JMenu menu = (JMenu)menuItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                MenuElement selectedPath[] = manager.getSelectedPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                if(!(selectedPath.length > 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                     selectedPath[selectedPath.length-1] ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                     menu.getPopupMenu())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                    if(menu.isTopLevelMenu() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                       menu.getDelay() == 0  ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                       e.getID() == MouseEvent.MOUSE_DRAGGED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                        appendPath(path, menu.getPopupMenu());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                        manager.setSelectedPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                        setupPostTimer(menu);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            } else if(e.getID() == MouseEvent.MOUSE_RELEASED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                Component comp = manager.componentForPoint(e.getComponent(), e.getPoint());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                if (comp == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                    manager.clearSelectedPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        public void menuDragMouseExited(MenuDragMouseEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        public void menuDragMouseReleased(MenuDragMouseEvent e) {}
7246
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   638
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   639
        //
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   640
        // MenuKeyListener
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   641
        //
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   642
        /**
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   643
         * Open the Menu
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   644
         */
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   645
        public void menuKeyTyped(MenuKeyEvent e) {
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   646
            if (!crossMenuMnemonic && BasicPopupMenuUI.getLastPopup() != null) {
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   647
                // when crossMenuMnemonic is not set, we don't open a toplevel
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   648
                // menu if another toplevel menu is already open
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   649
                return;
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   650
            }
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   651
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   652
            if (BasicPopupMenuUI.getPopups().size() != 0) {
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   653
                //Fix 6939261: to return in case not on the main menu
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   654
                //and has a pop-up.
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   655
                //after return code will be handled in BasicPopupMenuUI.java
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   656
                return;
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   657
            }
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   658
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   659
            char key = Character.toLowerCase((char)menuItem.getMnemonic());
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   660
            MenuElement path[] = e.getPath();
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   661
            if (key == Character.toLowerCase(e.getKeyChar())) {
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   662
                JPopupMenu popupMenu = ((JMenu)menuItem).getPopupMenu();
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 23010
diff changeset
   663
                ArrayList<MenuElement> newList = new ArrayList<>(Arrays.asList(path));
7246
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   664
                newList.add(popupMenu);
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   665
                MenuElement subs[] = popupMenu.getSubElements();
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   666
                MenuElement sub =
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   667
                        BasicPopupMenuUI.findEnabledChild(subs, -1, true);
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   668
                if(sub != null) {
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   669
                    newList.add(sub);
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   670
                }
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   671
                MenuSelectionManager manager = e.getMenuSelectionManager();
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   672
                MenuElement newPath[] = new MenuElement[0];;
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 23010
diff changeset
   673
                newPath = newList.toArray(newPath);
7246
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   674
                manager.setSelectedPath(newPath);
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   675
                e.consume();
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   676
            }
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   677
        }
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   678
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   679
        public void menuKeyPressed(MenuKeyEvent e) {}
97ce36d18925 6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
vikram
parents: 5506
diff changeset
   680
        public void menuKeyReleased(MenuKeyEvent e) {}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
}