jdk/src/solaris/classes/sun/awt/X11/XKeyboardFocusManagerPeer.java
author dcherepanov
Thu, 09 Jul 2009 15:23:22 -0400
changeset 3234 f0007f6747b0
parent 2472 b7aba00cabb6
child 3938 ef327bd847c0
permissions -rw-r--r--
6847958: MouseWheel event is getting triggered for the disabled Textarea in jdk7 b60 pit build. Reviewed-by: art
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);
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    86
        XWindowPeer from = null, to = null;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    87
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        synchronized(lock) {
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    89
            if (currentFocusedWindow != null) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    90
                from = (XWindowPeer)currentFocusedWindow.getPeer();
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    91
            }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    92
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            currentFocusedWindow = win;
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    94
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    95
            if (currentFocusedWindow != null) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
    96
                to = (XWindowPeer)currentFocusedWindow.getPeer();
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
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
   100
        if (from != null) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
   101
            from.updateSecurityWarningVisibility();
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
   102
        }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
   103
        if (to != null) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
   104
            to.updateSecurityWarningVisibility();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   108
    public static Window getCurrentNativeFocusedWindow() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        synchronized(lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            return currentFocusedWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   114
    // TODO: do something to eliminate this forwarding
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   115
    public static boolean deliverFocus(Component lightweightChild,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   116
                                       Component target,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   117
                                       boolean temporary,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   118
                                       boolean focusedWindowChangeAllowed,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   119
                                       long time,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   120
                                       CausedFocusEvent.Cause cause)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    {
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   122
        return KeyboardFocusManagerPeerImpl.deliverFocus(lightweightChild,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   123
                                                         target,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   124
                                                         temporary,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   125
                                                         focusedWindowChangeAllowed,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   126
                                                         time,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   127
                                                         cause,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 715
diff changeset
   128
                                                         getCurrentNativeFocusOwner());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
}