jdk/src/solaris/classes/sun/awt/X11/XKeyboardFocusManagerPeer.java
author ant
Fri, 22 Feb 2013 15:13:13 +0400
changeset 15983 26a673dec5b2
parent 13648 90effcfc064f
child 18178 ee71c923891d
child 18130 d6c807285ce0
permissions -rw-r--r--
8006406: lightweight embedding in other Java UI toolkits Reviewed-by: serb, anthony, art
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     2
 * Copyright (c) 2003, 2008, 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: 3938
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: 3938
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: 3938
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Window;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
    29
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.awt.CausedFocusEvent;
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    31
import sun.awt.KeyboardFocusManagerPeerImpl;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    33
public class XKeyboardFocusManagerPeer extends KeyboardFocusManagerPeerImpl {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
    34
    private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.X11.focus.XKeyboardFocusManagerPeer");
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 5506
diff changeset
    35
    private static final XKeyboardFocusManagerPeer inst = new XKeyboardFocusManagerPeer();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 5506
diff changeset
    37
    private Component currentFocusOwner;
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 5506
diff changeset
    38
    private Window currentFocusedWindow;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 5506
diff changeset
    40
    public static XKeyboardFocusManagerPeer getInstance() {
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 5506
diff changeset
    41
        return inst;
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 5506
diff changeset
    42
    }
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 5506
diff changeset
    43
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 5506
diff changeset
    44
    private XKeyboardFocusManagerPeer() {
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    45
    }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    46
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    47
    @Override
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    48
    public void setCurrentFocusOwner(Component comp) {
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 5506
diff changeset
    49
        synchronized (this) {
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 5506
diff changeset
    50
            currentFocusOwner = comp;
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 5506
diff changeset
    51
        }
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    52
    }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    53
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    54
    @Override
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    55
    public Component getCurrentFocusOwner() {
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 5506
diff changeset
    56
        synchronized(this) {
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    57
            return currentFocusOwner;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    58
        }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    59
    }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    60
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 5506
diff changeset
    61
    @Override
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 5506
diff changeset
    62
    public void setCurrentFocusedWindow(Window win) {
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 5506
diff changeset
    63
        if (focusLog.isLoggable(PlatformLogger.FINER)) {
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 5506
diff changeset
    64
            focusLog.finer("Setting current focused window " + win);
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 5506
diff changeset
    65
        }
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 5506
diff changeset
    66
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    67
        XWindowPeer from = null, to = null;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    68
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 5506
diff changeset
    69
        synchronized(this) {
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    70
            if (currentFocusedWindow != null) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    71
                from = (XWindowPeer)currentFocusedWindow.getPeer();
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    72
            }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    73
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            currentFocusedWindow = win;
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    75
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    76
            if (currentFocusedWindow != null) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    77
                to = (XWindowPeer)currentFocusedWindow.getPeer();
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    78
            }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    79
        }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    80
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    81
        if (from != null) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    82
            from.updateSecurityWarningVisibility();
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    83
        }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    84
        if (to != null) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    85
            to.updateSecurityWarningVisibility();
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
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 5506
diff changeset
    89
    @Override
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 5506
diff changeset
    90
    public Window getCurrentFocusedWindow() {
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 5506
diff changeset
    91
        synchronized(this) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            return currentFocusedWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    96
    // TODO: do something to eliminate this forwarding
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    97
    public static boolean deliverFocus(Component lightweightChild,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    98
                                       Component target,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    99
                                       boolean temporary,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   100
                                       boolean focusedWindowChangeAllowed,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   101
                                       long time,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   102
                                       CausedFocusEvent.Cause cause)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    {
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   104
        return KeyboardFocusManagerPeerImpl.deliverFocus(lightweightChild,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   105
                                                         target,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   106
                                                         temporary,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   107
                                                         focusedWindowChangeAllowed,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   108
                                                         time,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   109
                                                         cause,
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 5506
diff changeset
   110
                                                         getInstance().getCurrentFocusOwner());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
}