jdk/src/macosx/classes/sun/lwawt/LWLightweightFramePeer.java
author mcherkas
Mon, 28 Jul 2014 16:09:26 +0400
changeset 26008 ccab11700f07
parent 20127 a3a34675d847
child 26342 3637212ae8f2
permissions -rw-r--r--
8047288: Fixes endless loop on mac caused by invoking Windows.isFocusable() on Appkit thread. Reviewed-by: ant, pchelko Contributed-by: artem.malinko@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
     1
/*
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
     4
 *
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    10
 *
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    15
 * accompanied this code).
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    16
 *
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    20
 *
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    23
 * questions.
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    24
 */
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    25
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    26
package sun.lwawt;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    27
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    28
import java.awt.Graphics;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    29
import java.awt.Insets;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    30
import java.awt.Point;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    31
import java.awt.Rectangle;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    32
import java.awt.Window;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    33
import java.awt.dnd.DropTarget;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    34
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    35
import sun.awt.CausedFocusEvent;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    36
import sun.awt.LightweightFrame;
20127
a3a34675d847 8024170: [SwingNode] Implement cursor change
pchelko
parents: 15983
diff changeset
    37
import sun.swing.JLightweightFrame;
a3a34675d847 8024170: [SwingNode] Implement cursor change
pchelko
parents: 15983
diff changeset
    38
import sun.swing.SwingAccessor;
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    39
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    40
public class LWLightweightFramePeer extends LWWindowPeer {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    41
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    42
    public LWLightweightFramePeer(LightweightFrame target,
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    43
                                  PlatformComponent platformComponent,
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    44
                                  PlatformWindow platformWindow)
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    45
    {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    46
        super(target, platformComponent, platformWindow, LWWindowPeer.PeerType.LW_FRAME);
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    47
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    48
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    49
    private LightweightFrame getLwTarget() {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    50
        return (LightweightFrame)getTarget();
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    51
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    52
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    53
    @Override
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    54
    public Graphics getGraphics() {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    55
        return getLwTarget().getGraphics();
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    56
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    57
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    58
    @Override
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    59
    protected void setVisibleImpl(final boolean visible) {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    60
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    61
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    62
    @Override
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    63
    public boolean requestWindowFocus(CausedFocusEvent.Cause cause) {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    64
        if (!focusAllowedFor()) {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    65
            return false;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    66
        }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    67
        if (getPlatformWindow().rejectFocusRequest(cause)) {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    68
            return false;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    69
        }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    70
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    71
        Window opposite = LWKeyboardFocusManagerPeer.getInstance().
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    72
            getCurrentFocusedWindow();
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    73
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    74
        changeFocusedWindow(true, opposite);
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    75
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    76
        return true;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    77
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    78
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    79
    @Override
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    80
    public Point getLocationOnScreen() {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    81
        Rectangle bounds = getBounds();
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    82
        return new Point(bounds.x, bounds.y); // todo
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    83
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    84
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    85
    @Override
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    86
    public Insets getInsets() {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    87
        return new Insets(0, 0, 0, 0);
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    88
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    89
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    90
    @Override
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    91
    public void setBounds(int x, int y, int w, int h, int op) {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    92
        setBounds(x, y, w, h, op, true, false);
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    93
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    94
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    95
    @Override
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    96
    public void addDropTarget(DropTarget dt) {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    97
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    98
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    99
    @Override
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   100
    public void removeDropTarget(DropTarget dt) {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   101
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   102
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   103
    @Override
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   104
    public void grab() {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   105
        getLwTarget().grabFocus();
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   106
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   107
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   108
    @Override
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   109
    public void ungrab() {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   110
        getLwTarget().ungrabFocus();
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   111
    }
20127
a3a34675d847 8024170: [SwingNode] Implement cursor change
pchelko
parents: 15983
diff changeset
   112
a3a34675d847 8024170: [SwingNode] Implement cursor change
pchelko
parents: 15983
diff changeset
   113
    @Override
a3a34675d847 8024170: [SwingNode] Implement cursor change
pchelko
parents: 15983
diff changeset
   114
    public void updateCursorImmediately() {
a3a34675d847 8024170: [SwingNode] Implement cursor change
pchelko
parents: 15983
diff changeset
   115
        SwingAccessor.getJLightweightFrameAccessor().updateCursor((JLightweightFrame)getLwTarget());
a3a34675d847 8024170: [SwingNode] Implement cursor change
pchelko
parents: 15983
diff changeset
   116
    }
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   117
}