jdk/src/share/classes/java/awt/DefaultKeyboardFocusManager.java
author mchung
Tue, 29 Sep 2009 16:03:03 -0700
changeset 3938 ef327bd847c0
parent 2451 597df8e1d786
child 4214 0fa32d38146b
permissions -rw-r--r--
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes Summary: Replace calls to Logger with sun.util.logging.PlatformLogger Reviewed-by: prr, art, alexp, dcherepanov, igor, dav, anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 441
diff changeset
     2
 * Copyright 2000-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package 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.KeyEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.WindowEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.peer.ComponentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.peer.LightweightPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.lang.ref.WeakReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.LinkedList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.ListIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
    38
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.awt.AppContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.awt.CausedFocusEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * The default KeyboardFocusManager for AWT applications. Focus traversal is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * done in response to a Component's focus traversal keys, and using a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * Container's FocusTraversalPolicy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Please see
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * How to Use the Focus Subsystem</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * a section in <em>The Java Tutorial</em>, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @author David Mendenhall
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @see FocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @see Component#setFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @see Component#getFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
public class DefaultKeyboardFocusManager extends KeyboardFocusManager {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
    64
    private static final PlatformLogger focusLog = PlatformLogger.getLogger("java.awt.focus.DefaultKeyboardFocusManager");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    // null weak references to not create too many objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private static final WeakReference<Window> NULL_WINDOW_WR =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        new WeakReference<Window>(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private static final WeakReference<Component> NULL_COMPONENT_WR =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        new WeakReference<Component>(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private WeakReference<Window> realOppositeWindowWR = NULL_WINDOW_WR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private WeakReference<Component> realOppositeComponentWR = NULL_COMPONENT_WR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private int inSendMessage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private LinkedList enqueuedKeyEvents = new LinkedList(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        typeAheadMarkers = new LinkedList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private boolean consumeNextKeyTyped;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private static class TypeAheadMarker {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        long after;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        Component untilFocused;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        TypeAheadMarker(long after, Component untilFocused) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            this.after = after;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            this.untilFocused = untilFocused;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
         * Returns string representation of the marker
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            return ">>> Marker after " + after + " on " + untilFocused;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private Window getOwningFrameDialog(Window window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        while (window != null && !(window instanceof Frame ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                                   window instanceof Dialog)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            window = (Window)window.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        return window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * This series of restoreFocus methods is used for recovering from a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * rejected focus or activation change. Rejections typically occur when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * the user attempts to focus a non-focusable Component or Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private void restoreFocus(FocusEvent fe, Window newFocusedWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        Component realOppositeComponent = this.realOppositeComponentWR.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        Component vetoedComponent = fe.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        if (newFocusedWindow != null && restoreFocus(newFocusedWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                                                     vetoedComponent, false))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        } else if (realOppositeComponent != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                   doRestoreFocus(realOppositeComponent, vetoedComponent, false)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        } else if (fe.getOppositeComponent() != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                   doRestoreFocus(fe.getOppositeComponent(), vetoedComponent, false)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            clearGlobalFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    private void restoreFocus(WindowEvent we) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        Window realOppositeWindow = this.realOppositeWindowWR.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        if (realOppositeWindow != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            && restoreFocus(realOppositeWindow, null, false))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            // do nothing, everything is done in restoreFocus()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        } else if (we.getOppositeWindow() != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                   restoreFocus(we.getOppositeWindow(), null, false))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            // do nothing, everything is done in restoreFocus()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            clearGlobalFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    private boolean restoreFocus(Window aWindow, Component vetoedComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                                 boolean clearOnFailure) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        Component toFocus =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            KeyboardFocusManager.getMostRecentFocusOwner(aWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        if (toFocus != null && toFocus != vetoedComponent && doRestoreFocus(toFocus, vetoedComponent, false)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        } else if (clearOnFailure) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            clearGlobalFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    private boolean restoreFocus(Component toFocus, boolean clearOnFailure) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        return doRestoreFocus(toFocus, null, clearOnFailure);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    private boolean doRestoreFocus(Component toFocus, Component vetoedComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                                   boolean clearOnFailure)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    {
1171
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 441
diff changeset
   156
        if (toFocus != vetoedComponent && toFocus.isShowing() && toFocus.canBeFocusOwner() &&
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 419
diff changeset
   157
            toFocus.requestFocus(false, CausedFocusEvent.Cause.ROLLBACK))
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 419
diff changeset
   158
        {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        } else {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 419
diff changeset
   161
            Component nextFocus = toFocus.getNextFocusCandidate();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 419
diff changeset
   162
            if (nextFocus != null && nextFocus != vetoedComponent &&
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 419
diff changeset
   163
                nextFocus.requestFocusInWindow(CausedFocusEvent.Cause.ROLLBACK))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            } else if (clearOnFailure) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                clearGlobalFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * A special type of SentEvent which updates a counter in the target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * KeyboardFocusManager if it is an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * DefaultKeyboardFocusManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    private static class DefaultKeyboardFocusManagerSentEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        extends SentEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
         * serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        private static final long serialVersionUID = -2924743257508701758L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        public DefaultKeyboardFocusManagerSentEvent(AWTEvent nested,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                                                    AppContext toNotify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            super(nested, toNotify);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        public final void dispatch() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            KeyboardFocusManager manager =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                KeyboardFocusManager.getCurrentKeyboardFocusManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            DefaultKeyboardFocusManager defaultManager =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                (manager instanceof DefaultKeyboardFocusManager)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                ? (DefaultKeyboardFocusManager)manager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            if (defaultManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                synchronized (defaultManager) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                    defaultManager.inSendMessage++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            super.dispatch();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            if (defaultManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                synchronized (defaultManager) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    defaultManager.inSendMessage--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Sends a synthetic AWTEvent to a Component. If the Component is in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * the current AppContext, then the event is immediately dispatched.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * If the Component is in a different AppContext, then the event is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * posted to the other AppContext's EventQueue, and this method blocks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * until the event is handled or target AppContext is disposed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * Returns true if successfuly dispatched event, false if failed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * to dispatch.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    static boolean sendMessage(Component target, AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        e.isPosted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        AppContext myAppContext = AppContext.getAppContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        final AppContext targetAppContext = target.appContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        final SentEvent se =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            new DefaultKeyboardFocusManagerSentEvent(e, myAppContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        if (myAppContext == targetAppContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            se.dispatch();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            if (targetAppContext.isDisposed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            SunToolkit.postEvent(targetAppContext, se);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            if (EventQueue.isDispatchThread()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                EventDispatchThread edt = (EventDispatchThread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    Thread.currentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                edt.pumpEvents(SentEvent.ID, new Conditional() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                        public boolean evaluate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                            return !se.dispatched && !targetAppContext.isDisposed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                    });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                synchronized (se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                    while (!se.dispatched && !targetAppContext.isDisposed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                            se.wait(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                        } catch (InterruptedException ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        return se.dispatched;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * This method is called by the AWT event dispatcher requesting that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * current KeyboardFocusManager dispatch the specified event on its behalf.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * DefaultKeyboardFocusManagers dispatch all FocusEvents, all WindowEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * related to focus, and all KeyEvents. These events are dispatched based
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * on the KeyboardFocusManager's notion of the focus owner and the focused
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * and active Windows, sometimes overriding the source of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * AWTEvent. If this method returns <code>false</code>, then the AWT event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * dispatcher will attempt to dispatch the event itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @param e the AWTEvent to be dispatched
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @return <code>true</code> if this method dispatched the event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *         <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    public boolean dispatchEvent(AWTEvent e) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
   277
        if (focusLog.isLoggable(PlatformLogger.FINE) && (e instanceof WindowEvent || e instanceof FocusEvent)) focusLog.fine("" + e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        switch (e.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            case WindowEvent.WINDOW_GAINED_FOCUS: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                WindowEvent we = (WindowEvent)e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                Window oldFocusedWindow = getGlobalFocusedWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                Window newFocusedWindow = we.getWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                if (newFocusedWindow == oldFocusedWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                if (!(newFocusedWindow.isFocusableWindow()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                      && newFocusedWindow.isVisible()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                      && newFocusedWindow.isDisplayable()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                    // we can not accept focus on such window, so reject it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                    restoreFocus(we);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                // If there exists a current focused window, then notify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                // that it has lost focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                if (oldFocusedWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                    boolean isEventDispatched =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                        sendMessage(oldFocusedWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                                new WindowEvent(oldFocusedWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                                                WindowEvent.WINDOW_LOST_FOCUS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                                                newFocusedWindow));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                    // Failed to dispatch, clear by ourselfves
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                    if (!isEventDispatched) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                        setGlobalFocusOwner(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                        setGlobalFocusedWindow(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                // Because the native libraries do not post WINDOW_ACTIVATED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                // events, we need to synthesize one if the active Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                // changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                Window newActiveWindow =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                    getOwningFrameDialog(newFocusedWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                Window currentActiveWindow = getGlobalActiveWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                if (newActiveWindow != currentActiveWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                    sendMessage(newActiveWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                                new WindowEvent(newActiveWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                                                WindowEvent.WINDOW_ACTIVATED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                                                currentActiveWindow));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                    if (newActiveWindow != getGlobalActiveWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                        // Activation change was rejected. Unlikely, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                        // possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                        restoreFocus(we);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                setGlobalFocusedWindow(newFocusedWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                if (newFocusedWindow != getGlobalFocusedWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                    // Focus change was rejected. Will happen if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                    // newFocusedWindow is not a focusable Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                    restoreFocus(we);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                // Restore focus to the Component which last held it. We do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                // this here so that client code can override our choice in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                // a WINDOW_GAINED_FOCUS handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                // Make sure that the focus change request doesn't change the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                // focused Window in case we are no longer the focused Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                // when the request is handled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                if (inSendMessage == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                    // Identify which Component should initially gain focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                    // in the Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                    // * If we're in SendMessage, then this is a synthetic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                    //   WINDOW_GAINED_FOCUS message which was generated by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                    //   the FOCUS_GAINED handler. Allow the Component to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                    //   which the FOCUS_GAINED message was targeted to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                    //   receive the focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                    // * Otherwise, look up the correct Component here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                    //   We don't use Window.getMostRecentFocusOwner because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                    //   window is focused now and 'null' will be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                    // Calculating of most recent focus owner and focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                    // request should be synchronized on KeyboardFocusManager.class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                    // to prevent from thread race when user will request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                    // focus between calculation and our request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                    // But if focus transfer is synchronous, this synchronization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                    // may cause deadlock, thus we don't synchronize this block.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                    Component toFocus = KeyboardFocusManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                        getMostRecentFocusOwner(newFocusedWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                    if ((toFocus == null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                        newFocusedWindow.isFocusableWindow())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                        toFocus = newFocusedWindow.getFocusTraversalPolicy().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                            getInitialComponent(newFocusedWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                    Component tempLost = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                    synchronized(KeyboardFocusManager.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                        tempLost = newFocusedWindow.setTemporaryLostComponent(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                    // The component which last has the focus when this window was focused
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                    // should receive focus first
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
   380
                    if (focusLog.isLoggable(PlatformLogger.FINER)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
   381
                        focusLog.finer("tempLost {0}, toFocus {1}",
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
   382
                                       tempLost, toFocus);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                    if (tempLost != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                        tempLost.requestFocusInWindow(CausedFocusEvent.Cause.ACTIVATION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                    if (toFocus != null && toFocus != tempLost) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                        // If there is a component which requested focus when this window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                        // was inactive it expects to receive focus after activation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                        toFocus.requestFocusInWindow(CausedFocusEvent.Cause.ACTIVATION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                Window realOppositeWindow = this.realOppositeWindowWR.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                if (realOppositeWindow != we.getOppositeWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                    we = new WindowEvent(newFocusedWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                                         WindowEvent.WINDOW_GAINED_FOCUS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                                         realOppositeWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                return typeAheadAssertions(newFocusedWindow, we);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            case WindowEvent.WINDOW_ACTIVATED: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                WindowEvent we = (WindowEvent)e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                Window oldActiveWindow = getGlobalActiveWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                Window newActiveWindow = we.getWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                if (oldActiveWindow == newActiveWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                // If there exists a current active window, then notify it that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                // it has lost activation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                if (oldActiveWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                    boolean isEventDispatched =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                        sendMessage(oldActiveWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                                new WindowEvent(oldActiveWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                                                WindowEvent.WINDOW_DEACTIVATED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                                                newActiveWindow));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                    // Failed to dispatch, clear by ourselfves
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                    if (!isEventDispatched) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                        setGlobalActiveWindow(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                    if (getGlobalActiveWindow() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                        // Activation change was rejected. Unlikely, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                        // possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                setGlobalActiveWindow(newActiveWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                if (newActiveWindow != getGlobalActiveWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                    // Activation change was rejected. Unlikely, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                    // possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                return typeAheadAssertions(newActiveWindow, we);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            case FocusEvent.FOCUS_GAINED: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                FocusEvent fe = (FocusEvent)e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                CausedFocusEvent.Cause cause = (fe instanceof CausedFocusEvent) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                    ((CausedFocusEvent)fe).getCause() : CausedFocusEvent.Cause.UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                Component oldFocusOwner = getGlobalFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                Component newFocusOwner = fe.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                if (oldFocusOwner == newFocusOwner) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
   449
                    if (focusLog.isLoggable(PlatformLogger.FINE)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
   450
                        focusLog.fine("Skipping {0} because focus owner is the same", e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                    // We can't just drop the event - there could be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                    // type-ahead markers associated with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                    dequeueKeyEvents(-1, newFocusOwner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                // If there exists a current focus owner, then notify it that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                // it has lost focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                if (oldFocusOwner != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    boolean isEventDispatched =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                        sendMessage(oldFocusOwner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                                    new CausedFocusEvent(oldFocusOwner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                                                   FocusEvent.FOCUS_LOST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                                                   fe.isTemporary(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                                                   newFocusOwner, cause));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                    // Failed to dispatch, clear by ourselfves
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                    if (!isEventDispatched) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                        setGlobalFocusOwner(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                        if (!fe.isTemporary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                            setGlobalPermanentFocusOwner(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                // Because the native windowing system has a different notion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                // of the current focus and activation states, it is possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                // that a Component outside of the focused Window receives a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                // FOCUS_GAINED event. We synthesize a WINDOW_GAINED_FOCUS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                // event in that case.
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1188
diff changeset
   481
                final Window newFocusedWindow = SunToolkit.getContainingWindow(newFocusOwner);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                final Window currentFocusedWindow = getGlobalFocusedWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                if (newFocusedWindow != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                    newFocusedWindow != currentFocusedWindow)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                    sendMessage(newFocusedWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                                new WindowEvent(newFocusedWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                                        WindowEvent.WINDOW_GAINED_FOCUS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                                                currentFocusedWindow));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                    if (newFocusedWindow != getGlobalFocusedWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                        // Focus change was rejected. Will happen if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                        // newFocusedWindow is not a focusable Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                        // Need to recover type-ahead, but don't bother
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                        // restoring focus. That was done by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                        // WINDOW_GAINED_FOCUS handler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                        dequeueKeyEvents(-1, newFocusOwner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
1171
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 441
diff changeset
   502
                if (!(newFocusOwner.isFocusable() && newFocusOwner.isShowing() &&
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 441
diff changeset
   503
                    // Refuse focus on a disabled component if the focus event
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 441
diff changeset
   504
                    // isn't of UNKNOWN reason (i.e. not a result of a direct request
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 441
diff changeset
   505
                    // but traversal, activation or system generated).
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 441
diff changeset
   506
                    (newFocusOwner.isEnabled() || cause.equals(CausedFocusEvent.Cause.UNKNOWN))))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                    // we should not accept focus on such component, so reject it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                    dequeueKeyEvents(-1, newFocusOwner);
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 419
diff changeset
   510
                    if (KeyboardFocusManager.isAutoFocusTransferEnabled()) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 419
diff changeset
   511
                        // If FOCUS_GAINED is for a disposed component (however
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 419
diff changeset
   512
                        // it shouldn't happen) its toplevel parent is null. In this
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 419
diff changeset
   513
                        // case we have to try to restore focus in the current focused
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 419
diff changeset
   514
                        // window (for the details: 6607170).
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 419
diff changeset
   515
                        if (newFocusedWindow == null) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 419
diff changeset
   516
                            restoreFocus(fe, currentFocusedWindow);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 419
diff changeset
   517
                        } else {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 419
diff changeset
   518
                            restoreFocus(fe, newFocusedWindow);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 419
diff changeset
   519
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                setGlobalFocusOwner(newFocusOwner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                if (newFocusOwner != getGlobalFocusOwner()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                    // Focus change was rejected. Will happen if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                    // newFocusOwner is not focus traversable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                    dequeueKeyEvents(-1, newFocusOwner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                    if (KeyboardFocusManager.isAutoFocusTransferEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                        restoreFocus(fe, (Window)newFocusedWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                if (!fe.isTemporary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                    setGlobalPermanentFocusOwner(newFocusOwner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                    if (newFocusOwner != getGlobalPermanentFocusOwner()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                        // Focus change was rejected. Unlikely, but possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                        dequeueKeyEvents(-1, newFocusOwner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                        if (KeyboardFocusManager.isAutoFocusTransferEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                            restoreFocus(fe, (Window)newFocusedWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                setNativeFocusOwner(getHeavyweight(newFocusOwner));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                Component realOppositeComponent = this.realOppositeComponentWR.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                if (realOppositeComponent != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                    realOppositeComponent != fe.getOppositeComponent()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                    fe = new CausedFocusEvent(newFocusOwner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                                        FocusEvent.FOCUS_GAINED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                                        fe.isTemporary(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                                        realOppositeComponent, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                    ((AWTEvent) fe).isPosted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                return typeAheadAssertions(newFocusOwner, fe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            case FocusEvent.FOCUS_LOST: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                FocusEvent fe = (FocusEvent)e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                Component currentFocusOwner = getGlobalFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                if (currentFocusOwner == null) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
   567
                    if (focusLog.isLoggable(PlatformLogger.FINE))
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
   568
                        focusLog.fine("Skipping {0} because focus owner is null", e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                // Ignore cases where a Component loses focus to itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                // If we make a mistake because of retargeting, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                // FOCUS_GAINED handler will correct it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                if (currentFocusOwner == fe.getOppositeComponent()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
   575
                    if (focusLog.isLoggable(PlatformLogger.FINE))
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
   576
                        focusLog.fine("Skipping {0} because current focus owner is equal to opposite", e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                setGlobalFocusOwner(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                if (getGlobalFocusOwner() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                    // Focus change was rejected. Unlikely, but possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                    restoreFocus(currentFocusOwner, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                if (!fe.isTemporary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                    setGlobalPermanentFocusOwner(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                    if (getGlobalPermanentFocusOwner() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                        // Focus change was rejected. Unlikely, but possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                        restoreFocus(currentFocusOwner, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                    Window owningWindow = currentFocusOwner.getContainingWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                    if (owningWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                        owningWindow.setTemporaryLostComponent(currentFocusOwner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                setNativeFocusOwner(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                fe.setSource(currentFocusOwner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                realOppositeComponentWR = (fe.getOppositeComponent() != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                    ? new WeakReference<Component>(currentFocusOwner)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                    : NULL_COMPONENT_WR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                return typeAheadAssertions(currentFocusOwner, fe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            case WindowEvent.WINDOW_DEACTIVATED: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                WindowEvent we = (WindowEvent)e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                Window currentActiveWindow = getGlobalActiveWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                if (currentActiveWindow == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                if (currentActiveWindow != e.getSource()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                    // The event is lost in time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                    // Allow listeners to precess the event but do not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                    // change any global states
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                setGlobalActiveWindow(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                if (getGlobalActiveWindow() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                    // Activation change was rejected. Unlikely, but possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                we.setSource(currentActiveWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                return typeAheadAssertions(currentActiveWindow, we);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            case WindowEvent.WINDOW_LOST_FOCUS: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                WindowEvent we = (WindowEvent)e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                Window currentFocusedWindow = getGlobalFocusedWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                Window losingFocusWindow = we.getWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                Window activeWindow = getGlobalActiveWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                Window oppositeWindow = we.getOppositeWindow();
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
   644
                if (focusLog.isLoggable(PlatformLogger.FINE))
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
   645
                    focusLog.fine("Active {0}, Current focused {1}, losing focus {2} opposite {3}",
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
   646
                                  activeWindow, currentFocusedWindow,
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
   647
                                  losingFocusWindow, oppositeWindow);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                if (currentFocusedWindow == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                // Special case -- if the native windowing system posts an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                // event claiming that the active Window has lost focus to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                // focused Window, then discard the event. This is an artifact
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                // of the native windowing system not knowing which Window is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                // really focused.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                if (inSendMessage == 0 && losingFocusWindow == activeWindow &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                    oppositeWindow == currentFocusedWindow)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                Component currentFocusOwner = getGlobalFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                if (currentFocusOwner != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                    // The focus owner should always receive a FOCUS_LOST event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                    // before the Window is defocused.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                    Component oppositeComp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                    if (oppositeWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                        oppositeComp = oppositeWindow.getTemporaryLostComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                        if (oppositeComp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                            oppositeComp = oppositeWindow.getMostRecentFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                    if (oppositeComp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                        oppositeComp = oppositeWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                    sendMessage(currentFocusOwner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                                new CausedFocusEvent(currentFocusOwner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                                               FocusEvent.FOCUS_LOST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                                               true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                                               oppositeComp, CausedFocusEvent.Cause.ACTIVATION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                setGlobalFocusedWindow(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                if (getGlobalFocusedWindow() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                    // Focus change was rejected. Unlikely, but possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                    restoreFocus(currentFocusedWindow, null, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                we.setSource(currentFocusedWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                realOppositeWindowWR = (oppositeWindow != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                    ? new WeakReference<Window>(currentFocusedWindow)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                    : NULL_WINDOW_WR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                typeAheadAssertions(currentFocusedWindow, we);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                if (oppositeWindow == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                    // Then we need to deactive the active Window as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                    // No need to synthesize in other cases, because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                    // WINDOW_ACTIVATED will handle it if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                    sendMessage(activeWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                                new WindowEvent(activeWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                                                WindowEvent.WINDOW_DEACTIVATED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                                                null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                    if (getGlobalActiveWindow() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                        // Activation change was rejected. Unlikely,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                        // but possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                        restoreFocus(currentFocusedWindow, null, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            case KeyEvent.KEY_TYPED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            case KeyEvent.KEY_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            case KeyEvent.KEY_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                return typeAheadAssertions(null, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * Called by <code>dispatchEvent</code> if no other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * KeyEventDispatcher in the dispatcher chain dispatched the KeyEvent, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * if no other KeyEventDispatchers are registered. If the event has not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * been consumed, its target is enabled, and the focus owner is not null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * this method dispatches the event to its target. This method will also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * subsequently dispatch the event to all registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * KeyEventPostProcessors. After all this operations are finished,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * the event is passed to peers for processing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * In all cases, this method returns <code>true</code>, since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * DefaultKeyboardFocusManager is designed so that neither
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * <code>dispatchEvent</code>, nor the AWT event dispatcher, should take
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * further action on the event in any situation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * @param e the KeyEvent to be dispatched
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * @return <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * @see Component#dispatchEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    public boolean dispatchKeyEvent(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        Component focusOwner = (((AWTEvent)e).isPosted) ? getFocusOwner() : e.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
1171
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 441
diff changeset
   748
        if (focusOwner != null && focusOwner.isShowing() && focusOwner.canBeFocusOwner()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            if (!e.isConsumed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                Component comp = e.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                if (comp != null && comp.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                    redispatchEvent(comp, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        boolean stopPostProcessing = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        java.util.List processors = getKeyEventPostProcessors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        if (processors != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            for (java.util.Iterator iter = processors.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                 !stopPostProcessing && iter.hasNext(); )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                stopPostProcessing = (((KeyEventPostProcessor)(iter.next())).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                            postProcessKeyEvent(e));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        if (!stopPostProcessing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            postProcessKeyEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        // Allow the peer to process KeyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        Component source = e.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        ComponentPeer peer = source.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        if (peer == null || peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            // if focus owner is lightweight then its native container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            // processes event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            Container target = source.getNativeContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                peer = target.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            peer.handleEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * This method will be called by <code>dispatchKeyEvent</code>. It will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * handle any unconsumed KeyEvents that map to an AWT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * <code>MenuShortcut</code> by consuming the event and activating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * shortcut.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * @param e the KeyEvent to post-process
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * @return <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * @see #dispatchKeyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * @see MenuShortcut
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    public boolean postProcessKeyEvent(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        if (!e.isConsumed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            Component target = e.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            Container p = (Container)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                (target instanceof Container ? target : target.getParent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            if (p != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                p.postProcessKeyEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    private void pumpApprovedKeyEvents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        KeyEvent ke;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            ke = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                if (enqueuedKeyEvents.size() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                    ke = (KeyEvent)enqueuedKeyEvents.getFirst();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                    if (typeAheadMarkers.size() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                        TypeAheadMarker marker = (TypeAheadMarker)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                            typeAheadMarkers.getFirst();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                        // Fixed 5064013: may appears that the events have the same time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                        // if (ke.getWhen() >= marker.after) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                        // The fix is rolled out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                        if (ke.getWhen() > marker.after) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                            ke = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                    if (ke != null) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
   831
                        focusLog.finer("Pumping approved event {0}", ke);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                        enqueuedKeyEvents.removeFirst();
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 (ke != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                preDispatchKeyEvent(ke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        } while (ke != null);
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
     * Dumps the list of type-ahead queue markers to stderr
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
    void dumpMarkers() {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
   846
        if (focusLog.isLoggable(PlatformLogger.FINEST)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
   847
            focusLog.finest(">>> Markers dump, time: {0}", System.currentTimeMillis());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                if (typeAheadMarkers.size() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                    Iterator iter = typeAheadMarkers.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                    while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                        TypeAheadMarker marker = (TypeAheadMarker)iter.next();
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
   853
                        focusLog.finest("    {0}", marker);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    private boolean typeAheadAssertions(Component target, AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        // Clear any pending events here as well as in the FOCUS_GAINED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        // handler. We need this call here in case a marker was removed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        // response to a call to dequeueKeyEvents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        pumpApprovedKeyEvents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        switch (e.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            case KeyEvent.KEY_TYPED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            case KeyEvent.KEY_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            case KeyEvent.KEY_RELEASED: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                KeyEvent ke = (KeyEvent)e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                    if (e.isPosted && typeAheadMarkers.size() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                        TypeAheadMarker marker = (TypeAheadMarker)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                            typeAheadMarkers.getFirst();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                        // Fixed 5064013: may appears that the events have the same time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                        // if (ke.getWhen() >= marker.after) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                        // The fix is rolled out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                        if (ke.getWhen() > marker.after) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
   881
                            focusLog.finer("Storing event {0} because of marker {1}", ke, marker);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                            enqueuedKeyEvents.addLast(ke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                // KeyEvent was posted before focus change request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                return preDispatchKeyEvent(ke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            case FocusEvent.FOCUS_GAINED:
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
   893
                focusLog.finest("Markers before FOCUS_GAINED on {0}", target);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                dumpMarkers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                // Search the marker list for the first marker tied to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                // the Component which just gained focus. Then remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                // that marker, any markers which immediately follow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                // and are tied to the same component, and all markers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                // that preceed it. This handles the case where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                // multiple focus requests were made for the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                // Component in a row and when we lost some of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                // earlier requests. Since FOCUS_GAINED events will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                // not be generated for these additional requests, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                // need to clear those markers too.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                    boolean found = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                    if (hasMarker(target)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                        for (Iterator iter = typeAheadMarkers.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                             iter.hasNext(); )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
                            if (((TypeAheadMarker)iter.next()).untilFocused ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
                                target)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                                found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                            } else if (found) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                            iter.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                        // Exception condition - event without marker
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
   922
                        focusLog.finer("Event without marker {0}", e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                }
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
   925
                focusLog.finest("Markers after FOCUS_GAINED");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                dumpMarkers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                redispatchEvent(target, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                // Now, dispatch any pending KeyEvents which have been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                // released because of the FOCUS_GAINED event so that we don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                // have to wait for another event to be posted to the queue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                pumpApprovedKeyEvents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                redispatchEvent(target, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        }
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 true if there are some marker associated with component <code>comp</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     * in a markers' queue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
    private boolean hasMarker(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        for (Iterator iter = typeAheadMarkers.iterator(); iter.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            if (((TypeAheadMarker)iter.next()).untilFocused == comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        return false;
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
     * Clears markers queue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
    void clearMarkers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            typeAheadMarkers.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
    private boolean preDispatchKeyEvent(KeyEvent ke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        if (((AWTEvent) ke).isPosted) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
            Component focusOwner = getFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
            ke.setSource(((focusOwner != null) ? focusOwner : getFocusedWindow()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        if (ke.getSource() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        // Explicitly set the current event and most recent timestamp here in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        // addition to the call in Component.dispatchEventImpl. Because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        // KeyEvents can be delivered in response to a FOCUS_GAINED event, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        // current timestamp may be incorrect. We need to set it here so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        // KeyEventDispatchers will use the correct time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        EventQueue.setCurrentEventAndMostRecentTime(ke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
         * Fix for 4495473.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
         * This fix allows to correctly dispatch events when native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
         * event proxying mechanism is active.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
         * If it is active we should redispatch key events after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
         * we detected its correct target.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        if (KeyboardFocusManager.isProxyActive(ke)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            Component source = (Component)ke.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            Container target = source.getNativeContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
                ComponentPeer peer = target.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                    peer.handleEvent(ke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
                    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
                     * Fix for 4478780 - consume event after it was dispatched by peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                    ke.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        java.util.List dispatchers = getKeyEventDispatchers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
        if (dispatchers != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
            for (java.util.Iterator iter = dispatchers.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                 iter.hasNext(); )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
             {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                 if (((KeyEventDispatcher)(iter.next())).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                     dispatchKeyEvent(ke))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                     return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        return dispatchKeyEvent(ke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * @param e is a KEY_PRESSED event that can be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     *          to track the next KEY_TYPED related.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
    private void consumeNextKeyTyped(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        consumeNextKeyTyped = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
    private void consumeTraversalKey(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        consumeNextKeyTyped = (e.getID() == KeyEvent.KEY_PRESSED) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                              !e.isActionKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     * return true if event was consumed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    private boolean consumeProcessedKeyEvent(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        if ((e.getID() == KeyEvent.KEY_TYPED) && consumeNextKeyTyped) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
            e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
            consumeNextKeyTyped = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     * This method initiates a focus traversal operation if and only if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     * KeyEvent represents a focus traversal key for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     * focusedComponent. It is expected that focusedComponent is the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     * focus owner, although this need not be the case. If it is not,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     * focus traversal will nevertheless proceed as if focusedComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     * were the focus owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     * @param focusedComponent the Component that is the basis for a focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
     *        traversal operation if the specified event represents a focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
     *        traversal key for the Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     * @param e the event that may represent a focus traversal key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
    public void processKeyEvent(Component focusedComponent, KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        // consume processed event if needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        if (consumeProcessedKeyEvent(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        // KEY_TYPED events cannot be focus traversal keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        if (e.getID() == KeyEvent.KEY_TYPED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        if (focusedComponent.getFocusTraversalKeysEnabled() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
            !e.isConsumed())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
            AWTKeyStroke stroke = AWTKeyStroke.getAWTKeyStrokeForEvent(e),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                oppStroke = AWTKeyStroke.getAWTKeyStroke(stroke.getKeyCode(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                                                 stroke.getModifiers(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                                                 !stroke.isOnKeyRelease());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
            Set toTest;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
            boolean contains, containsOpp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            toTest = focusedComponent.getFocusTraversalKeys(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            contains = toTest.contains(stroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            containsOpp = toTest.contains(oppStroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
            if (contains || containsOpp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                consumeTraversalKey(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                if (contains) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                    focusNextComponent(focusedComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                return;
419
2d7b6a4f8002 6637607: 1st char. is discarded after a modal dialogue shows up and disappears
ant
parents: 134
diff changeset
  1091
            } else if (e.getID() == KeyEvent.KEY_PRESSED) {
2d7b6a4f8002 6637607: 1st char. is discarded after a modal dialogue shows up and disappears
ant
parents: 134
diff changeset
  1092
                // Fix for 6637607: consumeNextKeyTyped should be reset.
2d7b6a4f8002 6637607: 1st char. is discarded after a modal dialogue shows up and disappears
ant
parents: 134
diff changeset
  1093
                consumeNextKeyTyped = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            toTest = focusedComponent.getFocusTraversalKeys(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
            contains = toTest.contains(stroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
            containsOpp = toTest.contains(oppStroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            if (contains || containsOpp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                consumeTraversalKey(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                if (contains) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                    focusPreviousComponent(focusedComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
            toTest = focusedComponent.getFocusTraversalKeys(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
            contains = toTest.contains(stroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
            containsOpp = toTest.contains(oppStroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
            if (contains || containsOpp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                consumeTraversalKey(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                if (contains) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                    upFocusCycle(focusedComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
            if (!((focusedComponent instanceof Container) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
                  ((Container)focusedComponent).isFocusCycleRoot())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            toTest = focusedComponent.getFocusTraversalKeys(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
            contains = toTest.contains(stroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
            containsOpp = toTest.contains(oppStroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
            if (contains || containsOpp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
                consumeTraversalKey(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                if (contains) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
                    downFocusCycle((Container)focusedComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     * Delays dispatching of KeyEvents until the specified Component becomes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     * the focus owner. KeyEvents with timestamps later than the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     * timestamp will be enqueued until the specified Component receives a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     * FOCUS_GAINED event, or the AWT cancels the delay request by invoking
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     * <code>dequeueKeyEvents</code> or <code>discardKeyEvents</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     * @param after timestamp of current event, or the current, system time if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     *        the current event has no timestamp, or the AWT cannot determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     *        which event is currently being handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     * @param untilFocused Component which will receive a FOCUS_GAINED event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     *        before any pending KeyEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
     * @see #dequeueKeyEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     * @see #discardKeyEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
    protected synchronized void enqueueKeyEvents(long after,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
                                                 Component untilFocused) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        if (untilFocused == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
  1162
        focusLog.finer("Enqueue at {0} for {1}",
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
  1163
                       after, untilFocused);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        int insertionIndex = 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
            i = typeAheadMarkers.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
        ListIterator iter = typeAheadMarkers.listIterator(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        for (; i > 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
            TypeAheadMarker marker = (TypeAheadMarker)iter.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
            if (marker.after <= after) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                insertionIndex = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
        typeAheadMarkers.add(insertionIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
                             new TypeAheadMarker(after, untilFocused));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
     * Releases for normal dispatching to the current focus owner all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
     * KeyEvents which were enqueued because of a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     * <code>enqueueKeyEvents</code> with the same timestamp and Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
     * If the given timestamp is less than zero, the outstanding enqueue
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     * request for the given Component with the <b>oldest</b> timestamp (if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     * any) should be cancelled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
     * @param after the timestamp specified in the call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
     *        <code>enqueueKeyEvents</code>, or any value < 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     * @param untilFocused the Component specified in the call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     *        <code>enqueueKeyEvents</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     * @see #enqueueKeyEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     * @see #discardKeyEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
    protected synchronized void dequeueKeyEvents(long after,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
                                                 Component untilFocused) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        if (untilFocused == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
  1202
        focusLog.finer("Dequeue at {0} for {1}",
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2451
diff changeset
  1203
                       after, untilFocused);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
        TypeAheadMarker marker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        ListIterator iter = typeAheadMarkers.listIterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
            ((after >= 0) ? typeAheadMarkers.size() : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        if (after < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
            while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                marker = (TypeAheadMarker)iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
                if (marker.untilFocused == untilFocused)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                    iter.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
            while (iter.hasPrevious()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
                marker = (TypeAheadMarker)iter.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
                if (marker.untilFocused == untilFocused &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
                    marker.after == after)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
                    iter.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     * Discards all KeyEvents which were enqueued because of one or more calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * to <code>enqueueKeyEvents</code> with the specified Component, or one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     * its descendants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
     * @param comp the Component specified in one or more calls to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
     *        <code>enqueueKeyEvents</code>, or a parent of such a Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     * @see #enqueueKeyEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     * @see #dequeueKeyEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
    protected synchronized void discardKeyEvents(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        if (comp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
        long start = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        for (Iterator iter = typeAheadMarkers.iterator(); iter.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
            TypeAheadMarker marker = (TypeAheadMarker)iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
            Component toTest = marker.untilFocused;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
            boolean match = (toTest == comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
            while (!match && toTest != null && !(toTest instanceof Window)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                toTest = toTest.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
                match = (toTest == comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
            if (match) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
                if (start < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                    start = marker.after;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
                iter.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
            } else if (start >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                purgeStampedEvents(start, marker.after);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                start = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
        purgeStampedEvents(start, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    // Notes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
    //   * must be called inside a synchronized block
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
    //   * if 'start' is < 0, then this function does nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
    //   * if 'end' is < 0, then all KeyEvents from 'start' to the end of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    //     queue will be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
    private void purgeStampedEvents(long start, long end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
        if (start < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
        for (Iterator iter = enqueuedKeyEvents.iterator(); iter.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
            KeyEvent ke = (KeyEvent)iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
            long time = ke.getWhen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
            if (start < time && (end < 0 || time <= end)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                iter.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
            if (end >= 0 && time > end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
     * Focuses the Component before aComponent, typically based on a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
     * FocusTraversalPolicy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
     * @param aComponent the Component that is the basis for the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
     *        traversal operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     * @see FocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     * @see Component#transferFocusBackward
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
    public void focusPreviousComponent(Component aComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
        if (aComponent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
            aComponent.transferFocusBackward();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
     * Focuses the Component after aComponent, typically based on a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
     * FocusTraversalPolicy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
     * @param aComponent the Component that is the basis for the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
     *        traversal operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
     * @see FocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
     * @see Component#transferFocus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
    public void focusNextComponent(Component aComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        if (aComponent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
            aComponent.transferFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
     * Moves the focus up one focus traversal cycle. Typically, the focus owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
     * is set to aComponent's focus cycle root, and the current focus cycle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
     * root is set to the new focus owner's focus cycle root. If, however,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
     * aComponent's focus cycle root is a Window, then the focus owner is set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
     * to the focus cycle root's default Component to focus, and the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
     * focus cycle root is unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
     * @param aComponent the Component that is the basis for the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
     *        traversal operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
     * @see Component#transferFocusUpCycle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
    public void upFocusCycle(Component aComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
        if (aComponent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
            aComponent.transferFocusUpCycle();
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
     * Moves the focus down one focus traversal cycle. If aContainer is a focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
     * cycle root, then the focus owner is set to aContainer's default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
     * Component to focus, and the current focus cycle root is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
     * aContainer. If aContainer is not a focus cycle root, then no focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
     * traversal operation occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
     * @param aContainer the Container that is the basis for the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
     *        traversal operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
     * @see Container#transferFocusDownCycle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
    public void downFocusCycle(Container aContainer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
        if (aContainer != null && aContainer.isFocusCycleRoot()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
            aContainer.transferFocusDownCycle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
}