jdk/src/share/classes/javax/swing/Popup.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 414 05c1395dbe48
child 1190 f27065d0d9f0
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 414
diff changeset
     2
 * Copyright 1999-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import sun.awt.ModalExclude;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * Popups are used to display a <code>Component</code> to the user, typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * on top of all the other <code>Component</code>s in a particular containment
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * hierarchy. <code>Popup</code>s have a very small life cycle. Once you
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * have obtained a <code>Popup</code>, and hidden it (invoked the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <code>hide</code> method), you should no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * invoke any methods on it. This allows the <code>PopupFactory</code> to cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <code>Popup</code>s for later use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * The general contract is that if you need to change the size of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <code>Component</code>, or location of the <code>Popup</code>, you should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * obtain a new <code>Popup</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <code>Popup</code> does not descend from <code>Component</code>, rather
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * implementations of <code>Popup</code> are responsible for creating
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * and maintaining their own <code>Component</code>s to render the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * requested <code>Component</code> to the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * You typically do not explicitly create an instance of <code>Popup</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * instead obtain one from a <code>PopupFactory</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @see PopupFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
public class Popup {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * The Component representing the Popup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private Component component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * Creates a <code>Popup</code> for the Component <code>owner</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * containing the Component <code>contents</code>. <code>owner</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * is used to determine which <code>Window</code> the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * <code>Popup</code> will parent the <code>Component</code> the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * <code>Popup</code> creates to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * A null <code>owner</code> implies there is no valid parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * <code>x</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * <code>y</code> specify the preferred initial location to place
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * the <code>Popup</code> at. Based on screen size, or other paramaters,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * the <code>Popup</code> may not display at <code>x</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * <code>y</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * @param owner    Component mouse coordinates are relative to, may be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @param contents Contents of the Popup
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @param x        Initial x screen coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @param y        Initial y screen coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @exception IllegalArgumentException if contents is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    protected Popup(Component owner, Component contents, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        this();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        if (contents == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            throw new IllegalArgumentException("Contents must be non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        reset(owner, contents, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Creates a <code>Popup</code>. This is provided for subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    protected Popup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Makes the <code>Popup</code> visible. If the <code>Popup</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * currently visible, this has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public void show() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        Component component = getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        if (component != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            component.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Hides and disposes of the <code>Popup</code>. Once a <code>Popup</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * has been disposed you should no longer invoke methods on it. A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * <code>dispose</code>d <code>Popup</code> may be reclaimed and later used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * based on the <code>PopupFactory</code>. As such, if you invoke methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * on a <code>disposed</code> <code>Popup</code>, indeterminate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * behavior will result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public void hide() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        Component component = getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        if (component instanceof JWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            component.hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            ((JWindow)component).getContentPane().removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Frees any resources the <code>Popup</code> may be holding onto.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        Component component = getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        Window window = SwingUtilities.getWindowAncestor(component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        if (component instanceof JWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            ((Window)component).dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            component = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        // If our parent is a DefaultFrame, we need to dispose it, too.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if (window instanceof DefaultFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            window.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * Resets the <code>Popup</code> to an initial state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    void reset(Component owner, Component contents, int ownerX, int ownerY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        if (getComponent() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            component = createComponent(owner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        Component c = getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if (c instanceof JWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            JWindow component = (JWindow)getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            component.setLocation(ownerX, ownerY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            component.getContentPane().add(contents, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            contents.invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            if(component.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                // Do not call pack() if window is not visible to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                // avoid early native peer creation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
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
     * Causes the <code>Popup</code> to be sized to fit the preferred size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * of the <code>Component</code> it contains.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    void pack() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        Component component = getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        if (component instanceof Window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            ((Window)component).pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * Returns the <code>Window</code> to use as the parent of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * <code>Window</code> created for the <code>Popup</code>. This creates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * a new <code>DefaultFrame</code>, if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    private Window getParentWindow(Component owner) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        Window window = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        if (owner instanceof Window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            window = (Window)owner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        else if (owner != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            window = SwingUtilities.getWindowAncestor(owner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (window == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            window = new DefaultFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        return window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * Creates the Component to use as the parent of the <code>Popup</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * The default implementation creates a <code>Window</code>, subclasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * should override.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    Component createComponent(Component owner) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            // Generally not useful, bail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        return new HeavyWeightWindow(getParentWindow(owner));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * Returns the <code>Component</code> returned from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * <code>createComponent</code> that will hold the <code>Popup</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    Component getComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        return component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * Component used to house window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    static class HeavyWeightWindow extends JWindow implements ModalExclude {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        HeavyWeightWindow(Window parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            super(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            setFocusableWindowState(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            setName("###overrideRedirect###");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            // Popups are typically transient and most likely won't benefit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            // from true double buffering.  Turn it off here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            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
   232
            // 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
   233
            // 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
   234
            // 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
   235
            try {
05c1395dbe48 6691503: Malicious applet can show always-on-top popup menu which has whole screen size
mlapshin
parents: 413
diff changeset
   236
                setAlwaysOnTop(true);
05c1395dbe48 6691503: Malicious applet can show always-on-top popup menu which has whole screen size
mlapshin
parents: 413
diff changeset
   237
            } catch (SecurityException se) {
05c1395dbe48 6691503: Malicious applet can show always-on-top popup menu which has whole screen size
mlapshin
parents: 413
diff changeset
   238
                // setAlwaysOnTop is restricted,
05c1395dbe48 6691503: Malicious applet can show always-on-top popup menu which has whole screen size
mlapshin
parents: 413
diff changeset
   239
                // 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
   240
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        public void update(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            paint(g);
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 show() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            this.pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            if (getWidth() > 0 && getHeight() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                super.show();
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * Used if no valid Window ancestor of the supplied owner is found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * PopupFactory uses this as a way to know when the Popup shouldn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * be cached based on the Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    static class DefaultFrame extends Frame {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
}