jdk/src/java.desktop/share/classes/java/awt/KeyboardFocusManager.java
author martin
Thu, 30 Oct 2014 07:31:41 -0700
changeset 28059 e576535359cc
parent 26749 b6598aa90114
child 28236 610561ed1847
permissions -rw-r--r--
8067377: My hobby: caning, then then canning, the the can-can Summary: Fix ALL the stutters! Reviewed-by: rriggs, mchung, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21278
diff changeset
     2
 * Copyright (c) 2000, 2014, 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: 4374
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: 4374
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: 4374
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4374
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4374
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.event.FocusEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.event.InputEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.KeyEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.event.WindowEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.peer.KeyboardFocusManagerPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.peer.LightweightPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.beans.PropertyChangeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.beans.PropertyVetoException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.beans.VetoableChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.beans.VetoableChangeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.lang.ref.WeakReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.lang.reflect.Field;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.util.LinkedList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.util.WeakHashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
4374
f672d9cf521e 6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset
mchung
parents: 4214
diff changeset
    56
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import sun.awt.AppContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import sun.awt.CausedFocusEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import sun.awt.KeyboardFocusManagerPeerProvider;
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
    62
import sun.awt.AWTAccessor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * The KeyboardFocusManager is responsible for managing the active and focused
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * Windows, and the current focus owner. The focus owner is defined as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * Component in an application that will typically receive all KeyEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * generated by the user. The focused Window is the Window that is, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * contains, the focus owner. Only a Frame or a Dialog can be the active
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * Window. The native windowing system may denote the active Window or its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * children with special decorations, such as a highlighted title bar. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * active Window is always either the focused Window, or the first Frame or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * Dialog that is an owner of the focused Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * The KeyboardFocusManager is both a centralized location for client code to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * query for the focus owner and initiate focus changes, and an event
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * dispatcher for all FocusEvents, WindowEvents related to focus, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * KeyEvents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * Some browsers partition applets in different code bases into separate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * contexts, and establish walls between these contexts. In such a scenario,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * there will be one KeyboardFocusManager per context. Other browsers place all
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * applets into the same context, implying that there will be only a single,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * global KeyboardFocusManager for all applets. This behavior is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * implementation-dependent. Consult your browser's documentation for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * information. No matter how many contexts there may be, however, there can
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * never be more than one focus owner, focused Window, or active Window, per
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * ClassLoader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * Please see
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20172
diff changeset
    91
 * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * How to Use the Focus Subsystem</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * a section in <em>The Java Tutorial</em>, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * @author David Mendenhall
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * @see Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * @see Frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * @see Dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * @see java.awt.event.FocusEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * @see java.awt.event.WindowEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * @see java.awt.event.KeyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
public abstract class KeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    implements KeyEventDispatcher, KeyEventPostProcessor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    // Shared focus engine logger
4374
f672d9cf521e 6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset
mchung
parents: 4214
diff changeset
   112
    private static final PlatformLogger focusLog = PlatformLogger.getLogger("java.awt.focus.KeyboardFocusManager");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        /* ensure that the necessary native libraries are loaded */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        Toolkit.loadLibraries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        if (!GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   120
        AWTAccessor.setKeyboardFocusManagerAccessor(
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   121
            new AWTAccessor.KeyboardFocusManagerAccessor() {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   122
                public int shouldNativelyFocusHeavyweight(Component heavyweight,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   123
                                                   Component descendant,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   124
                                                   boolean temporary,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   125
                                                   boolean focusedWindowChangeAllowed,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   126
                                                   long time,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   127
                                                   CausedFocusEvent.Cause cause)
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   128
                {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   129
                    return KeyboardFocusManager.shouldNativelyFocusHeavyweight(
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   130
                        heavyweight, descendant, temporary, focusedWindowChangeAllowed, time, cause);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   131
                }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   132
                public boolean processSynchronousLightweightTransfer(Component heavyweight,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   133
                                                              Component descendant,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   134
                                                              boolean temporary,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   135
                                                              boolean focusedWindowChangeAllowed,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   136
                                                              long time)
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   137
                {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   138
                    return KeyboardFocusManager.processSynchronousLightweightTransfer(
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   139
                        heavyweight, descendant, temporary, focusedWindowChangeAllowed, time);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   140
                }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   141
                public void removeLastFocusRequest(Component heavyweight) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   142
                    KeyboardFocusManager.removeLastFocusRequest(heavyweight);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   143
                }
6634
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   144
                public void setMostRecentFocusOwner(Window window, Component component) {
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   145
                    KeyboardFocusManager.setMostRecentFocusOwner(window, component);
439221465ac5 6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents: 5506
diff changeset
   146
                }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7668
diff changeset
   147
                public KeyboardFocusManager getCurrentKeyboardFocusManager(AppContext ctx) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7668
diff changeset
   148
                    return KeyboardFocusManager.getCurrentKeyboardFocusManager(ctx);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7668
diff changeset
   149
                }
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 12820
diff changeset
   150
                public Container getCurrentFocusCycleRoot() {
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 12820
diff changeset
   151
                    return KeyboardFocusManager.currentFocusCycleRoot;
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 12820
diff changeset
   152
                }
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   153
            }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   154
        );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    transient KeyboardFocusManagerPeer peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * Initialize JNI field and method IDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
