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