jdk/src/share/classes/javax/swing/Popup.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 7162 74f019c6e7f2
child 11268 f0e59c4852de
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 7162
diff changeset
     2
 * Copyright (c) 1999, 2010, 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: 4366
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: 4366
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: 4366
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4366
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4366
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
1190
f27065d0d9f0 6708392: Provide internal API to create OverrideRedirect windows, XToolkit
art
parents: 715
diff changeset
    29
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.awt.ModalExclude;
1190
f27065d0d9f0 6708392: Provide internal API to create OverrideRedirect windows, XToolkit
art
parents: 715
diff changeset
    31
import sun.awt.SunToolkit;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Popups are used to display a <code>Component</code> to the user, typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * on top of all the other <code>Component</code>s in a particular containment
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * hierarchy. <code>Popup</code>s have a very small life cycle. Once you
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * have obtained a <code>Popup</code>, and hidden it (invoked the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <code>hide</code> method), you should no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * invoke any methods on it. This allows the <code>PopupFactory</code> to cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <code>Popup</code>s for later use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * The general contract is that if you need to change the size of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <code>Component</code>, or location of the <code>Popup</code>, you should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * obtain a new <code>Popup</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <code>Popup</code> does not descend from <code>Component</code>, rather
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * implementations of <code>Popup</code> are responsible for creating
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * and maintaining their own <code>Component</code>s to render the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * requested <code>Component</code> to the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * You typically do not explicitly create an instance of <code>Popup</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * instead obtain one from a <code>PopupFactory</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @see PopupFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
public class Popup {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * The Component representing the Popup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private Component component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Creates a <code>Popup</code> for the Component <code>owner</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * containing the Component <code>contents</code>. <code>owner</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * is used to determine which <code>Window</code> the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * <code>Popup</code> will parent the <code>Component</code> the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * <code>Popup</code> creates to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * A null <code>owner</code> implies there is no valid parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * <code>x</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * <code>y</code> specify the preferred initial location to place
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * the <code>Popup</code> at. Based on screen size, or other paramaters,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * the <code>Popup</code> may not display at <code>x</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * <code>y</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @param owner    Component mouse coordinates are relative to, may be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @param contents Contents of the Popup
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @param x        Initial x screen coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @param y        Initial y screen coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @exception IllegalArgumentException if contents is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    protected Popup(Component owner, Component contents, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        this();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        if (contents == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            throw new IllegalArgumentException("Contents must be non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        reset(owner, contents, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Creates a <code>Popup</code>. This is provided for subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    protected Popup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Makes the <code>Popup</code> visible. If the <code>Popup</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * currently visible, this has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public void show() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        Component component = getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        if (component != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            component.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Hides and disposes of the <code>Popup</code>. Once a <code>Popup</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * has been disposed you should no longer invoke methods on it. A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * <code>dispose</code>d <code>Popup</code> may be reclaimed and later used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * based on the <code>PopupFactory</code>. As such, if you invoke methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * on a <code>disposed</code> <code>Popup</code>, indeterminate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * behavior will result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public void hide() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        Component component = getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        if (component instanceof JWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            component.hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            ((JWindow)component).getContentPane().removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Frees any resources the <code>Popup</code> may be holding onto.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        Component component = getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        Window window = SwingUtilities.getWindowAncestor(component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        if (component instanceof JWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            ((Window)component).dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            component = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        // If our parent is a DefaultFrame, we need to dispose it, too.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if (window instanceof DefaultFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            window.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * Resets the <code>Popup</code> to an initial state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    void reset(Component owner, Component contents, int ownerX, int ownerY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        if (getComponent() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            component = createComponent(owner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        Component c = getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        if (c instanceof JWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            JWindow component = (JWindow)getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            component.setLocation(ownerX, ownerY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            component.getContentPane().add(contents, BorderLayout.CENTER);
7162
74f019c6e7f2 6987844: Incorrect width of JComboBox drop down
alexp
parents: 5506
diff changeset
   159
            component.invalidate();
74f019c6e7f2 6987844: Incorrect width of JComboBox drop down
alexp
parents: 5506
diff changeset
   160
            component.validate();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            if(component.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                // Do not call pack() if window is not visible to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                // avoid early native peer creation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * Causes the <code>Popup</code> to be sized to fit the preferred size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * of the <code>Component</code> it contains.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    void pack() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        Component component = getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (component instanceof Window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            ((Window)component).pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * Returns the <code>Window</code> to use as the parent of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * <code>Window</code> created for the <code>Popup</code>. This creates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * a new <code>DefaultFrame</code>, if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    private Window getParentWindow(Component owner) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        Window window = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if (owner instanceof Window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            window = (Window)owner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        else if (owner != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            window = SwingUtilities.getWindowAncestor(owner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (window == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            window = new DefaultFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        return window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * Creates the Component to use as the parent of the <code>Popup</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * The default implementation creates a <code>Window</code>, subclasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * should override.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    Component createComponent(Component owner) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        if (GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            // Generally not useful, bail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        return new HeavyWeightWindow(getParentWindow(owner));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * Returns the <code>Component</code> returned from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * <code>createComponent</code> that will hold the <code>Popup</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    Component getComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        return component;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Component used to house window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    static class HeavyWeightWindow extends JWindow implements ModalExclude {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        HeavyWeightWindow(Window parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            super(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            setFocusableWindowState(false);
4366
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 1190
diff changeset
   231
            setType(Window.Type.POPUP);
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 1190
diff changeset
   232
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            // Popups are typically transient and most likely won't benefit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            // from true double buffering.  Turn it off here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            getRootPane().setUseTrueDoubleBuffering(false);
414
05c1395dbe48 6691503: Malicious applet can show always-on-top popup menu which has whole screen size
mlapshin
parents: 413
diff changeset
   236
            // Try to set "always-on-top" for the popup window.
05c1395dbe48 6691503: Malicious applet can show always-on-top popup menu which has whole screen size
mlapshin
parents: 413
diff changeset
   237
            // Applets usually don't have sufficient permissions to do it.
05c1395dbe48 6691503: Malicious applet can show always-on-top popup menu which has whole screen size
mlapshin
parents: 413
diff changeset
   238
            // In this case simply ignore the exception.
05c1395dbe48 6691503: Malicious applet can show always-on-top popup menu which has whole screen size
mlapshin
parents: 413
diff changeset
   239
            try {
05c1395dbe48 6691503: Malicious applet can show always-on-top popup menu which has whole screen size
mlapshin
parents: 413
diff changeset
   240
                setAlwaysOnTop(true);
05c1395dbe48 6691503: Malicious applet can show always-on-top popup menu which has whole screen size
mlapshin
parents: 413
diff changeset
   241
            } catch (SecurityException se) {
05c1395dbe48 6691503: Malicious applet can show always-on-top popup menu which has whole screen size
mlapshin
parents: 413
diff changeset
   242
                // setAlwaysOnTop is restricted,
05c1395dbe48 6691503: Malicious applet can show always-on-top popup menu which has whole screen size
mlapshin
parents: 413
diff changeset
   243
                // the exception is ignored
05c1395dbe48 6691503: Malicious applet can show always-on-top popup menu which has whole screen size
mlapshin
parents: 413
diff changeset
   244
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        public void update(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        public void show() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            this.pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            if (getWidth() > 0 && getHeight() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                super.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * Used if no valid Window ancestor of the supplied owner is found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * PopupFactory uses this as a way to know when the Popup shouldn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * be cached based on the Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    static class DefaultFrame extends Frame {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
}