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