jdk/src/share/classes/javax/swing/PopupFactory.java
author darcy
Sun, 23 Mar 2014 13:49:48 -0700
changeset 23697 e556a715949f
parent 23010 6dadb192ad81
child 25120 8b6a41c3752f
permissions -rw-r--r--
8034169: Fix serial lint warnings in javax.swing Reviewed-by: alanb, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
     2
 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2496
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: 2496
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: 2496
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2496
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2496
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.applet.Applet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.event.WindowAdapter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.event.WindowEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import static javax.swing.ClientPropertyKey.PopupFactory_FORCE_HEAVYWEIGHT_POPUP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <code>PopupFactory</code>, as the name implies, is used to obtain
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * instances of <code>Popup</code>s. <code>Popup</code>s are used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * display a <code>Component</code> above all other <code>Component</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * in a particular containment hierarchy. The general contract is that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * once you have obtained a <code>Popup</code> from a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <code>PopupFactory</code>, you must invoke <code>hide</code> on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <code>Popup</code>. The typical usage is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *   PopupFactory factory = PopupFactory.getSharedInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *   Popup popup = factory.getPopup(owner, contents, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *   popup.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *   ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *   popup.hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @see Popup
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 PopupFactory {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * The shared instanceof <code>PopupFactory</code> is per
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * <code>AppContext</code>. This is the key used in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * <code>AppContext</code> to locate the <code>PopupFactory</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private static final Object SharedInstanceKey =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        new StringBuffer("PopupFactory.SharedInstanceKey");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * Max number of items to store in any one particular cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private static final int MAX_CACHE_SIZE = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Key used to indicate a light weight popup should be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    static final int LIGHT_WEIGHT_POPUP   = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * Key used to indicate a medium weight Popup should be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    static final int MEDIUM_WEIGHT_POPUP  = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Key used to indicate a heavy weight Popup should be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    static final int HEAVY_WEIGHT_POPUP   = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * Default type of Popup to create.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private int popupType = LIGHT_WEIGHT_POPUP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * Sets the <code>PopupFactory</code> that will be used to obtain
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * <code>Popup</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * This will throw an <code>IllegalArgumentException</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * <code>factory</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @param factory Shared PopupFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @exception IllegalArgumentException if <code>factory</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @see #getPopup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public static void setSharedInstance(PopupFactory factory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        if (factory == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            throw new IllegalArgumentException("PopupFactory can not be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        SwingUtilities.appContextPut(SharedInstanceKey, factory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Returns the shared <code>PopupFactory</code> which can be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * to obtain <code>Popup</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @return Shared PopupFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public static PopupFactory getSharedInstance() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        PopupFactory factory = (PopupFactory)SwingUtilities.appContextGet(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                         SharedInstanceKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        if (factory == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            factory = new PopupFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            setSharedInstance(factory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        return factory;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Provides a hint as to the type of <code>Popup</code> that should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * be created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    void setPopupType(int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        popupType = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * Returns the preferred type of Popup to create.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    int getPopupType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        return popupType;
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
     * Creates a <code>Popup</code> for the Component <code>owner</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * containing the Component <code>contents</code>. <code>owner</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * is used to determine which <code>Window</code> the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * <code>Popup</code> will parent the <code>Component</code> the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * <code>Popup</code> creates to. A null <code>owner</code> implies there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * is no valid parent. <code>x</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * <code>y</code> specify the preferred initial location to place
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * the <code>Popup</code> at. Based on screen size, or other paramaters,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * the <code>Popup</code> may not display at <code>x</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * <code>y</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @param owner    Component mouse coordinates are relative to, may be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @param contents Contents of the Popup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @param x        Initial x screen coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @param y        Initial y screen coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @exception IllegalArgumentException if contents is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @return Popup containing Contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public Popup getPopup(Component owner, Component contents,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                          int x, int y) throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        if (contents == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                          "Popup.getPopup must be passed non-null contents");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        int popupType = getPopupType(owner, contents, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        Popup popup = getPopup(owner, contents, x, y, popupType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        if (popup == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            // Didn't fit, force to heavy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            popup = getPopup(owner, contents, x, y, HEAVY_WEIGHT_POPUP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        return popup;
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 popup type to use for the specified parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    private int getPopupType(Component owner, Component contents,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                             int ownerX, int ownerY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        int popupType = getPopupType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        if (owner == null || invokerInHeavyWeightPopup(owner)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            popupType = HEAVY_WEIGHT_POPUP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        else if (popupType == LIGHT_WEIGHT_POPUP &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                 !(contents instanceof JToolTip) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                 !(contents instanceof JPopupMenu)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            popupType = MEDIUM_WEIGHT_POPUP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        // Check if the parent component is an option pane.  If so we need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        // force a heavy weight popup in order to have event dispatching work
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        // correctly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        Component c = owner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        while (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            if (c instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                if (((JComponent)c).getClientProperty(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                            PopupFactory_FORCE_HEAVYWEIGHT_POPUP) == Boolean.TRUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    popupType = HEAVY_WEIGHT_POPUP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            c = c.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        return popupType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * Obtains the appropriate <code>Popup</code> based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * <code>popupType</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    private Popup getPopup(Component owner, Component contents,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                           int ownerX, int ownerY, int popupType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        if (GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            return getHeadlessPopup(owner, contents, ownerX, ownerY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        switch(popupType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        case LIGHT_WEIGHT_POPUP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            return getLightWeightPopup(owner, contents, ownerX, ownerY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        case MEDIUM_WEIGHT_POPUP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            return getMediumWeightPopup(owner, contents, ownerX, ownerY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        case HEAVY_WEIGHT_POPUP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            return getHeavyWeightPopup(owner, contents, ownerX, ownerY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * Creates a headless popup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    private Popup getHeadlessPopup(Component owner, Component contents,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                                   int ownerX, int ownerY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        return HeadlessPopup.getHeadlessPopup(owner, contents, ownerX, ownerY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * Creates a light weight popup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    private Popup getLightWeightPopup(Component owner, Component contents,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                                         int ownerX, int ownerY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        return LightWeightPopup.getLightWeightPopup(owner, contents, ownerX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                                                    ownerY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * Creates a medium weight popup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    private Popup getMediumWeightPopup(Component owner, Component contents,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                                          int ownerX, int ownerY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        return MediumWeightPopup.getMediumWeightPopup(owner, contents,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                                                      ownerX, ownerY);
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
     * Creates a heavy weight popup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    private Popup getHeavyWeightPopup(Component owner, Component contents,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                                         int ownerX, int ownerY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        if (GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            return getMediumWeightPopup(owner, contents, ownerX, ownerY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        return HeavyWeightPopup.getHeavyWeightPopup(owner, contents, ownerX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                                                    ownerY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * Returns true if the Component <code>i</code> inside a heavy weight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * <code>Popup</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    private boolean invokerInHeavyWeightPopup(Component i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        if (i != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            Container parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            for(parent = i.getParent() ; parent != null ; parent =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    parent.getParent()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                if (parent instanceof Popup.HeavyWeightWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * Popup implementation that uses a Window as the popup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    private static class HeavyWeightPopup extends Popup {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        private static final Object heavyWeightPopupCacheKey =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                 new StringBuffer("PopupFactory.heavyWeightPopupCache");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
         * Returns either a new or recycled <code>Popup</code> containing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
         * the specified children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        static Popup getHeavyWeightPopup(Component owner, Component contents,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                                         int ownerX, int ownerY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            Window window = (owner != null) ? SwingUtilities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                              getWindowAncestor(owner) : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            HeavyWeightPopup popup = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            if (window != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                popup = getRecycledHeavyWeightPopup(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            boolean focusPopup = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            if(contents != null && contents.isFocusable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                if(contents instanceof JPopupMenu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                    JPopupMenu jpm = (JPopupMenu) contents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                    Component popComps[] = jpm.getComponents();
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   316
                    for (Component popComp : popComps) {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   317
                        if (!(popComp instanceof MenuElement) &&
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   318
                                !(popComp instanceof JSeparator)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                            focusPopup = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            if (popup == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                ((JWindow) popup.getComponent())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                 .getFocusableWindowState() != focusPopup) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                if(popup != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                    // The recycled popup can't serve us well
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                    // dispose it and create new one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                    popup._dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                popup = new HeavyWeightPopup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            popup.reset(owner, contents, ownerX, ownerY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            if(focusPopup) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                JWindow wnd = (JWindow) popup.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                wnd.setFocusableWindowState(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                // Set window name. We need this in BasicPopupMenuUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                // to identify focusable popup window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                wnd.setName("###focusableSwingPopup###");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            return popup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
         * Returns a previously disposed heavy weight <code>Popup</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
         * associated with <code>window</code>. This will return null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
         * there is no <code>HeavyWeightPopup</code> associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
         * <code>window</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        private static HeavyWeightPopup getRecycledHeavyWeightPopup(Window w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            synchronized (HeavyWeightPopup.class) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   360
                List<HeavyWeightPopup> cache;
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   361
                Map<Window, List<HeavyWeightPopup>> heavyPopupCache = getHeavyWeightPopupCache();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                if (heavyPopupCache.containsKey(w)) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   364
                    cache = heavyPopupCache.get(w);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                }
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   368
                if (cache.size() > 0) {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   369
                    HeavyWeightPopup r = cache.get(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                    cache.remove(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                    return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
         * Returns the cache to use for heavy weight popups. Maps from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
         * <code>Window</code> to a <code>List</code> of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
         * <code>HeavyWeightPopup</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
         */
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   382
        private static Map<Window, List<HeavyWeightPopup>> getHeavyWeightPopupCache() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            synchronized (HeavyWeightPopup.class) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   384
                Map<Window, List<HeavyWeightPopup>> cache = (Map<Window, List<HeavyWeightPopup>>)SwingUtilities.appContextGet(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                                  heavyWeightPopupCacheKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                if (cache == null) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   388
                    cache = new HashMap<Window, List<HeavyWeightPopup>>(2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                    SwingUtilities.appContextPut(heavyWeightPopupCacheKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                                                 cache);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                return cache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
         * Recycles the passed in <code>HeavyWeightPopup</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        private static void recycleHeavyWeightPopup(HeavyWeightPopup popup) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            synchronized (HeavyWeightPopup.class) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   401
                List<HeavyWeightPopup> cache;
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   402
                Window window = SwingUtilities.getWindowAncestor(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                                     popup.getComponent());
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   404
                Map<Window, List<HeavyWeightPopup>> heavyPopupCache = getHeavyWeightPopupCache();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                if (window instanceof Popup.DefaultFrame ||
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   407
                                      !window.isVisible()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                    // If the Window isn't visible, we don't cache it as we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                    // likely won't ever get a windowClosed event to clean up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                    // We also don't cache DefaultFrames as this indicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                    // there wasn't a valid Window parent, and thus we don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                    // know when to clean up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                    popup._dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                } else if (heavyPopupCache.containsKey(window)) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   416
                    cache = heavyPopupCache.get(window);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                } else {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   418
                    cache = new ArrayList<HeavyWeightPopup>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                    heavyPopupCache.put(window, cache);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                    // Clean up if the Window is closed
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   421
                    final Window w = window;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                    w.addWindowListener(new WindowAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                        public void windowClosed(WindowEvent e) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   425
                            List<HeavyWeightPopup> popups;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                            synchronized(HeavyWeightPopup.class) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   428
                                Map<Window, List<HeavyWeightPopup>> heavyPopupCache2 =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                                              getHeavyWeightPopupCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   431
                                popups = heavyPopupCache2.remove(w);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                            if (popups != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                                for (int counter = popups.size() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                                                   counter >= 0; counter--) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   436
                                    popups.get(counter)._dispose();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                    });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                if(cache.size() < MAX_CACHE_SIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                    cache.add(popup);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    popup._dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        // Popup methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        public void hide() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            super.hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            recycleHeavyWeightPopup(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
         * As we recycle the <code>Window</code>, we don't want to dispose it,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
         * thus this method does nothing, instead use <code>_dipose</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
         * which will handle the disposing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        void _dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            super.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * ContainerPopup consolidates the common code used in the light/medium
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * weight implementations of <code>Popup</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    private static class ContainerPopup extends Popup {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        /** Component we are to be added to. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        Component owner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        /** Desired x location. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        int x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        /** Desired y location. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        int y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        public void hide() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            Component component = getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            if (component != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                Container parent = component.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                    Rectangle bounds = component.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                    parent.remove(component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                    parent.repaint(bounds.x, bounds.y, bounds.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                                   bounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            owner = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        public void pack() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            Component component = getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            if (component != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                component.setSize(component.getPreferredSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        void reset(Component owner, Component contents, int ownerX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                   int ownerY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            if ((owner instanceof JFrame) || (owner instanceof JDialog) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                                                 (owner instanceof JWindow)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                // Force the content to be added to the layered pane, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                // we'll get an exception when adding to the RootPaneContainer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                owner = ((RootPaneContainer)owner).getLayeredPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            super.reset(owner, contents, ownerX, ownerY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            x = ownerX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            y = ownerY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            this.owner = owner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        boolean overlappedByOwnedWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            Component component = getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            if(owner != null && component != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                Window w = SwingUtilities.getWindowAncestor(owner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                if (w == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                Window[] ownedWindows = w.getOwnedWindows();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                if(ownedWindows != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                    Rectangle bnd = component.getBounds();
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   535
                    for (Window window : ownedWindows) {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   536
                        if (window.isVisible() &&
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   537
                                bnd.intersects(window.getBounds())) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                        }
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
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        /**
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   548
         * Returns true if popup can fit the screen and the owner's top parent.
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   549
         * It determines can popup be lightweight or mediumweight.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        boolean fitsOnScreen() {
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   552
            boolean result = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            Component component = getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            if (owner != null && component != null) {
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   555
                int popupWidth = component.getWidth();
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   556
                int popupHeight = component.getHeight();
2496
c0dfcd9b27f7 6740974: api/javax_swing/PopupFactory/index.html#Ctor[PopupFactory2002] fails with NPE
peterz
parents: 1301
diff changeset
   557
c0dfcd9b27f7 6740974: api/javax_swing/PopupFactory/index.html#Ctor[PopupFactory2002] fails with NPE
peterz
parents: 1301
diff changeset
   558
                Container parent = (Container) SwingUtilities.getRoot(owner);
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   559
                if (parent instanceof JFrame ||
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   560
                    parent instanceof JDialog ||
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   561
                    parent instanceof JWindow) {
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   562
2496
c0dfcd9b27f7 6740974: api/javax_swing/PopupFactory/index.html#Ctor[PopupFactory2002] fails with NPE
peterz
parents: 1301
diff changeset
   563
                    Rectangle parentBounds = parent.getBounds();
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   564
                    Insets i = parent.getInsets();
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   565
                    parentBounds.x += i.left;
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   566
                    parentBounds.y += i.top;
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   567
                    parentBounds.width -= i.left + i.right;
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   568
                    parentBounds.height -= i.top + i.bottom;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   570
                    if (JPopupMenu.canPopupOverlapTaskBar()) {
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   571
                        GraphicsConfiguration gc =
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   572
                                parent.getGraphicsConfiguration();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                        Rectangle popupArea = getContainerPopupArea(gc);
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   574
                        result = parentBounds.intersection(popupArea)
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   575
                                .contains(x, y, popupWidth, popupHeight);
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   576
                    } else {
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   577
                        result = parentBounds
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   578
                                .contains(x, y, popupWidth, popupHeight);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                    }
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   580
                } else if (parent instanceof JApplet) {
2496
c0dfcd9b27f7 6740974: api/javax_swing/PopupFactory/index.html#Ctor[PopupFactory2002] fails with NPE
peterz
parents: 1301
diff changeset
   581
                    Rectangle parentBounds = parent.getBounds();
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   582
                    Point p = parent.getLocationOnScreen();
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   583
                    parentBounds.x = p.x;
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   584
                    parentBounds.y = p.y;
2496
c0dfcd9b27f7 6740974: api/javax_swing/PopupFactory/index.html#Ctor[PopupFactory2002] fails with NPE
peterz
parents: 1301
diff changeset
   585
                    result = parentBounds.contains(x, y, popupWidth, popupHeight);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            }
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents: 2
diff changeset
   588
            return result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        Rectangle getContainerPopupArea(GraphicsConfiguration gc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            Rectangle screenBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            Toolkit toolkit = Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            Insets insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            if(gc != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                // If we have GraphicsConfiguration use it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                // to get screen bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                screenBounds = gc.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                insets = toolkit.getScreenInsets(gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                // If we don't have GraphicsConfiguration use primary screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                screenBounds = new Rectangle(toolkit.getScreenSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                insets = new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            // Take insets into account
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            screenBounds.x += insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            screenBounds.y += insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            screenBounds.width -= (insets.left + insets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            screenBounds.height -= (insets.top + insets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            return screenBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * Popup implementation that is used in headless environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    private static class HeadlessPopup extends ContainerPopup {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        static Popup getHeadlessPopup(Component owner, Component contents,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                                      int ownerX, int ownerY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            HeadlessPopup popup = new HeadlessPopup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            popup.reset(owner, contents, ownerX, ownerY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            return popup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        Component createComponent(Component owner) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            return new Panel(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        public void show() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        public void hide() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * Popup implementation that uses a JPanel as the popup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    private static class LightWeightPopup extends ContainerPopup {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        private static final Object lightWeightPopupCacheKey =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                         new StringBuffer("PopupFactory.lightPopupCache");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
         * Returns a light weight <code>Popup</code> implementation. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
         * the <code>Popup</code> needs more space that in available in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
         * <code>owner</code>, this will return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        static Popup getLightWeightPopup(Component owner, Component contents,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                                         int ownerX, int ownerY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            LightWeightPopup popup = getRecycledLightWeightPopup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            if (popup == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                popup = new LightWeightPopup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            popup.reset(owner, contents, ownerX, ownerY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            if (!popup.fitsOnScreen() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                 popup.overlappedByOwnedWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                popup.hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            return popup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
         * Returns the cache to use for heavy weight popups.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
         */
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   668
        private static List<LightWeightPopup> getLightWeightPopupCache() {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   669
            List<LightWeightPopup> cache = (List<LightWeightPopup>)SwingUtilities.appContextGet(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                                   lightWeightPopupCacheKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            if (cache == null) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   672
                cache = new ArrayList<LightWeightPopup>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                SwingUtilities.appContextPut(lightWeightPopupCacheKey, cache);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            return cache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
         * Recycles the LightWeightPopup <code>popup</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        private static void recycleLightWeightPopup(LightWeightPopup popup) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            synchronized (LightWeightPopup.class) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   683
                List<LightWeightPopup> lightPopupCache = getLightWeightPopupCache();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                if (lightPopupCache.size() < MAX_CACHE_SIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                    lightPopupCache.add(popup);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
         * Returns a previously used <code>LightWeightPopup</code>, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
         * if none of the popups have been recycled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        private static LightWeightPopup getRecycledLightWeightPopup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            synchronized (LightWeightPopup.class) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   696
                List<LightWeightPopup> lightPopupCache = getLightWeightPopupCache();
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   697
                if (lightPopupCache.size() > 0) {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   698
                    LightWeightPopup r = lightPopupCache.get(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                    lightPopupCache.remove(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                    return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        // Popup methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        public void hide() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            super.hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            Container component = (Container)getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            component.removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            recycleLightWeightPopup(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        public void show() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            Container parent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            if (owner != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                parent = (owner instanceof Container? (Container)owner : owner.getParent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            // Try to find a JLayeredPane and Window to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            for (Container p = parent; p != null; p = p.getParent()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                if (p instanceof JRootPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                    if (p.getParent() instanceof JInternalFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                    parent = ((JRootPane)p).getLayeredPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                    // Continue, so that if there is a higher JRootPane, we'll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                    // pick it up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                } else if(p instanceof Window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                    if (parent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                        parent = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                } else if (p instanceof JApplet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                    // Painting code stops at Applets, we don't want
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                    // to add to a Component above an Applet otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                    // you'll never see it painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            Point p = SwingUtilities.convertScreenLocationToParent(parent, x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                                                                   y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            Component component = getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            component.setLocation(p.x, p.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            if (parent instanceof JLayeredPane) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   754
                parent.add(component, JLayeredPane.POPUP_LAYER, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                parent.add(component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        Component createComponent(Component owner) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            JComponent component = new JPanel(new BorderLayout(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            component.setOpaque(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            return component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        // Local methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
         * Resets the <code>Popup</code> to an initial state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        void reset(Component owner, Component contents, int ownerX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                   int ownerY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            super.reset(owner, contents, ownerX, ownerY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            JComponent component = (JComponent)getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            component.setOpaque(contents.isOpaque());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            component.setLocation(ownerX, ownerY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            component.add(contents, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            contents.invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * Popup implementation that uses a Panel as the popup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    private static class MediumWeightPopup extends ContainerPopup {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        private static final Object mediumWeightPopupCacheKey =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                             new StringBuffer("PopupFactory.mediumPopupCache");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        /** Child of the panel. The contents are added to this. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        private JRootPane rootPane;
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
         * Returns a medium weight <code>Popup</code> implementation. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
         * the <code>Popup</code> needs more space that in available in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
         * <code>owner</code>, this will return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        static Popup getMediumWeightPopup(Component owner, Component contents,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                                          int ownerX, int ownerY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            MediumWeightPopup popup = getRecycledMediumWeightPopup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            if (popup == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                popup = new MediumWeightPopup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            popup.reset(owner, contents, ownerX, ownerY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            if (!popup.fitsOnScreen() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                 popup.overlappedByOwnedWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                popup.hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            return popup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
         * Returns the cache to use for medium weight popups.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
         */
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   824
        private static List<MediumWeightPopup> getMediumWeightPopupCache() {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   825
            List<MediumWeightPopup> cache = (List<MediumWeightPopup>)SwingUtilities.appContextGet(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                                    mediumWeightPopupCacheKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            if (cache == null) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   829
                cache = new ArrayList<MediumWeightPopup>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                SwingUtilities.appContextPut(mediumWeightPopupCacheKey, cache);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            return cache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
         * Recycles the MediumWeightPopup <code>popup</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        private static void recycleMediumWeightPopup(MediumWeightPopup popup) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            synchronized (MediumWeightPopup.class) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   840
                List<MediumWeightPopup> mediumPopupCache = getMediumWeightPopupCache();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                if (mediumPopupCache.size() < MAX_CACHE_SIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                    mediumPopupCache.add(popup);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
         * Returns a previously used <code>MediumWeightPopup</code>, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
         * if none of the popups have been recycled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        private static MediumWeightPopup getRecycledMediumWeightPopup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            synchronized (MediumWeightPopup.class) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   853
                List<MediumWeightPopup> mediumPopupCache = getMediumWeightPopupCache();
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   854
                if (mediumPopupCache.size() > 0) {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   855
                    MediumWeightPopup r = mediumPopupCache.get(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                    mediumPopupCache.remove(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                    return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        // Popup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        public void hide() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            super.hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            rootPane.getContentPane().removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            recycleMediumWeightPopup(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        public void show() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            Component component = getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            Container parent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            if (owner != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                parent = owner.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
              Find the top level window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
              if it has a layered pane,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
              add to that, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
              add to the window. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
            while (!(parent instanceof Window || parent instanceof Applet) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                   (parent!=null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                parent = parent.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            // Set the visibility to false before adding to workaround a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            // bug in Solaris in which the Popup gets added at the wrong
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            // location, which will result in a mouseExit, which will then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            // result in the ToolTip being removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            if (parent instanceof RootPaneContainer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                parent = ((RootPaneContainer)parent).getLayeredPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                Point p = SwingUtilities.convertScreenLocationToParent(parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                                                                       x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                component.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                component.setLocation(p.x, p.y);
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   899
                parent.add(component, JLayeredPane.POPUP_LAYER,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                                           0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                Point p = SwingUtilities.convertScreenLocationToParent(parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                                                                       x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                component.setLocation(p.x, p.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                component.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                parent.add(component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            component.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        Component createComponent(Component owner) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            Panel component = new MediumWeightComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            rootPane = new JRootPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            // NOTE: this uses setOpaque vs LookAndFeel.installProperty as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            // there is NO reason for the RootPane not to be opaque. For
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            // painting to work the contentPane must be opaque, therefor the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            // RootPane can also be opaque.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            rootPane.setOpaque(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            component.add(rootPane, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            return component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
         * Resets the <code>Popup</code> to an initial state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        void reset(Component owner, Component contents, int ownerX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                   int ownerY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            super.reset(owner, contents, ownerX, ownerY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            Component component = getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            component.setLocation(ownerX, ownerY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            rootPane.getContentPane().add(contents, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            contents.invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            component.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        // This implements SwingHeavyWeight so that repaints on it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        // are processed by the RepaintManager and SwingPaintEventDispatcher.
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   944
        @SuppressWarnings("serial") // JDK-implementation class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        private static class MediumWeightComponent extends Panel implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                                                           SwingHeavyWeight {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            MediumWeightComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                super(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
}