jdk/src/share/classes/sun/awt/EmbeddedFrame.java
author denis
Wed, 27 Mar 2013 16:19:51 +0400
changeset 16705 1caaa379eded
parent 15983 26a673dec5b2
child 16892 24a521782b42
child 16734 da1901d79073
permissions -rw-r--r--
7075105: WIN: Provide a way to format HTML on drop Reviewed-by: uta, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 6634
diff changeset
     2
 * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2808
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: 2808
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: 2808
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2808
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2808
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 sun.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.image.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.peer.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.AWTKeyStroke;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.applet.Applet;
12813
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 11264
diff changeset
    37
import javax.tools.annotation.GenerateNativeHeader;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.applet.AppletPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * A generic container used for embedding Java components, usually applets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * An EmbeddedFrame has two related uses:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * . Within a Java-based application, an EmbeddedFrame serves as a sort of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *   firewall, preventing the contained components or applets from using
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *   getParent() to find parent components, such as menubars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * . Within a C-based application, an EmbeddedFrame contains a window handle
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *   which was created by the application, which serves as the top-level
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *   Java window.  EmbeddedFrames created for this purpose are passed-in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *   handle of an existing window created by the application.  The window
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *   handle should be of the appropriate native type for a specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *   platform, as stored in the pData field of the ComponentPeer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @author      Thomas Ball
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 */
12813
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 11264
diff changeset
    57
/* No native methods here, but the constants are needed in the supporting JNI code */
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 11264
diff changeset
    58