4374
f672d9cf521e 6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset
mchung
parents: 4214
diff changeset
   164
    private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.KeyboardFocusManager");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * The identifier for the Forward focus traversal keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @see #setDefaultFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @see #getDefaultFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @see Component#setFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @see Component#getFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public static final int FORWARD_TRAVERSAL_KEYS = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * The identifier for the Backward focus traversal keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @see #setDefaultFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @see #getDefaultFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @see Component#setFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @see Component#getFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public static final int BACKWARD_TRAVERSAL_KEYS = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * The identifier for the Up Cycle focus traversal keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @see #setDefaultFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @see #getDefaultFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @see Component#setFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @see Component#getFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public static final int UP_CYCLE_TRAVERSAL_KEYS = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * The identifier for the Down Cycle focus traversal keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @see #setDefaultFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @see #getDefaultFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @see Component#setFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @see Component#getFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public static final int DOWN_CYCLE_TRAVERSAL_KEYS = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    static final int TRAVERSAL_KEY_LENGTH = DOWN_CYCLE_TRAVERSAL_KEYS + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * Returns the current KeyboardFocusManager instance for the calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * thread's context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @return this thread's context's KeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @see #setCurrentKeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    public static KeyboardFocusManager getCurrentKeyboardFocusManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        return getCurrentKeyboardFocusManager(AppContext.getAppContext());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    synchronized static KeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        getCurrentKeyboardFocusManager(AppContext appcontext)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        KeyboardFocusManager manager = (KeyboardFocusManager)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            appcontext.get(KeyboardFocusManager.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        if (manager == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            manager = new DefaultKeyboardFocusManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            appcontext.put(KeyboardFocusManager.class, manager);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        return manager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * Sets the current KeyboardFocusManager instance for the calling thread's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * context. If null is specified, then the current KeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * is replaced with a new instance of DefaultKeyboardFocusManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * If a SecurityManager is installed, the calling thread must be granted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * the AWTPermission "replaceKeyboardFocusManager" in order to replace the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * the current KeyboardFocusManager. If this permission is not granted,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * this method will throw a SecurityException, and the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * KeyboardFocusManager will be unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @param newManager the new KeyboardFocusManager for this thread's context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @see #getCurrentKeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @see DefaultKeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @throws SecurityException if the calling thread does not have permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *         to replace the current KeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public static void setCurrentKeyboardFocusManager(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        KeyboardFocusManager newManager) throws SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    {
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   251
        checkReplaceKFMPermission();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        KeyboardFocusManager oldManager = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        synchronized (KeyboardFocusManager.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            AppContext appcontext = AppContext.getAppContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            if (newManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                oldManager = getCurrentKeyboardFocusManager(appcontext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                appcontext.put(KeyboardFocusManager.class, newManager);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                oldManager = getCurrentKeyboardFocusManager(appcontext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                appcontext.remove(KeyboardFocusManager.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        if (oldManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            oldManager.firePropertyChange("managingFocus",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                                          Boolean.TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                                          Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        if (newManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            newManager.firePropertyChange("managingFocus",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                                          Boolean.FALSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                                          Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * The Component in an application that will typically receive all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * KeyEvents generated by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    private static Component focusOwner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * The Component in an application that will regain focus when an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * outstanding temporary focus transfer has completed, or the focus owner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * if no outstanding temporary transfer exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    private static Component permanentFocusOwner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * The Window which is, or contains, the focus owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    private static Window focusedWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * Only a Frame or a Dialog can be the active Window. The native windowing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * system may denote the active Window with a special decoration, such as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * highlighted title bar. The active Window is always either the focused
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * Window, or the first Frame or Dialog which is an owner of the focused
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    private static Window activeWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * The default FocusTraversalPolicy for all Windows that have no policy of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * their own set. If those Windows have focus-cycle-root children that have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * no keyboard-traversal policy of their own, then those children will also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * inherit this policy (as will, recursively, their focus-cycle-root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * children).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    private FocusTraversalPolicy defaultPolicy =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        new DefaultFocusTraversalPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * The bound property names of each focus traversal key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    private static final String[] defaultFocusTraversalKeyPropertyNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        "forwardDefaultFocusTraversalKeys",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        "backwardDefaultFocusTraversalKeys",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        "upCycleDefaultFocusTraversalKeys",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        "downCycleDefaultFocusTraversalKeys"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * The default strokes for initializing the default focus traversal keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    private static final AWTKeyStroke[][] defaultFocusTraversalKeyStrokes = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                                         InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK | InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                                         false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        {},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        {},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
      };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * The default focus traversal keys. Each array of traversal keys will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * in effect on all Windows that have no such array of their own explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * set. Each array will also be inherited, recursively, by any child
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * Component of those Windows that has no such array of its own explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     */
24549
147a5c8b7793 8039109: Fix unchecked and raw lint warnings in java.awt
darcy
parents: 22584
diff changeset
   351
    @SuppressWarnings({"unchecked", "rawtypes"})
20107
18e644411f0b 8022184: Fix static , Raw warnings in classes belonging to java.awt
art
parents: 19359
diff changeset
   352
    private Set<AWTKeyStroke>[] defaultFocusTraversalKeys = new Set[4];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * The current focus cycle root. If the focus owner is itself a focus cycle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * root, then it may be ambiguous as to which Components represent the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * and previous Components to focus during normal focus traversal. In that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * case, the current focus cycle root is used to differentiate among the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * possibilities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    private static Container currentFocusCycleRoot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * A description of any VetoableChangeListeners which have been registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    private VetoableChangeSupport vetoableSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * A description of any PropertyChangeListeners which have been registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    private PropertyChangeSupport changeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * This KeyboardFocusManager's KeyEventDispatcher chain. The List does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * include this KeyboardFocusManager unless it was explicitly re-registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * via a call to <code>addKeyEventDispatcher</code>. If no other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * KeyEventDispatchers are registered, this field may be null or refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * a List of length 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     */
20107
18e644411f0b 8022184: Fix static , Raw warnings in classes belonging to java.awt
art
parents: 19359
diff changeset
   380
    private java.util.LinkedList<KeyEventDispatcher> keyEventDispatchers;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * This KeyboardFocusManager's KeyEventPostProcessor chain. The List does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * not include this KeyboardFocusManager unless it was explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * re-registered via a call to <code>addKeyEventPostProcessor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * If no other KeyEventPostProcessors are registered, this field may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * null or refer to a List of length 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     */
20107
18e644411f0b 8022184: Fix static , Raw warnings in classes belonging to java.awt
art
parents: 19359
diff changeset
   389
    private java.util.LinkedList<KeyEventPostProcessor> keyEventPostProcessors;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * Maps Windows to those Windows' most recent focus owners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     */
20107
18e644411f0b 8022184: Fix static , Raw warnings in classes belonging to java.awt
art
parents: 19359
diff changeset
   394
    private static java.util.Map<Window, WeakReference<Component>> mostRecentFocusOwners = new WeakHashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * We cache the permission used to verify that the calling thread is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * permitted to access the global focus state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    private static AWTPermission replaceKeyboardFocusManagerPermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * SequencedEvent which is currently dispatched in AppContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    transient SequencedEvent currentSequencedEvent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    final void setCurrentSequencedEvent(SequencedEvent current) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        synchronized (SequencedEvent.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            assert(current == null || currentSequencedEvent == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            currentSequencedEvent = current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    final SequencedEvent getCurrentSequencedEvent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        synchronized (SequencedEvent.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            return currentSequencedEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
15318
607db339afcc 8005492: Reduce number of warnings in sun/awt/* classes
mcherkas
parents: 13656
diff changeset
   420
    static Set<AWTKeyStroke> initFocusTraversalKeysSet(String value, Set<AWTKeyStroke> targetSet) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        StringTokenizer tokens = new StringTokenizer(value, ",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        while (tokens.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            targetSet.add(AWTKeyStroke.getAWTKeyStroke(tokens.nextToken()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        return (targetSet.isEmpty())
24549
147a5c8b7793 8039109: Fix unchecked and raw lint warnings in java.awt
darcy
parents: 22584
diff changeset
   426
            ? Collections.emptySet()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            : Collections.unmodifiableSet(targetSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * Initializes a KeyboardFocusManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    public KeyboardFocusManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        for (int i = 0; i < TRAVERSAL_KEY_LENGTH; i++) {
20107
18e644411f0b 8022184: Fix static , Raw warnings in classes belonging to java.awt
art
parents: 19359
diff changeset
   435
            Set<AWTKeyStroke> work_set = new HashSet<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            for (int j = 0; j < defaultFocusTraversalKeyStrokes[i].length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                work_set.add(defaultFocusTraversalKeyStrokes[i][j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            defaultFocusTraversalKeys[i] = (work_set.isEmpty())
24549
147a5c8b7793 8039109: Fix unchecked and raw lint warnings in java.awt
darcy
parents: 22584
diff changeset
   440
                ? Collections.emptySet()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                : Collections.unmodifiableSet(work_set);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        initPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    private void initPeer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        Toolkit tk = Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        KeyboardFocusManagerPeerProvider peerProvider = (KeyboardFocusManagerPeerProvider)tk;
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 12820
diff changeset
   449
        peer = peerProvider.getKeyboardFocusManagerPeer();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * Returns the focus owner, if the focus owner is in the same context as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * the calling thread. The focus owner is defined as the Component in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * application that will typically receive all KeyEvents generated by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * user. KeyEvents which map to the focus owner's focus traversal keys will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * not be delivered if focus traversal keys are enabled for the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * owner. In addition, KeyEventDispatchers may retarget or consume
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * KeyEvents before they reach the focus owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @return the focus owner, or null if the focus owner is not a member of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     *         the calling thread's context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * @see #getGlobalFocusOwner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * @see #setGlobalFocusOwner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    public Component getFocusOwner() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        synchronized (KeyboardFocusManager.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            if (focusOwner == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            return (focusOwner.appContext == AppContext.getAppContext())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                ? focusOwner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * Returns the focus owner, even if the calling thread is in a different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * context than the focus owner. The focus owner is defined as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * Component in an application that will typically receive all KeyEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * generated by the user. KeyEvents which map to the focus owner's focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * traversal keys will not be delivered if focus traversal keys are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * for the focus owner. In addition, KeyEventDispatchers may retarget or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * consume KeyEvents before they reach the focus owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * This method will throw a SecurityException if this KeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * is not the current KeyboardFocusManager for the calling thread's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * @return the focus owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * @see #getFocusOwner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @see #setGlobalFocusOwner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * @throws SecurityException if this KeyboardFocusManager is not the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     *         current KeyboardFocusManager for the calling thread's context
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   496
     *         and if the calling thread does not have "replaceKeyboardFocusManager"
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   497
     *         permission
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    protected Component getGlobalFocusOwner() throws SecurityException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        synchronized (KeyboardFocusManager.class) {
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   501
            checkKFMSecurity();
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   502
            return focusOwner;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * Sets the focus owner. The operation will be cancelled if the Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * is not focusable. The focus owner is defined as the Component in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * application that will typically receive all KeyEvents generated by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * user. KeyEvents which map to the focus owner's focus traversal keys will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * not be delivered if focus traversal keys are enabled for the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * owner. In addition, KeyEventDispatchers may retarget or consume
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * KeyEvents before they reach the focus owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * This method does not actually set the focus to the specified Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * It merely stores the value to be subsequently returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * <code>getFocusOwner()</code>. Use <code>Component.requestFocus()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * or <code>Component.requestFocusInWindow()</code> to change the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * owner, subject to platform limitations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * @param focusOwner the focus owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * @see #getFocusOwner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * @see #getGlobalFocusOwner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * @see Component#requestFocus()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * @see Component#requestFocusInWindow()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * @see Component#isFocusable
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   527
     * @throws SecurityException if this KeyboardFocusManager is not the
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   528
     *         current KeyboardFocusManager for the calling thread's context
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   529
     *         and if the calling thread does not have "replaceKeyboardFocusManager"
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   530
     *         permission
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     */
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   534
    protected void setGlobalFocusOwner(Component focusOwner)
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   535
        throws SecurityException
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   536
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        Component oldFocusOwner = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        boolean shouldFire = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        if (focusOwner == null || focusOwner.isFocusable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            synchronized (KeyboardFocusManager.class) {
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   542
                checkKFMSecurity();
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   543
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                oldFocusOwner = getFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                    fireVetoableChange("focusOwner", oldFocusOwner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                                       focusOwner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                } catch (PropertyVetoException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                    // rejected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                KeyboardFocusManager.focusOwner = focusOwner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                if (focusOwner != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                    (getCurrentFocusCycleRoot() == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                     !focusOwner.isFocusCycleRoot(getCurrentFocusCycleRoot())))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                    Container rootAncestor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                        focusOwner.getFocusCycleRootAncestor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                    if (rootAncestor == null && (focusOwner instanceof Window))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                        rootAncestor = (Container)focusOwner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                    if (rootAncestor != null) {
12820
e3a3e523a846 7171776: one more setGlobalCurrentFocusCycleRoot call requires doPrivileged
ant
parents: 12666
diff changeset
   567
                        setGlobalCurrentFocusCycleRootPriv(rootAncestor);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                shouldFire = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        if (shouldFire) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            firePropertyChange("focusOwner", oldFocusOwner, focusOwner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    /**
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   581
     * Clears the focus owner at both the Java and native levels if the
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   582
     * focus owner exists and resides in the same context as the calling thread,
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   583
     * otherwise the method returns silently.
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   584
     * <p>
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   585
     * The focus owner component will receive a permanent FOCUS_LOST event.
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   586
     * After this operation completes, the native windowing system will discard
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   587
     * all user-generated KeyEvents until the user selects a new Component to
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   588
     * receive focus, or a Component is given focus explicitly via a call to
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   589
     * {@code requestFocus()}. This operation does not change the focused or
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   590
     * active Windows.
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   591
     *
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   592
     * @see Component#requestFocus()
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   593
     * @see java.awt.event.FocusEvent#FOCUS_LOST
20466
21c52a4c548b 7172597: java.awt.KeyboardFocusManager.clearFocusOwner() missed javadoc tag @since 1.8
malenkov
parents: 20455
diff changeset
   594
     * @since 1.8
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   595
     */
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   596
    public void clearFocusOwner() {
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   597
        if (getFocusOwner() != null) {
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   598
            clearGlobalFocusOwner();
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   599
        }
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   600
    }
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   601
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   602
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * Clears the global focus owner at both the Java and native levels. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * there exists a focus owner, that Component will receive a permanent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * FOCUS_LOST event. After this operation completes, the native windowing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * system will discard all user-generated KeyEvents until the user selects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * a new Component to receive focus, or a Component is given focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * explicitly via a call to <code>requestFocus()</code>. This operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * does not change the focused or active Windows.
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   610
     * <p>
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   611
     * If a SecurityManager is installed, the calling thread must be granted
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   612
     * the "replaceKeyboardFocusManager" AWTPermission. If this permission is
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   613
     * not granted, this method will throw a SecurityException, and the current
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   614
     * focus owner will not be cleared.
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   615
     * <p>
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   616
     * This method is intended to be used only by KeyboardFocusManager set as
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   617
     * current KeyboardFocusManager for the calling thread's context. It is not
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   618
     * for general client use.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     *
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   620
     * @see KeyboardFocusManager#clearFocusOwner
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * @see Component#requestFocus()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * @see java.awt.event.FocusEvent#FOCUS_LOST
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   623
     * @throws SecurityException if the calling thread does not have
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   624
     *         "replaceKeyboardFocusManager" permission
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     */
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   626
    public void clearGlobalFocusOwner()
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   627
        throws SecurityException
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   628
    {
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   629
        checkReplaceKFMPermission();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        if (!GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            // Toolkit must be fully initialized, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            // _clearGlobalFocusOwner will crash or throw an exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            _clearGlobalFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    private void _clearGlobalFocusOwner() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        Window activeWindow = markClearGlobalFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        peer.clearGlobalFocusOwner(activeWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   643
    void clearGlobalFocusOwnerPriv() {
12666
0799075de9d6 7170427: setGlobalCurrentFocusCycleRoot unexpectedly throws SecurityException
ant
parents: 12651
diff changeset
   644
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
0799075de9d6 7170427: setGlobalCurrentFocusCycleRoot unexpectedly throws SecurityException
ant
parents: 12651
diff changeset
   645
            public Void run() {
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   646
                clearGlobalFocusOwner();
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   647
                return null;
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   648
            }
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   649
        });
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   650
    }
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   651
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    Component getNativeFocusOwner() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        return peer.getCurrentFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    void setNativeFocusOwner(Component comp) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   657
        if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
4374
f672d9cf521e 6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset
mchung
parents: 4214
diff changeset
   658
            focusLog.finest("Calling peer {0} setCurrentFocusOwner for {1}",
f672d9cf521e 6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset
mchung
parents: 4214
diff changeset
   659
                            String.valueOf(peer), String.valueOf(comp));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        peer.setCurrentFocusOwner(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    Window getNativeFocusedWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        return peer.getCurrentFocusedWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * Returns the permanent focus owner, if the permanent focus owner is in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * the same context as the calling thread. The permanent focus owner is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * defined as the last Component in an application to receive a permanent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * FOCUS_GAINED event. The focus owner and permanent focus owner are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * equivalent unless a temporary focus change is currently in effect. In
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * such a situation, the permanent focus owner will again be the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * owner when the temporary focus change ends.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * @return the permanent focus owner, or null if the permanent focus owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     *         is not a member of the calling thread's context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * @see #getGlobalPermanentFocusOwner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * @see #setGlobalPermanentFocusOwner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    public Component getPermanentFocusOwner() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        synchronized (KeyboardFocusManager.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            if (permanentFocusOwner == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            return (permanentFocusOwner.appContext ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                    AppContext.getAppContext())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                ? permanentFocusOwner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * Returns the permanent focus owner, even if the calling thread is in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * different context than the permanent focus owner. The permanent focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * owner is defined as the last Component in an application to receive a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * permanent FOCUS_GAINED event. The focus owner and permanent focus owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * are equivalent unless a temporary focus change is currently in effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * In such a situation, the permanent focus owner will again be the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * owner when the temporary focus change ends.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * @return the permanent focus owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * @see #getPermanentFocusOwner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * @see #setGlobalPermanentFocusOwner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * @throws SecurityException if this KeyboardFocusManager is not the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     *         current KeyboardFocusManager for the calling thread's context
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   709
     *         and if the calling thread does not have "replaceKeyboardFocusManager"
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   710
     *         permission
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    protected Component getGlobalPermanentFocusOwner()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        throws SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        synchronized (KeyboardFocusManager.class) {
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   716
            checkKFMSecurity();
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   717
            return permanentFocusOwner;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * Sets the permanent focus owner. The operation will be cancelled if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * Component is not focusable. The permanent focus owner is defined as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * last Component in an application to receive a permanent FOCUS_GAINED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * event. The focus owner and permanent focus owner are equivalent unless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * a temporary focus change is currently in effect. In such a situation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * the permanent focus owner will again be the focus owner when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * temporary focus change ends.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * This method does not actually set the focus to the specified Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * It merely stores the value to be subsequently returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * <code>getPermanentFocusOwner()</code>. Use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * <code>Component.requestFocus()</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * <code>Component.requestFocusInWindow()</code> to change the focus owner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * subject to platform limitations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * @param permanentFocusOwner the permanent focus owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * @see #getPermanentFocusOwner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * @see #getGlobalPermanentFocusOwner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * @see Component#requestFocus()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * @see Component#requestFocusInWindow()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * @see Component#isFocusable
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   743
     * @throws SecurityException if this KeyboardFocusManager is not the
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   744
     *         current KeyboardFocusManager for the calling thread's context
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   745
     *         and if the calling thread does not have "replaceKeyboardFocusManager"
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   746
     *         permission
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    protected void setGlobalPermanentFocusOwner(Component permanentFocusOwner)
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   751
        throws SecurityException
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        Component oldPermanentFocusOwner = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        boolean shouldFire = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        if (permanentFocusOwner == null || permanentFocusOwner.isFocusable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            synchronized (KeyboardFocusManager.class) {
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   758
                checkKFMSecurity();
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   759
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                oldPermanentFocusOwner = getPermanentFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                    fireVetoableChange("permanentFocusOwner",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                                       oldPermanentFocusOwner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                                       permanentFocusOwner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                } catch (PropertyVetoException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                    // rejected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                KeyboardFocusManager.permanentFocusOwner = permanentFocusOwner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                KeyboardFocusManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                    setMostRecentFocusOwner(permanentFocusOwner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                shouldFire = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        if (shouldFire) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            firePropertyChange("permanentFocusOwner", oldPermanentFocusOwner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                               permanentFocusOwner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * Returns the focused Window, if the focused Window is in the same context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * as the calling thread. The focused Window is the Window that is or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * contains the focus owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * @return the focused Window, or null if the focused Window is not a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     *         member of the calling thread's context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * @see #getGlobalFocusedWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * @see #setGlobalFocusedWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    public Window getFocusedWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        synchronized (KeyboardFocusManager.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            if (focusedWindow == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            return (focusedWindow.appContext == AppContext.getAppContext())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                ? focusedWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * Returns the focused Window, even if the calling thread is in a different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * context than the focused Window. The focused Window is the Window that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * is or contains the focus owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     * @return the focused Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     * @see #getFocusedWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * @see #setGlobalFocusedWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * @throws SecurityException if this KeyboardFocusManager is not the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     *         current KeyboardFocusManager for the calling thread's context
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   818
     *         and if the calling thread does not have "replaceKeyboardFocusManager"
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   819
     *         permission
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    protected Window getGlobalFocusedWindow() throws SecurityException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        synchronized (KeyboardFocusManager.class) {
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   823
            checkKFMSecurity();
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   824
            return focusedWindow;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * Sets the focused Window. The focused Window is the Window that is or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * contains the focus owner. The operation will be cancelled if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * specified Window to focus is not a focusable Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * This method does not actually change the focused Window as far as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * native windowing system is concerned. It merely stores the value to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * subsequently returned by <code>getFocusedWindow()</code>. Use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * <code>Component.requestFocus()</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * <code>Component.requestFocusInWindow()</code> to change the focused
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * Window, subject to platform limitations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * @param focusedWindow the focused Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * @see #getFocusedWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * @see #getGlobalFocusedWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * @see Component#requestFocus()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * @see Component#requestFocusInWindow()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * @see Window#isFocusableWindow
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   846
     * @throws SecurityException if this KeyboardFocusManager is not the
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   847
     *         current KeyboardFocusManager for the calling thread's context
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   848
     *         and if the calling thread does not have "replaceKeyboardFocusManager"
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   849
     *         permission
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     */
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   853
    protected void setGlobalFocusedWindow(Window focusedWindow)
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   854
        throws SecurityException
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   855
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        Window oldFocusedWindow = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        boolean shouldFire = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        if (focusedWindow == null || focusedWindow.isFocusableWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            synchronized (KeyboardFocusManager.class) {
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   861
                checkKFMSecurity();
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   862
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                oldFocusedWindow = getFocusedWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                    fireVetoableChange("focusedWindow", oldFocusedWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                                       focusedWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                } catch (PropertyVetoException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                    // rejected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                KeyboardFocusManager.focusedWindow = focusedWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                shouldFire = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        if (shouldFire) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            firePropertyChange("focusedWindow", oldFocusedWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                               focusedWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * Returns the active Window, if the active Window is in the same context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * as the calling thread. Only a Frame or a Dialog can be the active
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * Window. The native windowing system may denote the active Window or its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * children with special decorations, such as a highlighted title bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     * The active Window is always either the focused Window, or the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     * Frame or Dialog that is an owner of the focused Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     * @return the active Window, or null if the active Window is not a member
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     *         of the calling thread's context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     * @see #getGlobalActiveWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * @see #setGlobalActiveWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    public Window getActiveWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        synchronized (KeyboardFocusManager.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            if (activeWindow == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            return (activeWindow.appContext == AppContext.getAppContext())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                ? activeWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * Returns the active Window, even if the calling thread is in a different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     * context than the active Window. Only a Frame or a Dialog can be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * active Window. The native windowing system may denote the active Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * or its children with special decorations, such as a highlighted title
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * bar. The active Window is always either the focused Window, or the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * Frame or Dialog that is an owner of the focused Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     * @return the active Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * @see #getActiveWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * @see #setGlobalActiveWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * @throws SecurityException if this KeyboardFocusManager is not the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     *         current KeyboardFocusManager for the calling thread's context
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   922
     *         and if the calling thread does not have "replaceKeyboardFocusManager"
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   923
     *         permission
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    protected Window getGlobalActiveWindow() throws SecurityException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        synchronized (KeyboardFocusManager.class) {
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   927
            checkKFMSecurity();
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   928
            return activeWindow;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     * Sets the active Window. Only a Frame or a Dialog can be the active
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     * Window. The native windowing system may denote the active Window or its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * children with special decorations, such as a highlighted title bar. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     * active Window is always either the focused Window, or the first Frame or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     * Dialog that is an owner of the focused Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * This method does not actually change the active Window as far as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     * native windowing system is concerned. It merely stores the value to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * subsequently returned by <code>getActiveWindow()</code>. Use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     * <code>Component.requestFocus()</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     * <code>Component.requestFocusInWindow()</code>to change the active
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     * Window, subject to platform limitations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * @param activeWindow the active Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     * @see #getActiveWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     * @see #getGlobalActiveWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * @see Component#requestFocus()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * @see Component#requestFocusInWindow()
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   951
     * @throws SecurityException if this KeyboardFocusManager is not the
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   952
     *         current KeyboardFocusManager for the calling thread's context
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   953
     *         and if the calling thread does not have "replaceKeyboardFocusManager"
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   954
     *         permission
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     */
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   958
    protected void setGlobalActiveWindow(Window activeWindow)
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   959
        throws SecurityException
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   960
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        Window oldActiveWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        synchronized (KeyboardFocusManager.class) {
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   963
            checkKFMSecurity();
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
   964
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            oldActiveWindow = getActiveWindow();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   966
            if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
4374
f672d9cf521e 6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset
mchung
parents: 4214
diff changeset
   967
                focusLog.finer("Setting global active window to " + activeWindow + ", old active " + oldActiveWindow);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                fireVetoableChange("activeWindow", oldActiveWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                                   activeWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
            } catch (PropertyVetoException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                // rejected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            KeyboardFocusManager.activeWindow = activeWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        firePropertyChange("activeWindow", oldActiveWindow, activeWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * Returns the default FocusTraversalPolicy. Top-level components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * use this value on their creation to initialize their own focus traversal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * policy by explicit call to Container.setFocusTraversalPolicy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     * @return the default FocusTraversalPolicy. null will never be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     * @see #setDefaultFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     * @see Container#setFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     * @see Container#getFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
    public synchronized FocusTraversalPolicy getDefaultFocusTraversalPolicy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        return defaultPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * Sets the default FocusTraversalPolicy. Top-level components
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * use this value on their creation to initialize their own focus traversal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     * policy by explicit call to Container.setFocusTraversalPolicy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * Note: this call doesn't affect already created components as they have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     * their policy initialized. Only new components will use this policy as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * their default policy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     * @param defaultPolicy the new, default FocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     * @see #getDefaultFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     * @see Container#setFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     * @see Container#getFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     * @throws IllegalArgumentException if defaultPolicy is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    public void setDefaultFocusTraversalPolicy(FocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
                                               defaultPolicy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        if (defaultPolicy == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            throw new IllegalArgumentException("default focus traversal policy cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        FocusTraversalPolicy oldPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            oldPolicy = this.defaultPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            this.defaultPolicy = defaultPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        firePropertyChange("defaultFocusTraversalPolicy", oldPolicy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                           defaultPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     * Sets the default focus traversal keys for a given traversal operation.
12643
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1033
     * This traversal key {@code Set} will be in effect on all
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1034
     * {@code Window}s that have no such {@code Set} of
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1035
     * their own explicitly defined. This {@code Set} will also be
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1036
     * inherited, recursively, by any child {@code Component} of
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1037
     * those {@code Windows} that has
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1038
     * no such {@code Set} of its own explicitly defined.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     * The default values for the default focus traversal keys are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     * implementation-dependent. Sun recommends that all implementations for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
     * particular native platform use the same default values. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     * recommendations for Windows and Unix are listed below. These
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     * recommendations are used in the Sun AWT implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     * <table border=1 summary="Recommended default values for focus traversal keys">
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     *    <th>Identifier</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     *    <th>Meaning</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     *    <th>Default</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     * <tr>
12643
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1053
     *    <td>{@code KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS}</td>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     *    <td>Normal forward keyboard traversal</td>
12643
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1055
     *    <td>{@code TAB} on {@code KEY_PRESSED},
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1056
     *        {@code CTRL-TAB} on {@code KEY_PRESSED}</td>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     * <tr>
12643
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1059
     *    <td>{@code KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS}</td>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     *    <td>Normal reverse keyboard traversal</td>
12643
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1061
     *    <td>{@code SHIFT-TAB} on {@code KEY_PRESSED},
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1062
     *        {@code CTRL-SHIFT-TAB} on {@code KEY_PRESSED}</td>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * <tr>
12643
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1065
     *    <td>{@code KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS}</td>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     *    <td>Go up one focus traversal cycle</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     *    <td>none</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     * <tr>
12643
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1070
     *    <td>{@code KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS}</td>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     *    <td>Go down one focus traversal cycle</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     *    <td>none</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     *
12643
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1076
     * To disable a traversal key, use an empty {@code Set};
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1077
     * {@code Collections.EMPTY_SET} is recommended.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     * <p>
12643
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1079
     * Using the {@code AWTKeyStroke} API, client code can
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
     * specify on which of two
12643
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1081
     * specific {@code KeyEvent}s, {@code KEY_PRESSED} or
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1082
     * {@code KEY_RELEASED}, the focus traversal operation will
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1083
     * occur. Regardless of which {@code KeyEvent} is specified,
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1084
     * however, all {@code KeyEvent}s related to the focus
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1085
     * traversal key, including the associated {@code KEY_TYPED}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     * event, will be consumed, and will not be dispatched
12643
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1087
     * to any {@code Component}. It is a runtime error to
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1088
     * specify a {@code KEY_TYPED} event as
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     * mapping to a focus traversal operation, or to map the same event to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     * multiple default focus traversal operations.
12643
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1091
     * <p>
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1092
     * This method may throw a {@code ClassCastException} if any {@code Object}
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1093
     * in {@code keystrokes} is not an {@code AWTKeyStroke}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
     * @param id one of
12643
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1096
     *        {@code KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS},
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1097
     *        {@code KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS},
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1098
     *        {@code KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS}, or
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1099
     *        {@code KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS}
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1100
     * @param keystrokes the Set of {@code AWTKeyStroke}s for the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     *        specified operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     * @see #getDefaultFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     * @see Component#setFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     * @see Component#getFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     * @throws IllegalArgumentException if id is not one of
12643
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1106
     *         {@code KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS},
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1107
     *         {@code KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS},
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1108
     *         {@code KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS}, or
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1109
     *         {@code KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS},
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1110
     *         or if keystrokes is {@code null},
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1111
     *         or if keystrokes contains {@code null},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     *         or if any keystroke
12643
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1113
     *         represents a {@code KEY_TYPED} event,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     *         or if any keystroke already maps
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     *         to another default focus traversal operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
    public void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        setDefaultFocusTraversalKeys(int id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
                                     Set<? extends AWTKeyStroke> keystrokes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        if (id < 0 || id >= TRAVERSAL_KEY_LENGTH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
            throw new IllegalArgumentException("invalid focus traversal key identifier");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        if (keystrokes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            throw new IllegalArgumentException("cannot set null Set of default focus traversal keys");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
20107
18e644411f0b 8022184: Fix static , Raw warnings in classes belonging to java.awt
art
parents: 19359
diff changeset
  1130
        Set<AWTKeyStroke> oldKeys;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        synchronized (this) {
12643
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1133
            for (AWTKeyStroke keystroke : keystrokes) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
12643
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12047
diff changeset
  1135
                if (keystroke == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
                    throw new IllegalArgumentException("cannot set null focus traversal key");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
                if (keystroke.getKeyChar() != KeyEvent.CHAR_UNDEFINED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                    throw new IllegalArgumentException("focus traversal keys cannot map to KEY_TYPED events");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
                // Check to see if key already maps to another traversal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
                // operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
                for (int i = 0; i < TRAVERSAL_KEY_LENGTH; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
                    if (i == id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                    if (defaultFocusTraversalKeys[i].contains(keystroke)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
                        throw new IllegalArgumentException("focus traversal keys must be unique for a Component");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
            oldKeys = defaultFocusTraversalKeys[id];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            defaultFocusTraversalKeys[id] =
20107
18e644411f0b 8022184: Fix static , Raw warnings in classes belonging to java.awt
art
parents: 19359
diff changeset
  1158
                Collections.unmodifiableSet(new HashSet<>(keystrokes));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
        firePropertyChange(defaultFocusTraversalKeyPropertyNames[id],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                           oldKeys, keystrokes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     * Returns a Set of default focus traversal keys for a given traversal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     * operation. This traversal key Set will be in effect on all Windows that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     * have no such Set of their own explicitly defined. This Set will also be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     * inherited, recursively, by any child Component of those Windows that has
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     * no such Set of its own explicitly defined. (See
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     * <code>setDefaultFocusTraversalKeys</code> for a full description of each
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     * operation.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     *        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     *        KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     *        KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     * @return the <code>Set</code> of <code>AWTKeyStroke</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
     *         for the specified operation; the <code>Set</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
     *         will be unmodifiable, and may be empty; <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     *         will never be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
     * @see #setDefaultFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
     * @see Component#setFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     * @see Component#getFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
     * @throws IllegalArgumentException if id is not one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     *         KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     *         KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     *         KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
     *         KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    public Set<AWTKeyStroke> getDefaultFocusTraversalKeys(int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
        if (id < 0 || id >= TRAVERSAL_KEY_LENGTH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
            throw new IllegalArgumentException("invalid focus traversal key identifier");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        // Okay to return Set directly because it is an unmodifiable view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        return defaultFocusTraversalKeys[id];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
     * Returns the current focus cycle root, if the current focus cycle root is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     * in the same context as the calling thread. If the focus owner is itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     * a focus cycle root, then it may be ambiguous as to which Components
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
     * represent the next and previous Components to focus during normal focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
     * traversal. In that case, the current focus cycle root is used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
     * differentiate among the possibilities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
     * This method is intended to be used only by KeyboardFocusManagers and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
     * focus implementations. It is not for general client use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
     * @return the current focus cycle root, or null if the current focus cycle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
     *         root is not a member of the calling thread's context
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
     * @see #getGlobalCurrentFocusCycleRoot
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
     * @see #setGlobalCurrentFocusCycleRoot
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
    public Container getCurrentFocusCycleRoot() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        synchronized (KeyboardFocusManager.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
            if (currentFocusCycleRoot == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
            return (currentFocusCycleRoot.appContext ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
                    AppContext.getAppContext())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
                ? currentFocusCycleRoot
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     * Returns the current focus cycle root, even if the calling thread is in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     * different context than the current focus cycle root. If the focus owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     * is itself a focus cycle root, then it may be ambiguous as to which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * Components represent the next and previous Components to focus during
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     * normal focus traversal. In that case, the current focus cycle root is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     * used to differentiate among the possibilities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
     * @return the current focus cycle root, or null if the current focus cycle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     *         root is not a member of the calling thread's context
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     * @see #getCurrentFocusCycleRoot
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     * @see #setGlobalCurrentFocusCycleRoot
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     * @throws SecurityException if this KeyboardFocusManager is not the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     *         current KeyboardFocusManager for the calling thread's context
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  1243
     *         and if the calling thread does not have "replaceKeyboardFocusManager"
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  1244
     *         permission
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
    protected Container getGlobalCurrentFocusCycleRoot()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        throws SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        synchronized (KeyboardFocusManager.class) {
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  1250
            checkKFMSecurity();
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  1251
            return currentFocusCycleRoot;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     * Sets the current focus cycle root. If the focus owner is itself a focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
     * cycle root, then it may be ambiguous as to which Components represent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     * the next and previous Components to focus during normal focus traversal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     * In that case, the current focus cycle root is used to differentiate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
     * among the possibilities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
     * <p>
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  1262
     * If a SecurityManager is installed, the calling thread must be granted
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  1263
     * the "replaceKeyboardFocusManager" AWTPermission. If this permission is
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  1264
     * not granted, this method will throw a SecurityException, and the current
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  1265
     * focus cycle root will not be changed.
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  1266
     * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     * This method is intended to be used only by KeyboardFocusManagers and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
     * focus implementations. It is not for general client use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     * @param newFocusCycleRoot the new focus cycle root
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
     * @see #getCurrentFocusCycleRoot
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
     * @see #getGlobalCurrentFocusCycleRoot
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  1273
     * @throws SecurityException if the calling thread does not have
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  1274
     *         "replaceKeyboardFocusManager" permission
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
     */
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  1278
    public void setGlobalCurrentFocusCycleRoot(Container newFocusCycleRoot)
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  1279
        throws SecurityException
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  1280
    {
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  1281
        checkReplaceKFMPermission();
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  1282
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        Container oldFocusCycleRoot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        synchronized (KeyboardFocusManager.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
            oldFocusCycleRoot  = getCurrentFocusCycleRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
            currentFocusCycleRoot = newFocusCycleRoot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
        firePropertyChange("currentFocusCycleRoot", oldFocusCycleRoot,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
                           newFocusCycleRoot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
12666
0799075de9d6 7170427: setGlobalCurrentFocusCycleRoot unexpectedly throws SecurityException
ant
parents: 12651
diff changeset
  1294
    void setGlobalCurrentFocusCycleRootPriv(final Container newFocusCycleRoot) {
0799075de9d6 7170427: setGlobalCurrentFocusCycleRoot unexpectedly throws SecurityException
ant
parents: 12651
diff changeset
  1295
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
0799075de9d6 7170427: setGlobalCurrentFocusCycleRoot unexpectedly throws SecurityException
ant
parents: 12651
diff changeset
  1296
            public Void run() {
0799075de9d6 7170427: setGlobalCurrentFocusCycleRoot unexpectedly throws SecurityException
ant
parents: 12651
diff changeset
  1297
                setGlobalCurrentFocusCycleRoot(newFocusCycleRoot);
0799075de9d6 7170427: setGlobalCurrentFocusCycleRoot unexpectedly throws SecurityException
ant
parents: 12651
diff changeset
  1298
                return null;
0799075de9d6 7170427: setGlobalCurrentFocusCycleRoot unexpectedly throws SecurityException
ant
parents: 12651
diff changeset
  1299
            }
0799075de9d6 7170427: setGlobalCurrentFocusCycleRoot unexpectedly throws SecurityException
ant
parents: 12651
diff changeset
  1300
        });
0799075de9d6 7170427: setGlobalCurrentFocusCycleRoot unexpectedly throws SecurityException
ant
parents: 12651
diff changeset
  1301
    }
0799075de9d6 7170427: setGlobalCurrentFocusCycleRoot unexpectedly throws SecurityException
ant
parents: 12651
diff changeset
  1302
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
     * Adds a PropertyChangeListener to the listener list. The listener is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
     * registered for all bound properties of this class, including the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
     * following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
     *    <li>whether the KeyboardFocusManager is currently managing focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
     *        for this application or applet's browser context
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
     *        ("managingFocus")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
     *    <li>the focus owner ("focusOwner")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
     *    <li>the permanent focus owner ("permanentFocusOwner")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
     *    <li>the focused Window ("focusedWindow")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
     *    <li>the active Window ("activeWindow")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
     *    <li>the default focus traversal policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
     *        ("defaultFocusTraversalPolicy")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
     *    <li>the Set of default FORWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
     *        ("forwardDefaultFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
     *    <li>the Set of default BACKWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
     *        ("backwardDefaultFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
     *    <li>the Set of default UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
     *        ("upCycleDefaultFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
     *    <li>the Set of default DOWN_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
     *        ("downCycleDefaultFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
     *    <li>the current focus cycle root ("currentFocusCycleRoot")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
     * If listener is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
     * @param listener the PropertyChangeListener to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
     * @see #removePropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
     * @see #getPropertyChangeListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
     * @see #addPropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
    public void addPropertyChangeListener(PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                if (changeSupport == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
                    changeSupport = new PropertyChangeSupport(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
                changeSupport.addPropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
     * Removes a PropertyChangeListener from the listener list. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
     * should be used to remove the PropertyChangeListeners that were
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
     * registered for all bound properties of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
     * If listener is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
     * @param listener the PropertyChangeListener to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
     * @see #addPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
     * @see #getPropertyChangeListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
     * @see #removePropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    public void removePropertyChangeListener(PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
                if (changeSupport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
                    changeSupport.removePropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
     * Returns an array of all the property change listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
     * registered on this keyboard focus manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
     * @return all of this keyboard focus manager's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
     *         <code>PropertyChangeListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
     *         or an empty array if no property change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
     * @see #addPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
     * @see #removePropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
     * @see #getPropertyChangeListeners(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
    public synchronized PropertyChangeListener[] getPropertyChangeListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
        if (changeSupport == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
            changeSupport = new PropertyChangeSupport(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
        return changeSupport.getPropertyChangeListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
     * Adds a PropertyChangeListener to the listener list for a specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
     * property. The specified property may be user-defined, or one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
     * following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
     *    <li>whether the KeyboardFocusManager is currently managing focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
     *        for this application or applet's browser context
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
     *        ("managingFocus")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
     *    <li>the focus owner ("focusOwner")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
     *    <li>the permanent focus owner ("permanentFocusOwner")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
     *    <li>the focused Window ("focusedWindow")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
     *    <li>the active Window ("activeWindow")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
     *    <li>the default focus traversal policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
     *        ("defaultFocusTraversalPolicy")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
     *    <li>the Set of default FORWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
     *        ("forwardDefaultFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
     *    <li>the Set of default BACKWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
     *        ("backwardDefaultFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
     *    <li>the Set of default UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
     *        ("upCycleDefaultFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
     *    <li>the Set of default DOWN_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
     *        ("downCycleDefaultFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
     *    <li>the current focus cycle root ("currentFocusCycleRoot")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     * If listener is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     * @param propertyName one of the property names listed above
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
     * @param listener the PropertyChangeListener to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
     * @see #addPropertyChangeListener(java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
     * @see #removePropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
     * @see #getPropertyChangeListeners(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
    public void addPropertyChangeListener(String propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
                                          PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
                if (changeSupport == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
                    changeSupport = new PropertyChangeSupport(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
                changeSupport.addPropertyChangeListener(propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
                                                        listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
     * Removes a PropertyChangeListener from the listener list for a specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
     * property. This method should be used to remove PropertyChangeListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
     * that were registered for a specific bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
     * If listener is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
     * @param propertyName a valid property name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
     * @param listener the PropertyChangeListener to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
     * @see #addPropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
     * @see #getPropertyChangeListeners(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
     * @see #removePropertyChangeListener(java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
    public void removePropertyChangeListener(String propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
                                             PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
                if (changeSupport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
                    changeSupport.removePropertyChangeListener(propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
                                                               listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
     * Returns an array of all the <code>PropertyChangeListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
     * associated with the named property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
     *
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24549
diff changeset
  1462
     * @param  propertyName the property name
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
     * @return all of the <code>PropertyChangeListener</code>s associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
     *         the named property or an empty array if no such listeners have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
     *         been added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
     * @see #addPropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
     * @see #removePropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
    public synchronized PropertyChangeListener[] getPropertyChangeListeners(String propertyName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
        if (changeSupport == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
            changeSupport = new PropertyChangeSupport(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
        return changeSupport.getPropertyChangeListeners(propertyName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
     * Fires a PropertyChangeEvent in response to a change in a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
     * The event will be delivered to all registered PropertyChangeListeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
     * No event will be delivered if oldValue and newValue are the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
     * @param propertyName the name of the property that has changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
     * @param oldValue the property's previous value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
     * @param newValue the property's new value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
    protected void firePropertyChange(String propertyName, Object oldValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
                                      Object newValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
        if (oldValue == newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
        PropertyChangeSupport changeSupport = this.changeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
        if (changeSupport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
            changeSupport.firePropertyChange(propertyName, oldValue, newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
     * Adds a VetoableChangeListener to the listener list. The listener is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
     * registered for all vetoable properties of this class, including the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
     * following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
     *    <li>the focus owner ("focusOwner")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
     *    <li>the permanent focus owner ("permanentFocusOwner")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
     *    <li>the focused Window ("focusedWindow")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
     *    <li>the active Window ("activeWindow")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
     * If listener is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
     * @param listener the VetoableChangeListener to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
     * @see #removeVetoableChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
     * @see #getVetoableChangeListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
     * @see #addVetoableChangeListener(java.lang.String,java.beans.VetoableChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
    public void addVetoableChangeListener(VetoableChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
                if (vetoableSupport == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
                    vetoableSupport =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
                        new VetoableChangeSupport(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
                vetoableSupport.addVetoableChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
     * Removes a VetoableChangeListener from the listener list. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
     * should be used to remove the VetoableChangeListeners that were
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
     * registered for all vetoable properties of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
     * If listener is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
     * @param listener the VetoableChangeListener to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
     * @see #addVetoableChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
     * @see #getVetoableChangeListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
     * @see #removeVetoableChangeListener(java.lang.String,java.beans.VetoableChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
    public void removeVetoableChangeListener(VetoableChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
                if (vetoableSupport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
                    vetoableSupport.removeVetoableChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
     * Returns an array of all the vetoable change listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
     * registered on this keyboard focus manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
     * @return all of this keyboard focus manager's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
     *         <code>VetoableChangeListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
     *         or an empty array if no vetoable change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
     * @see #addVetoableChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
     * @see #removeVetoableChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
     * @see #getVetoableChangeListeners(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
    public synchronized VetoableChangeListener[] getVetoableChangeListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
        if (vetoableSupport == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
            vetoableSupport = new VetoableChangeSupport(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
        return vetoableSupport.getVetoableChangeListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
     * Adds a VetoableChangeListener to the listener list for a specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
     * property. The specified property may be user-defined, or one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
     * following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
     *    <li>the focus owner ("focusOwner")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
     *    <li>the permanent focus owner ("permanentFocusOwner")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
     *    <li>the focused Window ("focusedWindow")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
     *    <li>the active Window ("activeWindow")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
     * If listener is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
     * @param propertyName one of the property names listed above
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
     * @param listener the VetoableChangeListener to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
     * @see #addVetoableChangeListener(java.beans.VetoableChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
     * @see #removeVetoableChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
     * @see #getVetoableChangeListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
    public void addVetoableChangeListener(String propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
                                          VetoableChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
                if (vetoableSupport == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
                    vetoableSupport =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
                        new VetoableChangeSupport(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
                vetoableSupport.addVetoableChangeListener(propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
                                                          listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
     * Removes a VetoableChangeListener from the listener list for a specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
     * property. This method should be used to remove VetoableChangeListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
     * that were registered for a specific bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
     * If listener is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
     * @param propertyName a valid property name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
     * @param listener the VetoableChangeListener to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
     * @see #addVetoableChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
     * @see #getVetoableChangeListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
     * @see #removeVetoableChangeListener(java.beans.VetoableChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
    public void removeVetoableChangeListener(String propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
                                             VetoableChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
                if (vetoableSupport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
                    vetoableSupport.removeVetoableChangeListener(propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
                                                                 listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
     * Returns an array of all the <code>VetoableChangeListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
     * associated with the named property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
     *
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24549
diff changeset
  1632
     * @param  propertyName the property name
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
     * @return all of the <code>VetoableChangeListener</code>s associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
     *         the named property or an empty array if no such listeners have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
     *         been added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
     * @see #addVetoableChangeListener(java.lang.String,java.beans.VetoableChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
     * @see #removeVetoableChangeListener(java.lang.String,java.beans.VetoableChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
     * @see #getVetoableChangeListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
    public synchronized VetoableChangeListener[] getVetoableChangeListeners(String propertyName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
        if (vetoableSupport == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
            vetoableSupport = new VetoableChangeSupport(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
        return vetoableSupport.getVetoableChangeListeners(propertyName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
     * Fires a PropertyChangeEvent in response to a change in a vetoable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
     * property. The event will be delivered to all registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
     * VetoableChangeListeners. If a VetoableChangeListener throws a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
     * PropertyVetoException, a new event is fired reverting all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
     * VetoableChangeListeners to the old value and the exception is then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
     * rethrown. No event will be delivered if oldValue and newValue are the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
     * same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
     * @param propertyName the name of the property that has changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
     * @param oldValue the property's previous value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
     * @param newValue the property's new value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
     * @throws java.beans.PropertyVetoException if a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
     *         <code>VetoableChangeListener</code> threw
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
     *         <code>PropertyVetoException</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
    protected void fireVetoableChange(String propertyName, Object oldValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
                                      Object newValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
        throws PropertyVetoException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
        if (oldValue == newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
        VetoableChangeSupport vetoableSupport =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
            this.vetoableSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
        if (vetoableSupport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
            vetoableSupport.fireVetoableChange(propertyName, oldValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
                                               newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
     * Adds a KeyEventDispatcher to this KeyboardFocusManager's dispatcher
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
     * chain. This KeyboardFocusManager will request that each
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
     * KeyEventDispatcher dispatch KeyEvents generated by the user before
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
     * finally dispatching the KeyEvent itself. KeyEventDispatchers will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
     * notified in the order in which they were added. Notifications will halt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
     * as soon as one KeyEventDispatcher returns <code>true</code> from its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
     * <code>dispatchKeyEvent</code> method. There is no limit to the total
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
     * number of KeyEventDispatchers which can be added, nor to the number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
     * times which a particular KeyEventDispatcher instance can be added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
     * If a null dispatcher is specified, no action is taken and no exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
     * is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
     * In a multithreaded application, {@link KeyEventDispatcher} behaves
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
     * the same as other AWT listeners.  See
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
     * <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
     * >AWT Threading Issues</a> for more details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
     * @param dispatcher the KeyEventDispatcher to add to the dispatcher chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
     * @see #removeKeyEventDispatcher
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
    public void addKeyEventDispatcher(KeyEventDispatcher dispatcher) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
        if (dispatcher != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
                if (keyEventDispatchers == null) {
20107
18e644411f0b 8022184: Fix static , Raw warnings in classes belonging to java.awt
art
parents: 19359
diff changeset
  1706
                    keyEventDispatchers = new java.util.LinkedList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
                keyEventDispatchers.add(dispatcher);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
     * Removes a KeyEventDispatcher which was previously added to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
     * KeyboardFocusManager's dispatcher chain. This KeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
     * cannot itself be removed, unless it was explicitly re-registered via a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
     * call to <code>addKeyEventDispatcher</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
     * If a null dispatcher is specified, if the specified dispatcher is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
     * in the dispatcher chain, or if this KeyboardFocusManager is specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
     * without having been explicitly re-registered, no action is taken and no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
     * exception is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
     * In a multithreaded application, {@link KeyEventDispatcher} behaves
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
     * the same as other AWT listeners.  See
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
     * <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
     * >AWT Threading Issues</a> for more details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
     * @param dispatcher the KeyEventDispatcher to remove from the dispatcher
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
     *        chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
     * @see #addKeyEventDispatcher
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
    public void removeKeyEventDispatcher(KeyEventDispatcher dispatcher) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
        if (dispatcher != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
                if (keyEventDispatchers != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
                    keyEventDispatchers.remove(dispatcher);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
     * Returns this KeyboardFocusManager's KeyEventDispatcher chain as a List.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
     * The List will not include this KeyboardFocusManager unless it was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
     * explicitly re-registered via a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
     * <code>addKeyEventDispatcher</code>. If no other KeyEventDispatchers are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
     * registered, implementations are free to return null or a List of length
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
     * 0. Client code should not assume one behavior over another, nor should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
     * it assume that the behavior, once established, will not change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
     * @return a possibly null or empty List of KeyEventDispatchers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
     * @see #addKeyEventDispatcher
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
     * @see #removeKeyEventDispatcher
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
     */
24549
147a5c8b7793 8039109: Fix unchecked and raw lint warnings in java.awt
darcy
parents: 22584
diff changeset
  1756
    @SuppressWarnings("unchecked") // Cast of result of clone
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
    protected synchronized java.util.List<KeyEventDispatcher>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
        getKeyEventDispatchers()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
        return (keyEventDispatchers != null)
24549
147a5c8b7793 8039109: Fix unchecked and raw lint warnings in java.awt
darcy
parents: 22584
diff changeset
  1761
            ? (java.util.List<KeyEventDispatcher>)keyEventDispatchers.clone()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
            : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
     * Adds a KeyEventPostProcessor to this KeyboardFocusManager's post-
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
     * processor chain. After a KeyEvent has been dispatched to and handled by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
     * its target, KeyboardFocusManager will request that each
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
     * KeyEventPostProcessor perform any necessary post-processing as part
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
     * of the KeyEvent's final resolution. KeyEventPostProcessors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
     * will be notified in the order in which they were added; the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
     * KeyboardFocusManager will be notified last. Notifications will halt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
     * as soon as one KeyEventPostProcessor returns <code>true</code> from its
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 26749
diff changeset
  1774
     * <code>postProcessKeyEvent</code> method. There is no limit to the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
     * total number of KeyEventPostProcessors that can be added, nor to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
     * number of times that a particular KeyEventPostProcessor instance can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
     * added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
     * If a null post-processor is specified, no action is taken and no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
     * exception is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
     * In a multithreaded application, {@link KeyEventPostProcessor} behaves
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
     * the same as other AWT listeners.  See
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
     * <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
     * >AWT Threading Issues</a> for more details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
     * @param processor the KeyEventPostProcessor to add to the post-processor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
     *        chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
     * @see #removeKeyEventPostProcessor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
    public void addKeyEventPostProcessor(KeyEventPostProcessor processor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
        if (processor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
                if (keyEventPostProcessors == null) {
20107
18e644411f0b 8022184: Fix static , Raw warnings in classes belonging to java.awt
art
parents: 19359
diff changeset
  1795
                    keyEventPostProcessors = new java.util.LinkedList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
                keyEventPostProcessors.add(processor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
     * Removes a previously added KeyEventPostProcessor from this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
     * KeyboardFocusManager's post-processor chain. This KeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
     * cannot itself be entirely removed from the chain. Only additional
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
     * references added via <code>addKeyEventPostProcessor</code> can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
     * removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
     * If a null post-processor is specified, if the specified post-processor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
     * is not in the post-processor chain, or if this KeyboardFocusManager is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
     * specified without having been explicitly added, no action is taken and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
     * no exception is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
     * In a multithreaded application, {@link KeyEventPostProcessor} behaves
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
     * the same as other AWT listeners.  See
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
     * <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
     * >AWT Threading Issues</a> for more details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
     * @param processor the KeyEventPostProcessor to remove from the post-
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
     *        processor chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
     * @see #addKeyEventPostProcessor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
    public void removeKeyEventPostProcessor(KeyEventPostProcessor processor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
        if (processor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
                if (keyEventPostProcessors != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
                    keyEventPostProcessors.remove(processor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
     * Returns this KeyboardFocusManager's KeyEventPostProcessor chain as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
     * List. The List will not include this KeyboardFocusManager unless it was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
     * explicitly added via a call to <code>addKeyEventPostProcessor</code>. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
     * no KeyEventPostProcessors are registered, implementations are free to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
     * return null or a List of length 0. Client code should not assume one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
     * behavior over another, nor should it assume that the behavior, once
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
     * established, will not change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
     * @return a possibly null or empty List of KeyEventPostProcessors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
     * @see #addKeyEventPostProcessor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
     * @see #removeKeyEventPostProcessor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
     */
24549
147a5c8b7793 8039109: Fix unchecked and raw lint warnings in java.awt
darcy
parents: 22584
diff changeset
  1848
    @SuppressWarnings("unchecked") // Cast of result of clone
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
    protected java.util.List<KeyEventPostProcessor>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
        getKeyEventPostProcessors()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
        return (keyEventPostProcessors != null)
24549
147a5c8b7793 8039109: Fix unchecked and raw lint warnings in java.awt
darcy
parents: 22584
diff changeset
  1853
            ? (java.util.List<KeyEventPostProcessor>)keyEventPostProcessors.clone()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
            : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
    static void setMostRecentFocusOwner(Component component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
        Component window = component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
        while (window != null && !(window instanceof Window)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
            window = window.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
        if (window != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
            setMostRecentFocusOwner((Window)window, component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
    static synchronized void setMostRecentFocusOwner(Window window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
                                                     Component component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
        // ATTN: component has a strong reference to window via chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
        // of Component.parent fields.  Since WeakHasMap refers to its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
        // values strongly, we need to break the strong link from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
        // value (component) back to its key (window).
20107
18e644411f0b 8022184: Fix static , Raw warnings in classes belonging to java.awt
art
parents: 19359
diff changeset
  1874
        WeakReference<Component> weakValue = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
        if (component != null) {
20107
18e644411f0b 8022184: Fix static , Raw warnings in classes belonging to java.awt
art
parents: 19359
diff changeset
  1876
            weakValue = new WeakReference<>(component);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
        mostRecentFocusOwners.put(window, weakValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
    static void clearMostRecentFocusOwner(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
        Container window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
        if (comp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
        synchronized (comp.getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
            window = comp.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
            while (window != null && !(window instanceof Window)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
                window = window.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
        synchronized (KeyboardFocusManager.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
            if ((window != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
                && (getMostRecentFocusOwner((Window)window) == comp))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
                setMostRecentFocusOwner((Window)window, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
            // Also clear temporary lost component stored in Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
            if (window != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
                Window realWindow = (Window)window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
                if (realWindow.getTemporaryLostComponent() == comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
                    realWindow.setTemporaryLostComponent(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
     * Please be careful changing this method! It is called from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
     * javax.swing.JComponent.runInputVerifier() using reflection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
    static synchronized Component getMostRecentFocusOwner(Window window) {
24549
147a5c8b7793 8039109: Fix unchecked and raw lint warnings in java.awt
darcy
parents: 22584
diff changeset
  1915
        WeakReference<Component> weakValue = mostRecentFocusOwners.get(window);
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21278
diff changeset
  1916
        return weakValue == null ? null : weakValue.get();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
     * This method is called by the AWT event dispatcher requesting that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
     * current KeyboardFocusManager dispatch the specified event on its behalf.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
     * It is expected that all KeyboardFocusManagers will dispatch all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
     * FocusEvents, all WindowEvents related to focus, and all KeyEvents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
     * These events should be dispatched based on the KeyboardFocusManager's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
     * notion of the focus owner and the focused and active Windows, sometimes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
     * overriding the source of the specified AWTEvent. Dispatching must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
     * done using <code>redispatchEvent</code> to prevent the AWT event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
     * dispatcher from recursively requesting that the KeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
     * dispatch the event again. If this method returns <code>false</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
     * then the AWT event dispatcher will attempt to dispatch the event itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
     * @param e the AWTEvent to be dispatched
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
     * @return <code>true</code> if this method dispatched the event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
     *         <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
     * @see #redispatchEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
     * @see #dispatchKeyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
    public abstract boolean dispatchEvent(AWTEvent e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
     * Redispatches an AWTEvent in such a way that the AWT event dispatcher
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
     * will not recursively request that the KeyboardFocusManager, or any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
     * installed KeyEventDispatchers, dispatch the event again. Client
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
     * implementations of <code>dispatchEvent</code> and client-defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
     * KeyEventDispatchers must call <code>redispatchEvent(target, e)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
     * instead of <code>target.dispatchEvent(e)</code> to dispatch an event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
     * This method is intended to be used only by KeyboardFocusManagers and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
     * KeyEventDispatchers. It is not for general client use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
     * @param target the Component to which the event should be dispatched
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
     * @param e the event to dispatch
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
     * @see #dispatchEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
     * @see KeyEventDispatcher
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
    public final void redispatchEvent(Component target, AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
        e.focusManagerIsDispatching = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
        target.dispatchEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
        e.focusManagerIsDispatching = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
     * Typically this method will be called by <code>dispatchEvent</code> if no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
     * other KeyEventDispatcher in the dispatcher chain dispatched the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
     * KeyEvent, or if no other KeyEventDispatchers are registered. If an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
     * implementation of this method returns <code>false</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
     * <code>dispatchEvent</code> may try to dispatch the KeyEvent itself, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
     * may simply return <code>false</code>. If <code>true</code> is returned,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
     * <code>dispatchEvent</code> should return <code>true</code> as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
     * @param e the KeyEvent which the current KeyboardFocusManager has
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
     *        requested that this KeyEventDispatcher dispatch
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
     * @return <code>true</code> if the KeyEvent was dispatched;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
     *         <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
     * @see #dispatchEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
    public abstract boolean dispatchKeyEvent(KeyEvent e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
     * This method will be called by <code>dispatchKeyEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
     * By default, this method will handle any unconsumed KeyEvents that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
     * map to an AWT <code>MenuShortcut</code> by consuming the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
     * and activating the shortcut.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
     * @param e the KeyEvent to post-process
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
     * @return <code>true</code> to indicate that no other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
     *         KeyEventPostProcessor will be notified of the KeyEvent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
     * @see #dispatchKeyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
     * @see MenuShortcut
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
    public abstract boolean postProcessKeyEvent(KeyEvent e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
     * This method initiates a focus traversal operation if and only if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
     * KeyEvent represents a focus traversal key for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
     * focusedComponent. It is expected that focusedComponent is the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
     * focus owner, although this need not be the case. If it is not,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
     * focus traversal will nevertheless proceed as if focusedComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
     * were the current focus owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
     * @param focusedComponent the Component that will be the basis for a focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
     *        traversal operation if the specified event represents a focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
     *        traversal key for the Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
     * @param e the event that may represent a focus traversal key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
    public abstract void processKeyEvent(Component focusedComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
                                         KeyEvent e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
     * Called by the AWT to notify the KeyboardFocusManager that it should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
     * delay dispatching of KeyEvents until the specified Component becomes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
     * the focus owner. If client code requests a focus change, and the AWT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
     * determines that this request might be granted by the native windowing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
     * system, then the AWT will call this method. It is the responsibility of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
     * the KeyboardFocusManager to delay dispatching of KeyEvents with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
     * timestamps later than the specified time stamp until the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
     * Component receives a FOCUS_GAINED event, or the AWT cancels the delay
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
     * request by invoking <code>dequeueKeyEvents</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
     * <code>discardKeyEvents</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
     * @param after timestamp of current event, or the current, system time if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
     *        the current event has no timestamp, or the AWT cannot determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
     *        which event is currently being handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
     * @param untilFocused Component which should receive a FOCUS_GAINED event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
     *        before any pending KeyEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
     * @see #dequeueKeyEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
     * @see #discardKeyEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
    protected abstract void enqueueKeyEvents(long after,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
                                             Component untilFocused);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
     * Called by the AWT to notify the KeyboardFocusManager that it should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
     * cancel delayed dispatching of KeyEvents. All KeyEvents which were
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
     * enqueued because of a call to <code>enqueueKeyEvents</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
     * same timestamp and Component should be released for normal dispatching
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
     * to the current focus owner. If the given timestamp is less than zero,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
     * the outstanding enqueue request for the given Component with the <b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
     * oldest</b> timestamp (if any) should be cancelled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
     * @param after the timestamp specified in the call to
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 20107
diff changeset
  2042
     *        <code>enqueueKeyEvents</code>, or any value &lt; 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
     * @param untilFocused the Component specified in the call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
     *        <code>enqueueKeyEvents</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
     * @see #enqueueKeyEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
     * @see #discardKeyEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
    protected abstract void dequeueKeyEvents(long after,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
                                             Component untilFocused);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
     * Called by the AWT to notify the KeyboardFocusManager that it should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
     * cancel delayed dispatching of KeyEvents. All KeyEvents which were
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
     * enqueued because of one or more calls to <code>enqueueKeyEvents</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
     * with the same Component should be discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
     * @param comp the Component specified in one or more calls to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
     *        <code>enqueueKeyEvents</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
     * @see #enqueueKeyEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
     * @see #dequeueKeyEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
    protected abstract void discardKeyEvents(Component comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
     * Focuses the Component after aComponent, typically based on a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
     * FocusTraversalPolicy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
     * @param aComponent the Component that is the basis for the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
     *        traversal operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
     * @see FocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
    public abstract void focusNextComponent(Component aComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
     * Focuses the Component before aComponent, typically based on a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
     * FocusTraversalPolicy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
     * @param aComponent the Component that is the basis for the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
     *        traversal operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
     * @see FocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
    public abstract void focusPreviousComponent(Component aComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
     * Moves the focus up one focus traversal cycle. Typically, the focus owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
     * is set to aComponent's focus cycle root, and the current focus cycle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
     * root is set to the new focus owner's focus cycle root. If, however,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
     * aComponent's focus cycle root is a Window, then typically the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
     * owner is set to the Window's default Component to focus, and the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
     * focus cycle root is unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
     * @param aComponent the Component that is the basis for the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
     *        traversal operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
    public abstract void upFocusCycle(Component aComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
     * Moves the focus down one focus traversal cycle. Typically, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
     * aContainer is a focus cycle root, then the focus owner is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
     * aContainer's default Component to focus, and the current focus cycle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
     * root is set to aContainer. If aContainer is not a focus cycle root, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
     * no focus traversal operation occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
     * @param aContainer the Container that is the basis for the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
     *        traversal operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
    public abstract void downFocusCycle(Container aContainer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
     * Focuses the Component after the current focus owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
    public final void focusNextComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
        Component focusOwner = getFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
        if (focusOwner != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
            focusNextComponent(focusOwner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
     * Focuses the Component before the current focus owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
    public final void focusPreviousComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
        Component focusOwner = getFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
        if (focusOwner != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
            focusPreviousComponent(focusOwner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
     * Moves the focus up one focus traversal cycle from the current focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
     * owner. Typically, the new focus owner is set to the current focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
     * owner's focus cycle root, and the current focus cycle root is set to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
     * new focus owner's focus cycle root. If, however, the current focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
     * owner's focus cycle root is a Window, then typically the focus owner is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
     * set to the focus cycle root's default Component to focus, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
     * current focus cycle root is unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
    public final void upFocusCycle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
        Component focusOwner = getFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
        if (focusOwner != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
            upFocusCycle(focusOwner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
     * Moves the focus down one focus traversal cycle from the current focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
     * owner, if and only if the current focus owner is a Container that is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
     * focus cycle root. Typically, the focus owner is set to the current focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
     * owner's default Component to focus, and the current focus cycle root is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
     * set to the current focus owner. If the current focus owner is not a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
     * Container that is a focus cycle root, then no focus traversal operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
     * occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
    public final void downFocusCycle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
        Component focusOwner = getFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
        if (focusOwner instanceof Container) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
            downFocusCycle((Container)focusOwner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
     * Dumps the list of focus requests to stderr
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
    void dumpRequests() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
        System.err.println(">>> Requests dump, time: " + System.currentTimeMillis());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
        synchronized (heavyweightRequests) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
            for (HeavyweightFocusRequest req : heavyweightRequests) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
                System.err.println(">>> Req: " + req);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
        System.err.println("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
    private static final class LightweightFocusRequest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
        final Component component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
        final boolean temporary;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
        final CausedFocusEvent.Cause cause;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
        LightweightFocusRequest(Component component, boolean temporary, CausedFocusEvent.Cause cause) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
            this.component = component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
            this.temporary = temporary;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
            this.cause = cause;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
            return "LightweightFocusRequest[component=" + component +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
                ",temporary=" + temporary + ", cause=" + cause + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
    private static final class HeavyweightFocusRequest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
        final Component heavyweight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
        final LinkedList<LightweightFocusRequest> lightweightRequests;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
        static final HeavyweightFocusRequest CLEAR_GLOBAL_FOCUS_OWNER =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
            new HeavyweightFocusRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
        private HeavyweightFocusRequest() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
            heavyweight = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
            lightweightRequests = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
        HeavyweightFocusRequest(Component heavyweight, Component descendant,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
                                boolean temporary, CausedFocusEvent.Cause cause) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  2204
            if (log.isLoggable(PlatformLogger.Level.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
                if (heavyweight == null) {
4374
f672d9cf521e 6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset
mchung
parents: 4214
diff changeset
  2206
                    log.fine("Assertion (heavyweight != null) failed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
            this.heavyweight = heavyweight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
            this.lightweightRequests = new LinkedList<LightweightFocusRequest>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
            addLightweightRequest(descendant, temporary, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
        boolean addLightweightRequest(Component descendant,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
                                      boolean temporary, CausedFocusEvent.Cause cause) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  2216
            if (log.isLoggable(PlatformLogger.Level.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
                if (this == HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER) {
4374
f672d9cf521e 6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset
mchung
parents: 4214
diff changeset
  2218
                    log.fine("Assertion (this != HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER) failed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
                if (descendant == null) {
4374
f672d9cf521e 6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset
mchung
parents: 4214
diff changeset
  2221
                    log.fine("Assertion (descendant != null) failed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
            Component lastDescendant = ((lightweightRequests.size() > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
                ? lightweightRequests.getLast().component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
                : null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
            if (descendant != lastDescendant) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
                // Not a duplicate request
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
                lightweightRequests.add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
                    (new LightweightFocusRequest(descendant, temporary, cause));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
        LightweightFocusRequest getFirstLightweightRequest() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
            if (this == CLEAR_GLOBAL_FOCUS_OWNER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
            return lightweightRequests.getFirst();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
            boolean first = true;
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 25859
diff changeset
  2247
            String str = "HeavyweightFocusRequest[heavyweight=" + heavyweight +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
                ",lightweightRequests=";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
            if (lightweightRequests == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
                str += null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
                str += "[";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
                for (LightweightFocusRequest lwRequest : lightweightRequests) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
                    if (first) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
                        first = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
                        str += ",";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
                    str += lwRequest;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
                str += "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
            str += "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
            return str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
     * heavyweightRequests is used as a monitor for synchronized changes of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
     * currentLightweightRequests, clearingCurrentLightweightRequests and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
     * newFocusOwner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
    private static LinkedList<HeavyweightFocusRequest> heavyweightRequests =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
        new LinkedList<HeavyweightFocusRequest>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
    private static LinkedList<LightweightFocusRequest> currentLightweightRequests;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
    private static boolean clearingCurrentLightweightRequests;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
    private static boolean allowSyncFocusRequests = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
    private static Component newFocusOwner = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
    private static volatile boolean disableRestoreFocus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
    static final int SNFH_FAILURE = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
    static final int SNFH_SUCCESS_HANDLED = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
    static final int SNFH_SUCCESS_PROCEED = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
    static boolean processSynchronousLightweightTransfer(Component heavyweight, Component descendant,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
                                                  boolean temporary, boolean focusedWindowChangeAllowed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
                                                  long time)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
    {
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
  2290
        Window parentWindow = SunToolkit.getContainingWindow(heavyweight);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
        if (parentWindow == null || !parentWindow.syncLWRequests) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
        if (descendant == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
            // Focus transfers from a lightweight child back to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
            // heavyweight Container should be treated like lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
            // focus transfers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
            descendant = heavyweight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
        KeyboardFocusManager manager = getCurrentKeyboardFocusManager(SunToolkit.targetToAppContext(descendant));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
        FocusEvent currentFocusOwnerEvent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
        FocusEvent newFocusOwnerEvent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
        Component currentFocusOwner = manager.getGlobalFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
        synchronized (heavyweightRequests) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
            HeavyweightFocusRequest hwFocusRequest = getLastHWRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
            if (hwFocusRequest == null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
                heavyweight == manager.getNativeFocusOwner() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
                allowSyncFocusRequests)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
                if (descendant == currentFocusOwner) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
                    // Redundant request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
                // 'heavyweight' owns the native focus and there are no pending
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
                // requests. 'heavyweight' must be a Container and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
                // 'descendant' must not be the focus owner. Otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
                // we would never have gotten this far.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
                manager.enqueueKeyEvents(time, descendant);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
                hwFocusRequest =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
                    new HeavyweightFocusRequest(heavyweight, descendant,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
                                                temporary, CausedFocusEvent.Cause.UNKNOWN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
                heavyweightRequests.add(hwFocusRequest);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
                if (currentFocusOwner != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
                    currentFocusOwnerEvent =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
                        new FocusEvent(currentFocusOwner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
                                       FocusEvent.FOCUS_LOST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
                                       temporary, descendant);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
                newFocusOwnerEvent =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
                    new FocusEvent(descendant, FocusEvent.FOCUS_GAINED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
                                   temporary, currentFocusOwner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
        boolean result = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
        final boolean clearing = clearingCurrentLightweightRequests;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
        Throwable caughtEx = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
            clearingCurrentLightweightRequests = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
            synchronized(Component.LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
                if (currentFocusOwnerEvent != null && currentFocusOwner != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
                    ((AWTEvent) currentFocusOwnerEvent).isPosted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
                    caughtEx = dispatchAndCatchException(caughtEx, currentFocusOwner, currentFocusOwnerEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
                    result = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
                if (newFocusOwnerEvent != null && descendant != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
                    ((AWTEvent) newFocusOwnerEvent).isPosted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
                    caughtEx = dispatchAndCatchException(caughtEx, descendant, newFocusOwnerEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
                    result = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
            clearingCurrentLightweightRequests = clearing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
        if (caughtEx instanceof RuntimeException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
            throw (RuntimeException)caughtEx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
        } else if (caughtEx instanceof Error) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
            throw (Error)caughtEx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
     * Indicates whether the native implementation should proceed with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
     * pending, native focus request. Before changing the focus at the native
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
     * level, the AWT implementation should always call this function for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
     * permission. This function will reject the request if a duplicate request
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
     * preceded it, or if the specified heavyweight Component already owns the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
     * focus and no native focus changes are pending. Otherwise, the request
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
     * will be approved and the focus request list will be updated so that,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
     * if necessary, the proper descendant will be focused when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
     * corresponding FOCUS_GAINED event on the heavyweight is received.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
     * An implementation must ensure that calls to this method and native
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
     * focus changes are atomic. If this is not guaranteed, then the ordering
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
     * of the focus request list may be incorrect, leading to errors in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
     * type-ahead mechanism. Typically this is accomplished by only calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
     * this function from the native event pumping thread, or by holding a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
     * global, native lock during invocation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
    static int shouldNativelyFocusHeavyweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
        (Component heavyweight, Component descendant, boolean temporary,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
         boolean focusedWindowChangeAllowed, long time, CausedFocusEvent.Cause cause)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
    {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  2394
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
            if (heavyweight == null) {
4374
f672d9cf521e 6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset
mchung
parents: 4214
diff changeset
  2396
                log.fine("Assertion (heavyweight != null) failed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
            if (time == 0) {
4374
f672d9cf521e 6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset
mchung
parents: 4214
diff changeset
  2399
                log.fine("Assertion (time != 0) failed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
        if (descendant == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
            // Focus transfers from a lightweight child back to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
            // heavyweight Container should be treated like lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
            // focus transfers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
            descendant = heavyweight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
        KeyboardFocusManager manager =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
            getCurrentKeyboardFocusManager(SunToolkit.targetToAppContext(descendant));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
        KeyboardFocusManager thisManager = getCurrentKeyboardFocusManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
        Component currentFocusOwner = thisManager.getGlobalFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
        Component nativeFocusOwner = thisManager.getNativeFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
        Window nativeFocusedWindow = thisManager.getNativeFocusedWindow();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  2416
        if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
4374
f672d9cf521e 6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset
mchung
parents: 4214
diff changeset
  2417
            focusLog.finer("SNFH for {0} in {1}",
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 15318
diff changeset
  2418
                       String.valueOf(descendant), String.valueOf(heavyweight));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
        }
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  2420
        if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
4374
f672d9cf521e 6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset
mchung
parents: 4214
diff changeset
  2421
            focusLog.finest("0. Current focus owner {0}",
f672d9cf521e 6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset
mchung
parents: 4214
diff changeset
  2422
                            String.valueOf(currentFocusOwner));
f672d9cf521e 6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset
mchung
parents: 4214
diff changeset
  2423
            focusLog.finest("0. Native focus owner {0}",
f672d9cf521e 6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset
mchung
parents: 4214
diff changeset
  2424
                            String.valueOf(nativeFocusOwner));
f672d9cf521e 6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset
mchung
parents: 4214
diff changeset
  2425
            focusLog.finest("0. Native focused window {0}",
f672d9cf521e 6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset
mchung
parents: 4214
diff changeset
  2426
                            String.valueOf(nativeFocusedWindow));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
        synchronized (heavyweightRequests) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
            HeavyweightFocusRequest hwFocusRequest = getLastHWRequest();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  2430
            if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
4374
f672d9cf521e 6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset
mchung
parents: 4214
diff changeset
  2431
                focusLog.finest("Request {0}", String.valueOf(hwFocusRequest));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
            if (hwFocusRequest == null &&
19359
f6c72fbf9e7e 8013611: Modal dialog fails to obtain keyboard focus
ant
parents: 18178
diff changeset
  2434
                heavyweight == nativeFocusOwner &&
f6c72fbf9e7e 8013611: Modal dialog fails to obtain keyboard focus
ant
parents: 18178
diff changeset
  2435
                heavyweight.getContainingWindow() == nativeFocusedWindow)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
                if (descendant == currentFocusOwner) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
                    // Redundant request.
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  2439
                    if (focusLog.isLoggable(PlatformLogger.Level.FINEST))
4374
f672d9cf521e 6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset
mchung
parents: 4214
diff changeset
  2440
                        focusLog.finest("1. SNFH_FAILURE for {0}",
f672d9cf521e 6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset
mchung
parents: 4214
diff changeset
  2441
                                        String.valueOf(descendant));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
                    return SNFH_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
                // 'heavyweight' owns the native focus and there are no pending
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
                // requests. 'heavyweight' must be a Container and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
                // 'descendant' must not be the focus owner. Otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
                // we would never have gotten this far.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
                manager.enqueueKeyEvents(time, descendant);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
                hwFocusRequest =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
                    new HeavyweightFocusRequest(heavyweight, descendant,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
                                                temporary, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
                heavyweightRequests.add(hwFocusRequest);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
                if (currentFocusOwner != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
                    FocusEvent currentFocusOwnerEvent =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
                        new CausedFocusEvent(currentFocusOwner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
                                       FocusEvent.FOCUS_LOST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
                                       temporary, descendant, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
                    // Fix 5028014. Rolled out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
                    // SunToolkit.postPriorityEvent(currentFocusOwnerEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
                    SunToolkit.postEvent(currentFocusOwner.appContext,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
                                         currentFocusOwnerEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
                FocusEvent newFocusOwnerEvent =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
                    new CausedFocusEvent(descendant, FocusEvent.FOCUS_GAINED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
                                   temporary, currentFocusOwner, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
                // Fix 5028014. Rolled out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
                // SunToolkit.postPriorityEvent(newFocusOwnerEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
                SunToolkit.postEvent(descendant.appContext, newFocusOwnerEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  2473
                if (focusLog.isLoggable(PlatformLogger.Level.FINEST))
4374
f672d9cf521e 6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset
mchung
parents: 4214
diff changeset
  2474
                    focusLog.finest("2. SNFH_HANDLED for {0}", String.valueOf(descendant));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
                return SNFH_SUCCESS_HANDLED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
            } else if (hwFocusRequest != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
                       hwFocusRequest.heavyweight == heavyweight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
                // 'heavyweight' doesn't have the native focus right now, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
                // if all pending requests were completed, it would. Add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
                // descendant to the heavyweight's list of pending
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
                // lightweight focus transfers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
                if (hwFocusRequest.addLightweightRequest(descendant,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
                                                         temporary, cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
                    manager.enqueueKeyEvents(time, descendant);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  2487
                if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
                    focusLog.finest("3. SNFH_HANDLED for lightweight" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
                                    descendant + " in " + heavyweight);
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 15318
diff changeset
  2490
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
                return SNFH_SUCCESS_HANDLED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
                if (!focusedWindowChangeAllowed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
                    // For purposes of computing oldFocusedWindow, we should look at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
                    // the second to last HeavyweightFocusRequest on the queue iff the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
                    // last HeavyweightFocusRequest is CLEAR_GLOBAL_FOCUS_OWNER. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
                    // there is no second to last HeavyweightFocusRequest, null is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
                    // acceptable value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
                    if (hwFocusRequest ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
                        HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
                        int size = heavyweightRequests.size();
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21278
diff changeset
  2503
                        hwFocusRequest = (size >= 2)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
                            ? heavyweightRequests.get(size - 2)
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21278
diff changeset
  2505
                            : null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
                    if (focusedWindowChanged(heavyweight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
                                             (hwFocusRequest != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
                                             ? hwFocusRequest.heavyweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
                                             : nativeFocusedWindow)) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  2511
                        if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
                            focusLog.finest("4. SNFH_FAILURE for " + descendant);
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 15318
diff changeset
  2513
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
                        return SNFH_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
                manager.enqueueKeyEvents(time, descendant);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
                heavyweightRequests.add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
                    (new HeavyweightFocusRequest(heavyweight, descendant,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
                                                 temporary, cause));
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  2522
                if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
                    focusLog.finest("5. SNFH_PROCEED for " + descendant);
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 15318
diff changeset
  2524
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
                return SNFH_SUCCESS_PROCEED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
     * Returns the Window which will be active after processing this request,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
     * or null if this is a duplicate request. The active Window is useful
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
     * because some native platforms do not support setting the native focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
     * owner to null. On these platforms, the obvious choice is to set the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
     * focus owner to the focus proxy of the active Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
    static Window markClearGlobalFocusOwner() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
        // need to call this out of synchronized block to avoid possible deadlock
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
        // see 6454631.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
        final Component nativeFocusedWindow =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
                getCurrentKeyboardFocusManager().getNativeFocusedWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
        synchronized (heavyweightRequests) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
            HeavyweightFocusRequest hwFocusRequest = getLastHWRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
            if (hwFocusRequest ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
                HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
                // duplicate request
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
            heavyweightRequests.add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
                (HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
            Component activeWindow = ((hwFocusRequest != null)
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
  2556
                ? SunToolkit.getContainingWindow(hwFocusRequest.heavyweight)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
                : nativeFocusedWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
            while (activeWindow != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
                   !((activeWindow instanceof Frame) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
                     (activeWindow instanceof Dialog)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
                activeWindow = activeWindow.getParent_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
            return (Window) activeWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
    Component getCurrentWaitingRequest(Component parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
        synchronized (heavyweightRequests) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
            HeavyweightFocusRequest hwFocusRequest = getFirstHWRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
            if (hwFocusRequest != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
                if (hwFocusRequest.heavyweight == parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
                    LightweightFocusRequest lwFocusRequest =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
                        hwFocusRequest.lightweightRequests.getFirst();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
                    if (lwFocusRequest != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
                        return lwFocusRequest.component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
    static boolean isAutoFocusTransferEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
        synchronized (heavyweightRequests) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
            return (heavyweightRequests.size() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
                    && !disableRestoreFocus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
                    && (null == currentLightweightRequests);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 2
diff changeset
  2592
    static boolean isAutoFocusTransferEnabledFor(Component comp) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 2
diff changeset
  2593
        return isAutoFocusTransferEnabled() && comp.isAutoFocusTransferOnDisposal();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 2
diff changeset
  2594
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 2
diff changeset
  2595
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
     * Used to process exceptions in dispatching focus event (in focusLost/focusGained callbacks).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
     * @param ex previously caught exception that may be processed right here, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
     * @param comp the component to dispatch the event to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
     * @param event the event to dispatch to the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
    static private Throwable dispatchAndCatchException(Throwable ex, Component comp, FocusEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
        Throwable retEx = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
            comp.dispatchEvent(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
        } catch (RuntimeException re) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
            retEx = re;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
        } catch (Error er) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
            retEx = er;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
        if (retEx != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
            if (ex != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
                handleException(ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
            return retEx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
        return ex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
    static private void handleException(Throwable ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
        ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
    static void processCurrentLightweightRequests() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
        KeyboardFocusManager manager = getCurrentKeyboardFocusManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
        LinkedList<LightweightFocusRequest> localLightweightRequests = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
        Component globalFocusOwner = manager.getGlobalFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
        if ((globalFocusOwner != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
            (globalFocusOwner.appContext != AppContext.getAppContext()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
            // The current app context differs from the app context of a focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
            // owner (and all pending lightweight requests), so we do nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
            // now and wait for a next event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
        synchronized(heavyweightRequests) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
            if (currentLightweightRequests != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
                clearingCurrentLightweightRequests = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
                disableRestoreFocus = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
                localLightweightRequests = currentLightweightRequests;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
                allowSyncFocusRequests = (localLightweightRequests.size() < 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
                currentLightweightRequests = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
                // do nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
        Throwable caughtEx = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2653
            if (localLightweightRequests != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
                Component lastFocusOwner = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
                Component currentFocusOwner = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
20107
18e644411f0b 8022184: Fix static , Raw warnings in classes belonging to java.awt
art
parents: 19359
diff changeset
  2657
                for (Iterator<KeyboardFocusManager.LightweightFocusRequest> iter = localLightweightRequests.iterator(); iter.hasNext(); ) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
                    currentFocusOwner = manager.getGlobalFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
                    LightweightFocusRequest lwFocusRequest =
20107
18e644411f0b 8022184: Fix static , Raw warnings in classes belonging to java.awt
art
parents: 19359
diff changeset
  2661
                        iter.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
                    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
                     * WARNING: This is based on DKFM's logic solely!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
                     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2666
                     * We allow to trigger restoreFocus() in the dispatching process
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
                     * only if we have the last request to dispatch. If the last request
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2668
                     * fails, focus will be restored to either the component of the last
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 26749
diff changeset
  2669
                     * previously succeeded request, or to the focus owner that was
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20466
diff changeset
  2670
                     * before this clearing process.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
                    if (!iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2673
                        disableRestoreFocus = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2674
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
                    FocusEvent currentFocusOwnerEvent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
                    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
                     * We're not dispatching FOCUS_LOST while the current focus owner is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
                     * But regardless of whether it's null or not, we're clearing ALL the local
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2680
                     * lw requests.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2682
                    if (currentFocusOwner != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
                        currentFocusOwnerEvent = new CausedFocusEvent(currentFocusOwner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
                                       FocusEvent.FOCUS_LOST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2685
                                       lwFocusRequest.temporary,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2686
                                       lwFocusRequest.component, lwFocusRequest.cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2687
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
                    FocusEvent newFocusOwnerEvent =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
                        new CausedFocusEvent(lwFocusRequest.component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2690
                                       FocusEvent.FOCUS_GAINED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2691
                                       lwFocusRequest.temporary,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
                                       currentFocusOwner == null ? lastFocusOwner : currentFocusOwner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
                                       lwFocusRequest.cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
                    if (currentFocusOwner != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
                        ((AWTEvent) currentFocusOwnerEvent).isPosted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
                        caughtEx = dispatchAndCatchException(caughtEx, currentFocusOwner, currentFocusOwnerEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
                    ((AWTEvent) newFocusOwnerEvent).isPosted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
                    caughtEx = dispatchAndCatchException(caughtEx, lwFocusRequest.component, newFocusOwnerEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
                    if (manager.getGlobalFocusOwner() == lwFocusRequest.component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
                        lastFocusOwner = lwFocusRequest.component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2708
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
            clearingCurrentLightweightRequests = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
            disableRestoreFocus = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
            localLightweightRequests = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
            allowSyncFocusRequests = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
        if (caughtEx instanceof RuntimeException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
            throw (RuntimeException)caughtEx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
        } else if (caughtEx instanceof Error) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
            throw (Error)caughtEx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
    static FocusEvent retargetUnexpectedFocusEvent(FocusEvent fe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
        synchronized (heavyweightRequests) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
            // Any other case represents a failure condition which we did
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
            // not expect. We need to clearFocusRequestList() and patch up
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
            // the event as best as possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
            if (removeFirstRequest()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
                return (FocusEvent)retargetFocusEvent(fe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
            Component source = fe.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
            Component opposite = fe.getOppositeComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
            boolean temporary = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
            if (fe.getID() == FocusEvent.FOCUS_LOST &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
                (opposite == null || isTemporary(opposite, source)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
                temporary = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
            return new CausedFocusEvent(source, fe.getID(), temporary, opposite,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
                                        CausedFocusEvent.Cause.NATIVE_SYSTEM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
    static FocusEvent retargetFocusGained(FocusEvent fe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
        assert (fe.getID() == FocusEvent.FOCUS_GAINED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
        Component currentFocusOwner = getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
            getGlobalFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
        Component source = fe.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
        Component opposite = fe.getOppositeComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
        Component nativeSource = getHeavyweight(source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
        synchronized (heavyweightRequests) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
            HeavyweightFocusRequest hwFocusRequest = getFirstHWRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
            if (hwFocusRequest == HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
                return retargetUnexpectedFocusEvent(fe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
            if (source != null && nativeSource == null && hwFocusRequest != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
                // if source w/o peer and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
                // if source is equal to first lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
                // then we should correct source and nativeSource
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
                if (source == hwFocusRequest.getFirstLightweightRequest().component)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
                    source = hwFocusRequest.heavyweight;
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 25859
diff changeset
  2768
                    nativeSource = source; // source is heavyweight itself
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
            if (hwFocusRequest != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
                nativeSource == hwFocusRequest.heavyweight)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
                // Focus change as a result of a known call to requestFocus(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
                // or known click on a peer focusable heavyweight Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
                heavyweightRequests.removeFirst();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
                LightweightFocusRequest lwFocusRequest =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
                    hwFocusRequest.lightweightRequests.removeFirst();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
                Component newSource = lwFocusRequest.component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
                if (currentFocusOwner != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
                    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
                     * Since we receive FOCUS_GAINED when current focus
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 25859
diff changeset
  2786
                     * owner is not null, corresponding FOCUS_LOST is supposed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
                     * to be lost.  And so,  we keep new focus owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
                     * to determine synthetic FOCUS_LOST event which will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
                     * generated by KeyboardFocusManager for this FOCUS_GAINED.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
                     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
                     * This code based on knowledge of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
                     * DefaultKeyboardFocusManager's implementation and might
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
                     * be not applicable for another KeyboardFocusManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2794
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
                    newFocusOwner = newSource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
                boolean temporary = (opposite == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
                                     isTemporary(newSource, opposite))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
                        ? false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
                        : lwFocusRequest.temporary;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
                if (hwFocusRequest.lightweightRequests.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
                    currentLightweightRequests =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
                        hwFocusRequest.lightweightRequests;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
                    EventQueue.invokeLater(new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
                            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
                                processCurrentLightweightRequests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
                        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
                // 'opposite' will be fixed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
                // DefaultKeyboardFocusManager.realOppositeComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
                return new CausedFocusEvent(newSource,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
                                      FocusEvent.FOCUS_GAINED, temporary,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
                                      opposite, lwFocusRequest.cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
            if (currentFocusOwner != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
                && currentFocusOwner.getContainingWindow() == source
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
                && (hwFocusRequest == null || source != hwFocusRequest.heavyweight))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
                // Special case for FOCUS_GAINED in top-levels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
                // If it arrives as the result of activation we should skip it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
                // This event will not have appropriate request record and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
                // on arrival there will be already some focus owner set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
                return new CausedFocusEvent(currentFocusOwner, FocusEvent.FOCUS_GAINED, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
                                            null, CausedFocusEvent.Cause.ACTIVATION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
            return retargetUnexpectedFocusEvent(fe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
        } // end synchronized(heavyweightRequests)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
    static FocusEvent retargetFocusLost(FocusEvent fe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
        assert (fe.getID() == FocusEvent.FOCUS_LOST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
        Component currentFocusOwner = getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
            getGlobalFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
        Component opposite = fe.getOppositeComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
        Component nativeOpposite = getHeavyweight(opposite);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
        synchronized (heavyweightRequests) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
            HeavyweightFocusRequest hwFocusRequest = getFirstHWRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
            if (hwFocusRequest == HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
                if (currentFocusOwner != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
                    // Call to KeyboardFocusManager.clearGlobalFocusOwner()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
                    heavyweightRequests.removeFirst();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
                    return new CausedFocusEvent(currentFocusOwner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
                                                FocusEvent.FOCUS_LOST, false, null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
                                                CausedFocusEvent.Cause.CLEAR_GLOBAL_FOCUS_OWNER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
                // Otherwise, fall through to failure case below
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
            } else if (opposite == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2861
                // Focus leaving application
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
                if (currentFocusOwner != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
                    return new CausedFocusEvent(currentFocusOwner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
                                                FocusEvent.FOCUS_LOST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
                                                true, null, CausedFocusEvent.Cause.ACTIVATION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
                    return fe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
            } else if (hwFocusRequest != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
                       (nativeOpposite == hwFocusRequest.heavyweight ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
                        nativeOpposite == null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
                        opposite == hwFocusRequest.getFirstLightweightRequest().component))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2873
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2874
                if (currentFocusOwner == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
                    return fe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
                // Focus change as a result of a known call to requestFocus(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
                // or click on a peer focusable heavyweight Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
                // If a focus transfer is made across top-levels, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2880
                // FOCUS_LOST event is always temporary, and the FOCUS_GAINED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
                // event is always permanent. Otherwise, the stored temporary
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
                // value is honored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
                LightweightFocusRequest lwFocusRequest =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
                    hwFocusRequest.lightweightRequests.getFirst();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2887
                boolean temporary = isTemporary(opposite, currentFocusOwner)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
                    ? true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
                    : lwFocusRequest.temporary;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
                return new CausedFocusEvent(currentFocusOwner, FocusEvent.FOCUS_LOST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
                                            temporary, lwFocusRequest.component, lwFocusRequest.cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
            } else if (focusedWindowChanged(opposite, currentFocusOwner)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
                // If top-level changed there might be no focus request in a list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
                // But we know the opposite, we now it is temporary - dispatch the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2896
                if (!fe.isTemporary() && currentFocusOwner != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
                    // Create copy of the event with only difference in temporary parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
                    fe = new CausedFocusEvent(currentFocusOwner, FocusEvent.FOCUS_LOST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
                                              true, opposite, CausedFocusEvent.Cause.ACTIVATION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
                return fe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
            return retargetUnexpectedFocusEvent(fe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
        }  // end synchronized(heavyweightRequests)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
    static AWTEvent retargetFocusEvent(AWTEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
        if (clearingCurrentLightweightRequests) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
            return event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
        KeyboardFocusManager manager = getCurrentKeyboardFocusManager();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  2914
        if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
            if (event instanceof FocusEvent || event instanceof WindowEvent) {
4374
f672d9cf521e 6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset
mchung
parents: 4214
diff changeset
  2916
                focusLog.finer(">>> {0}", String.valueOf(event));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2917
            }
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  2918
            if (focusLog.isLoggable(PlatformLogger.Level.FINER) && event instanceof KeyEvent) {
4374
f672d9cf521e 6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset
mchung
parents: 4214
diff changeset
  2919
                focusLog.finer("    focus owner is {0}",
f672d9cf521e 6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset
mchung
parents: 4214
diff changeset
  2920
                               String.valueOf(manager.getGlobalFocusOwner()));
f672d9cf521e 6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset
mchung
parents: 4214
diff changeset
  2921
                focusLog.finer(">>> {0}", String.valueOf(event));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
        synchronized(heavyweightRequests) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
             * This code handles FOCUS_LOST event which is generated by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
             * DefaultKeyboardFocusManager for FOCUS_GAINED.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
             * This code based on knowledge of DefaultKeyboardFocusManager's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
             * implementation and might be not applicable for another
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2932
             * KeyboardFocusManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2934
             * Fix for 4472032
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2935
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2936
            if (newFocusOwner != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
                event.getID() == FocusEvent.FOCUS_LOST)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
                FocusEvent fe = (FocusEvent)event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
                if (manager.getGlobalFocusOwner() == fe.getComponent() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2942
                    fe.getOppositeComponent() == newFocusOwner)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2943
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2944
                    newFocusOwner = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2945
                    return event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2946
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2948
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2949
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2950
        processCurrentLightweightRequests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2951
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2952
        switch (event.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
            case FocusEvent.FOCUS_GAINED: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
                event = retargetFocusGained((FocusEvent)event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2957
            case FocusEvent.FOCUS_LOST: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2958
                event = retargetFocusLost((FocusEvent)event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2959
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2960
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2961
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2962
                /* do nothing */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2963
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2964
        return event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2965
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2966
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2967
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2968
     * Clears markers queue
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2969
     * This method is not intended to be overridden by KFM's.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
     * Only DefaultKeyboardFocusManager can implement it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2971
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2972
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2973
    void clearMarkers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2974
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2975
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2976
    static boolean removeFirstRequest() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2977
        KeyboardFocusManager manager =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2978
            KeyboardFocusManager.getCurrentKeyboardFocusManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2979
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2980
        synchronized(heavyweightRequests) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2981
            HeavyweightFocusRequest hwFocusRequest = getFirstHWRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2982
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2983
            if (hwFocusRequest != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2984
                heavyweightRequests.removeFirst();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2985
                if (hwFocusRequest.lightweightRequests != null) {
20107
18e644411f0b 8022184: Fix static , Raw warnings in classes belonging to java.awt
art
parents: 19359
diff changeset
  2986
                    for (Iterator<KeyboardFocusManager.LightweightFocusRequest> lwIter = hwFocusRequest.lightweightRequests.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2987
                             iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2988
                         lwIter.hasNext(); )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2989
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2990
                        manager.dequeueKeyEvents
20107
18e644411f0b 8022184: Fix static , Raw warnings in classes belonging to java.awt
art
parents: 19359
diff changeset
  2991
                            (-1, lwIter.next().
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2992
                             component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2993
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2994
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2995
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2996
            // Fix for 4799136 - clear type-ahead markers if requests queue is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2997
            // We do it here because this method is called only when problems happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2998
            if (heavyweightRequests.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2999
                manager.clearMarkers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3000
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3001
            return (heavyweightRequests.size() > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3002
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3003
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3004
    static void removeLastFocusRequest(Component heavyweight) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  3005
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3006
            if (heavyweight == null) {
4374
f672d9cf521e 6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset
mchung
parents: 4214
diff changeset
  3007
                log.fine("Assertion (heavyweight != null) failed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3008
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3009
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3010
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3011
        KeyboardFocusManager manager =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3012
            KeyboardFocusManager.getCurrentKeyboardFocusManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3013
        synchronized(heavyweightRequests) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3014
            HeavyweightFocusRequest hwFocusRequest = getLastHWRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3015
            if (hwFocusRequest != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3016
                hwFocusRequest.heavyweight == heavyweight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3017
                heavyweightRequests.removeLast();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3018
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3019
            // Fix for 4799136 - clear type-ahead markers if requests queue is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3020
            // We do it here because this method is called only when problems happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3021
            if (heavyweightRequests.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3022
                manager.clearMarkers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3023
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3024
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3025
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3026
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3027
    private static boolean focusedWindowChanged(Component to, Component from) {
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
  3028
        Window wto = SunToolkit.getContainingWindow(to);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
  3029
        Window wfrom = SunToolkit.getContainingWindow(from);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3030
        if (wto == null && wfrom == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3031
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3032
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3033
        if (wto == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3034
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3035
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3036
        if (wfrom == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3037
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3038
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3039
        return (wto != wfrom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3040
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3042
    private static boolean isTemporary(Component to, Component from) {
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
  3043
        Window wto = SunToolkit.getContainingWindow(to);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
  3044
        Window wfrom = SunToolkit.getContainingWindow(from);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3045
        if (wto == null && wfrom == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3046
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3047
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3048
        if (wto == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3049
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3050
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3051
        if (wfrom == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3052
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3053
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3054
        return (wto != wfrom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3055
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3056
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3057
    static Component getHeavyweight(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3058
        if (comp == null || comp.getPeer() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3059
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3060
        } else if (comp.getPeer() instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3061
            return comp.getNativeContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3062
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3063
            return comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3064
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3065
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3066
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3067
    static Field proxyActive;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3068
    // Accessor to private field isProxyActive of KeyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3069
    private static boolean isProxyActiveImpl(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3070
        if (proxyActive == null) {
20107
18e644411f0b 8022184: Fix static , Raw warnings in classes belonging to java.awt
art
parents: 19359
diff changeset
  3071
            proxyActive =  AccessController.doPrivileged(new PrivilegedAction<Field>() {
18e644411f0b 8022184: Fix static , Raw warnings in classes belonging to java.awt
art
parents: 19359
diff changeset
  3072
                    public Field run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3073
                        Field field = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3074
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3075
                            field = KeyEvent.class.getDeclaredField("isProxyActive");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3076
                            if (field != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3077
                                field.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3078
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3079
                        } catch (NoSuchFieldException nsf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3080
                            assert(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3081
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3082
                        return field;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3083
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3084
                });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3085
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3087
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3088
            return proxyActive.getBoolean(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3089
        } catch (IllegalAccessException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3090
            assert(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3091
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3092
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3093
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3095
    // Returns the value of this KeyEvent's field isProxyActive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3096
    static boolean isProxyActive(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3097
        if (!GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3098
            return isProxyActiveImpl(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3099
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3100
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3103
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3104
    private static HeavyweightFocusRequest getLastHWRequest() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3105
        synchronized(heavyweightRequests) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3106
            return (heavyweightRequests.size() > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3107
                ? heavyweightRequests.getLast()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3108
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3112
    private static HeavyweightFocusRequest getFirstHWRequest() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3113
        synchronized(heavyweightRequests) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3114
            return (heavyweightRequests.size() > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3115
                ? heavyweightRequests.getFirst()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3116
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3118
    }
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3119
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3120
    private static void checkReplaceKFMPermission()
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3121
        throws SecurityException
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3122
    {
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3123
        SecurityManager security = System.getSecurityManager();
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3124
        if (security != null) {
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3125
            if (replaceKeyboardFocusManagerPermission == null) {
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3126
                replaceKeyboardFocusManagerPermission =
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3127
                    new AWTPermission("replaceKeyboardFocusManager");
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3128
            }
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3129
            security.
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3130
                checkPermission(replaceKeyboardFocusManagerPermission);
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3131
        }
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3132
    }
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3133
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3134
    // Checks if this KeyboardFocusManager instance is the current KFM,
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3135
    // or otherwise checks if the calling thread has "replaceKeyboardFocusManager"
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3136
    // permission. Here's the reasoning to do so:
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3137
    //
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3138
    // A system KFM instance (which is the current KFM by default) may have no
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3139
    // "replaceKFM" permission when a client code is on the call stack beneath,
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3140
    // but still it should be able to execute the methods protected by this check
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3141
    // due to the system KFM is trusted (and so it does like "privileged").
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3142
    //
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3143
    // If this KFM instance is not the current KFM but the client code has all
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3144
    // permissions we can't throw SecurityException because it would contradict
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3145
    // the security concepts. In this case the trusted client code is responsible
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3146
    // for calling the secured methods from KFM instance which is not current.
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3147
    private void checkKFMSecurity()
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3148
        throws SecurityException
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3149
    {
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3150
        if (this != getCurrentKeyboardFocusManager()) {
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3151
            checkReplaceKFMPermission();
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3152
        }
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  3153
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3154
}