jdk/src/solaris/classes/sun/awt/X11/XKeyboardFocusManagerPeer.java
author mchung
Tue, 29 Sep 2009 16:03:03 -0700
changeset 3938 ef327bd847c0
parent 2472 b7aba00cabb6
child 5506 202f599c92aa
permissions -rw-r--r--
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes Summary: Replace calls to Logger with sun.util.logging.PlatformLogger Reviewed-by: prr, art, alexp, dcherepanov, igor, dav, anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 441
diff changeset
     2
 * Copyright 2003-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
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.KeyboardFocusManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.event.FocusEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.peer.KeyboardFocusManagerPeer;
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    34
import java.awt.peer.ComponentPeer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.lang.reflect.InvocationTargetException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
    39
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.awt.CausedFocusEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.awt.SunToolkit;
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    43
import sun.awt.KeyboardFocusManagerPeerImpl;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    45
public class XKeyboardFocusManagerPeer extends KeyboardFocusManagerPeerImpl {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
    46
    private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.X11.focus.XKeyboardFocusManagerPeer");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static Object lock = new Object() {};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private static Component currentFocusOwner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private static Window currentFocusedWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    52
    XKeyboardFocusManagerPeer(KeyboardFocusManager manager) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    53
        super(manager);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    54
    }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    55
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    56
    @Override
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    57
    public void setCurrentFocusOwner(Component comp) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    58
        setCurrentNativeFocusOwner(comp);
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
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    61
    @Override
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    62
    public Component getCurrentFocusOwner() {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    63
        return getCurrentNativeFocusOwner();
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    64
    }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    65
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    66
    @Override
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    67
    public Window getCurrentFocusedWindow() {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    68
        return getCurrentNativeFocusedWindow();
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    69
    }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    70
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    71
    public static void setCurrentNativeFocusOwner(Component comp) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    72
        synchronized (lock) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            currentFocusOwner = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    77
    public static Component getCurrentNativeFocusOwner() {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    78
        synchronized(lock) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    79
            return currentFocusOwner;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    80
        }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    81
    }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    82
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    83
    public static void setCurrentNativeFocusedWindow(Window win) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
    84
        if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer("Setting current native focused window " + win);
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    85
        XWindowPeer from = null, to = null;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    86
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        synchronized(lock) {
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    88
            if (currentFocusedWindow != null) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    89
                from = (XWindowPeer)currentFocusedWindow.getPeer();
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    90
            }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    91
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            currentFocusedWindow = win;
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    93
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    94
            if (currentFocusedWindow != null) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    95
                to = (XWindowPeer)currentFocusedWindow.getPeer();
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    96
            }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    97
        }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    98
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    99
        if (from != null) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
   100
            from.updateSecurityWarningVisibility();
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
   101
        }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
   102
        if (to != null) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
   103
            to.updateSecurityWarningVisibility();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   107
    public static Window getCurrentNativeFocusedWindow() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        synchronized(lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            return currentFocusedWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   113
    // TODO: do something to eliminate this forwarding
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   114
    public static boolean deliverFocus(Component lightweightChild,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   115
                                       Component target,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   116
                                       boolean temporary,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   117
                                       boolean focusedWindowChangeAllowed,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   118
                                       long time,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   119
                                       CausedFocusEvent.Cause cause)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    {
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   121
        return KeyboardFocusManagerPeerImpl.deliverFocus(lightweightChild,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   122
                                                         target,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   123
                                                         temporary,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   124
                                                         focusedWindowChangeAllowed,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   125
                                                         time,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   126
                                                         cause,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   127
                                                         getCurrentNativeFocusOwner());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
}