jdk/src/java.desktop/share/classes/javax/swing/JPopupMenu.java
author ddehaven
Tue, 19 Aug 2014 10:32:16 -0700
changeset 26037 508779ce6619
parent 26001 jdk/src/share/classes/javax/swing/JPopupMenu.java@991e1be0b235
parent 25859 jdk/src/share/classes/javax/swing/JPopupMenu.java@3317bb8137f4
child 32865 f9cb6e427f9e
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
21794
3a7def8aa5fb 7160604: Using non-opaque windows - popups are initially not painted correctly
bagiras
parents: 21278
diff changeset
     2
 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3956
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: 3956
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: 3956
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3956
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3956
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.swing.plaf.PopupMenuUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.swing.plaf.ComponentUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.swing.plaf.basic.BasicComboPopup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.swing.event.*;
12529
6da056faf511 7154480: [macosx] Not all popup menu items are visible
leonidr
parents: 12278
diff changeset
    44
6da056faf511 7154480: [macosx] Not all popup menu items are visible
leonidr
parents: 12278
diff changeset
    45
import sun.awt.SunToolkit;
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
    46
import sun.security.util.SecurityConstants;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.applet.Applet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * An implementation of a popup menu -- a small window that pops up
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * and displays a series of choices. A <code>JPopupMenu</code> is used for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * menu that appears when the user selects an item on the menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * It is also used for "pull-right" menu that appears when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * selects a menu item that activates it. Finally, a <code>JPopupMenu</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * can also be used anywhere else you want a menu to appear.  For
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * example, when the user right-clicks in a specified area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * For information and examples of using popup menus, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <a
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20157
diff changeset
    61
 href="http://docs.oracle.com/javase/tutorial/uiswing/components/menu.html">How to Use Menus</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * in <em>The Java Tutorial.</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <strong>Warning:</strong> Swing is not thread safe. For more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * information see <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * href="package-summary.html#threading">Swing's Threading
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * Policy</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
    74
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *   attribute: isContainer false
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * description: A small window that pops up and displays a series of choices.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * @author Georges Saab
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * @author David Karlton
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * @author Arnaud Weber
25201
4adc75e0c4e5 8046485: Add missing @since tag under javax.swing.*
henryjen
parents: 21794
diff changeset
    85
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 */
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 9493
diff changeset
    87
@SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
public class JPopupMenu extends JComponent implements Accessible,MenuElement {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @see #getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @see #readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private static final String uiClassID = "PopupMenuUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * Key used in AppContext to determine if light way popups are the default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private static final Object defaultLWPopupEnabledKey =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        new StringBuffer("JPopupMenu.defaultLWPopupEnabledKey");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /** Bug#4425878-Property javax.swing.adjustPopupLocationToFit introduced */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    static boolean popupPostionFixDisabled = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        popupPostionFixDisabled = java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                new sun.security.action.GetPropertyAction(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                "javax.swing.adjustPopupLocationToFit","")).equals("false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    transient  Component invoker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    transient  Popup popup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    transient  Frame frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private    int desiredLocationX,desiredLocationY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    private    String     label                   = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    private    boolean   paintBorder              = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    private    Insets    margin                   = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Used to indicate if lightweight popups should be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    private    boolean   lightWeightPopup         = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * Model for the selected subcontrol.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private SingleSelectionModel selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /* Lock object used in place of class object for synchronization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * (4187686)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    private static final Object classLock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /* diagnostic aids -- should be false for production builds. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    private static final boolean TRACE =   false; // trace creates and disposes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    private static final boolean VERBOSE = false; // show reuse hits/misses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    private static final boolean DEBUG =   false;  // show bad params, misc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *  Sets the default value of the <code>lightWeightPopupEnabled</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *  property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *  @param aFlag <code>true</code> if popups can be lightweight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *               otherwise <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *  @see #getDefaultLightWeightPopupEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *  @see #setLightWeightPopupEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public static void setDefaultLightWeightPopupEnabled(boolean aFlag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        SwingUtilities.appContextPut(defaultLWPopupEnabledKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                                     Boolean.valueOf(aFlag));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *  Gets the <code>defaultLightWeightPopupEnabled</code> property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *  which by default is <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *  @return the value of the <code>defaultLightWeightPopupEnabled</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *          property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *  @see #setDefaultLightWeightPopupEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public static boolean getDefaultLightWeightPopupEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        Boolean b = (Boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            SwingUtilities.appContextGet(defaultLWPopupEnabledKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (b == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            SwingUtilities.appContextPut(defaultLWPopupEnabledKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                                         Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        return b.booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * Constructs a <code>JPopupMenu</code> without an "invoker".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public JPopupMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        this(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * Constructs a <code>JPopupMenu</code> with the specified title.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @param label  the string that a UI may use to display as a title
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * for the popup menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public JPopupMenu(String label) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        this.label = label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        lightWeightPopup = getDefaultLightWeightPopupEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        setSelectionModel(new DefaultSingleSelectionModel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        enableEvents(AWTEvent.MOUSE_EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        setFocusTraversalKeysEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        updateUI();
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    /**
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 12833
diff changeset
   200
     * Returns the look and feel (L&amp;F) object that renders this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @return the <code>PopupMenuUI</code> object that renders this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public PopupMenuUI getUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        return (PopupMenuUI)ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /**
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 12833
diff changeset
   209
     * Sets the L&amp;F object that renders this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 12833
diff changeset
   211
     * @param ui the new <code>PopupMenuUI</code> L&amp;F object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *       hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *  description: The UI object that implements the Component's LookAndFeel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    public void setUI(PopupMenuUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        super.setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * Resets the UI property to a value from the current look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @see JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        setUI((PopupMenuUI)UIManager.getUI(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    /**
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 12833
diff changeset
   234
     * Returns the name of the L&amp;F class that renders this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @return the string "PopupMenuUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        return uiClassID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    protected void processFocusEvent(FocusEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        super.processFocusEvent(evt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * Processes key stroke events such as mnemonics and accelerators.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @param evt  the key event to be processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    protected void processKeyEvent(KeyEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        MenuSelectionManager.defaultManager().processKeyEvent(evt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        if (evt.isConsumed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        super.processKeyEvent(evt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * Returns the model object that handles single selections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @return the <code>selectionModel</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @see SingleSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public SingleSelectionModel getSelectionModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        return selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * Sets the model object to handle single selections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @param model the new <code>SingleSelectionModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @see SingleSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * description: The selection model for the popup menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *      expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    public void setSelectionModel(SingleSelectionModel model) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        selectionModel = model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * Appends the specified menu item to the end of this menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @param menuItem the <code>JMenuItem</code> to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @return the <code>JMenuItem</code> added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    public JMenuItem add(JMenuItem menuItem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        super.add(menuItem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        return menuItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * Creates a new menu item with the specified text and appends
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * it to the end of this menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @param s the string for the menu item to be added
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
   301
     * @return a new {@code JMenuItem} created using {@code s}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    public JMenuItem add(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        return add(new JMenuItem(s));
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
     * Appends a new menu item to the end of the menu which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * dispatches the specified <code>Action</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @param a the <code>Action</code> to add to the menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @return the new menu item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @see Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public JMenuItem add(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        JMenuItem mi = createActionComponent(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        mi.setAction(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        add(mi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        return mi;
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
     * Returns an point which has been adjusted to take into account of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * desktop bounds, taskbar and multi-monitor configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * This adustment may be cancelled by invoking the application with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * -Djavax.swing.adjustPopupLocationToFit=false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     */
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   329
    Point adjustPopupLocationToFitScreen(int xPosition, int yPosition) {
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   330
        Point popupLocation = new Point(xPosition, yPosition);
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   331
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   332
        if(popupPostionFixDisabled == true || GraphicsEnvironment.isHeadless()) {
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   333
            return popupLocation;
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   334
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   336
        // Get screen bounds
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   337
        Rectangle scrBounds;
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   338
        GraphicsConfiguration gc = getCurrentGraphicsConfiguration(popupLocation);
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   339
        Toolkit toolkit = Toolkit.getDefaultToolkit();
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   340
        if(gc != null) {
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   341
            // If we have GraphicsConfiguration use it to get screen bounds
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   342
            scrBounds = gc.getBounds();
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   343
        } else {
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   344
            // If we don't have GraphicsConfiguration use primary screen
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   345
            scrBounds = new Rectangle(toolkit.getScreenSize());
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   346
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   348
        // Calculate the screen size that popup should fit
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   349
        Dimension popupSize = JPopupMenu.this.getPreferredSize();
9493
249a58037fde 6888633: test/closed/javax/swing/JPopupMenu/4786415/bug4786415.java fails
dav
parents: 5506
diff changeset
   350
        long popupRightX = (long)popupLocation.x + (long)popupSize.width;
249a58037fde 6888633: test/closed/javax/swing/JPopupMenu/4786415/bug4786415.java fails
dav
parents: 5506
diff changeset
   351
        long popupBottomY = (long)popupLocation.y + (long)popupSize.height;
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   352
        int scrWidth = scrBounds.width;
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   353
        int scrHeight = scrBounds.height;
12529
6da056faf511 7154480: [macosx] Not all popup menu items are visible
leonidr
parents: 12278
diff changeset
   354
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   355
        if (!canPopupOverlapTaskBar()) {
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   356
            // Insets include the task bar. Take them into account.
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   357
            Insets scrInsets = toolkit.getScreenInsets(gc);
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   358
            scrBounds.x += scrInsets.left;
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   359
            scrBounds.y += scrInsets.top;
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   360
            scrWidth -= scrInsets.left + scrInsets.right;
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   361
            scrHeight -= scrInsets.top + scrInsets.bottom;
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   362
        }
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   363
        int scrRightX = scrBounds.x + scrWidth;
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   364
        int scrBottomY = scrBounds.y + scrHeight;
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   365
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   366
        // Ensure that popup menu fits the screen
12278
f3519c549711 6888634: test/closed/javax/swing/Popup/TaskbarPositionTest.java fails
rupashka
parents: 11268
diff changeset
   367
        if (popupRightX > (long) scrRightX) {
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   368
            popupLocation.x = scrRightX - popupSize.width;
12278
f3519c549711 6888634: test/closed/javax/swing/Popup/TaskbarPositionTest.java fails
rupashka
parents: 11268
diff changeset
   369
        }
f3519c549711 6888634: test/closed/javax/swing/Popup/TaskbarPositionTest.java fails
rupashka
parents: 11268
diff changeset
   370
f3519c549711 6888634: test/closed/javax/swing/Popup/TaskbarPositionTest.java fails
rupashka
parents: 11268
diff changeset
   371
        if (popupBottomY > (long) scrBottomY) {
f3519c549711 6888634: test/closed/javax/swing/Popup/TaskbarPositionTest.java fails
rupashka
parents: 11268
diff changeset
   372
            popupLocation.y = scrBottomY - popupSize.height;
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   373
        }
12278
f3519c549711 6888634: test/closed/javax/swing/Popup/TaskbarPositionTest.java fails
rupashka
parents: 11268
diff changeset
   374
f3519c549711 6888634: test/closed/javax/swing/Popup/TaskbarPositionTest.java fails
rupashka
parents: 11268
diff changeset
   375
        if (popupLocation.x < scrBounds.x) {
f3519c549711 6888634: test/closed/javax/swing/Popup/TaskbarPositionTest.java fails
rupashka
parents: 11268
diff changeset
   376
            popupLocation.x = scrBounds.x;
f3519c549711 6888634: test/closed/javax/swing/Popup/TaskbarPositionTest.java fails
rupashka
parents: 11268
diff changeset
   377
        }
f3519c549711 6888634: test/closed/javax/swing/Popup/TaskbarPositionTest.java fails
rupashka
parents: 11268
diff changeset
   378
f3519c549711 6888634: test/closed/javax/swing/Popup/TaskbarPositionTest.java fails
rupashka
parents: 11268
diff changeset
   379
        if (popupLocation.y < scrBounds.y) {
f3519c549711 6888634: test/closed/javax/swing/Popup/TaskbarPositionTest.java fails
rupashka
parents: 11268
diff changeset
   380
            popupLocation.y = scrBounds.y;
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   381
        }
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   382
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   383
        return popupLocation;
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   384
    }
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   385
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   386
    /**
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   387
     * Tries to find GraphicsConfiguration
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   388
     * that contains the mouse cursor position.
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   389
     * Can return null.
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   390
     */
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   391
    private GraphicsConfiguration getCurrentGraphicsConfiguration(
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   392
            Point popupLocation) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        GraphicsConfiguration gc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        GraphicsEnvironment ge =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            GraphicsEnvironment.getLocalGraphicsEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        GraphicsDevice[] gd = ge.getScreenDevices();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        for(int i = 0; i < gd.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            if(gd[i].getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                GraphicsConfiguration dgc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                    gd[i].getDefaultConfiguration();
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   401
                if(dgc.getBounds().contains(popupLocation)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                    gc = dgc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        // If not found and we have invoker, ask invoker about his gc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        if(gc == null && getInvoker() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            gc = getInvoker().getGraphicsConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        }
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   411
        return gc;
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   412
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   414
    /**
12529
6da056faf511 7154480: [macosx] Not all popup menu items are visible
leonidr
parents: 12278
diff changeset
   415
     * Returns whether popup is allowed to be shown above the task bar.
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   416
     */
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   417
    static boolean canPopupOverlapTaskBar() {
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   418
        boolean result = true;
12529
6da056faf511 7154480: [macosx] Not all popup menu items are visible
leonidr
parents: 12278
diff changeset
   419
6da056faf511 7154480: [macosx] Not all popup menu items are visible
leonidr
parents: 12278
diff changeset
   420
        Toolkit tk = Toolkit.getDefaultToolkit();
6da056faf511 7154480: [macosx] Not all popup menu items are visible
leonidr
parents: 12278
diff changeset
   421
        if (tk instanceof SunToolkit) {
6da056faf511 7154480: [macosx] Not all popup menu items are visible
leonidr
parents: 12278
diff changeset
   422
            result = ((SunToolkit)tk).canPopupOverlapTaskBar();
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   423
        }
12529
6da056faf511 7154480: [macosx] Not all popup menu items are visible
leonidr
parents: 12278
diff changeset
   424
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   425
        return result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * Factory method which creates the <code>JMenuItem</code> for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * <code>Actions</code> added to the <code>JPopupMenu</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * @param a the <code>Action</code> for the menu item to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * @return the new menu item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * @see Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    protected JMenuItem createActionComponent(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        JMenuItem mi = new JMenuItem() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            protected PropertyChangeListener createActionPropertyChangeListener(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                PropertyChangeListener pcl = createActionChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                if (pcl == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                    pcl = super.createActionPropertyChangeListener(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                return pcl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        mi.setHorizontalTextPosition(JButton.TRAILING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        mi.setVerticalTextPosition(JButton.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        return mi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * Returns a properly configured <code>PropertyChangeListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * which updates the control as changes to the <code>Action</code> occur.
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
   456
     *
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
   457
     * @param b the menu item for which to create a listener
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
   458
     * @return a properly configured {@code PropertyChangeListener}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    protected PropertyChangeListener createActionChangeListener(JMenuItem b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        return b.createActionPropertyChangeListener0(b.getAction());
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
     * Removes the component at the specified index from this popup menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * @param       pos the position of the item to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * @exception   IllegalArgumentException if the value of
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 12833
diff changeset
   469
     *                          <code>pos</code> &lt; 0, or if the value of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     *                          <code>pos</code> is greater than the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     *                          number of items
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    public void remove(int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        if (pos < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            throw new IllegalArgumentException("index less than zero.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        if (pos > getComponentCount() -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            throw new IllegalArgumentException("index greater than the number of items.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        super.remove(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * Sets the value of the <code>lightWeightPopupEnabled</code> property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * which by default is <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * By default, when a look and feel displays a popup,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * it can choose to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * use a lightweight (all-Java) popup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * Lightweight popup windows are more efficient than heavyweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * (native peer) windows,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * but lightweight and heavyweight components do not mix well in a GUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * If your application mixes lightweight and heavyweight components,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * you should disable lightweight popups.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * Some look and feels might always use heavyweight popups,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * no matter what the value of this property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * @param aFlag  <code>false</code> to disable lightweight popups
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * description: Determines whether lightweight popups are used when possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     *      expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @see #isLightWeightPopupEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    public void setLightWeightPopupEnabled(boolean aFlag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        // NOTE: this use to set the flag on a shared JPopupMenu, which meant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        // this effected ALL JPopupMenus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        lightWeightPopup = aFlag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * Gets the <code>lightWeightPopupEnabled</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * @return the value of the <code>lightWeightPopupEnabled</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * @see #setLightWeightPopupEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    public boolean isLightWeightPopupEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        return lightWeightPopup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * Returns the popup menu's label
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * @return a string containing the popup menu's label
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * @see #setLabel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    public String getLabel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        return label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * Sets the popup menu's label.  Different look and feels may choose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * to display or not display this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * @param label a string specifying the label for the popup menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * @see #setLabel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * description: The label for the popup menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    public void setLabel(String label) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        String oldValue = this.label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        this.label = label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        firePropertyChange("label", oldValue, label);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                oldValue, label);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * Appends a new separator at the end of the menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    public void addSeparator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        add( new JPopupMenu.Separator() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * Inserts a menu item for the specified <code>Action</code> object at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * a given position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * @param a  the <code>Action</code> object to insert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * @param index      specifies the position at which to insert the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     *                   <code>Action</code>, where 0 is the first
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 12833
diff changeset
   568
     * @exception IllegalArgumentException if <code>index</code> &lt; 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * @see Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    public void insert(Action a, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        JMenuItem mi = createActionComponent(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        mi.setAction(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        insert(mi, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * Inserts the specified component into the menu at a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * @param component  the <code>Component</code> to insert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * @param index      specifies the position at which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     *                   to insert the component, where 0 is the first
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 12833
diff changeset
   584
     * @exception IllegalArgumentException if <code>index</code> &lt; 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    public void insert(Component component, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        if (index < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            throw new IllegalArgumentException("index less than zero.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        int nitems = getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        // PENDING(ges): Why not use an array?
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   593
        Vector<Component> tempItems = new Vector<Component>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        /* Remove the item at index, nitems-index times
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
           storing them in a temporary vector in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
           order they appear on the menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
           */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        for (int i = index ; i < nitems; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            tempItems.addElement(getComponent(index));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            remove(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        add(component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        /* Add the removed items back to the menu, they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
           already in the correct order in the temp vector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
           */
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   609
        for (Component tempItem : tempItems) {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   610
            add(tempItem);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     *  Adds a <code>PopupMenu</code> listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     *  @param l  the <code>PopupMenuListener</code> to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    public void addPopupMenuListener(PopupMenuListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        listenerList.add(PopupMenuListener.class,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * Removes a <code>PopupMenu</code> listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * @param l  the <code>PopupMenuListener</code> to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    public void removePopupMenuListener(PopupMenuListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        listenerList.remove(PopupMenuListener.class,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * Returns an array of all the <code>PopupMenuListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * to this JMenuItem with addPopupMenuListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * @return all of the <code>PopupMenuListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    public PopupMenuListener[] getPopupMenuListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   641
        return listenerList.getListeners(PopupMenuListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * Adds a <code>MenuKeyListener</code> to the popup menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * @param l the <code>MenuKeyListener</code> to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    public void addMenuKeyListener(MenuKeyListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        listenerList.add(MenuKeyListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * Removes a <code>MenuKeyListener</code> from the popup menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * @param l the <code>MenuKeyListener</code> to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    public void removeMenuKeyListener(MenuKeyListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        listenerList.remove(MenuKeyListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * Returns an array of all the <code>MenuKeyListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * to this JPopupMenu with addMenuKeyListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * @return all of the <code>MenuKeyListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    public MenuKeyListener[] getMenuKeyListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   673
        return listenerList.getListeners(MenuKeyListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * Notifies <code>PopupMenuListener</code>s that this popup menu will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * become visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    protected void firePopupMenuWillBecomeVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        PopupMenuEvent e=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            if (listeners[i]==PopupMenuListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                    e = new PopupMenuEvent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                ((PopupMenuListener)listeners[i+1]).popupMenuWillBecomeVisible(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * Notifies <code>PopupMenuListener</code>s that this popup menu will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * become invisible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    protected void firePopupMenuWillBecomeInvisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        PopupMenuEvent e=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            if (listeners[i]==PopupMenuListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                    e = new PopupMenuEvent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                ((PopupMenuListener)listeners[i+1]).popupMenuWillBecomeInvisible(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * Notifies <code>PopupMenuListeners</code> that this popup menu is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * cancelled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    protected void firePopupMenuCanceled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        PopupMenuEvent e=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            if (listeners[i]==PopupMenuListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                    e = new PopupMenuEvent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                ((PopupMenuListener)listeners[i+1]).popupMenuCanceled(e);
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * Always returns true since popups, by definition, should always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * be on top of all other windows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * @return true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    // package private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    boolean alwaysOnTop() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * Lays out the container so that it uses the minimum space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * needed to display its contents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    public void pack() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        if(popup != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            Dimension pref = getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            if (pref == null || pref.width != getWidth() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                                pref.height != getHeight()) {
21794
3a7def8aa5fb 7160604: Using non-opaque windows - popups are initially not painted correctly
bagiras
parents: 21278
diff changeset
   744
                showPopup();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * Sets the visibility of the popup menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * @param b true to make the popup visible, or false to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     *          hide it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     *           bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     *     description: Makes the popup visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    public void setVisible(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            System.out.println("JPopupMenu.setVisible " + b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        // Is it a no-op?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        if (b == isVisible())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        // if closing, first close all Submenus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        if (b == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            // 4234793: This is a workaround because JPopupMenu.firePopupMenuCanceled is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            // a protected method and cannot be called from BasicPopupMenuUI directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            // The real solution could be to make
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            // firePopupMenuCanceled public and call it directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            Boolean doCanceled = (Boolean)getClientProperty("JPopupMenu.firePopupMenuCanceled");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            if (doCanceled != null && doCanceled == Boolean.TRUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                putClientProperty("JPopupMenu.firePopupMenuCanceled", Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                firePopupMenuCanceled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            getSelectionModel().clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            // This is a popup menu with MenuElement children,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            // set selection path before popping up!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            if (isPopupMenu()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                MenuElement me[] = new MenuElement[1];
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   788
                me[0] = this;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                MenuSelectionManager.defaultManager().setSelectedPath(me);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        if(b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            firePopupMenuWillBecomeVisible();
21794
3a7def8aa5fb 7160604: Using non-opaque windows - popups are initially not painted correctly
bagiras
parents: 21278
diff changeset
   795
            showPopup();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            firePropertyChange("visible", Boolean.FALSE, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        } else if(popup != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            firePopupMenuWillBecomeInvisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            popup.hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            popup = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            firePropertyChange("visible", Boolean.TRUE, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
            // 4694797: When popup menu is made invisible, selected path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            // should be cleared
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            if (isPopupMenu()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                MenuSelectionManager.defaultManager().clearSelectedPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    /**
21794
3a7def8aa5fb 7160604: Using non-opaque windows - popups are initially not painted correctly
bagiras
parents: 21278
diff changeset
   813
     * Retrieves <code>Popup</code> instance from the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     * <code>PopupMenuUI</code> that has had <code>show</code> invoked on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * it. If the current <code>popup</code> is non-null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * this will invoke <code>dispose</code> of it, and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * <code>show</code> the new one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * This does NOT fire any events, it is up the caller to dispatch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * the necessary events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     */
21794
3a7def8aa5fb 7160604: Using non-opaque windows - popups are initially not painted correctly
bagiras
parents: 21278
diff changeset
   822
    private void showPopup() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        Popup oldPopup = popup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        if (oldPopup != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            oldPopup.hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        PopupFactory popupFactory = PopupFactory.getSharedInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        if (isLightWeightPopupEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            popupFactory.setPopupType(PopupFactory.LIGHT_WEIGHT_POPUP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        else {
12819
26ca9ac71349 6800513: GTK-LaF renders menus incompletely
neugens
parents: 12529
diff changeset
   834
            popupFactory.setPopupType(PopupFactory.HEAVY_WEIGHT_POPUP);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        // adjust the location of the popup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        Point p = adjustPopupLocationToFitScreen(desiredLocationX,desiredLocationY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        desiredLocationX = p.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        desiredLocationY = p.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        Popup newPopup = getUI().getPopup(this, desiredLocationX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                                          desiredLocationY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        popupFactory.setPopupType(PopupFactory.LIGHT_WEIGHT_POPUP);
21794
3a7def8aa5fb 7160604: Using non-opaque windows - popups are initially not painted correctly
bagiras
parents: 21278
diff changeset
   846
        popup = newPopup;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        newPopup.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * Returns true if the popup menu is visible (currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * being displayed).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    public boolean isVisible() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   855
        return popup != null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * Sets the location of the upper left corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * popup menu using x, y coordinates.
12833
1732e46e976b 7169285: [macosx] Test api/javax_swing/JPopupMenu/descriptions.html#setgetXXX doesn't take Mac main menu
alexsch
parents: 12819
diff changeset
   861
     * <p>
1732e46e976b 7169285: [macosx] Test api/javax_swing/JPopupMenu/descriptions.html#setgetXXX doesn't take Mac main menu
alexsch
parents: 12819
diff changeset
   862
     * The method changes the geometry-related data. Therefore,
1732e46e976b 7169285: [macosx] Test api/javax_swing/JPopupMenu/descriptions.html#setgetXXX doesn't take Mac main menu
alexsch
parents: 12819
diff changeset
   863
     * the native windowing system may ignore such requests, or it may modify
1732e46e976b 7169285: [macosx] Test api/javax_swing/JPopupMenu/descriptions.html#setgetXXX doesn't take Mac main menu
alexsch
parents: 12819
diff changeset
   864
     * the requested data, so that the {@code JPopupMenu} object is placed and sized
1732e46e976b 7169285: [macosx] Test api/javax_swing/JPopupMenu/descriptions.html#setgetXXX doesn't take Mac main menu
alexsch
parents: 12819
diff changeset
   865
     * in a way that corresponds closely to the desktop settings.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * @param x the x coordinate of the popup's new position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     *          in the screen's coordinate space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * @param y the y coordinate of the popup's new position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     *          in the screen's coordinate space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * description: The location of the popup menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    public void setLocation(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        int oldX = desiredLocationX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        int oldY = desiredLocationY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        desiredLocationX = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        desiredLocationY = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        if(popup != null && (x != oldX || y != oldY)) {
21794
3a7def8aa5fb 7160604: Using non-opaque windows - popups are initially not painted correctly
bagiras
parents: 21278
diff changeset
   881
            showPopup();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * Returns true if the popup menu is a standalone popup menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * rather than the submenu of a <code>JMenu</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     * @return true if this menu is a standalone popup menu, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
    private boolean isPopupMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        return  ((invoker != null) && !(invoker instanceof JMenu));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * Returns the component which is the 'invoker' of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * popup menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * @return the <code>Component</code> in which the popup menu is displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    public Component getInvoker() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        return this.invoker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * Sets the invoker of this popup menu -- the component in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     * the popup menu menu is to be displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     * @param invoker the <code>Component</code> in which the popup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     *          menu is displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * description: The invoking component for the popup menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     *      expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
    public void setInvoker(Component invoker) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        Component oldInvoker = this.invoker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        this.invoker = invoker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        if ((oldInvoker != this.invoker) && (ui != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            ui.uninstallUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * Displays the popup menu at the position x,y in the coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     * space of the component invoker.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     * @param invoker the component in whose space the popup menu is to appear
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * @param x the x coordinate in invoker's coordinate space at which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     * the popup menu is to be displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * @param y the y coordinate in invoker's coordinate space at which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     * the popup menu is to be displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
    public void show(Component invoker, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            System.out.println("in JPopupMenu.show " );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        setInvoker(invoker);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        Frame newFrame = getFrame(invoker);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        if (newFrame != frame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            // Use the invoker's frame so that events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            // are propagated properly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            if (newFrame!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                this.frame = newFrame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                if(popup != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                    setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        Point invokerOrigin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        if (invoker != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            invokerOrigin = invoker.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            // To avoid integer overflow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            long lx, ly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            lx = ((long) invokerOrigin.x) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                 ((long) x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            ly = ((long) invokerOrigin.y) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                 ((long) y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            if(lx > Integer.MAX_VALUE) lx = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            if(lx < Integer.MIN_VALUE) lx = Integer.MIN_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            if(ly > Integer.MAX_VALUE) ly = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            if(ly < Integer.MIN_VALUE) ly = Integer.MIN_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            setLocation((int) lx, (int) ly);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
            setLocation(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     * Returns the popup menu which is at the root of the menu system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     * for this popup menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * @return the topmost grandparent <code>JPopupMenu</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
    JPopupMenu getRootPopupMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        JPopupMenu mp = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        while((mp!=null) && (mp.isPopupMenu()!=true) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
              (mp.getInvoker() != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
              (mp.getInvoker().getParent() != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
              (mp.getInvoker().getParent() instanceof JPopupMenu)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
              ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
            mp = (JPopupMenu) mp.getInvoker().getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        return mp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     * Returns the component at the specified index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     * @param i  the index of the component, where 0 is the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     * @return the <code>Component</code> at that index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * @deprecated replaced by {@link java.awt.Container#getComponent(int)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    public Component getComponentAtIndex(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        return getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * Returns the index of the specified component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     * @param  c the <code>Component</code> to find
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     * @return the index of the component, where 0 is the first;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     *         or -1 if the component is not found
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
    public int getComponentIndex(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        int ncomponents = this.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        Component[] component = this.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        for (int i = 0 ; i < ncomponents ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
            Component comp = component[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
            if (comp == c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     * Sets the size of the Popup window using a <code>Dimension</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     * This is equivalent to <code>setPreferredSize(d)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * @param d   the <code>Dimension</code> specifying the new size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * description: The size of the popup menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
    public void setPopupSize(Dimension d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        Dimension oldSize = getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        setPreferredSize(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        if (popup != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            Dimension newSize = getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            if (!oldSize.equals(newSize)) {
21794
3a7def8aa5fb 7160604: Using non-opaque windows - popups are initially not painted correctly
bagiras
parents: 21278
diff changeset
  1038
                showPopup();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     * Sets the size of the Popup window to the specified width and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     * height. This is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     *  <code>setPreferredSize(new Dimension(width, height))</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     * @param width the new width of the Popup in pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     * @param height the new height of the Popup in pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     * description: The size of the popup menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
    public void setPopupSize(int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        setPopupSize(new Dimension(width, height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     * Sets the currently selected component,  This will result
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     * in a change to the selection model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     * @param sel the <code>Component</code> to select
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * description: The selected component on the popup menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     *      expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     *      hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
    public void setSelected(Component sel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        SingleSelectionModel model = getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        int index = getComponentIndex(sel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        model.setSelectedIndex(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     * Checks whether the border should be painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     * @return true if the border is painted, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * @see #setBorderPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
    public boolean isBorderPainted() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        return paintBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
     * Sets whether the border should be painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     * @param b if true, the border is painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     * @see #isBorderPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     * description: Is the border of the popup menu painted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
    public void setBorderPainted(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        paintBorder = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
     * Paints the popup menu's border if the <code>borderPainted</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
     * property is <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
     * @param g  the <code>Graphics</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     * @see JComponent#paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     * @see JComponent#setBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
    protected void paintBorder(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        if (isBorderPainted()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
            super.paintBorder(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
     * Returns the margin, in pixels, between the popup menu's border and
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20458
diff changeset
  1112
     * its containers.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     * @return an <code>Insets</code> object containing the margin values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
    public Insets getMargin() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
        if(margin == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
            return new Insets(0,0,0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
            return margin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
     * Examines the list of menu items to determine whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
     * <code>popup</code> is a popup menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
     * @param popup  a <code>JPopupMenu</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
     * @return true if <code>popup</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
    boolean isSubPopupMenu(JPopupMenu popup) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        int ncomponents = this.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        Component[] component = this.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        for (int i = 0 ; i < ncomponents ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            Component comp = component[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
            if (comp instanceof JMenu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
                JMenu menu = (JMenu)comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
                JPopupMenu subPopup = menu.getPopupMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                if (subPopup == popup)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                if (subPopup.isSubPopupMenu(popup))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
    private static Frame getFrame(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        Component w = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        while(!(w instanceof Frame) && (w!=null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
            w = w.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        return (Frame)w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
     * Returns a string representation of this <code>JPopupMenu</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
     * This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     * @return  a string representation of this <code>JPopupMenu</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        String labelString = (label != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                              label : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        String paintBorderString = (paintBorder ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
                                    "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        String marginString = (margin != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                              margin.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
        String lightWeightPopupEnabledString = (isLightWeightPopupEnabled() ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
                                                "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
            ",desiredLocationX=" + desiredLocationX +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
            ",desiredLocationY=" + desiredLocationY +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        ",label=" + labelString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
        ",lightWeightPopupEnabled=" + lightWeightPopupEnabledString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        ",margin=" + marginString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        ",paintBorder=" + paintBorderString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     * Gets the AccessibleContext associated with this JPopupMenu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     * For JPopupMenus, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     * AccessibleJPopupMenu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     * A new AccessibleJPopupMenu instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
     * @return an AccessibleJPopupMenu that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
     *         AccessibleContext of this JPopupMenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
            accessibleContext = new AccessibleJPopupMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
     * <code>JPopupMenu</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
     * Java Accessibility API appropriate to popup menu user-interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
     * elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
     */
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 9493
diff changeset
  1214
    @SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
    protected class AccessibleJPopupMenu extends AccessibleJComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        implements PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
         * AccessibleJPopupMenu constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
         * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        protected AccessibleJPopupMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            JPopupMenu.this.addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
         * @return an instance of AccessibleRole describing the role of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
         * the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
            return AccessibleRole.POPUP_MENU;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
         * This method gets called when a bound property is changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
         * @param e A <code>PropertyChangeEvent</code> object describing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
         * the event source and the property that has changed. Must not be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
         * @throws NullPointerException if the parameter is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
         * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
            String propertyName = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
            if (propertyName == "visible") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
                if (e.getOldValue() == Boolean.FALSE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
                    e.getNewValue() == Boolean.TRUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
                    handlePopupIsVisibleEvent(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
                } else if (e.getOldValue() == Boolean.TRUE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                           e.getNewValue() == Boolean.FALSE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
                    handlePopupIsVisibleEvent(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
         * Handles popup "visible" PropertyChangeEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
        private void handlePopupIsVisibleEvent(boolean visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
            if (visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                // notify listeners that the popup became visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
                firePropertyChange(ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
                                   null, AccessibleState.VISIBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                // notify listeners that a popup list item is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                fireActiveDescendant();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
                // notify listeners that the popup became hidden
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
                firePropertyChange(ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
                                   AccessibleState.VISIBLE, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
         * Fires AccessibleActiveDescendant PropertyChangeEvent to notify listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
         * on the popup menu invoker that a popup list item has been selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
        private void fireActiveDescendant() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
            if (JPopupMenu.this instanceof BasicComboPopup) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
                // get the popup list
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 9493
diff changeset
  1283
                JList<?> popupList = ((BasicComboPopup)JPopupMenu.this).getList();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
                if (popupList == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
                // get the first selected item
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
                AccessibleContext ac = popupList.getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
                AccessibleSelection selection = ac.getAccessibleSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
                if (selection == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
                Accessible a = selection.getAccessibleSelection(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                if (a == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                AccessibleContext selectedItem = a.getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                // fire the event with the popup invoker as the source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
                if (selectedItem != null && invoker != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
                    AccessibleContext invokerContext = invoker.getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                    if (invokerContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                        // Check invokerContext because Component.getAccessibleContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
                        // returns null. Classes that extend Component are responsible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
                        // for returning a non-null AccessibleContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
                        invokerContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
                            ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
                            null, selectedItem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
    } // inner class AccessibleJPopupMenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
// Serialization support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
    private void writeObject(ObjectOutputStream s) throws IOException {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1321
        Vector<Object> values = new Vector<Object>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        // Save the invoker, if its Serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        if(invoker != null && invoker instanceof Serializable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
            values.addElement("invoker");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
            values.addElement(invoker);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
        // Save the popup, if its Serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
        if(popup != null && popup instanceof Serializable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
            values.addElement("popup");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
            values.addElement(popup);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        s.writeObject(values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
    // implements javax.swing.MenuElement
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        throws IOException, ClassNotFoundException {
26001
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  1348
        ObjectInputStream.GetField f = s.readFields();
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  1349
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  1350
        int newDesiredLocationX = f.get("desiredLocationX", 0);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  1351
        int newDesiredLocationY = f.get("desiredLocationY", 0);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  1352
        Point p = adjustPopupLocationToFitScreen(
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  1353
                newDesiredLocationX, newDesiredLocationY);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  1354
        desiredLocationX = p.x;
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  1355
        desiredLocationY = p.y;
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  1356
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  1357
        label = (String) f.get("label", null);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  1358
        paintBorder = f.get("paintBorder", false);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  1359
        margin = (Insets) f.get("margin", null);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  1360
        lightWeightPopup = f.get("lightWeightPopup", false);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  1361
        selectionModel = (SingleSelectionModel) f.get("selectionModel", null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 9493
diff changeset
  1363
        Vector<?>          values = (Vector)s.readObject();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
        int             indexCounter = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
        int             maxCounter = values.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
        if(indexCounter < maxCounter && values.elementAt(indexCounter).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
           equals("invoker")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
            invoker = (Component)values.elementAt(++indexCounter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
            indexCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
        if(indexCounter < maxCounter && values.elementAt(indexCounter).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
           equals("popup")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
            popup = (Popup)values.elementAt(++indexCounter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
            indexCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
     * This method is required to conform to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
     * <code>MenuElement</code> interface, but it not implemented.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
     * @see MenuElement#processMouseEvent(MouseEvent, MenuElement[], MenuSelectionManager)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
    public void processMouseEvent(MouseEvent event,MenuElement path[],MenuSelectionManager manager) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
     * Processes a key event forwarded from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
     * <code>MenuSelectionManager</code> and changes the menu selection,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
     * if necessary, by using <code>MenuSelectionManager</code>'s API.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
     * Note: you do not have to forward the event to sub-components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
     * This is done automatically by the <code>MenuSelectionManager</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
     * @param e  a <code>KeyEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
     * @param path the <code>MenuElement</code> path array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
     * @param manager   the <code>MenuSelectionManager</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
    public void processKeyEvent(KeyEvent e, MenuElement path[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                                MenuSelectionManager manager) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
        MenuKeyEvent mke = new MenuKeyEvent(e.getComponent(), e.getID(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
                                             e.getWhen(), e.getModifiers(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
                                             e.getKeyCode(), e.getKeyChar(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
                                             path, manager);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
        processMenuKeyEvent(mke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
        if (mke.isConsumed())  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
            e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     * Handles a keystroke in a menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
     * @param e  a <code>MenuKeyEvent</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
    private void processMenuKeyEvent(MenuKeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
        switch (e.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
        case KeyEvent.KEY_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
            fireMenuKeyPressed(e); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
        case KeyEvent.KEY_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
            fireMenuKeyReleased(e); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
        case KeyEvent.KEY_TYPED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
            fireMenuKeyTyped(e); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
     * notification on this event type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
     * @param event a <code>MenuKeyEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
    private void fireMenuKeyPressed(MenuKeyEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
            if (listeners[i]==MenuKeyListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
                ((MenuKeyListener)listeners[i+1]).menuKeyPressed(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
     * notification on this event type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
     * @param event a <code>MenuKeyEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
    private void fireMenuKeyReleased(MenuKeyEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
            if (listeners[i]==MenuKeyListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
                ((MenuKeyListener)listeners[i+1]).menuKeyReleased(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
     * notification on this event type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
     * @param event a <code>MenuKeyEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
    private void fireMenuKeyTyped(MenuKeyEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
            if (listeners[i]==MenuKeyListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
                ((MenuKeyListener)listeners[i+1]).menuKeyTyped(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
     * Messaged when the menubar selection changes to activate or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
     * deactivate this menu. This implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
     * <code>javax.swing.MenuElement</code> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
     * Overrides <code>MenuElement.menuSelectionChanged</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
     * @param isIncluded  true if this menu is active, false if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
     *        it is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
     * @see MenuElement#menuSelectionChanged(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
    public void menuSelectionChanged(boolean isIncluded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
            System.out.println("In JPopupMenu.menuSelectionChanged " + isIncluded);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
        if(invoker instanceof JMenu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
            JMenu m = (JMenu) invoker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
            if(isIncluded)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
                m.setPopupMenuVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
                m.setPopupMenuVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
        if (isPopupMenu() && !isIncluded)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
          setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
     * Returns an array of <code>MenuElement</code>s containing the submenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
     * for this menu component.  It will only return items conforming to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
     * the <code>JMenuElement</code> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
     * If popup menu is <code>null</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
     * an empty array.  This method is required to conform to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
     * <code>MenuElement</code> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
     * @return an array of <code>MenuElement</code> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
     * @see MenuElement#getSubElements
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
    public MenuElement[] getSubElements() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
        MenuElement result[];
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1517
        Vector<MenuElement> tmp = new Vector<MenuElement>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
        int c = getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
        Component m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
        for(i=0 ; i < c ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
            m = getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
            if(m instanceof MenuElement)
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1525
                tmp.addElement((MenuElement) m);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
        result = new MenuElement[tmp.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
        for(i=0,c=tmp.size() ; i < c ; i++)
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1530
            result[i] = tmp.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
     * Returns this <code>JPopupMenu</code> component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
     * @return this <code>JPopupMenu</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
     * @see MenuElement#getComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
    public Component getComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
     * A popup menu-specific separator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
     */
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 9493
diff changeset
  1547
    @SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
    static public class Separator extends JSeparator
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
    {
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
  1550
        /**
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
  1551
         * Constructs a popup menu-specific Separator.
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
  1552
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
        public Separator( )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
            super( JSeparator.HORIZONTAL );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
        /**
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 12833
diff changeset
  1559
         * Returns the name of the L&amp;F class that renders this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
         * @return the string "PopupMenuSeparatorUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
         * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
         * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
        public String getUIClassID()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
            return "PopupMenuSeparatorUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
     * Returns true if the <code>MouseEvent</code> is considered a popup trigger
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
     * by the <code>JPopupMenu</code>'s currently installed UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
     *
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
  1576
     * @param e a {@code MouseEvent}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
     * @return true if the mouse event is a popup trigger
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
    public boolean isPopupTrigger(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
        return getUI().isPopupTrigger(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
}