jdk/src/solaris/classes/sun/awt/X11/XKeyboardFocusManagerPeer.java
author ant
Tue, 10 Mar 2009 18:33:29 +0300
changeset 2464 3c6755bdc55f
parent 715 f16baef3a20e
child 2472 b7aba00cabb6
permissions -rw-r--r--
6806217: implement synthetic focus model for MS Windows Reviewed-by: art, dcherepanov
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.logging.Level;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.logging.Logger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.awt.CausedFocusEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.awt.SunToolkit;
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    44
import sun.awt.KeyboardFocusManagerPeerImpl;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    46
public class XKeyboardFocusManagerPeer extends KeyboardFocusManagerPeerImpl {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private static final Logger focusLog = Logger.getLogger("sun.awt.X11.focus.XKeyboardFocusManagerPeer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private static Object lock = new Object() {};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private static Component currentFocusOwner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static Window currentFocusedWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    53
    XKeyboardFocusManagerPeer(KeyboardFocusManager manager) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    54
        super(manager);
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
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    57
    @Override
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    58
    public void setCurrentFocusOwner(Component comp) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    59
        setCurrentNativeFocusOwner(comp);
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
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    62
    @Override
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    63
    public Component getCurrentFocusOwner() {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    64
        return getCurrentNativeFocusOwner();
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
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    67
    @Override
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    68
    public Window getCurrentFocusedWindow() {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    69
        return getCurrentNativeFocusedWindow();
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
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    72
    public static void setCurrentNativeFocusOwner(Component comp) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    73
        synchronized (lock) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            currentFocusOwner = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    78
    public static Component getCurrentNativeFocusOwner() {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    79
        synchronized(lock) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    80
            return currentFocusOwner;
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
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    84
    public static void setCurrentNativeFocusedWindow(Window win) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        if (focusLog.isLoggable(Level.FINER)) focusLog.finer("Setting current native focused window " + win);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        synchronized(lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            currentFocusedWindow = win;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    91
    public static Window getCurrentNativeFocusedWindow() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        synchronized(lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            return currentFocusedWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    97
    // TODO: do something to eliminate this forwarding
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    98
    public static boolean deliverFocus(Component lightweightChild,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
    99
                                       Component target,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   100
                                       boolean temporary,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   101
                                       boolean focusedWindowChangeAllowed,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   102
                                       long time,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   103
                                       CausedFocusEvent.Cause cause)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    {
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   105
        return KeyboardFocusManagerPeerImpl.deliverFocus(lightweightChild,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   106
                                                         target,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   107
                                                         temporary,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   108
                                                         focusedWindowChangeAllowed,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   109
                                                         time,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   110
                                                         cause,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   111
                                                         getCurrentNativeFocusOwner());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
}