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