@GenerateNativeHeader
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
public abstract class EmbeddedFrame extends Frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                          implements KeyEventDispatcher, PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private boolean isCursorAllowed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private boolean supportsXEmbed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private KeyboardFocusManager appletKFM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    // JDK 1.1 compatibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private static final long serialVersionUID = 2967042741780317130L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
6634
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
    68
    /*
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
    69
     * The constants define focus traversal directions.
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
    70
     * Use them in {@code traverseIn}, {@code traverseOut} methods.
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
    71
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    protected static final boolean FORWARD = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    protected static final boolean BACKWARD = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public boolean supportsXEmbed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        return supportsXEmbed && SunToolkit.needsXEmbed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    protected EmbeddedFrame(boolean supportsXEmbed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        this((long)0, supportsXEmbed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    protected EmbeddedFrame() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        this((long)0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @deprecated This constructor will be removed in 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    protected EmbeddedFrame(int handle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        this((long)handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    protected EmbeddedFrame(long handle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        this(handle, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    protected EmbeddedFrame(long handle, boolean supportsXEmbed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        this.supportsXEmbed = supportsXEmbed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        registerListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Block introspection of a parent window by this child.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public Container getParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Needed to track which KeyboardFocusManager is current. We want to avoid memory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * leaks, so when KFM stops being current, we remove ourselves as listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public void propertyChange(PropertyChangeEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        // We don't handle any other properties. Skip it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        if (!evt.getPropertyName().equals("managingFocus")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        // We only do it if it stops being current. Technically, we should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        // never get an event about KFM starting being current.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        if (evt.getNewValue() == Boolean.TRUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        // should be the same as appletKFM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        removeTraversingOutListeners((KeyboardFocusManager)evt.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        appletKFM = KeyboardFocusManager.getCurrentKeyboardFocusManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        if (isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            addTraversingOutListeners(appletKFM);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Register us as KeyEventDispatcher and property "managingFocus" listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    private void addTraversingOutListeners(KeyboardFocusManager kfm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        kfm.addKeyEventDispatcher(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        kfm.addPropertyChangeListener("managingFocus", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * Deregister us as KeyEventDispatcher and property "managingFocus" listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    private void removeTraversingOutListeners(KeyboardFocusManager kfm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        kfm.removeKeyEventDispatcher(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        kfm.removePropertyChangeListener("managingFocus", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * Because there may be many AppContexts, and we can't be sure where this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * EmbeddedFrame is first created or shown, we can't automatically determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * the correct KeyboardFocusManager to attach to as KeyEventDispatcher.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Those who want to use the functionality of traversing out of the EmbeddedFrame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * must call this method on the Applet's AppContext. After that, all the changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * can be handled automatically, including possible replacement of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * KeyboardFocusManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public void registerListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (appletKFM != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            removeTraversingOutListeners(appletKFM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        appletKFM = KeyboardFocusManager.getCurrentKeyboardFocusManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            addTraversingOutListeners(appletKFM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * Needed to avoid memory leak: we register this EmbeddedFrame as a listener with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * KeyboardFocusManager of applet's AppContext. We don't want the KFM to keep
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * reference to our EmbeddedFrame forever if the Frame is no longer in use, so we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * add listeners in show() and remove them in hide().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
11264
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 7668
diff changeset
   178
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public void show() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        if (appletKFM != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            addTraversingOutListeners(appletKFM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        super.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * Needed to avoid memory leak: we register this EmbeddedFrame as a listener with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * KeyboardFocusManager of applet's AppContext. We don't want the KFM to keep
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * reference to our EmbeddedFrame forever if the Frame is no longer in use, so we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * add listeners in show() and remove them in hide().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
11264
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 7668
diff changeset
   192
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public void hide() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        if (appletKFM != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            removeTraversingOutListeners(appletKFM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        super.hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * Need this method to detect when the focus may have chance to leave the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * focus cycle root which is EmbeddedFrame. Mostly, the code here is copied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * from DefaultKeyboardFocusManager.processKeyEvent with some minor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * modifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public boolean dispatchKeyEvent(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 12813
diff changeset
   208
        Container currentRoot = AWTAccessor.getKeyboardFocusManagerAccessor()
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 12813
diff changeset
   209
                                    .getCurrentFocusCycleRoot();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        // if we are not in EmbeddedFrame's cycle, we should not try to leave.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        if (this != currentRoot) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        // KEY_TYPED events cannot be focus traversal keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        if (e.getID() == KeyEvent.KEY_TYPED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        if (!getFocusTraversalKeysEnabled() || e.isConsumed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        AWTKeyStroke stroke = AWTKeyStroke.getAWTKeyStrokeForEvent(e);
11264
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 7668
diff changeset
   226
        Set<AWTKeyStroke> toTest;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        Component currentFocused = e.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        toTest = getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
1179
b0d106998757 6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents: 2
diff changeset
   230
        if (toTest.contains(stroke)) {
b0d106998757 6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents: 2
diff changeset
   231
            // 6581899: performance improvement for SortingFocusTraversalPolicy
b0d106998757 6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents: 2
diff changeset
   232
            Component last = getFocusTraversalPolicy().getLastComponent(this);
b0d106998757 6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents: 2
diff changeset
   233
            if (currentFocused == last || last == null) {
b0d106998757 6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents: 2
diff changeset
   234
                if (traverseOut(FORWARD)) {
b0d106998757 6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents: 2
diff changeset
   235
                    e.consume();
b0d106998757 6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents: 2
diff changeset
   236
                    return true;
b0d106998757 6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents: 2
diff changeset
   237
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        toTest = getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
1179
b0d106998757 6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents: 2
diff changeset
   242
        if (toTest.contains(stroke)) {
b0d106998757 6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents: 2
diff changeset
   243
            // 6581899: performance improvement for SortingFocusTraversalPolicy
b0d106998757 6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents: 2
diff changeset
   244
            Component first = getFocusTraversalPolicy().getFirstComponent(this);
b0d106998757 6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents: 2
diff changeset
   245
            if (currentFocused == first || first == null) {
b0d106998757 6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents: 2
diff changeset
   246
                if (traverseOut(BACKWARD)) {
b0d106998757 6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents: 2
diff changeset
   247
                    e.consume();
b0d106998757 6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents: 2
diff changeset
   248
                    return true;
b0d106998757 6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents: 2
diff changeset
   249
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    /**
6634
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   256
     * This method is called by the embedder when we should receive focus as element
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   257
     * of the traversal chain.  The method requests focus on:
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   258
     * 1. the first Component of this EmbeddedFrame if user moves focus forward
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   259
     *    in the focus traversal cycle.
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   260
     * 2. the last Component of this EmbeddedFrame if user moves focus backward
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   261
     *    in the focus traversal cycle.
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   262
     *
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   263
     * The direction parameter specifies which of the two mentioned cases is
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   264
     * happening. Use FORWARD and BACKWARD constants defined in the EmbeddedFrame class
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   265
     * to avoid confusing boolean values.
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   266
     *
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   267
     * A concrete implementation of this method is defined in the platform-dependent
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   268
     * subclasses.
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   269
     *
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   270
     * @param direction FORWARD or BACKWARD
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   271
     * @return true, if the EmbeddedFrame wants to get focus, false otherwise.
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   272
     */
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   273
    public boolean traverseIn(boolean direction) {
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   274
        Component comp = null;
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   275
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   276
        if (direction == FORWARD) {
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   277
            comp = getFocusTraversalPolicy().getFirstComponent(this);
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   278
        } else {
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   279
            comp = getFocusTraversalPolicy().getLastComponent(this);
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   280
        }
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   281
        if (comp != null) {
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   282
            // comp.requestFocus(); - Leads to a hung.
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   283
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   284
            AWTAccessor.getKeyboardFocusManagerAccessor().setMostRecentFocusOwner(this, comp);
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   285
            synthesizeWindowActivation(true);
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   286
        }
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   287
        return (null != comp);
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   288
    }
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   289
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   290
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * This method is called from dispatchKeyEvent in the following two cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * 1. The focus is on the first Component of this EmbeddedFrame and we are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     *    about to transfer the focus backward.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * 2. The focus in on the last Component of this EmbeddedFrame and we are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     *    about to transfer the focus forward.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * This is needed to give the opportuity for keyboard focus to leave the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * EmbeddedFrame. Override this method, initiate focus transfer in it and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * return true if you want the focus to leave EmbeddedFrame's cycle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * The direction parameter specifies which of the two mentioned cases is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * happening. Use FORWARD and BACKWARD constants defined in EmbeddedFrame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * to avoid confusing boolean values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @param direction FORWARD or BACKWARD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @return true, if EmbeddedFrame wants the focus to leave it,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *         false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    protected boolean traverseOut(boolean direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * Block modifying any frame attributes, since they aren't applicable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * for EmbeddedFrames.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public void setTitle(String title) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    public void setIconImage(Image image) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public void setIconImages(java.util.List<? extends Image> icons) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    public void setMenuBar(MenuBar mb) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    public void setResizable(boolean resizable) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    public void remove(MenuComponent m) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    public boolean isResizable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
11264
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 7668
diff changeset
   326
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    public void addNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            if (getPeer() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                setPeer(new NullEmbeddedFramePeer());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            super.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    // These three functions consitute RFE 4100710. Do not remove.
11264
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 7668
diff changeset
   337
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    public void setCursorAllowed(boolean isCursorAllowed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        this.isCursorAllowed = isCursorAllowed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        getPeer().updateCursorImmediately();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    public boolean isCursorAllowed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        return isCursorAllowed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    public Cursor getCursor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        return (isCursorAllowed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            ? super.getCursor()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            : Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
11264
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 7668
diff changeset
   351
    @SuppressWarnings("deprecation")
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 7668
diff changeset
   352
    protected void setPeer(final ComponentPeer p){
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 12813
diff changeset
   353
        AWTAccessor.getComponentAccessor().setPeer(EmbeddedFrame.this, p);
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 12813
diff changeset
   354
    };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * Synthesize native message to activate or deactivate EmbeddedFrame window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * depending on the value of parameter <code>b</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * Peers should override this method if they are to implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * this functionality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @param doActivate  if <code>true</code>, activates the window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * otherwise, deactivates the window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    public void synthesizeWindowActivation(boolean doActivate) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * Moves this embedded frame to a new location. The top-left corner of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * the new location is specified by the <code>x</code> and <code>y</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * parameters relative to the native parent component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * setLocation() and setBounds() for EmbeddedFrame really don't move it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * within the native parent. These methods always put embedded frame to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * (0, 0) for backward compatibility. To allow moving embedded frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * setLocationPrivate() and setBoundsPrivate() were introduced, and they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * work just the same way as setLocation() and setBounds() for usual,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * non-embedded components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * Using usual get/setLocation() and get/setBounds() together with new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * get/setLocationPrivate() and get/setBoundsPrivate() is not recommended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * For example, calling getBoundsPrivate() after setLocation() works fine,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * but getBounds() after setBoundsPrivate() may return unpredictable value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * @param x the new <i>x</i>-coordinate relative to the parent component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * @param y the new <i>y</i>-coordinate relative to the parent component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * @see java.awt.Component#setLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * @see #getLocationPrivate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * @see #setBoundsPrivate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * @see #getBoundsPrivate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    protected void setLocationPrivate(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        Dimension size = getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        setBoundsPrivate(x, y, size.width, size.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * Gets the location of this embedded frame as a point specifying the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * top-left corner relative to parent component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * setLocation() and setBounds() for EmbeddedFrame really don't move it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * within the native parent. These methods always put embedded frame to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * (0, 0) for backward compatibility. To allow getting location and size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * of embedded frame getLocationPrivate() and getBoundsPrivate() were
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * introduced, and they work just the same way as getLocation() and getBounds()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * for ususal, non-embedded components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * Using usual get/setLocation() and get/setBounds() together with new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * get/setLocationPrivate() and get/setBoundsPrivate() is not recommended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * For example, calling getBoundsPrivate() after setLocation() works fine,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * but getBounds() after setBoundsPrivate() may return unpredictable value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @return a point indicating this embedded frame's top-left corner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @see java.awt.Component#getLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @see #setLocationPrivate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * @see #setBoundsPrivate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @see #getBoundsPrivate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    protected Point getLocationPrivate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        Rectangle bounds = getBoundsPrivate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        return new Point(bounds.x, bounds.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * Moves and resizes this embedded frame. The new location of the top-left
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * corner is specified by <code>x</code> and <code>y</code> parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * relative to the native parent component. The new size is specified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * <code>width</code> and <code>height</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * setLocation() and setBounds() for EmbeddedFrame really don't move it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * within the native parent. These methods always put embedded frame to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * (0, 0) for backward compatibility. To allow moving embedded frames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * setLocationPrivate() and setBoundsPrivate() were introduced, and they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * work just the same way as setLocation() and setBounds() for usual,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * non-embedded components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * Using usual get/setLocation() and get/setBounds() together with new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * get/setLocationPrivate() and get/setBoundsPrivate() is not recommended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * For example, calling getBoundsPrivate() after setLocation() works fine,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * but getBounds() after setBoundsPrivate() may return unpredictable value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * @param x the new <i>x</i>-coordinate relative to the parent component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * @param y the new <i>y</i>-coordinate relative to the parent component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @param width the new <code>width</code> of this embedded frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @param height the new <code>height</code> of this embedded frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @see java.awt.Component#setBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * @see #setLocationPrivate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * @see #getLocationPrivate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * @see #getBoundsPrivate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     */
11264
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 7668
diff changeset
   455
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    protected void setBoundsPrivate(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        final FramePeer peer = (FramePeer)getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            peer.setBoundsPrivate(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * Gets the bounds of this embedded frame as a rectangle specifying the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * width, height and location relative to the native parent component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * setLocation() and setBounds() for EmbeddedFrame really don't move it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * within the native parent. These methods always put embedded frame to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * (0, 0) for backward compatibility. To allow getting location and size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * of embedded frames getLocationPrivate() and getBoundsPrivate() were
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * introduced, and they work just the same way as getLocation() and getBounds()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * for ususal, non-embedded components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * Using usual get/setLocation() and get/setBounds() together with new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * get/setLocationPrivate() and get/setBoundsPrivate() is not recommended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * For example, calling getBoundsPrivate() after setLocation() works fine,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * but getBounds() after setBoundsPrivate() may return unpredictable value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * @return a rectangle indicating this embedded frame's bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * @see java.awt.Component#getBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * @see #setLocationPrivate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * @see #getLocationPrivate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * @see #setBoundsPrivate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     */
11264
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 7668
diff changeset
   487
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    protected Rectangle getBoundsPrivate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        final FramePeer peer = (FramePeer)getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            return peer.getBoundsPrivate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            return getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    public void toFront() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    public void toBack() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    public abstract void registerAccelerator(AWTKeyStroke stroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    public abstract void unregisterAccelerator(AWTKeyStroke stroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * Checks if the component is in an EmbeddedFrame. If so,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * returns the applet found in the hierarchy or null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * @return the parent applet or {@ null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    public static Applet getAppletIfAncestorOf(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        Container parent = comp.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        Applet applet = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        while (parent != null && !(parent instanceof EmbeddedFrame)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            if (parent instanceof Applet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                applet = (Applet)parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            parent = parent.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        return parent == null ? null : applet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * This method should be overriden in subclasses. It is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * called when window this frame is within should be blocked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * by some modal dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    public void notifyModalBlocked(Dialog blocker, boolean blocked) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    private static class NullEmbeddedFramePeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        extends NullComponentPeer implements FramePeer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        public void setTitle(String title) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        public void setIconImage(Image im) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        public void updateIconImages() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        public void setMenuBar(MenuBar mb) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        public void setResizable(boolean resizeable) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        public void setState(int state) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        public int getState() { return Frame.NORMAL; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        public void setMaximizedBounds(Rectangle b) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        public void toFront() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        public void toBack() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        public void updateFocusableWindowState() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        public void updateAlwaysOnTop() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        public void setAlwaysOnTop(boolean alwaysOnTop) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        public Component getGlobalHeavyweightFocusOwner() { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        public void setBoundsPrivate(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            setBounds(x, y, width, height, SET_BOUNDS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        public Rectangle getBoundsPrivate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            return getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        public void setModalBlocked(Dialog blocker, boolean blocked) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
         * @see java.awt.peer.ContainerPeer#restack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        public void restack() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
         * @see java.awt.peer.ContainerPeer#isRestackSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        public boolean isRestackSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        public boolean requestWindowFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        public void updateMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        }
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1179
diff changeset
   573
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1179
diff changeset
   574
        public void setOpacity(float opacity) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1179
diff changeset
   575
        }
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2472
diff changeset
   576
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1179
diff changeset
   577
        public void setOpaque(boolean isOpaque) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1179
diff changeset
   578
        }
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2472
diff changeset
   579
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   580
        public void updateWindow() {
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1179
diff changeset
   581
        }
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   582
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   583
        public void repositionSecurityWarning() {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   584
        }
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 13604
diff changeset
   585
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 13604
diff changeset
   586
        public void emulateActivation(boolean activate) {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 13604
diff changeset
   587
        }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 13604
diff changeset
   588
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
} // class EmbeddedFrame