0N/A/*
4743N/A * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage java.awt;
0N/A
0N/Aimport java.awt.event.FocusEvent;
0N/Aimport java.awt.event.InputEvent;
0N/Aimport java.awt.event.KeyEvent;
0N/Aimport java.awt.event.WindowEvent;
0N/A
0N/Aimport java.awt.peer.KeyboardFocusManagerPeer;
0N/Aimport java.awt.peer.LightweightPeer;
0N/A
0N/Aimport java.beans.PropertyChangeListener;
0N/Aimport java.beans.PropertyChangeSupport;
0N/Aimport java.beans.PropertyVetoException;
0N/Aimport java.beans.VetoableChangeListener;
0N/Aimport java.beans.VetoableChangeSupport;
0N/A
0N/Aimport java.lang.ref.WeakReference;
0N/A
0N/Aimport java.lang.reflect.Field;
0N/A
0N/Aimport java.security.AccessController;
0N/Aimport java.security.PrivilegedAction;
0N/A
0N/Aimport java.util.Collections;
0N/Aimport java.util.HashSet;
0N/Aimport java.util.Iterator;
0N/Aimport java.util.LinkedList;
0N/Aimport java.util.Set;
0N/Aimport java.util.StringTokenizer;
0N/Aimport java.util.WeakHashMap;
0N/A
1979N/Aimport sun.util.logging.PlatformLogger;
0N/A
0N/Aimport sun.awt.AppContext;
0N/Aimport sun.awt.SunToolkit;
0N/Aimport sun.awt.CausedFocusEvent;
0N/Aimport sun.awt.KeyboardFocusManagerPeerProvider;
1058N/Aimport sun.awt.AWTAccessor;
0N/A
0N/A/**
0N/A * The KeyboardFocusManager is responsible for managing the active and focused
0N/A * Windows, and the current focus owner. The focus owner is defined as the
0N/A * Component in an application that will typically receive all KeyEvents
0N/A * generated by the user. The focused Window is the Window that is, or
0N/A * contains, the focus owner. Only a Frame or a Dialog can be the active
0N/A * Window. The native windowing system may denote the active Window or its
0N/A * children with special decorations, such as a highlighted title bar. The
0N/A * active Window is always either the focused Window, or the first Frame or
0N/A * Dialog that is an owner of the focused Window.
0N/A * <p>
0N/A * The KeyboardFocusManager is both a centralized location for client code to
0N/A * query for the focus owner and initiate focus changes, and an event
0N/A * dispatcher for all FocusEvents, WindowEvents related to focus, and
0N/A * KeyEvents.
0N/A * <p>
0N/A * Some browsers partition applets in different code bases into separate
0N/A * contexts, and establish walls between these contexts. In such a scenario,
0N/A * there will be one KeyboardFocusManager per context. Other browsers place all
0N/A * applets into the same context, implying that there will be only a single,
0N/A * global KeyboardFocusManager for all applets. This behavior is
0N/A * implementation-dependent. Consult your browser's documentation for more
0N/A * information. No matter how many contexts there may be, however, there can
0N/A * never be more than one focus owner, focused Window, or active Window, per
0N/A * ClassLoader.
0N/A * <p>
0N/A * Please see
0N/A * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
0N/A * How to Use the Focus Subsystem</a>,
0N/A * a section in <em>The Java Tutorial</em>, and the
0N/A * <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
0N/A * for more information.
0N/A *
0N/A * @author David Mendenhall
0N/A *
0N/A * @see Window
0N/A * @see Frame
0N/A * @see Dialog
0N/A * @see java.awt.event.FocusEvent
0N/A * @see java.awt.event.WindowEvent
0N/A * @see java.awt.event.KeyEvent
0N/A * @since 1.4
0N/A */
0N/Apublic abstract class KeyboardFocusManager
0N/A implements KeyEventDispatcher, KeyEventPostProcessor
0N/A{
0N/A
0N/A // Shared focus engine logger
1979N/A private static final PlatformLogger focusLog = PlatformLogger.getLogger("java.awt.focus.KeyboardFocusManager");
0N/A
0N/A static {
0N/A /* ensure that the necessary native libraries are loaded */
0N/A Toolkit.loadLibraries();
0N/A if (!GraphicsEnvironment.isHeadless()) {
0N/A initIDs();
0N/A }
1058N/A AWTAccessor.setKeyboardFocusManagerAccessor(
1058N/A new AWTAccessor.KeyboardFocusManagerAccessor() {
1058N/A public int shouldNativelyFocusHeavyweight(Component heavyweight,
1058N/A Component descendant,
1058N/A boolean temporary,
1058N/A boolean focusedWindowChangeAllowed,
1058N/A long time,
1058N/A CausedFocusEvent.Cause cause)
1058N/A {
1058N/A return KeyboardFocusManager.shouldNativelyFocusHeavyweight(
1058N/A heavyweight, descendant, temporary, focusedWindowChangeAllowed, time, cause);
1058N/A }
1058N/A public boolean processSynchronousLightweightTransfer(Component heavyweight,
1058N/A Component descendant,
1058N/A boolean temporary,
1058N/A boolean focusedWindowChangeAllowed,
1058N/A long time)
1058N/A {
1058N/A return KeyboardFocusManager.processSynchronousLightweightTransfer(
1058N/A heavyweight, descendant, temporary, focusedWindowChangeAllowed, time);
1058N/A }
1058N/A public void removeLastFocusRequest(Component heavyweight) {
1058N/A KeyboardFocusManager.removeLastFocusRequest(heavyweight);
1058N/A }
2765N/A public void setMostRecentFocusOwner(Window window, Component component) {
2765N/A KeyboardFocusManager.setMostRecentFocusOwner(window, component);
2765N/A }
4639N/A public KeyboardFocusManager getCurrentKeyboardFocusManager(AppContext ctx) {
4639N/A return KeyboardFocusManager.getCurrentKeyboardFocusManager(ctx);
4639N/A }
5255N/A public Container getCurrentFocusCycleRoot() {
5255N/A return KeyboardFocusManager.currentFocusCycleRoot;
5255N/A }
1058N/A }
1058N/A );
0N/A }
0N/A
0N/A transient KeyboardFocusManagerPeer peer;
0N/A
0N/A /**
0N/A * Initialize JNI field and method IDs
0N/A */
0N/A private static native void initIDs();
0N/A
1979N/A private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.KeyboardFocusManager");
0N/A
0N/A /**
0N/A * The identifier for the Forward focus traversal keys.
0N/A *
0N/A * @see #setDefaultFocusTraversalKeys
0N/A * @see #getDefaultFocusTraversalKeys
0N/A * @see Component#setFocusTraversalKeys
0N/A * @see Component#getFocusTraversalKeys
0N/A */
0N/A public static final int FORWARD_TRAVERSAL_KEYS = 0;
0N/A
0N/A /**
0N/A * The identifier for the Backward focus traversal keys.
0N/A *
0N/A * @see #setDefaultFocusTraversalKeys
0N/A * @see #getDefaultFocusTraversalKeys
0N/A * @see Component#setFocusTraversalKeys
0N/A * @see Component#getFocusTraversalKeys
0N/A */
0N/A public static final int BACKWARD_TRAVERSAL_KEYS = 1;
0N/A
0N/A /**
0N/A * The identifier for the Up Cycle focus traversal keys.
0N/A *
0N/A * @see #setDefaultFocusTraversalKeys
0N/A * @see #getDefaultFocusTraversalKeys
0N/A * @see Component#setFocusTraversalKeys
0N/A * @see Component#getFocusTraversalKeys
0N/A */
0N/A public static final int UP_CYCLE_TRAVERSAL_KEYS = 2;
0N/A
0N/A /**
0N/A * The identifier for the Down Cycle focus traversal keys.
0N/A *
0N/A * @see #setDefaultFocusTraversalKeys
0N/A * @see #getDefaultFocusTraversalKeys
0N/A * @see Component#setFocusTraversalKeys
0N/A * @see Component#getFocusTraversalKeys
0N/A */
0N/A public static final int DOWN_CYCLE_TRAVERSAL_KEYS = 3;
0N/A
0N/A static final int TRAVERSAL_KEY_LENGTH = DOWN_CYCLE_TRAVERSAL_KEYS + 1;
0N/A
0N/A /**
0N/A * Returns the current KeyboardFocusManager instance for the calling
0N/A * thread's context.
0N/A *
0N/A * @return this thread's context's KeyboardFocusManager
0N/A * @see #setCurrentKeyboardFocusManager
0N/A */
0N/A public static KeyboardFocusManager getCurrentKeyboardFocusManager() {
0N/A return getCurrentKeyboardFocusManager(AppContext.getAppContext());
0N/A }
0N/A
0N/A synchronized static KeyboardFocusManager
0N/A getCurrentKeyboardFocusManager(AppContext appcontext)
0N/A {
0N/A KeyboardFocusManager manager = (KeyboardFocusManager)
0N/A appcontext.get(KeyboardFocusManager.class);
0N/A if (manager == null) {
0N/A manager = new DefaultKeyboardFocusManager();
0N/A appcontext.put(KeyboardFocusManager.class, manager);
0N/A }
0N/A return manager;
0N/A }
0N/A
0N/A /**
0N/A * Sets the current KeyboardFocusManager instance for the calling thread's
0N/A * context. If null is specified, then the current KeyboardFocusManager
0N/A * is replaced with a new instance of DefaultKeyboardFocusManager.
0N/A * <p>
0N/A * If a SecurityManager is installed, the calling thread must be granted
0N/A * the AWTPermission "replaceKeyboardFocusManager" in order to replace the
0N/A * the current KeyboardFocusManager. If this permission is not granted,
0N/A * this method will throw a SecurityException, and the current
0N/A * KeyboardFocusManager will be unchanged.
0N/A *
0N/A * @param newManager the new KeyboardFocusManager for this thread's context
0N/A * @see #getCurrentKeyboardFocusManager
0N/A * @see DefaultKeyboardFocusManager
0N/A * @throws SecurityException if the calling thread does not have permission
0N/A * to replace the current KeyboardFocusManager
0N/A */
0N/A public static void setCurrentKeyboardFocusManager(
0N/A KeyboardFocusManager newManager) throws SecurityException
0N/A {
0N/A SecurityManager security = System.getSecurityManager();
0N/A if (security != null) {
0N/A if (replaceKeyboardFocusManagerPermission == null) {
0N/A replaceKeyboardFocusManagerPermission =
0N/A new AWTPermission("replaceKeyboardFocusManager");
0N/A }
0N/A security.
0N/A checkPermission(replaceKeyboardFocusManagerPermission);
0N/A }
0N/A
0N/A KeyboardFocusManager oldManager = null;
0N/A
0N/A synchronized (KeyboardFocusManager.class) {
0N/A AppContext appcontext = AppContext.getAppContext();
0N/A
0N/A if (newManager != null) {
0N/A oldManager = getCurrentKeyboardFocusManager(appcontext);
0N/A
0N/A appcontext.put(KeyboardFocusManager.class, newManager);
0N/A } else {
0N/A oldManager = getCurrentKeyboardFocusManager(appcontext);
0N/A appcontext.remove(KeyboardFocusManager.class);
0N/A }
0N/A }
0N/A
0N/A if (oldManager != null) {
0N/A oldManager.firePropertyChange("managingFocus",
0N/A Boolean.TRUE,
0N/A Boolean.FALSE);
0N/A }
0N/A if (newManager != null) {
0N/A newManager.firePropertyChange("managingFocus",
0N/A Boolean.FALSE,
0N/A Boolean.TRUE);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * The Component in an application that will typically receive all
0N/A * KeyEvents generated by the user.
0N/A */
0N/A private static Component focusOwner;
0N/A
0N/A /**
0N/A * The Component in an application that will regain focus when an
0N/A * outstanding temporary focus transfer has completed, or the focus owner,
0N/A * if no outstanding temporary transfer exists.
0N/A */
0N/A private static Component permanentFocusOwner;
0N/A
0N/A /**
0N/A * The Window which is, or contains, the focus owner.
0N/A */
0N/A private static Window focusedWindow;
0N/A
0N/A /**
0N/A * Only a Frame or a Dialog can be the active Window. The native windowing
0N/A * system may denote the active Window with a special decoration, such as a
0N/A * highlighted title bar. The active Window is always either the focused
0N/A * Window, or the first Frame or Dialog which is an owner of the focused
0N/A * Window.
0N/A */
0N/A private static Window activeWindow;
0N/A
0N/A /**
0N/A * The default FocusTraversalPolicy for all Windows that have no policy of
0N/A * their own set. If those Windows have focus-cycle-root children that have
0N/A * no keyboard-traversal policy of their own, then those children will also
0N/A * inherit this policy (as will, recursively, their focus-cycle-root
0N/A * children).
0N/A */
0N/A private FocusTraversalPolicy defaultPolicy =
0N/A new DefaultFocusTraversalPolicy();
0N/A
0N/A /**
0N/A * The bound property names of each focus traversal key.
0N/A */
0N/A private static final String[] defaultFocusTraversalKeyPropertyNames = {
0N/A "forwardDefaultFocusTraversalKeys",
0N/A "backwardDefaultFocusTraversalKeys",
0N/A "upCycleDefaultFocusTraversalKeys",
0N/A "downCycleDefaultFocusTraversalKeys"
0N/A };
0N/A
0N/A /**
0N/A * The default strokes for initializing the default focus traversal keys.
0N/A */
0N/A private static final AWTKeyStroke[][] defaultFocusTraversalKeyStrokes = {
0N/A {
0N/A AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0, false),
0N/A AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK, false),
0N/A },
0N/A {
0N/A AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK, false),
0N/A AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,
0N/A InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK | InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK,
0N/A false),
0N/A },
0N/A {},
0N/A {},
0N/A };
0N/A /**
0N/A * The default focus traversal keys. Each array of traversal keys will be
0N/A * in effect on all Windows that have no such array of their own explicitly
0N/A * set. Each array will also be inherited, recursively, by any child
0N/A * Component of those Windows that has no such array of its own explicitly
0N/A * set.
0N/A */
0N/A private Set[] defaultFocusTraversalKeys = new Set[4];
0N/A
0N/A /**
0N/A * The current focus cycle root. If the focus owner is itself a focus cycle
0N/A * root, then it may be ambiguous as to which Components represent the next
0N/A * and previous Components to focus during normal focus traversal. In that
0N/A * case, the current focus cycle root is used to differentiate among the
0N/A * possibilities.
0N/A */
0N/A private static Container currentFocusCycleRoot;
0N/A
0N/A /**
0N/A * A description of any VetoableChangeListeners which have been registered.
0N/A */
0N/A private VetoableChangeSupport vetoableSupport;
0N/A
0N/A /**
0N/A * A description of any PropertyChangeListeners which have been registered.
0N/A */
0N/A private PropertyChangeSupport changeSupport;
0N/A
0N/A /**
0N/A * This KeyboardFocusManager's KeyEventDispatcher chain. The List does not
0N/A * include this KeyboardFocusManager unless it was explicitly re-registered
0N/A * via a call to <code>addKeyEventDispatcher</code>. If no other
0N/A * KeyEventDispatchers are registered, this field may be null or refer to
0N/A * a List of length 0.
0N/A */
0N/A private java.util.LinkedList keyEventDispatchers;
0N/A
0N/A /**
0N/A * This KeyboardFocusManager's KeyEventPostProcessor chain. The List does
0N/A * not include this KeyboardFocusManager unless it was explicitly
0N/A * re-registered via a call to <code>addKeyEventPostProcessor</code>.
0N/A * If no other KeyEventPostProcessors are registered, this field may be
0N/A * null or refer to a List of length 0.
0N/A */
0N/A private java.util.LinkedList keyEventPostProcessors;
0N/A
0N/A /**
0N/A * Maps Windows to those Windows' most recent focus owners.
0N/A */
0N/A private static java.util.Map mostRecentFocusOwners = new WeakHashMap();
0N/A
0N/A /**
0N/A * Error String for initializing SecurityExceptions.
0N/A */
0N/A private static final String notPrivileged = "this KeyboardFocusManager is not installed in the current thread's context";
0N/A
0N/A /**
0N/A * We cache the permission used to verify that the calling thread is
0N/A * permitted to access the global focus state.
0N/A */
0N/A private static AWTPermission replaceKeyboardFocusManagerPermission;
0N/A
0N/A /*
0N/A * SequencedEvent which is currently dispatched in AppContext.
0N/A */
0N/A transient SequencedEvent currentSequencedEvent = null;
0N/A
0N/A final void setCurrentSequencedEvent(SequencedEvent current) {
0N/A synchronized (SequencedEvent.class) {
0N/A assert(current == null || currentSequencedEvent == null);
0N/A currentSequencedEvent = current;
0N/A }
0N/A }
0N/A
0N/A final SequencedEvent getCurrentSequencedEvent() {
0N/A synchronized (SequencedEvent.class) {
0N/A return currentSequencedEvent;
0N/A }
0N/A }
0N/A
0N/A static Set initFocusTraversalKeysSet(String value, Set targetSet) {
0N/A StringTokenizer tokens = new StringTokenizer(value, ",");
0N/A while (tokens.hasMoreTokens()) {
0N/A targetSet.add(AWTKeyStroke.getAWTKeyStroke(tokens.nextToken()));
0N/A }
0N/A return (targetSet.isEmpty())
0N/A ? Collections.EMPTY_SET
0N/A : Collections.unmodifiableSet(targetSet);
0N/A }
0N/A
0N/A /**
0N/A * Initializes a KeyboardFocusManager.
0N/A */
0N/A public KeyboardFocusManager() {
0N/A for (int i = 0; i < TRAVERSAL_KEY_LENGTH; i++) {
0N/A Set work_set = new HashSet();
0N/A for (int j = 0; j < defaultFocusTraversalKeyStrokes[i].length; j++) {
0N/A work_set.add(defaultFocusTraversalKeyStrokes[i][j]);
0N/A }
0N/A defaultFocusTraversalKeys[i] = (work_set.isEmpty())
0N/A ? Collections.EMPTY_SET
0N/A : Collections.unmodifiableSet(work_set);
0N/A }
0N/A initPeer();
0N/A }
0N/A
0N/A private void initPeer() {
0N/A Toolkit tk = Toolkit.getDefaultToolkit();
0N/A KeyboardFocusManagerPeerProvider peerProvider = (KeyboardFocusManagerPeerProvider)tk;
5336N/A peer = peerProvider.getKeyboardFocusManagerPeer();
0N/A }
0N/A
0N/A /**
0N/A * Returns the focus owner, if the focus owner is in the same context as
0N/A * the calling thread. The focus owner is defined as the Component in an
0N/A * application that will typically receive all KeyEvents generated by the
0N/A * user. KeyEvents which map to the focus owner's focus traversal keys will
0N/A * not be delivered if focus traversal keys are enabled for the focus
0N/A * owner. In addition, KeyEventDispatchers may retarget or consume
0N/A * KeyEvents before they reach the focus owner.
0N/A *
0N/A * @return the focus owner, or null if the focus owner is not a member of
0N/A * the calling thread's context
0N/A * @see #getGlobalFocusOwner
0N/A * @see #setGlobalFocusOwner
0N/A */
0N/A public Component getFocusOwner() {
0N/A synchronized (KeyboardFocusManager.class) {
0N/A if (focusOwner == null) {
0N/A return null;
0N/A }
0N/A
0N/A return (focusOwner.appContext == AppContext.getAppContext())
0N/A ? focusOwner
0N/A : null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the focus owner, even if the calling thread is in a different
0N/A * context than the focus owner. The focus owner is defined as the
0N/A * Component in an application that will typically receive all KeyEvents
0N/A * generated by the user. KeyEvents which map to the focus owner's focus
0N/A * traversal keys will not be delivered if focus traversal keys are enabled
0N/A * for the focus owner. In addition, KeyEventDispatchers may retarget or
0N/A * consume KeyEvents before they reach the focus owner.
0N/A * <p>
0N/A * This method will throw a SecurityException if this KeyboardFocusManager
0N/A * is not the current KeyboardFocusManager for the calling thread's
0N/A * context.
0N/A *
0N/A * @return the focus owner
0N/A * @see #getFocusOwner
0N/A * @see #setGlobalFocusOwner
0N/A * @throws SecurityException if this KeyboardFocusManager is not the
0N/A * current KeyboardFocusManager for the calling thread's context
0N/A */
0N/A protected Component getGlobalFocusOwner() throws SecurityException {
0N/A synchronized (KeyboardFocusManager.class) {
4743N/A checkCurrentKFMSecurity();
4743N/A return focusOwner;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the focus owner. The operation will be cancelled if the Component
0N/A * is not focusable. The focus owner is defined as the Component in an
0N/A * application that will typically receive all KeyEvents generated by the
0N/A * user. KeyEvents which map to the focus owner's focus traversal keys will
0N/A * not be delivered if focus traversal keys are enabled for the focus
0N/A * owner. In addition, KeyEventDispatchers may retarget or consume
0N/A * KeyEvents before they reach the focus owner.
0N/A * <p>
0N/A * This method does not actually set the focus to the specified Component.
0N/A * It merely stores the value to be subsequently returned by
0N/A * <code>getFocusOwner()</code>. Use <code>Component.requestFocus()</code>
0N/A * or <code>Component.requestFocusInWindow()</code> to change the focus
0N/A * owner, subject to platform limitations.
0N/A *
0N/A * @param focusOwner the focus owner
0N/A * @see #getFocusOwner
0N/A * @see #getGlobalFocusOwner
0N/A * @see Component#requestFocus()
0N/A * @see Component#requestFocusInWindow()
0N/A * @see Component#isFocusable
0N/A * @beaninfo
0N/A * bound: true
0N/A */
4751N/A protected void setGlobalFocusOwner(Component focusOwner) {
0N/A Component oldFocusOwner = null;
0N/A boolean shouldFire = false;
0N/A
0N/A if (focusOwner == null || focusOwner.isFocusable()) {
0N/A synchronized (KeyboardFocusManager.class) {
4743N/A checkCurrentKFMSecurity();
4743N/A
0N/A oldFocusOwner = getFocusOwner();
0N/A
0N/A try {
0N/A fireVetoableChange("focusOwner", oldFocusOwner,
0N/A focusOwner);
0N/A } catch (PropertyVetoException e) {
0N/A // rejected
0N/A return;
0N/A }
0N/A
0N/A KeyboardFocusManager.focusOwner = focusOwner;
0N/A
0N/A if (focusOwner != null &&
0N/A (getCurrentFocusCycleRoot() == null ||
0N/A !focusOwner.isFocusCycleRoot(getCurrentFocusCycleRoot())))
0N/A {
0N/A Container rootAncestor =
0N/A focusOwner.getFocusCycleRootAncestor();
0N/A if (rootAncestor == null && (focusOwner instanceof Window))
0N/A {
0N/A rootAncestor = (Container)focusOwner;
0N/A }
0N/A if (rootAncestor != null) {
0N/A setGlobalCurrentFocusCycleRoot(rootAncestor);
0N/A }
0N/A }
0N/A
0N/A shouldFire = true;
0N/A }
0N/A }
0N/A
0N/A if (shouldFire) {
0N/A firePropertyChange("focusOwner", oldFocusOwner, focusOwner);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Clears the global focus owner at both the Java and native levels. If
0N/A * there exists a focus owner, that Component will receive a permanent
0N/A * FOCUS_LOST event. After this operation completes, the native windowing
0N/A * system will discard all user-generated KeyEvents until the user selects
0N/A * a new Component to receive focus, or a Component is given focus
0N/A * explicitly via a call to <code>requestFocus()</code>. This operation
0N/A * does not change the focused or active Windows.
0N/A *
0N/A * @see Component#requestFocus()
0N/A * @see java.awt.event.FocusEvent#FOCUS_LOST
0N/A */
4751N/A public void clearGlobalFocusOwner() {
4743N/A synchronized (KeyboardFocusManager.class) {
4743N/A checkCurrentKFMSecurity();
4743N/A }
0N/A if (!GraphicsEnvironment.isHeadless()) {
0N/A // Toolkit must be fully initialized, otherwise
0N/A // _clearGlobalFocusOwner will crash or throw an exception
0N/A Toolkit.getDefaultToolkit();
0N/A
0N/A _clearGlobalFocusOwner();
0N/A }
0N/A }
0N/A private void _clearGlobalFocusOwner() {
0N/A Window activeWindow = markClearGlobalFocusOwner();
0N/A peer.clearGlobalFocusOwner(activeWindow);
0N/A }
0N/A
0N/A Component getNativeFocusOwner() {
0N/A return peer.getCurrentFocusOwner();
0N/A }
0N/A
0N/A void setNativeFocusOwner(Component comp) {
1979N/A if (focusLog.isLoggable(PlatformLogger.FINEST)) {
1979N/A focusLog.finest("Calling peer {0} setCurrentFocusOwner for {1}",
1979N/A String.valueOf(peer), String.valueOf(comp));
0N/A }
0N/A peer.setCurrentFocusOwner(comp);
0N/A }
0N/A
0N/A Window getNativeFocusedWindow() {
0N/A return peer.getCurrentFocusedWindow();
0N/A }
0N/A
0N/A /**
0N/A * Returns the permanent focus owner, if the permanent focus owner is in
0N/A * the same context as the calling thread. The permanent focus owner is
0N/A * defined as the last Component in an application to receive a permanent
0N/A * FOCUS_GAINED event. The focus owner and permanent focus owner are
0N/A * equivalent unless a temporary focus change is currently in effect. In
0N/A * such a situation, the permanent focus owner will again be the focus
0N/A * owner when the temporary focus change ends.
0N/A *
0N/A * @return the permanent focus owner, or null if the permanent focus owner
0N/A * is not a member of the calling thread's context
0N/A * @see #getGlobalPermanentFocusOwner
0N/A * @see #setGlobalPermanentFocusOwner
0N/A */
0N/A public Component getPermanentFocusOwner() {
0N/A synchronized (KeyboardFocusManager.class) {
0N/A if (permanentFocusOwner == null) {
0N/A return null;
0N/A }
0N/A
0N/A return (permanentFocusOwner.appContext ==
0N/A AppContext.getAppContext())
0N/A ? permanentFocusOwner
0N/A : null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the permanent focus owner, even if the calling thread is in a
0N/A * different context than the permanent focus owner. The permanent focus
0N/A * owner is defined as the last Component in an application to receive a
0N/A * permanent FOCUS_GAINED event. The focus owner and permanent focus owner
0N/A * are equivalent unless a temporary focus change is currently in effect.
0N/A * In such a situation, the permanent focus owner will again be the focus
0N/A * owner when the temporary focus change ends.
0N/A * <p>
0N/A * This method will throw a SecurityException if this KeyboardFocusManager
0N/A * is not the current KeyboardFocusManager for the calling thread's
0N/A * context.
0N/A *
0N/A * @return the permanent focus owner
0N/A * @see #getPermanentFocusOwner
0N/A * @see #setGlobalPermanentFocusOwner
0N/A * @throws SecurityException if this KeyboardFocusManager is not the
0N/A * current KeyboardFocusManager for the calling thread's context
0N/A */
0N/A protected Component getGlobalPermanentFocusOwner()
0N/A throws SecurityException
0N/A {
0N/A synchronized (KeyboardFocusManager.class) {
4743N/A checkCurrentKFMSecurity();
4743N/A return permanentFocusOwner;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the permanent focus owner. The operation will be cancelled if the
0N/A * Component is not focusable. The permanent focus owner is defined as the
0N/A * last Component in an application to receive a permanent FOCUS_GAINED
0N/A * event. The focus owner and permanent focus owner are equivalent unless
0N/A * a temporary focus change is currently in effect. In such a situation,
0N/A * the permanent focus owner will again be the focus owner when the
0N/A * temporary focus change ends.
0N/A * <p>
0N/A * This method does not actually set the focus to the specified Component.
0N/A * It merely stores the value to be subsequently returned by
0N/A * <code>getPermanentFocusOwner()</code>. Use
0N/A * <code>Component.requestFocus()</code> or
0N/A * <code>Component.requestFocusInWindow()</code> to change the focus owner,
0N/A * subject to platform limitations.
0N/A *
0N/A * @param permanentFocusOwner the permanent focus owner
0N/A * @see #getPermanentFocusOwner
0N/A * @see #getGlobalPermanentFocusOwner
0N/A * @see Component#requestFocus()
0N/A * @see Component#requestFocusInWindow()
0N/A * @see Component#isFocusable
0N/A * @beaninfo
0N/A * bound: true
0N/A */
4751N/A protected void setGlobalPermanentFocusOwner(Component permanentFocusOwner) {
0N/A Component oldPermanentFocusOwner = null;
0N/A boolean shouldFire = false;
0N/A
0N/A if (permanentFocusOwner == null || permanentFocusOwner.isFocusable()) {
0N/A synchronized (KeyboardFocusManager.class) {
4743N/A checkCurrentKFMSecurity();
4743N/A
0N/A oldPermanentFocusOwner = getPermanentFocusOwner();
0N/A
0N/A try {
0N/A fireVetoableChange("permanentFocusOwner",
0N/A oldPermanentFocusOwner,
0N/A permanentFocusOwner);
0N/A } catch (PropertyVetoException e) {
0N/A // rejected
0N/A return;
0N/A }
0N/A
0N/A KeyboardFocusManager.permanentFocusOwner = permanentFocusOwner;
0N/A
0N/A KeyboardFocusManager.
0N/A setMostRecentFocusOwner(permanentFocusOwner);
0N/A
0N/A shouldFire = true;
0N/A }
0N/A }
0N/A
0N/A if (shouldFire) {
0N/A firePropertyChange("permanentFocusOwner", oldPermanentFocusOwner,
0N/A permanentFocusOwner);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the focused Window, if the focused Window is in the same context
0N/A * as the calling thread. The focused Window is the Window that is or
0N/A * contains the focus owner.
0N/A *
0N/A * @return the focused Window, or null if the focused Window is not a
0N/A * member of the calling thread's context
0N/A * @see #getGlobalFocusedWindow
0N/A * @see #setGlobalFocusedWindow
0N/A */
0N/A public Window getFocusedWindow() {
0N/A synchronized (KeyboardFocusManager.class) {
0N/A if (focusedWindow == null) {
0N/A return null;
0N/A }
0N/A
0N/A return (focusedWindow.appContext == AppContext.getAppContext())
0N/A ? focusedWindow
0N/A : null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the focused Window, even if the calling thread is in a different
0N/A * context than the focused Window. The focused Window is the Window that
0N/A * is or contains the focus owner.
0N/A * <p>
0N/A * This method will throw a SecurityException if this KeyboardFocusManager
0N/A * is not the current KeyboardFocusManager for the calling thread's
0N/A * context.
0N/A *
0N/A * @return the focused Window
0N/A * @see #getFocusedWindow
0N/A * @see #setGlobalFocusedWindow
0N/A * @throws SecurityException if this KeyboardFocusManager is not the
0N/A * current KeyboardFocusManager for the calling thread's context
0N/A */
0N/A protected Window getGlobalFocusedWindow() throws SecurityException {
0N/A synchronized (KeyboardFocusManager.class) {
4743N/A checkCurrentKFMSecurity();
4743N/A return focusedWindow;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the focused Window. The focused Window is the Window that is or
0N/A * contains the focus owner. The operation will be cancelled if the
0N/A * specified Window to focus is not a focusable Window.
0N/A * <p>
0N/A * This method does not actually change the focused Window as far as the
0N/A * native windowing system is concerned. It merely stores the value to be
0N/A * subsequently returned by <code>getFocusedWindow()</code>. Use
0N/A * <code>Component.requestFocus()</code> or
0N/A * <code>Component.requestFocusInWindow()</code> to change the focused
0N/A * Window, subject to platform limitations.
0N/A *
0N/A * @param focusedWindow the focused Window
0N/A * @see #getFocusedWindow
0N/A * @see #getGlobalFocusedWindow
0N/A * @see Component#requestFocus()
0N/A * @see Component#requestFocusInWindow()
0N/A * @see Window#isFocusableWindow
0N/A * @beaninfo
0N/A * bound: true
0N/A */
4751N/A protected void setGlobalFocusedWindow(Window focusedWindow) {
0N/A Window oldFocusedWindow = null;
0N/A boolean shouldFire = false;
0N/A
0N/A if (focusedWindow == null || focusedWindow.isFocusableWindow()) {
0N/A synchronized (KeyboardFocusManager.class) {
4743N/A checkCurrentKFMSecurity();
4743N/A
0N/A oldFocusedWindow = getFocusedWindow();
0N/A
0N/A try {
0N/A fireVetoableChange("focusedWindow", oldFocusedWindow,
0N/A focusedWindow);
0N/A } catch (PropertyVetoException e) {
0N/A // rejected
0N/A return;
0N/A }
0N/A
0N/A KeyboardFocusManager.focusedWindow = focusedWindow;
0N/A shouldFire = true;
0N/A }
0N/A }
0N/A
0N/A if (shouldFire) {
0N/A firePropertyChange("focusedWindow", oldFocusedWindow,
0N/A focusedWindow);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the active Window, if the active Window is in the same context
0N/A * as the calling thread. Only a Frame or a Dialog can be the active
0N/A * Window. The native windowing system may denote the active Window or its
0N/A * children with special decorations, such as a highlighted title bar.
0N/A * The active Window is always either the focused Window, or the first
0N/A * Frame or Dialog that is an owner of the focused Window.
0N/A *
0N/A * @return the active Window, or null if the active Window is not a member
0N/A * of the calling thread's context
0N/A * @see #getGlobalActiveWindow
0N/A * @see #setGlobalActiveWindow
0N/A */
0N/A public Window getActiveWindow() {
0N/A synchronized (KeyboardFocusManager.class) {
0N/A if (activeWindow == null) {
0N/A return null;
0N/A }
0N/A
0N/A return (activeWindow.appContext == AppContext.getAppContext())
0N/A ? activeWindow
0N/A : null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the active Window, even if the calling thread is in a different
0N/A * context than the active Window. Only a Frame or a Dialog can be the
0N/A * active Window. The native windowing system may denote the active Window
0N/A * or its children with special decorations, such as a highlighted title
0N/A * bar. The active Window is always either the focused Window, or the first
0N/A * Frame or Dialog that is an owner of the focused Window.
0N/A * <p>
0N/A * This method will throw a SecurityException if this KeyboardFocusManager
0N/A * is not the current KeyboardFocusManager for the calling thread's
0N/A * context.
0N/A *
0N/A * @return the active Window
0N/A * @see #getActiveWindow
0N/A * @see #setGlobalActiveWindow
0N/A * @throws SecurityException if this KeyboardFocusManager is not the
0N/A * current KeyboardFocusManager for the calling thread's context
0N/A */
0N/A protected Window getGlobalActiveWindow() throws SecurityException {
0N/A synchronized (KeyboardFocusManager.class) {
4743N/A checkCurrentKFMSecurity();
4743N/A return activeWindow;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the active Window. Only a Frame or a Dialog can be the active
0N/A * Window. The native windowing system may denote the active Window or its
0N/A * children with special decorations, such as a highlighted title bar. The
0N/A * active Window is always either the focused Window, or the first Frame or
0N/A * Dialog that is an owner of the focused Window.
0N/A * <p>
0N/A * This method does not actually change the active Window as far as the
0N/A * native windowing system is concerned. It merely stores the value to be
0N/A * subsequently returned by <code>getActiveWindow()</code>. Use
0N/A * <code>Component.requestFocus()</code> or
0N/A * <code>Component.requestFocusInWindow()</code>to change the active
0N/A * Window, subject to platform limitations.
0N/A *
0N/A * @param activeWindow the active Window
0N/A * @see #getActiveWindow
0N/A * @see #getGlobalActiveWindow
0N/A * @see Component#requestFocus()
0N/A * @see Component#requestFocusInWindow()
0N/A * @beaninfo
0N/A * bound: true
0N/A */
4751N/A protected void setGlobalActiveWindow(Window activeWindow) {
0N/A Window oldActiveWindow;
0N/A synchronized (KeyboardFocusManager.class) {
4743N/A checkCurrentKFMSecurity();
4743N/A
0N/A oldActiveWindow = getActiveWindow();
1979N/A if (focusLog.isLoggable(PlatformLogger.FINER)) {
1979N/A focusLog.finer("Setting global active window to " + activeWindow + ", old active " + oldActiveWindow);
0N/A }
0N/A
0N/A try {
0N/A fireVetoableChange("activeWindow", oldActiveWindow,
0N/A activeWindow);
0N/A } catch (PropertyVetoException e) {
0N/A // rejected
0N/A return;
0N/A }
0N/A
0N/A KeyboardFocusManager.activeWindow = activeWindow;
0N/A }
0N/A
0N/A firePropertyChange("activeWindow", oldActiveWindow, activeWindow);
0N/A }
0N/A
0N/A /**
0N/A * Returns the default FocusTraversalPolicy. Top-level components
0N/A * use this value on their creation to initialize their own focus traversal
0N/A * policy by explicit call to Container.setFocusTraversalPolicy.
0N/A *
0N/A * @return the default FocusTraversalPolicy. null will never be returned.
0N/A * @see #setDefaultFocusTraversalPolicy
0N/A * @see Container#setFocusTraversalPolicy
0N/A * @see Container#getFocusTraversalPolicy
0N/A */
0N/A public synchronized FocusTraversalPolicy getDefaultFocusTraversalPolicy() {
0N/A return defaultPolicy;
0N/A }
0N/A
0N/A /**
0N/A * Sets the default FocusTraversalPolicy. Top-level components
0N/A * use this value on their creation to initialize their own focus traversal
0N/A * policy by explicit call to Container.setFocusTraversalPolicy.
0N/A * Note: this call doesn't affect already created components as they have
0N/A * their policy initialized. Only new components will use this policy as
0N/A * their default policy.
0N/A *
0N/A * @param defaultPolicy the new, default FocusTraversalPolicy
0N/A * @see #getDefaultFocusTraversalPolicy
0N/A * @see Container#setFocusTraversalPolicy
0N/A * @see Container#getFocusTraversalPolicy
0N/A * @throws IllegalArgumentException if defaultPolicy is null
0N/A * @beaninfo
0N/A * bound: true
0N/A */
0N/A public void setDefaultFocusTraversalPolicy(FocusTraversalPolicy
0N/A defaultPolicy) {
0N/A if (defaultPolicy == null) {
0N/A throw new IllegalArgumentException("default focus traversal policy cannot be null");
0N/A }
0N/A
0N/A FocusTraversalPolicy oldPolicy;
0N/A
0N/A synchronized (this) {
0N/A oldPolicy = this.defaultPolicy;
0N/A this.defaultPolicy = defaultPolicy;
0N/A }
0N/A
0N/A firePropertyChange("defaultFocusTraversalPolicy", oldPolicy,
0N/A defaultPolicy);
0N/A }
0N/A
0N/A /**
0N/A * Sets the default focus traversal keys for a given traversal operation.
0N/A * This traversal key <code>Set</code> will be in effect on all
0N/A * <code>Window</code>s that have no such <code>Set</code> of
0N/A * their own explicitly defined. This <code>Set</code> will also be
0N/A * inherited, recursively, by any child <code>Component</code> of
0N/A * those <code>Windows</code> that has
0N/A * no such <code>Set</code> of its own explicitly defined.
0N/A * <p>
0N/A * The default values for the default focus traversal keys are
0N/A * implementation-dependent. Sun recommends that all implementations for a
0N/A * particular native platform use the same default values. The
0N/A * recommendations for Windows and Unix are listed below. These
0N/A * recommendations are used in the Sun AWT implementations.
0N/A *
0N/A * <table border=1 summary="Recommended default values for focus traversal keys">
0N/A * <tr>
0N/A * <th>Identifier</th>
0N/A * <th>Meaning</th>
0N/A * <th>Default</th>
0N/A * </tr>
0N/A * <tr>
0N/A * <td><code>KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS</code></td>
0N/A * <td>Normal forward keyboard traversal</td>
0N/A * <td><code>TAB</code> on <code>KEY_PRESSED</code>,
0N/A * <code>CTRL-TAB</code> on <code>KEY_PRESSED</code></td>
0N/A * </tr>
0N/A * <tr>
0N/A * <td><code>KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS</code></td>
0N/A * <td>Normal reverse keyboard traversal</td>
0N/A * <td><code>SHIFT-TAB</code> on <code>KEY_PRESSED</code>,
0N/A * <code>CTRL-SHIFT-TAB</code> on <code>KEY_PRESSED</code></td>
0N/A * </tr>
0N/A * <tr>
0N/A * <td><code>KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS</code></td>
0N/A * <td>Go up one focus traversal cycle</td>
0N/A * <td>none</td>
0N/A * </tr>
0N/A * <tr>
0N/A * <td><code>KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS</code></td>
0N/A * <td>Go down one focus traversal cycle</td>
0N/A * <td>none</td>
0N/A * </tr>
0N/A * </table>
0N/A *
0N/A * To disable a traversal key, use an empty <code>Set</code>;
0N/A * <code>Collections.EMPTY_SET</code> is recommended.
0N/A * <p>
0N/A * Using the <code>AWTKeyStroke</code> API, client code can
0N/A * specify on which of two
0N/A * specific <code>KeyEvent</code>s, <code>KEY_PRESSED</code> or
0N/A * <code>KEY_RELEASED</code>, the focus traversal operation will
0N/A * occur. Regardless of which <code>KeyEvent</code> is specified,
0N/A * however, all <code>KeyEvent</code>s related to the focus
0N/A * traversal key, including the associated <code>KEY_TYPED</code>
0N/A * event, will be consumed, and will not be dispatched
0N/A * to any <code>Component</code>. It is a runtime error to
0N/A * specify a <code>KEY_TYPED</code> event as
0N/A * mapping to a focus traversal operation, or to map the same event to
0N/A * multiple default focus traversal operations.
0N/A *
0N/A * @param id one of
0N/A * <code>KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS</code>,
0N/A * <code>KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS</code>,
0N/A * <code>KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS</code>, or
0N/A * <code>KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS</code>
0N/A * @param keystrokes the Set of <code>AWTKeyStroke</code>s for the
0N/A * specified operation
0N/A * @see #getDefaultFocusTraversalKeys
0N/A * @see Component#setFocusTraversalKeys
0N/A * @see Component#getFocusTraversalKeys
0N/A * @throws IllegalArgumentException if id is not one of
0N/A * <code>KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS</code>,
0N/A * <code>KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS</code>,
0N/A * <code>KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS</code>, or
0N/A * <code>KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS</code>,
0N/A * or if keystrokes is <code>null</code>,
0N/A * or if keystrokes contains <code>null</code>,
0N/A * or if any <code>Object</code> in
0N/A * keystrokes is not an <code>AWTKeyStroke</code>,
0N/A * or if any keystroke
0N/A * represents a <code>KEY_TYPED</code> event,
0N/A * or if any keystroke already maps
0N/A * to another default focus traversal operation
0N/A * @beaninfo
0N/A * bound: true
0N/A */
0N/A public void
0N/A setDefaultFocusTraversalKeys(int id,
0N/A Set<? extends AWTKeyStroke> keystrokes)
0N/A {
0N/A if (id < 0 || id >= TRAVERSAL_KEY_LENGTH) {
0N/A throw new IllegalArgumentException("invalid focus traversal key identifier");
0N/A }
0N/A if (keystrokes == null) {
0N/A throw new IllegalArgumentException("cannot set null Set of default focus traversal keys");
0N/A }
0N/A
0N/A Set oldKeys;
0N/A
0N/A synchronized (this) {
0N/A for (Iterator iter = keystrokes.iterator(); iter.hasNext(); ) {
0N/A Object obj = iter.next();
0N/A
0N/A if (obj == null) {
0N/A throw new IllegalArgumentException("cannot set null focus traversal key");
0N/A }
0N/A
0N/A // Fix for 6195831:
0N/A //According to javadoc this method should throw IAE instead of ClassCastException
0N/A if (!(obj instanceof AWTKeyStroke)) {
0N/A throw new IllegalArgumentException("object is expected to be AWTKeyStroke");
0N/A }
0N/A AWTKeyStroke keystroke = (AWTKeyStroke)obj;
0N/A
0N/A if (keystroke.getKeyChar() != KeyEvent.CHAR_UNDEFINED) {
0N/A throw new IllegalArgumentException("focus traversal keys cannot map to KEY_TYPED events");
0N/A }
0N/A
0N/A // Check to see if key already maps to another traversal
0N/A // operation
0N/A for (int i = 0; i < TRAVERSAL_KEY_LENGTH; i++) {
0N/A if (i == id) {
0N/A continue;
0N/A }
0N/A
0N/A if (defaultFocusTraversalKeys[i].contains(keystroke)) {
0N/A throw new IllegalArgumentException("focus traversal keys must be unique for a Component");
0N/A }
0N/A }
0N/A }
0N/A
0N/A oldKeys = defaultFocusTraversalKeys[id];
0N/A defaultFocusTraversalKeys[id] =
0N/A Collections.unmodifiableSet(new HashSet(keystrokes));
0N/A }
0N/A
0N/A firePropertyChange(defaultFocusTraversalKeyPropertyNames[id],
0N/A oldKeys, keystrokes);
0N/A }
0N/A
0N/A /**
0N/A * Returns a Set of default focus traversal keys for a given traversal
0N/A * operation. This traversal key Set will be in effect on all Windows that
0N/A * have no such Set of their own explicitly defined. This Set will also be
0N/A * inherited, recursively, by any child Component of those Windows that has
0N/A * no such Set of its own explicitly defined. (See
0N/A * <code>setDefaultFocusTraversalKeys</code> for a full description of each
0N/A * operation.)
0N/A *
0N/A * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
0N/A * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
0N/A * KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
0N/A * KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
0N/A * @return the <code>Set</code> of <code>AWTKeyStroke</code>s
0N/A * for the specified operation; the <code>Set</code>
0N/A * will be unmodifiable, and may be empty; <code>null</code>
0N/A * will never be returned
0N/A * @see #setDefaultFocusTraversalKeys
0N/A * @see Component#setFocusTraversalKeys
0N/A * @see Component#getFocusTraversalKeys
0N/A * @throws IllegalArgumentException if id is not one of
0N/A * KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
0N/A * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
0N/A * KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
0N/A * KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
0N/A */
0N/A public Set<AWTKeyStroke> getDefaultFocusTraversalKeys(int id) {
0N/A if (id < 0 || id >= TRAVERSAL_KEY_LENGTH) {
0N/A throw new IllegalArgumentException("invalid focus traversal key identifier");
0N/A }
0N/A
0N/A // Okay to return Set directly because it is an unmodifiable view
0N/A return defaultFocusTraversalKeys[id];
0N/A }
0N/A
0N/A /**
0N/A * Returns the current focus cycle root, if the current focus cycle root is
0N/A * in the same context as the calling thread. If the focus owner is itself
0N/A * a focus cycle root, then it may be ambiguous as to which Components
0N/A * represent the next and previous Components to focus during normal focus
0N/A * traversal. In that case, the current focus cycle root is used to
0N/A * differentiate among the possibilities.
0N/A * <p>
0N/A * This method is intended to be used only by KeyboardFocusManagers and
0N/A * focus implementations. It is not for general client use.
0N/A *
0N/A * @return the current focus cycle root, or null if the current focus cycle
0N/A * root is not a member of the calling thread's context
0N/A * @see #getGlobalCurrentFocusCycleRoot
0N/A * @see #setGlobalCurrentFocusCycleRoot
0N/A */
0N/A public Container getCurrentFocusCycleRoot() {
0N/A synchronized (KeyboardFocusManager.class) {
0N/A if (currentFocusCycleRoot == null) {
0N/A return null;
0N/A }
0N/A
0N/A return (currentFocusCycleRoot.appContext ==
0N/A AppContext.getAppContext())
0N/A ? currentFocusCycleRoot
0N/A : null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the current focus cycle root, even if the calling thread is in a
0N/A * different context than the current focus cycle root. If the focus owner
0N/A * is itself a focus cycle root, then it may be ambiguous as to which
0N/A * Components represent the next and previous Components to focus during
0N/A * normal focus traversal. In that case, the current focus cycle root is
0N/A * used to differentiate among the possibilities.
0N/A * <p>
0N/A * This method will throw a SecurityException if this KeyboardFocusManager
0N/A * is not the current KeyboardFocusManager for the calling thread's
0N/A * context.
0N/A *
0N/A * @return the current focus cycle root, or null if the current focus cycle
0N/A * root is not a member of the calling thread's context
0N/A * @see #getCurrentFocusCycleRoot
0N/A * @see #setGlobalCurrentFocusCycleRoot
0N/A * @throws SecurityException if this KeyboardFocusManager is not the
0N/A * current KeyboardFocusManager for the calling thread's context
0N/A */
0N/A protected Container getGlobalCurrentFocusCycleRoot()
0N/A throws SecurityException
0N/A {
0N/A synchronized (KeyboardFocusManager.class) {
4743N/A checkCurrentKFMSecurity();
4743N/A return currentFocusCycleRoot;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the current focus cycle root. If the focus owner is itself a focus
0N/A * cycle root, then it may be ambiguous as to which Components represent
0N/A * the next and previous Components to focus during normal focus traversal.
0N/A * In that case, the current focus cycle root is used to differentiate
0N/A * among the possibilities.
0N/A * <p>
0N/A * This method is intended to be used only by KeyboardFocusManagers and
0N/A * focus implementations. It is not for general client use.
0N/A *
0N/A * @param newFocusCycleRoot the new focus cycle root
0N/A * @see #getCurrentFocusCycleRoot
0N/A * @see #getGlobalCurrentFocusCycleRoot
0N/A * @beaninfo
0N/A * bound: true
0N/A */
4751N/A public void setGlobalCurrentFocusCycleRoot(Container newFocusCycleRoot) {
0N/A Container oldFocusCycleRoot;
0N/A
0N/A synchronized (KeyboardFocusManager.class) {
4743N/A checkCurrentKFMSecurity();
4743N/A
0N/A oldFocusCycleRoot = getCurrentFocusCycleRoot();
0N/A currentFocusCycleRoot = newFocusCycleRoot;
0N/A }
0N/A
0N/A firePropertyChange("currentFocusCycleRoot", oldFocusCycleRoot,
0N/A newFocusCycleRoot);
0N/A }
0N/A
0N/A /**
0N/A * Adds a PropertyChangeListener to the listener list. The listener is
0N/A * registered for all bound properties of this class, including the
0N/A * following:
0N/A * <ul>
0N/A * <li>whether the KeyboardFocusManager is currently managing focus
0N/A * for this application or applet's browser context
0N/A * ("managingFocus")</li>
0N/A * <li>the focus owner ("focusOwner")</li>
0N/A * <li>the permanent focus owner ("permanentFocusOwner")</li>
0N/A * <li>the focused Window ("focusedWindow")</li>
0N/A * <li>the active Window ("activeWindow")</li>
0N/A * <li>the default focus traversal policy
0N/A * ("defaultFocusTraversalPolicy")</li>
0N/A * <li>the Set of default FORWARD_TRAVERSAL_KEYS
0N/A * ("forwardDefaultFocusTraversalKeys")</li>
0N/A * <li>the Set of default BACKWARD_TRAVERSAL_KEYS
0N/A * ("backwardDefaultFocusTraversalKeys")</li>
0N/A * <li>the Set of default UP_CYCLE_TRAVERSAL_KEYS
0N/A * ("upCycleDefaultFocusTraversalKeys")</li>
0N/A * <li>the Set of default DOWN_CYCLE_TRAVERSAL_KEYS
0N/A * ("downCycleDefaultFocusTraversalKeys")</li>
0N/A * <li>the current focus cycle root ("currentFocusCycleRoot")</li>
0N/A * </ul>
0N/A * If listener is null, no exception is thrown and no action is performed.
0N/A *
0N/A * @param listener the PropertyChangeListener to be added
0N/A * @see #removePropertyChangeListener
0N/A * @see #getPropertyChangeListeners
0N/A * @see #addPropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
0N/A */
0N/A public void addPropertyChangeListener(PropertyChangeListener listener) {
0N/A if (listener != null) {
0N/A synchronized (this) {
0N/A if (changeSupport == null) {
0N/A changeSupport = new PropertyChangeSupport(this);
0N/A }
0N/A changeSupport.addPropertyChangeListener(listener);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Removes a PropertyChangeListener from the listener list. This method
0N/A * should be used to remove the PropertyChangeListeners that were
0N/A * registered for all bound properties of this class.
0N/A * <p>
0N/A * If listener is null, no exception is thrown and no action is performed.
0N/A *
0N/A * @param listener the PropertyChangeListener to be removed
0N/A * @see #addPropertyChangeListener
0N/A * @see #getPropertyChangeListeners
0N/A * @see #removePropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
0N/A */
0N/A public void removePropertyChangeListener(PropertyChangeListener listener) {
0N/A if (listener != null) {
0N/A synchronized (this) {
0N/A if (changeSupport != null) {
0N/A changeSupport.removePropertyChangeListener(listener);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the property change listeners
0N/A * registered on this keyboard focus manager.
0N/A *
0N/A * @return all of this keyboard focus manager's
0N/A * <code>PropertyChangeListener</code>s
0N/A * or an empty array if no property change
0N/A * listeners are currently registered
0N/A *
0N/A * @see #addPropertyChangeListener
0N/A * @see #removePropertyChangeListener
0N/A * @see #getPropertyChangeListeners(java.lang.String)
0N/A * @since 1.4
0N/A */
0N/A public synchronized PropertyChangeListener[] getPropertyChangeListeners() {
0N/A if (changeSupport == null) {
0N/A changeSupport = new PropertyChangeSupport(this);
0N/A }
0N/A return changeSupport.getPropertyChangeListeners();
0N/A }
0N/A
0N/A /**
0N/A * Adds a PropertyChangeListener to the listener list for a specific
0N/A * property. The specified property may be user-defined, or one of the
0N/A * following:
0N/A * <ul>
0N/A * <li>whether the KeyboardFocusManager is currently managing focus
0N/A * for this application or applet's browser context
0N/A * ("managingFocus")</li>
0N/A * <li>the focus owner ("focusOwner")</li>
0N/A * <li>the permanent focus owner ("permanentFocusOwner")</li>
0N/A * <li>the focused Window ("focusedWindow")</li>
0N/A * <li>the active Window ("activeWindow")</li>
0N/A * <li>the default focus traversal policy
0N/A * ("defaultFocusTraversalPolicy")</li>
0N/A * <li>the Set of default FORWARD_TRAVERSAL_KEYS
0N/A * ("forwardDefaultFocusTraversalKeys")</li>
0N/A * <li>the Set of default BACKWARD_TRAVERSAL_KEYS
0N/A * ("backwardDefaultFocusTraversalKeys")</li>
0N/A * <li>the Set of default UP_CYCLE_TRAVERSAL_KEYS
0N/A * ("upCycleDefaultFocusTraversalKeys")</li>
0N/A * <li>the Set of default DOWN_CYCLE_TRAVERSAL_KEYS
0N/A * ("downCycleDefaultFocusTraversalKeys")</li>
0N/A * <li>the current focus cycle root ("currentFocusCycleRoot")</li>
0N/A * </ul>
0N/A * If listener is null, no exception is thrown and no action is performed.
0N/A *
0N/A * @param propertyName one of the property names listed above
0N/A * @param listener the PropertyChangeListener to be added
0N/A * @see #addPropertyChangeListener(java.beans.PropertyChangeListener)
0N/A * @see #removePropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
0N/A * @see #getPropertyChangeListeners(java.lang.String)
0N/A */
0N/A public void addPropertyChangeListener(String propertyName,
0N/A PropertyChangeListener listener) {
0N/A if (listener != null) {
0N/A synchronized (this) {
0N/A if (changeSupport == null) {
0N/A changeSupport = new PropertyChangeSupport(this);
0N/A }
0N/A changeSupport.addPropertyChangeListener(propertyName,
0N/A listener);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Removes a PropertyChangeListener from the listener list for a specific
0N/A * property. This method should be used to remove PropertyChangeListeners
0N/A * that were registered for a specific bound property.
0N/A * <p>
0N/A * If listener is null, no exception is thrown and no action is performed.
0N/A *
0N/A * @param propertyName a valid property name
0N/A * @param listener the PropertyChangeListener to be removed
0N/A * @see #addPropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
0N/A * @see #getPropertyChangeListeners(java.lang.String)
0N/A * @see #removePropertyChangeListener(java.beans.PropertyChangeListener)
0N/A */
0N/A public void removePropertyChangeListener(String propertyName,
0N/A PropertyChangeListener listener) {
0N/A if (listener != null) {
0N/A synchronized (this) {
0N/A if (changeSupport != null) {
0N/A changeSupport.removePropertyChangeListener(propertyName,
0N/A listener);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the <code>PropertyChangeListener</code>s
0N/A * associated with the named property.
0N/A *
0N/A * @return all of the <code>PropertyChangeListener</code>s associated with
0N/A * the named property or an empty array if no such listeners have
0N/A * been added.
0N/A *
0N/A * @see #addPropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
0N/A * @see #removePropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
0N/A * @since 1.4
0N/A */
0N/A public synchronized PropertyChangeListener[] getPropertyChangeListeners(String propertyName) {
0N/A if (changeSupport == null) {
0N/A changeSupport = new PropertyChangeSupport(this);
0N/A }
0N/A return changeSupport.getPropertyChangeListeners(propertyName);
0N/A }
0N/A
0N/A /**
0N/A * Fires a PropertyChangeEvent in response to a change in a bound property.
0N/A * The event will be delivered to all registered PropertyChangeListeners.
0N/A * No event will be delivered if oldValue and newValue are the same.
0N/A *
0N/A * @param propertyName the name of the property that has changed
0N/A * @param oldValue the property's previous value
0N/A * @param newValue the property's new value
0N/A */
0N/A protected void firePropertyChange(String propertyName, Object oldValue,
0N/A Object newValue)
0N/A {
0N/A if (oldValue == newValue) {
0N/A return;
0N/A }
0N/A PropertyChangeSupport changeSupport = this.changeSupport;
0N/A if (changeSupport != null) {
0N/A changeSupport.firePropertyChange(propertyName, oldValue, newValue);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Adds a VetoableChangeListener to the listener list. The listener is
0N/A * registered for all vetoable properties of this class, including the
0N/A * following:
0N/A * <ul>
0N/A * <li>the focus owner ("focusOwner")</li>
0N/A * <li>the permanent focus owner ("permanentFocusOwner")</li>
0N/A * <li>the focused Window ("focusedWindow")</li>
0N/A * <li>the active Window ("activeWindow")</li>
0N/A * </ul>
0N/A * If listener is null, no exception is thrown and no action is performed.
0N/A *
0N/A * @param listener the VetoableChangeListener to be added
0N/A * @see #removeVetoableChangeListener
0N/A * @see #getVetoableChangeListeners
0N/A * @see #addVetoableChangeListener(java.lang.String,java.beans.VetoableChangeListener)
0N/A */
0N/A public void addVetoableChangeListener(VetoableChangeListener listener) {
0N/A if (listener != null) {
0N/A synchronized (this) {
0N/A if (vetoableSupport == null) {
0N/A vetoableSupport =
0N/A new VetoableChangeSupport(this);
0N/A }
0N/A vetoableSupport.addVetoableChangeListener(listener);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Removes a VetoableChangeListener from the listener list. This method
0N/A * should be used to remove the VetoableChangeListeners that were
0N/A * registered for all vetoable properties of this class.
0N/A * <p>
0N/A * If listener is null, no exception is thrown and no action is performed.
0N/A *
0N/A * @param listener the VetoableChangeListener to be removed
0N/A * @see #addVetoableChangeListener
0N/A * @see #getVetoableChangeListeners
0N/A * @see #removeVetoableChangeListener(java.lang.String,java.beans.VetoableChangeListener)
0N/A */
0N/A public void removeVetoableChangeListener(VetoableChangeListener listener) {
0N/A if (listener != null) {
0N/A synchronized (this) {
0N/A if (vetoableSupport != null) {
0N/A vetoableSupport.removeVetoableChangeListener(listener);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the vetoable change listeners
0N/A * registered on this keyboard focus manager.
0N/A *
0N/A * @return all of this keyboard focus manager's
0N/A * <code>VetoableChangeListener</code>s
0N/A * or an empty array if no vetoable change
0N/A * listeners are currently registered
0N/A *
0N/A * @see #addVetoableChangeListener
0N/A * @see #removeVetoableChangeListener
0N/A * @see #getVetoableChangeListeners(java.lang.String)
0N/A * @since 1.4
0N/A */
0N/A public synchronized VetoableChangeListener[] getVetoableChangeListeners() {
0N/A if (vetoableSupport == null) {
0N/A vetoableSupport = new VetoableChangeSupport(this);
0N/A }
0N/A return vetoableSupport.getVetoableChangeListeners();
0N/A }
0N/A
0N/A /**
0N/A * Adds a VetoableChangeListener to the listener list for a specific
0N/A * property. The specified property may be user-defined, or one of the
0N/A * following:
0N/A * <ul>
0N/A * <li>the focus owner ("focusOwner")</li>
0N/A * <li>the permanent focus owner ("permanentFocusOwner")</li>
0N/A * <li>the focused Window ("focusedWindow")</li>
0N/A * <li>the active Window ("activeWindow")</li>
0N/A * </ul>
0N/A * If listener is null, no exception is thrown and no action is performed.
0N/A *
0N/A * @param propertyName one of the property names listed above
0N/A * @param listener the VetoableChangeListener to be added
0N/A * @see #addVetoableChangeListener(java.beans.VetoableChangeListener)
0N/A * @see #removeVetoableChangeListener
0N/A * @see #getVetoableChangeListeners
0N/A */
0N/A public void addVetoableChangeListener(String propertyName,
0N/A VetoableChangeListener listener) {
0N/A if (listener != null) {
0N/A synchronized (this) {
0N/A if (vetoableSupport == null) {
0N/A vetoableSupport =
0N/A new VetoableChangeSupport(this);
0N/A }
0N/A vetoableSupport.addVetoableChangeListener(propertyName,
0N/A listener);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Removes a VetoableChangeListener from the listener list for a specific
0N/A * property. This method should be used to remove VetoableChangeListeners
0N/A * that were registered for a specific bound property.
0N/A * <p>
0N/A * If listener is null, no exception is thrown and no action is performed.
0N/A *
0N/A * @param propertyName a valid property name
0N/A * @param listener the VetoableChangeListener to be removed
0N/A * @see #addVetoableChangeListener
0N/A * @see #getVetoableChangeListeners
0N/A * @see #removeVetoableChangeListener(java.beans.VetoableChangeListener)
0N/A */
0N/A public void removeVetoableChangeListener(String propertyName,
0N/A VetoableChangeListener listener) {
0N/A if (listener != null) {
0N/A synchronized (this) {
0N/A if (vetoableSupport != null) {
0N/A vetoableSupport.removeVetoableChangeListener(propertyName,
0N/A listener);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the <code>VetoableChangeListener</code>s
0N/A * associated with the named property.
0N/A *
0N/A * @return all of the <code>VetoableChangeListener</code>s associated with
0N/A * the named property or an empty array if no such listeners have
0N/A * been added.
0N/A *
0N/A * @see #addVetoableChangeListener(java.lang.String,java.beans.VetoableChangeListener)
0N/A * @see #removeVetoableChangeListener(java.lang.String,java.beans.VetoableChangeListener)
0N/A * @see #getVetoableChangeListeners
0N/A * @since 1.4
0N/A */
0N/A public synchronized VetoableChangeListener[] getVetoableChangeListeners(String propertyName) {
0N/A if (vetoableSupport == null) {
0N/A vetoableSupport = new VetoableChangeSupport(this);
0N/A }
0N/A return vetoableSupport.getVetoableChangeListeners(propertyName);
0N/A }
0N/A
0N/A /**
0N/A * Fires a PropertyChangeEvent in response to a change in a vetoable
0N/A * property. The event will be delivered to all registered
0N/A * VetoableChangeListeners. If a VetoableChangeListener throws a
0N/A * PropertyVetoException, a new event is fired reverting all
0N/A * VetoableChangeListeners to the old value and the exception is then
0N/A * rethrown. No event will be delivered if oldValue and newValue are the
0N/A * same.
0N/A *
0N/A * @param propertyName the name of the property that has changed
0N/A * @param oldValue the property's previous value
0N/A * @param newValue the property's new value
0N/A * @throws java.beans.PropertyVetoException if a
0N/A * <code>VetoableChangeListener</code> threw
0N/A * <code>PropertyVetoException</code>
0N/A */
0N/A protected void fireVetoableChange(String propertyName, Object oldValue,
0N/A Object newValue)
0N/A throws PropertyVetoException
0N/A {
0N/A if (oldValue == newValue) {
0N/A return;
0N/A }
0N/A VetoableChangeSupport vetoableSupport =
0N/A this.vetoableSupport;
0N/A if (vetoableSupport != null) {
0N/A vetoableSupport.fireVetoableChange(propertyName, oldValue,
0N/A newValue);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Adds a KeyEventDispatcher to this KeyboardFocusManager's dispatcher
0N/A * chain. This KeyboardFocusManager will request that each
0N/A * KeyEventDispatcher dispatch KeyEvents generated by the user before
0N/A * finally dispatching the KeyEvent itself. KeyEventDispatchers will be
0N/A * notified in the order in which they were added. Notifications will halt
0N/A * as soon as one KeyEventDispatcher returns <code>true</code> from its
0N/A * <code>dispatchKeyEvent</code> method. There is no limit to the total
0N/A * number of KeyEventDispatchers which can be added, nor to the number of
0N/A * times which a particular KeyEventDispatcher instance can be added.
0N/A * <p>
0N/A * If a null dispatcher is specified, no action is taken and no exception
0N/A * is thrown.
0N/A * <p>
0N/A * In a multithreaded application, {@link KeyEventDispatcher} behaves
0N/A * the same as other AWT listeners. See
0N/A * <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for more details.
0N/A *
0N/A * @param dispatcher the KeyEventDispatcher to add to the dispatcher chain
0N/A * @see #removeKeyEventDispatcher
0N/A */
0N/A public void addKeyEventDispatcher(KeyEventDispatcher dispatcher) {
0N/A if (dispatcher != null) {
0N/A synchronized (this) {
0N/A if (keyEventDispatchers == null) {
0N/A keyEventDispatchers = new java.util.LinkedList();
0N/A }
0N/A keyEventDispatchers.add(dispatcher);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Removes a KeyEventDispatcher which was previously added to this
0N/A * KeyboardFocusManager's dispatcher chain. This KeyboardFocusManager
0N/A * cannot itself be removed, unless it was explicitly re-registered via a
0N/A * call to <code>addKeyEventDispatcher</code>.
0N/A * <p>
0N/A * If a null dispatcher is specified, if the specified dispatcher is not
0N/A * in the dispatcher chain, or if this KeyboardFocusManager is specified
0N/A * without having been explicitly re-registered, no action is taken and no
0N/A * exception is thrown.
0N/A * <p>
0N/A * In a multithreaded application, {@link KeyEventDispatcher} behaves
0N/A * the same as other AWT listeners. See
0N/A * <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for more details.
0N/A *
0N/A * @param dispatcher the KeyEventDispatcher to remove from the dispatcher
0N/A * chain
0N/A * @see #addKeyEventDispatcher
0N/A */
0N/A public void removeKeyEventDispatcher(KeyEventDispatcher dispatcher) {
0N/A if (dispatcher != null) {
0N/A synchronized (this) {
0N/A if (keyEventDispatchers != null) {
0N/A keyEventDispatchers.remove(dispatcher);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns this KeyboardFocusManager's KeyEventDispatcher chain as a List.
0N/A * The List will not include this KeyboardFocusManager unless it was
0N/A * explicitly re-registered via a call to
0N/A * <code>addKeyEventDispatcher</code>. If no other KeyEventDispatchers are
0N/A * registered, implementations are free to return null or a List of length
0N/A * 0. Client code should not assume one behavior over another, nor should
0N/A * it assume that the behavior, once established, will not change.
0N/A *
0N/A * @return a possibly null or empty List of KeyEventDispatchers
0N/A * @see #addKeyEventDispatcher
0N/A * @see #removeKeyEventDispatcher
0N/A */
0N/A protected synchronized java.util.List<KeyEventDispatcher>
0N/A getKeyEventDispatchers()
0N/A {
0N/A return (keyEventDispatchers != null)
0N/A ? (java.util.List)keyEventDispatchers.clone()
0N/A : null;
0N/A }
0N/A
0N/A /**
0N/A * Adds a KeyEventPostProcessor to this KeyboardFocusManager's post-
0N/A * processor chain. After a KeyEvent has been dispatched to and handled by
0N/A * its target, KeyboardFocusManager will request that each
0N/A * KeyEventPostProcessor perform any necessary post-processing as part
0N/A * of the KeyEvent's final resolution. KeyEventPostProcessors
0N/A * will be notified in the order in which they were added; the current
0N/A * KeyboardFocusManager will be notified last. Notifications will halt
0N/A * as soon as one KeyEventPostProcessor returns <code>true</code> from its
0N/A * <code>postProcessKeyEvent</code> method. There is no limit to the the
0N/A * total number of KeyEventPostProcessors that can be added, nor to the
0N/A * number of times that a particular KeyEventPostProcessor instance can be
0N/A * added.
0N/A * <p>
0N/A * If a null post-processor is specified, no action is taken and no
0N/A * exception is thrown.
0N/A * <p>
0N/A * In a multithreaded application, {@link KeyEventPostProcessor} behaves
0N/A * the same as other AWT listeners. See
0N/A * <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for more details.
0N/A *
0N/A * @param processor the KeyEventPostProcessor to add to the post-processor
0N/A * chain
0N/A * @see #removeKeyEventPostProcessor
0N/A */
0N/A public void addKeyEventPostProcessor(KeyEventPostProcessor processor) {
0N/A if (processor != null) {
0N/A synchronized (this) {
0N/A if (keyEventPostProcessors == null) {
0N/A keyEventPostProcessors = new java.util.LinkedList();
0N/A }
0N/A keyEventPostProcessors.add(processor);
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Removes a previously added KeyEventPostProcessor from this
0N/A * KeyboardFocusManager's post-processor chain. This KeyboardFocusManager
0N/A * cannot itself be entirely removed from the chain. Only additional
0N/A * references added via <code>addKeyEventPostProcessor</code> can be
0N/A * removed.
0N/A * <p>
0N/A * If a null post-processor is specified, if the specified post-processor
0N/A * is not in the post-processor chain, or if this KeyboardFocusManager is
0N/A * specified without having been explicitly added, no action is taken and
0N/A * no exception is thrown.
0N/A * <p>
0N/A * In a multithreaded application, {@link KeyEventPostProcessor} behaves
0N/A * the same as other AWT listeners. See
0N/A * <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for more details.
0N/A *
0N/A * @param processor the KeyEventPostProcessor to remove from the post-
0N/A * processor chain
0N/A * @see #addKeyEventPostProcessor
0N/A */
0N/A public void removeKeyEventPostProcessor(KeyEventPostProcessor processor) {
0N/A if (processor != null) {
0N/A synchronized (this) {
0N/A if (keyEventPostProcessors != null) {
0N/A keyEventPostProcessors.remove(processor);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns this KeyboardFocusManager's KeyEventPostProcessor chain as a
0N/A * List. The List will not include this KeyboardFocusManager unless it was
0N/A * explicitly added via a call to <code>addKeyEventPostProcessor</code>. If
0N/A * no KeyEventPostProcessors are registered, implementations are free to
0N/A * return null or a List of length 0. Client code should not assume one
0N/A * behavior over another, nor should it assume that the behavior, once
0N/A * established, will not change.
0N/A *
0N/A * @return a possibly null or empty List of KeyEventPostProcessors
0N/A * @see #addKeyEventPostProcessor
0N/A * @see #removeKeyEventPostProcessor
0N/A */
0N/A protected java.util.List<KeyEventPostProcessor>
0N/A getKeyEventPostProcessors()
0N/A {
0N/A return (keyEventPostProcessors != null)
0N/A ? (java.util.List)keyEventPostProcessors.clone()
0N/A : null;
0N/A }
0N/A
0N/A
0N/A
0N/A static void setMostRecentFocusOwner(Component component) {
0N/A Component window = component;
0N/A while (window != null && !(window instanceof Window)) {
0N/A window = window.parent;
0N/A }
0N/A if (window != null) {
0N/A setMostRecentFocusOwner((Window)window, component);
0N/A }
0N/A }
0N/A static synchronized void setMostRecentFocusOwner(Window window,
0N/A Component component) {
0N/A // ATTN: component has a strong reference to window via chain
0N/A // of Component.parent fields. Since WeakHasMap refers to its
0N/A // values strongly, we need to break the strong link from the
0N/A // value (component) back to its key (window).
0N/A WeakReference weakValue = null;
0N/A if (component != null) {
0N/A weakValue = new WeakReference(component);
0N/A }
0N/A mostRecentFocusOwners.put(window, weakValue);
0N/A }
0N/A static void clearMostRecentFocusOwner(Component comp) {
0N/A Container window;
0N/A
0N/A if (comp == null) {
0N/A return;
0N/A }
0N/A
0N/A synchronized (comp.getTreeLock()) {
0N/A window = comp.getParent();
0N/A while (window != null && !(window instanceof Window)) {
0N/A window = window.getParent();
0N/A }
0N/A }
0N/A
0N/A synchronized (KeyboardFocusManager.class) {
0N/A if ((window != null)
0N/A && (getMostRecentFocusOwner((Window)window) == comp))
0N/A {
0N/A setMostRecentFocusOwner((Window)window, null);
0N/A }
0N/A // Also clear temporary lost component stored in Window
0N/A if (window != null) {
0N/A Window realWindow = (Window)window;
0N/A if (realWindow.getTemporaryLostComponent() == comp) {
0N/A realWindow.setTemporaryLostComponent(null);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * Please be careful changing this method! It is called from
0N/A * javax.swing.JComponent.runInputVerifier() using reflection.
0N/A */
0N/A static synchronized Component getMostRecentFocusOwner(Window window) {
0N/A WeakReference weakValue =
0N/A (WeakReference)mostRecentFocusOwners.get(window);
0N/A return weakValue == null ? null : (Component)weakValue.get();
0N/A }
0N/A
0N/A /**
0N/A * This method is called by the AWT event dispatcher requesting that the
0N/A * current KeyboardFocusManager dispatch the specified event on its behalf.
0N/A * It is expected that all KeyboardFocusManagers will dispatch all
0N/A * FocusEvents, all WindowEvents related to focus, and all KeyEvents.
0N/A * These events should be dispatched based on the KeyboardFocusManager's
0N/A * notion of the focus owner and the focused and active Windows, sometimes
0N/A * overriding the source of the specified AWTEvent. Dispatching must be
0N/A * done using <code>redispatchEvent</code> to prevent the AWT event
0N/A * dispatcher from recursively requesting that the KeyboardFocusManager
0N/A * dispatch the event again. If this method returns <code>false</code>,
0N/A * then the AWT event dispatcher will attempt to dispatch the event itself.
0N/A *
0N/A * @param e the AWTEvent to be dispatched
0N/A * @return <code>true</code> if this method dispatched the event;
0N/A * <code>false</code> otherwise
0N/A * @see #redispatchEvent
0N/A * @see #dispatchKeyEvent
0N/A */
0N/A public abstract boolean dispatchEvent(AWTEvent e);
0N/A
0N/A /**
0N/A * Redispatches an AWTEvent in such a way that the AWT event dispatcher
0N/A * will not recursively request that the KeyboardFocusManager, or any
0N/A * installed KeyEventDispatchers, dispatch the event again. Client
0N/A * implementations of <code>dispatchEvent</code> and client-defined
0N/A * KeyEventDispatchers must call <code>redispatchEvent(target, e)</code>
0N/A * instead of <code>target.dispatchEvent(e)</code> to dispatch an event.
0N/A * <p>
0N/A * This method is intended to be used only by KeyboardFocusManagers and
0N/A * KeyEventDispatchers. It is not for general client use.
0N/A *
0N/A * @param target the Component to which the event should be dispatched
0N/A * @param e the event to dispatch
0N/A * @see #dispatchEvent
0N/A * @see KeyEventDispatcher
0N/A */
0N/A public final void redispatchEvent(Component target, AWTEvent e) {
0N/A e.focusManagerIsDispatching = true;
0N/A target.dispatchEvent(e);
0N/A e.focusManagerIsDispatching = false;
0N/A }
0N/A
0N/A /**
0N/A * Typically this method will be called by <code>dispatchEvent</code> if no
0N/A * other KeyEventDispatcher in the dispatcher chain dispatched the
0N/A * KeyEvent, or if no other KeyEventDispatchers are registered. If an
0N/A * implementation of this method returns <code>false</code>,
0N/A * <code>dispatchEvent</code> may try to dispatch the KeyEvent itself, or
0N/A * may simply return <code>false</code>. If <code>true</code> is returned,
0N/A * <code>dispatchEvent</code> should return <code>true</code> as well.
0N/A *
0N/A * @param e the KeyEvent which the current KeyboardFocusManager has
0N/A * requested that this KeyEventDispatcher dispatch
0N/A * @return <code>true</code> if the KeyEvent was dispatched;
0N/A * <code>false</code> otherwise
0N/A * @see #dispatchEvent
0N/A */
0N/A public abstract boolean dispatchKeyEvent(KeyEvent e);
0N/A
0N/A /**
0N/A * This method will be called by <code>dispatchKeyEvent</code>.
0N/A * By default, this method will handle any unconsumed KeyEvents that
0N/A * map to an AWT <code>MenuShortcut</code> by consuming the event
0N/A * and activating the shortcut.
0N/A *
0N/A * @param e the KeyEvent to post-process
0N/A * @return <code>true</code> to indicate that no other
0N/A * KeyEventPostProcessor will be notified of the KeyEvent.
0N/A * @see #dispatchKeyEvent
0N/A * @see MenuShortcut
0N/A */
0N/A public abstract boolean postProcessKeyEvent(KeyEvent e);
0N/A
0N/A /**
0N/A * This method initiates a focus traversal operation if and only if the
0N/A * KeyEvent represents a focus traversal key for the specified
0N/A * focusedComponent. It is expected that focusedComponent is the current
0N/A * focus owner, although this need not be the case. If it is not,
0N/A * focus traversal will nevertheless proceed as if focusedComponent
0N/A * were the current focus owner.
0N/A *
0N/A * @param focusedComponent the Component that will be the basis for a focus
0N/A * traversal operation if the specified event represents a focus
0N/A * traversal key for the Component
0N/A * @param e the event that may represent a focus traversal key
0N/A */
0N/A public abstract void processKeyEvent(Component focusedComponent,
0N/A KeyEvent e);
0N/A
0N/A /**
0N/A * Called by the AWT to notify the KeyboardFocusManager that it should
0N/A * delay dispatching of KeyEvents until the specified Component becomes
0N/A * the focus owner. If client code requests a focus change, and the AWT
0N/A * determines that this request might be granted by the native windowing
0N/A * system, then the AWT will call this method. It is the responsibility of
0N/A * the KeyboardFocusManager to delay dispatching of KeyEvents with
0N/A * timestamps later than the specified time stamp until the specified
0N/A * Component receives a FOCUS_GAINED event, or the AWT cancels the delay
0N/A * request by invoking <code>dequeueKeyEvents</code> or
0N/A * <code>discardKeyEvents</code>.
0N/A *
0N/A * @param after timestamp of current event, or the current, system time if
0N/A * the current event has no timestamp, or the AWT cannot determine
0N/A * which event is currently being handled
0N/A * @param untilFocused Component which should receive a FOCUS_GAINED event
0N/A * before any pending KeyEvents
0N/A * @see #dequeueKeyEvents
0N/A * @see #discardKeyEvents
0N/A */
0N/A protected abstract void enqueueKeyEvents(long after,
0N/A Component untilFocused);
0N/A
0N/A /**
0N/A * Called by the AWT to notify the KeyboardFocusManager that it should
0N/A * cancel delayed dispatching of KeyEvents. All KeyEvents which were
0N/A * enqueued because of a call to <code>enqueueKeyEvents</code> with the
0N/A * same timestamp and Component should be released for normal dispatching
0N/A * to the current focus owner. If the given timestamp is less than zero,
0N/A * the outstanding enqueue request for the given Component with the <b>
0N/A * oldest</b> timestamp (if any) should be cancelled.
0N/A *
0N/A * @param after the timestamp specified in the call to
0N/A * <code>enqueueKeyEvents</code>, or any value < 0
0N/A * @param untilFocused the Component specified in the call to
0N/A * <code>enqueueKeyEvents</code>
0N/A * @see #enqueueKeyEvents
0N/A * @see #discardKeyEvents
0N/A */
0N/A protected abstract void dequeueKeyEvents(long after,
0N/A Component untilFocused);
0N/A
0N/A /**
0N/A * Called by the AWT to notify the KeyboardFocusManager that it should
0N/A * cancel delayed dispatching of KeyEvents. All KeyEvents which were
0N/A * enqueued because of one or more calls to <code>enqueueKeyEvents</code>
0N/A * with the same Component should be discarded.
0N/A *
0N/A * @param comp the Component specified in one or more calls to
0N/A * <code>enqueueKeyEvents</code>
0N/A * @see #enqueueKeyEvents
0N/A * @see #dequeueKeyEvents
0N/A */
0N/A protected abstract void discardKeyEvents(Component comp);
0N/A
0N/A /**
0N/A * Focuses the Component after aComponent, typically based on a
0N/A * FocusTraversalPolicy.
0N/A *
0N/A * @param aComponent the Component that is the basis for the focus
0N/A * traversal operation
0N/A * @see FocusTraversalPolicy
0N/A */
0N/A public abstract void focusNextComponent(Component aComponent);
0N/A
0N/A /**
0N/A * Focuses the Component before aComponent, typically based on a
0N/A * FocusTraversalPolicy.
0N/A *
0N/A * @param aComponent the Component that is the basis for the focus
0N/A * traversal operation
0N/A * @see FocusTraversalPolicy
0N/A */
0N/A public abstract void focusPreviousComponent(Component aComponent);
0N/A
0N/A /**
0N/A * Moves the focus up one focus traversal cycle. Typically, the focus owner
0N/A * is set to aComponent's focus cycle root, and the current focus cycle
0N/A * root is set to the new focus owner's focus cycle root. If, however,
0N/A * aComponent's focus cycle root is a Window, then typically the focus
0N/A * owner is set to the Window's default Component to focus, and the current
0N/A * focus cycle root is unchanged.
0N/A *
0N/A * @param aComponent the Component that is the basis for the focus
0N/A * traversal operation
0N/A */
0N/A public abstract void upFocusCycle(Component aComponent);
0N/A
0N/A /**
0N/A * Moves the focus down one focus traversal cycle. Typically, if
0N/A * aContainer is a focus cycle root, then the focus owner is set to
0N/A * aContainer's default Component to focus, and the current focus cycle
0N/A * root is set to aContainer. If aContainer is not a focus cycle root, then
0N/A * no focus traversal operation occurs.
0N/A *
0N/A * @param aContainer the Container that is the basis for the focus
0N/A * traversal operation
0N/A */
0N/A public abstract void downFocusCycle(Container aContainer);
0N/A
0N/A /**
0N/A * Focuses the Component after the current focus owner.
0N/A */
0N/A public final void focusNextComponent() {
0N/A Component focusOwner = getFocusOwner();
0N/A if (focusOwner != null) {
0N/A focusNextComponent(focusOwner);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Focuses the Component before the current focus owner.
0N/A */
0N/A public final void focusPreviousComponent() {
0N/A Component focusOwner = getFocusOwner();
0N/A if (focusOwner != null) {
0N/A focusPreviousComponent(focusOwner);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Moves the focus up one focus traversal cycle from the current focus
0N/A * owner. Typically, the new focus owner is set to the current focus
0N/A * owner's focus cycle root, and the current focus cycle root is set to the
0N/A * new focus owner's focus cycle root. If, however, the current focus
0N/A * owner's focus cycle root is a Window, then typically the focus owner is
0N/A * set to the focus cycle root's default Component to focus, and the
0N/A * current focus cycle root is unchanged.
0N/A */
0N/A public final void upFocusCycle() {
0N/A Component focusOwner = getFocusOwner();
0N/A if (focusOwner != null) {
0N/A upFocusCycle(focusOwner);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Moves the focus down one focus traversal cycle from the current focus
0N/A * owner, if and only if the current focus owner is a Container that is a
0N/A * focus cycle root. Typically, the focus owner is set to the current focus
0N/A * owner's default Component to focus, and the current focus cycle root is
0N/A * set to the current focus owner. If the current focus owner is not a
0N/A * Container that is a focus cycle root, then no focus traversal operation
0N/A * occurs.
0N/A */
0N/A public final void downFocusCycle() {
0N/A Component focusOwner = getFocusOwner();
0N/A if (focusOwner instanceof Container) {
0N/A downFocusCycle((Container)focusOwner);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Dumps the list of focus requests to stderr
0N/A */
0N/A void dumpRequests() {
0N/A System.err.println(">>> Requests dump, time: " + System.currentTimeMillis());
0N/A synchronized (heavyweightRequests) {
0N/A for (HeavyweightFocusRequest req : heavyweightRequests) {
0N/A System.err.println(">>> Req: " + req);
0N/A }
0N/A }
0N/A System.err.println("");
0N/A }
0N/A
0N/A private static final class LightweightFocusRequest {
0N/A final Component component;
0N/A final boolean temporary;
0N/A final CausedFocusEvent.Cause cause;
0N/A
0N/A LightweightFocusRequest(Component component, boolean temporary, CausedFocusEvent.Cause cause) {
0N/A this.component = component;
0N/A this.temporary = temporary;
0N/A this.cause = cause;
0N/A }
0N/A public String toString() {
0N/A return "LightweightFocusRequest[component=" + component +
0N/A ",temporary=" + temporary + ", cause=" + cause + "]";
0N/A }
0N/A }
0N/A
0N/A private static final class HeavyweightFocusRequest {
0N/A final Component heavyweight;
0N/A final LinkedList<LightweightFocusRequest> lightweightRequests;
0N/A
0N/A static final HeavyweightFocusRequest CLEAR_GLOBAL_FOCUS_OWNER =
0N/A new HeavyweightFocusRequest();
0N/A
0N/A private HeavyweightFocusRequest() {
0N/A heavyweight = null;
0N/A lightweightRequests = null;
0N/A }
0N/A
0N/A HeavyweightFocusRequest(Component heavyweight, Component descendant,
0N/A boolean temporary, CausedFocusEvent.Cause cause) {
1979N/A if (log.isLoggable(PlatformLogger.FINE)) {
0N/A if (heavyweight == null) {
1979N/A log.fine("Assertion (heavyweight != null) failed");
0N/A }
0N/A }
0N/A
0N/A this.heavyweight = heavyweight;
0N/A this.lightweightRequests = new LinkedList<LightweightFocusRequest>();
0N/A addLightweightRequest(descendant, temporary, cause);
0N/A }
0N/A boolean addLightweightRequest(Component descendant,
0N/A boolean temporary, CausedFocusEvent.Cause cause) {
1979N/A if (log.isLoggable(PlatformLogger.FINE)) {
0N/A if (this == HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER) {
1979N/A log.fine("Assertion (this != HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER) failed");
0N/A }
0N/A if (descendant == null) {
1979N/A log.fine("Assertion (descendant != null) failed");
0N/A }
0N/A }
0N/A
0N/A Component lastDescendant = ((lightweightRequests.size() > 0)
0N/A ? lightweightRequests.getLast().component
0N/A : null);
0N/A
0N/A if (descendant != lastDescendant) {
0N/A // Not a duplicate request
0N/A lightweightRequests.add
0N/A (new LightweightFocusRequest(descendant, temporary, cause));
0N/A return true;
0N/A } else {
0N/A return false;
0N/A }
0N/A }
0N/A
0N/A LightweightFocusRequest getFirstLightweightRequest() {
0N/A if (this == CLEAR_GLOBAL_FOCUS_OWNER) {
0N/A return null;
0N/A }
0N/A return lightweightRequests.getFirst();
0N/A }
0N/A public String toString() {
0N/A boolean first = true;
0N/A String str = "HeavyweightFocusRequest[heavweight=" + heavyweight +
0N/A ",lightweightRequests=";
0N/A if (lightweightRequests == null) {
0N/A str += null;
0N/A } else {
0N/A str += "[";
0N/A
0N/A for (LightweightFocusRequest lwRequest : lightweightRequests) {
0N/A if (first) {
0N/A first = false;
0N/A } else {
0N/A str += ",";
0N/A }
0N/A str += lwRequest;
0N/A }
0N/A str += "]";
0N/A }
0N/A str += "]";
0N/A return str;
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * heavyweightRequests is used as a monitor for synchronized changes of
0N/A * currentLightweightRequests, clearingCurrentLightweightRequests and
0N/A * newFocusOwner.
0N/A */
0N/A private static LinkedList<HeavyweightFocusRequest> heavyweightRequests =
0N/A new LinkedList<HeavyweightFocusRequest>();
0N/A private static LinkedList<LightweightFocusRequest> currentLightweightRequests;
0N/A private static boolean clearingCurrentLightweightRequests;
0N/A private static boolean allowSyncFocusRequests = true;
0N/A private static Component newFocusOwner = null;
0N/A private static volatile boolean disableRestoreFocus;
0N/A
0N/A static final int SNFH_FAILURE = 0;
0N/A static final int SNFH_SUCCESS_HANDLED = 1;
0N/A static final int SNFH_SUCCESS_PROCEED = 2;
0N/A
0N/A static boolean processSynchronousLightweightTransfer(Component heavyweight, Component descendant,
0N/A boolean temporary, boolean focusedWindowChangeAllowed,
0N/A long time)
0N/A {
1045N/A Window parentWindow = SunToolkit.getContainingWindow(heavyweight);
0N/A if (parentWindow == null || !parentWindow.syncLWRequests) {
0N/A return false;
0N/A }
0N/A if (descendant == null) {
0N/A // Focus transfers from a lightweight child back to the
0N/A // heavyweight Container should be treated like lightweight
0N/A // focus transfers.
0N/A descendant = heavyweight;
0N/A }
0N/A
0N/A KeyboardFocusManager manager = getCurrentKeyboardFocusManager(SunToolkit.targetToAppContext(descendant));
0N/A
0N/A FocusEvent currentFocusOwnerEvent = null;
0N/A FocusEvent newFocusOwnerEvent = null;
0N/A Component currentFocusOwner = manager.getGlobalFocusOwner();
0N/A
0N/A synchronized (heavyweightRequests) {
0N/A HeavyweightFocusRequest hwFocusRequest = getLastHWRequest();
0N/A if (hwFocusRequest == null &&
0N/A heavyweight == manager.getNativeFocusOwner() &&
0N/A allowSyncFocusRequests)
0N/A {
0N/A
0N/A if (descendant == currentFocusOwner) {
0N/A // Redundant request.
0N/A return true;
0N/A }
0N/A
0N/A // 'heavyweight' owns the native focus and there are no pending
0N/A // requests. 'heavyweight' must be a Container and
0N/A // 'descendant' must not be the focus owner. Otherwise,
0N/A // we would never have gotten this far.
0N/A manager.enqueueKeyEvents(time, descendant);
0N/A
0N/A hwFocusRequest =
0N/A new HeavyweightFocusRequest(heavyweight, descendant,
0N/A temporary, CausedFocusEvent.Cause.UNKNOWN);
0N/A heavyweightRequests.add(hwFocusRequest);
0N/A
0N/A if (currentFocusOwner != null) {
0N/A currentFocusOwnerEvent =
0N/A new FocusEvent(currentFocusOwner,
0N/A FocusEvent.FOCUS_LOST,
0N/A temporary, descendant);
0N/A }
0N/A newFocusOwnerEvent =
0N/A new FocusEvent(descendant, FocusEvent.FOCUS_GAINED,
0N/A temporary, currentFocusOwner);
0N/A }
0N/A }
0N/A boolean result = false;
0N/A final boolean clearing = clearingCurrentLightweightRequests;
0N/A
0N/A Throwable caughtEx = null;
0N/A try {
0N/A clearingCurrentLightweightRequests = false;
0N/A synchronized(Component.LOCK) {
0N/A
0N/A if (currentFocusOwnerEvent != null && currentFocusOwner != null) {
0N/A ((AWTEvent) currentFocusOwnerEvent).isPosted = true;
0N/A caughtEx = dispatchAndCatchException(caughtEx, currentFocusOwner, currentFocusOwnerEvent);
0N/A result = true;
0N/A }
0N/A
0N/A if (newFocusOwnerEvent != null && descendant != null) {
0N/A ((AWTEvent) newFocusOwnerEvent).isPosted = true;
0N/A caughtEx = dispatchAndCatchException(caughtEx, descendant, newFocusOwnerEvent);
0N/A result = true;
0N/A }
0N/A }
0N/A } finally {
0N/A clearingCurrentLightweightRequests = clearing;
0N/A }
0N/A if (caughtEx instanceof RuntimeException) {
0N/A throw (RuntimeException)caughtEx;
0N/A } else if (caughtEx instanceof Error) {
0N/A throw (Error)caughtEx;
0N/A }
0N/A return result;
0N/A }
0N/A
0N/A /**
0N/A * Indicates whether the native implementation should proceed with a
0N/A * pending, native focus request. Before changing the focus at the native
0N/A * level, the AWT implementation should always call this function for
0N/A * permission. This function will reject the request if a duplicate request
0N/A * preceded it, or if the specified heavyweight Component already owns the
0N/A * focus and no native focus changes are pending. Otherwise, the request
0N/A * will be approved and the focus request list will be updated so that,
0N/A * if necessary, the proper descendant will be focused when the
0N/A * corresponding FOCUS_GAINED event on the heavyweight is received.
0N/A *
0N/A * An implementation must ensure that calls to this method and native
0N/A * focus changes are atomic. If this is not guaranteed, then the ordering
0N/A * of the focus request list may be incorrect, leading to errors in the
0N/A * type-ahead mechanism. Typically this is accomplished by only calling
0N/A * this function from the native event pumping thread, or by holding a
0N/A * global, native lock during invocation.
0N/A */
0N/A static int shouldNativelyFocusHeavyweight
0N/A (Component heavyweight, Component descendant, boolean temporary,
0N/A boolean focusedWindowChangeAllowed, long time, CausedFocusEvent.Cause cause)
0N/A {
1979N/A if (log.isLoggable(PlatformLogger.FINE)) {
0N/A if (heavyweight == null) {
1979N/A log.fine("Assertion (heavyweight != null) failed");
0N/A }
0N/A if (time == 0) {
1979N/A log.fine("Assertion (time != 0) failed");
0N/A }
0N/A }
0N/A
0N/A if (descendant == null) {
0N/A // Focus transfers from a lightweight child back to the
0N/A // heavyweight Container should be treated like lightweight
0N/A // focus transfers.
0N/A descendant = heavyweight;
0N/A }
0N/A
0N/A KeyboardFocusManager manager =
0N/A getCurrentKeyboardFocusManager(SunToolkit.targetToAppContext(descendant));
0N/A KeyboardFocusManager thisManager = getCurrentKeyboardFocusManager();
0N/A Component currentFocusOwner = thisManager.getGlobalFocusOwner();
0N/A Component nativeFocusOwner = thisManager.getNativeFocusOwner();
0N/A Window nativeFocusedWindow = thisManager.getNativeFocusedWindow();
1979N/A if (focusLog.isLoggable(PlatformLogger.FINER)) {
1979N/A focusLog.finer("SNFH for {0} in {1}",
1979N/A String.valueOf(descendant), String.valueOf(heavyweight));
0N/A }
1979N/A if (focusLog.isLoggable(PlatformLogger.FINEST)) {
1979N/A focusLog.finest("0. Current focus owner {0}",
1979N/A String.valueOf(currentFocusOwner));
1979N/A focusLog.finest("0. Native focus owner {0}",
1979N/A String.valueOf(nativeFocusOwner));
1979N/A focusLog.finest("0. Native focused window {0}",
1979N/A String.valueOf(nativeFocusedWindow));
0N/A }
0N/A synchronized (heavyweightRequests) {
0N/A HeavyweightFocusRequest hwFocusRequest = getLastHWRequest();
1979N/A if (focusLog.isLoggable(PlatformLogger.FINEST)) {
1979N/A focusLog.finest("Request {0}", String.valueOf(hwFocusRequest));
0N/A }
0N/A if (hwFocusRequest == null &&
0N/A heavyweight == nativeFocusOwner)
0N/A {
0N/A if (descendant == currentFocusOwner) {
0N/A // Redundant request.
1979N/A if (focusLog.isLoggable(PlatformLogger.FINEST))
1979N/A focusLog.finest("1. SNFH_FAILURE for {0}",
1979N/A String.valueOf(descendant));
0N/A return SNFH_FAILURE;
0N/A }
0N/A
0N/A // 'heavyweight' owns the native focus and there are no pending
0N/A // requests. 'heavyweight' must be a Container and
0N/A // 'descendant' must not be the focus owner. Otherwise,
0N/A // we would never have gotten this far.
0N/A manager.enqueueKeyEvents(time, descendant);
0N/A
0N/A hwFocusRequest =
0N/A new HeavyweightFocusRequest(heavyweight, descendant,
0N/A temporary, cause);
0N/A heavyweightRequests.add(hwFocusRequest);
0N/A
0N/A if (currentFocusOwner != null) {
0N/A FocusEvent currentFocusOwnerEvent =
0N/A new CausedFocusEvent(currentFocusOwner,
0N/A FocusEvent.FOCUS_LOST,
0N/A temporary, descendant, cause);
0N/A // Fix 5028014. Rolled out.
0N/A // SunToolkit.postPriorityEvent(currentFocusOwnerEvent);
0N/A SunToolkit.postEvent(currentFocusOwner.appContext,
0N/A currentFocusOwnerEvent);
0N/A }
0N/A FocusEvent newFocusOwnerEvent =
0N/A new CausedFocusEvent(descendant, FocusEvent.FOCUS_GAINED,
0N/A temporary, currentFocusOwner, cause);
0N/A // Fix 5028014. Rolled out.
0N/A // SunToolkit.postPriorityEvent(newFocusOwnerEvent);
0N/A SunToolkit.postEvent(descendant.appContext, newFocusOwnerEvent);
0N/A
1979N/A if (focusLog.isLoggable(PlatformLogger.FINEST))
1979N/A focusLog.finest("2. SNFH_HANDLED for {0}", String.valueOf(descendant));
0N/A return SNFH_SUCCESS_HANDLED;
0N/A } else if (hwFocusRequest != null &&
0N/A hwFocusRequest.heavyweight == heavyweight) {
0N/A // 'heavyweight' doesn't have the native focus right now, but
0N/A // if all pending requests were completed, it would. Add
0N/A // descendant to the heavyweight's list of pending
0N/A // lightweight focus transfers.
0N/A if (hwFocusRequest.addLightweightRequest(descendant,
0N/A temporary, cause)) {
0N/A manager.enqueueKeyEvents(time, descendant);
0N/A }
0N/A
1979N/A if (focusLog.isLoggable(PlatformLogger.FINEST))
0N/A focusLog.finest("3. SNFH_HANDLED for lightweight" +
0N/A descendant + " in " + heavyweight);
0N/A return SNFH_SUCCESS_HANDLED;
0N/A } else {
0N/A if (!focusedWindowChangeAllowed) {
0N/A // For purposes of computing oldFocusedWindow, we should look at
0N/A // the second to last HeavyweightFocusRequest on the queue iff the
0N/A // last HeavyweightFocusRequest is CLEAR_GLOBAL_FOCUS_OWNER. If
0N/A // there is no second to last HeavyweightFocusRequest, null is an
0N/A // acceptable value.
0N/A if (hwFocusRequest ==
0N/A HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER)
0N/A {
0N/A int size = heavyweightRequests.size();
0N/A hwFocusRequest = (HeavyweightFocusRequest)((size >= 2)
0N/A ? heavyweightRequests.get(size - 2)
0N/A : null);
0N/A }
0N/A if (focusedWindowChanged(heavyweight,
0N/A (hwFocusRequest != null)
0N/A ? hwFocusRequest.heavyweight
0N/A : nativeFocusedWindow)) {
1979N/A if (focusLog.isLoggable(PlatformLogger.FINEST))
0N/A focusLog.finest("4. SNFH_FAILURE for " + descendant);
0N/A return SNFH_FAILURE;
0N/A }
0N/A }
0N/A
0N/A manager.enqueueKeyEvents(time, descendant);
0N/A heavyweightRequests.add
0N/A (new HeavyweightFocusRequest(heavyweight, descendant,
0N/A temporary, cause));
1979N/A if (focusLog.isLoggable(PlatformLogger.FINEST))
0N/A focusLog.finest("5. SNFH_PROCEED for " + descendant);
0N/A return SNFH_SUCCESS_PROCEED;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the Window which will be active after processing this request,
0N/A * or null if this is a duplicate request. The active Window is useful
0N/A * because some native platforms do not support setting the native focus
0N/A * owner to null. On these platforms, the obvious choice is to set the
0N/A * focus owner to the focus proxy of the active Window.
0N/A */
0N/A static Window markClearGlobalFocusOwner() {
0N/A // need to call this out of synchronized block to avoid possible deadlock
0N/A // see 6454631.
0N/A final Component nativeFocusedWindow =
0N/A getCurrentKeyboardFocusManager().getNativeFocusedWindow();
0N/A
0N/A synchronized (heavyweightRequests) {
0N/A HeavyweightFocusRequest hwFocusRequest = getLastHWRequest();
0N/A if (hwFocusRequest ==
0N/A HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER)
0N/A {
0N/A // duplicate request
0N/A return null;
0N/A }
0N/A
0N/A heavyweightRequests.add
0N/A (HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER);
0N/A
0N/A Component activeWindow = ((hwFocusRequest != null)
1045N/A ? SunToolkit.getContainingWindow(hwFocusRequest.heavyweight)
0N/A : nativeFocusedWindow);
0N/A while (activeWindow != null &&
0N/A !((activeWindow instanceof Frame) ||
0N/A (activeWindow instanceof Dialog)))
0N/A {
0N/A activeWindow = activeWindow.getParent_NoClientCode();
0N/A }
0N/A
0N/A return (Window) activeWindow;
0N/A }
0N/A }
0N/A Component getCurrentWaitingRequest(Component parent) {
0N/A synchronized (heavyweightRequests) {
0N/A HeavyweightFocusRequest hwFocusRequest = getFirstHWRequest();
0N/A if (hwFocusRequest != null) {
0N/A if (hwFocusRequest.heavyweight == parent) {
0N/A LightweightFocusRequest lwFocusRequest =
0N/A hwFocusRequest.lightweightRequests.getFirst();
0N/A if (lwFocusRequest != null) {
0N/A return lwFocusRequest.component;
0N/A }
0N/A }
0N/A }
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A static boolean isAutoFocusTransferEnabled() {
0N/A synchronized (heavyweightRequests) {
0N/A return (heavyweightRequests.size() == 0)
0N/A && !disableRestoreFocus
0N/A && (null == currentLightweightRequests);
0N/A }
0N/A }
0N/A
218N/A static boolean isAutoFocusTransferEnabledFor(Component comp) {
218N/A return isAutoFocusTransferEnabled() && comp.isAutoFocusTransferOnDisposal();
218N/A }
218N/A
0N/A /*
0N/A * Used to process exceptions in dispatching focus event (in focusLost/focusGained callbacks).
0N/A * @param ex previously caught exception that may be processed right here, or null
0N/A * @param comp the component to dispatch the event to
0N/A * @param event the event to dispatch to the component
0N/A */
0N/A static private Throwable dispatchAndCatchException(Throwable ex, Component comp, FocusEvent event) {
0N/A Throwable retEx = null;
0N/A try {
0N/A comp.dispatchEvent(event);
0N/A } catch (RuntimeException re) {
0N/A retEx = re;
0N/A } catch (Error er) {
0N/A retEx = er;
0N/A }
0N/A if (retEx != null) {
0N/A if (ex != null) {
0N/A handleException(ex);
0N/A }
0N/A return retEx;
0N/A }
0N/A return ex;
0N/A }
0N/A
0N/A static private void handleException(Throwable ex) {
0N/A ex.printStackTrace();
0N/A }
0N/A
0N/A static void processCurrentLightweightRequests() {
0N/A KeyboardFocusManager manager = getCurrentKeyboardFocusManager();
0N/A LinkedList<LightweightFocusRequest> localLightweightRequests = null;
0N/A
0N/A Component globalFocusOwner = manager.getGlobalFocusOwner();
0N/A if ((globalFocusOwner != null) &&
0N/A (globalFocusOwner.appContext != AppContext.getAppContext()))
0N/A {
0N/A // The current app context differs from the app context of a focus
0N/A // owner (and all pending lightweight requests), so we do nothing
0N/A // now and wait for a next event.
0N/A return;
0N/A }
0N/A
0N/A synchronized(heavyweightRequests) {
0N/A if (currentLightweightRequests != null) {
0N/A clearingCurrentLightweightRequests = true;
0N/A disableRestoreFocus = true;
0N/A localLightweightRequests = currentLightweightRequests;
0N/A allowSyncFocusRequests = (localLightweightRequests.size() < 2);
0N/A currentLightweightRequests = null;
0N/A } else {
0N/A // do nothing
0N/A return;
0N/A }
0N/A }
0N/A
0N/A Throwable caughtEx = null;
0N/A try {
0N/A if (localLightweightRequests != null) {
0N/A Component lastFocusOwner = null;
0N/A Component currentFocusOwner = null;
0N/A
0N/A for (Iterator iter = localLightweightRequests.iterator(); iter.hasNext(); ) {
0N/A
0N/A currentFocusOwner = manager.getGlobalFocusOwner();
0N/A LightweightFocusRequest lwFocusRequest =
0N/A (LightweightFocusRequest)iter.next();
0N/A
0N/A /*
0N/A * WARNING: This is based on DKFM's logic solely!
0N/A *
0N/A * We allow to trigger restoreFocus() in the dispatching process
0N/A * only if we have the last request to dispatch. If the last request
0N/A * fails, focus will be restored to either the component of the last
0N/A * previously succedded request, or to to the focus owner that was
0N/A * before this clearing proccess.
0N/A */
0N/A if (!iter.hasNext()) {
0N/A disableRestoreFocus = false;
0N/A }
0N/A
0N/A FocusEvent currentFocusOwnerEvent = null;
0N/A /*
0N/A * We're not dispatching FOCUS_LOST while the current focus owner is null.
0N/A * But regardless of whether it's null or not, we're clearing ALL the local
0N/A * lw requests.
0N/A */
0N/A if (currentFocusOwner != null) {
0N/A currentFocusOwnerEvent = new CausedFocusEvent(currentFocusOwner,
0N/A FocusEvent.FOCUS_LOST,
0N/A lwFocusRequest.temporary,
0N/A lwFocusRequest.component, lwFocusRequest.cause);
0N/A }
0N/A FocusEvent newFocusOwnerEvent =
0N/A new CausedFocusEvent(lwFocusRequest.component,
0N/A FocusEvent.FOCUS_GAINED,
0N/A lwFocusRequest.temporary,
0N/A currentFocusOwner == null ? lastFocusOwner : currentFocusOwner,
0N/A lwFocusRequest.cause);
0N/A
0N/A if (currentFocusOwner != null) {
0N/A ((AWTEvent) currentFocusOwnerEvent).isPosted = true;
0N/A caughtEx = dispatchAndCatchException(caughtEx, currentFocusOwner, currentFocusOwnerEvent);
0N/A }
0N/A
0N/A ((AWTEvent) newFocusOwnerEvent).isPosted = true;
0N/A caughtEx = dispatchAndCatchException(caughtEx, lwFocusRequest.component, newFocusOwnerEvent);
0N/A
0N/A if (manager.getGlobalFocusOwner() == lwFocusRequest.component) {
0N/A lastFocusOwner = lwFocusRequest.component;
0N/A }
0N/A }
0N/A }
0N/A } finally {
0N/A clearingCurrentLightweightRequests = false;
0N/A disableRestoreFocus = false;
0N/A localLightweightRequests = null;
0N/A allowSyncFocusRequests = true;
0N/A }
0N/A if (caughtEx instanceof RuntimeException) {
0N/A throw (RuntimeException)caughtEx;
0N/A } else if (caughtEx instanceof Error) {
0N/A throw (Error)caughtEx;
0N/A }
0N/A }
0N/A
0N/A static FocusEvent retargetUnexpectedFocusEvent(FocusEvent fe) {
0N/A synchronized (heavyweightRequests) {
0N/A // Any other case represents a failure condition which we did
0N/A // not expect. We need to clearFocusRequestList() and patch up
0N/A // the event as best as possible.
0N/A
0N/A if (removeFirstRequest()) {
0N/A return (FocusEvent)retargetFocusEvent(fe);
0N/A }
0N/A
0N/A Component source = fe.getComponent();
0N/A Component opposite = fe.getOppositeComponent();
0N/A boolean temporary = false;
0N/A if (fe.getID() == FocusEvent.FOCUS_LOST &&
0N/A (opposite == null || isTemporary(opposite, source)))
0N/A {
0N/A temporary = true;
0N/A }
0N/A return new CausedFocusEvent(source, fe.getID(), temporary, opposite,
0N/A CausedFocusEvent.Cause.NATIVE_SYSTEM);
0N/A }
0N/A }
0N/A
0N/A static FocusEvent retargetFocusGained(FocusEvent fe) {
0N/A assert (fe.getID() == FocusEvent.FOCUS_GAINED);
0N/A
0N/A Component currentFocusOwner = getCurrentKeyboardFocusManager().
0N/A getGlobalFocusOwner();
0N/A Component source = fe.getComponent();
0N/A Component opposite = fe.getOppositeComponent();
0N/A Component nativeSource = getHeavyweight(source);
0N/A
0N/A synchronized (heavyweightRequests) {
0N/A HeavyweightFocusRequest hwFocusRequest = getFirstHWRequest();
0N/A
0N/A if (hwFocusRequest == HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER)
0N/A {
0N/A return retargetUnexpectedFocusEvent(fe);
0N/A }
0N/A
0N/A if (source != null && nativeSource == null && hwFocusRequest != null) {
0N/A // if source w/o peer and
0N/A // if source is equal to first lightweight
0N/A // then we should correct source and nativeSource
0N/A if (source == hwFocusRequest.getFirstLightweightRequest().component)
0N/A {
0N/A source = hwFocusRequest.heavyweight;
0N/A nativeSource = source; // source is heavuweight itself
0N/A }
0N/A }
0N/A if (hwFocusRequest != null &&
0N/A nativeSource == hwFocusRequest.heavyweight)
0N/A {
0N/A // Focus change as a result of a known call to requestFocus(),
0N/A // or known click on a peer focusable heavyweight Component.
0N/A
0N/A heavyweightRequests.removeFirst();
0N/A
0N/A LightweightFocusRequest lwFocusRequest =
0N/A hwFocusRequest.lightweightRequests.removeFirst();
0N/A
0N/A Component newSource = lwFocusRequest.component;
0N/A if (currentFocusOwner != null) {
0N/A /*
0N/A * Since we receive FOCUS_GAINED when current focus
0N/A * owner is not null, correcponding FOCUS_LOST is supposed
0N/A * to be lost. And so, we keep new focus owner
0N/A * to determine synthetic FOCUS_LOST event which will be
0N/A * generated by KeyboardFocusManager for this FOCUS_GAINED.
0N/A *
0N/A * This code based on knowledge of
0N/A * DefaultKeyboardFocusManager's implementation and might
0N/A * be not applicable for another KeyboardFocusManager.
0N/A */
0N/A newFocusOwner = newSource;
0N/A }
0N/A
0N/A boolean temporary = (opposite == null ||
0N/A isTemporary(newSource, opposite))
0N/A ? false
0N/A : lwFocusRequest.temporary;
0N/A
0N/A if (hwFocusRequest.lightweightRequests.size() > 0) {
0N/A currentLightweightRequests =
0N/A hwFocusRequest.lightweightRequests;
0N/A EventQueue.invokeLater(new Runnable() {
0N/A public void run() {
0N/A processCurrentLightweightRequests();
0N/A }
0N/A });
0N/A }
0N/A
0N/A // 'opposite' will be fixed by
0N/A // DefaultKeyboardFocusManager.realOppositeComponent
0N/A return new CausedFocusEvent(newSource,
0N/A FocusEvent.FOCUS_GAINED, temporary,
0N/A opposite, lwFocusRequest.cause);
0N/A }
0N/A
0N/A if (currentFocusOwner != null
0N/A && currentFocusOwner.getContainingWindow() == source
0N/A && (hwFocusRequest == null || source != hwFocusRequest.heavyweight))
0N/A {
0N/A // Special case for FOCUS_GAINED in top-levels
0N/A // If it arrives as the result of activation we should skip it
0N/A // This event will not have appropriate request record and
0N/A // on arrival there will be already some focus owner set.
0N/A return new CausedFocusEvent(currentFocusOwner, FocusEvent.FOCUS_GAINED, false,
0N/A null, CausedFocusEvent.Cause.ACTIVATION);
0N/A }
0N/A
0N/A return retargetUnexpectedFocusEvent(fe);
0N/A } // end synchronized(heavyweightRequests)
0N/A }
0N/A
0N/A static FocusEvent retargetFocusLost(FocusEvent fe) {
0N/A assert (fe.getID() == FocusEvent.FOCUS_LOST);
0N/A
0N/A Component currentFocusOwner = getCurrentKeyboardFocusManager().
0N/A getGlobalFocusOwner();
0N/A Component opposite = fe.getOppositeComponent();
0N/A Component nativeOpposite = getHeavyweight(opposite);
0N/A
0N/A synchronized (heavyweightRequests) {
0N/A HeavyweightFocusRequest hwFocusRequest = getFirstHWRequest();
0N/A
0N/A if (hwFocusRequest == HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER)
0N/A {
0N/A if (currentFocusOwner != null) {
0N/A // Call to KeyboardFocusManager.clearGlobalFocusOwner()
0N/A heavyweightRequests.removeFirst();
0N/A return new CausedFocusEvent(currentFocusOwner,
0N/A FocusEvent.FOCUS_LOST, false, null,
0N/A CausedFocusEvent.Cause.CLEAR_GLOBAL_FOCUS_OWNER);
0N/A }
0N/A
0N/A // Otherwise, fall through to failure case below
0N/A
0N/A } else if (opposite == null)
0N/A {
0N/A // Focus leaving application
0N/A if (currentFocusOwner != null) {
0N/A return new CausedFocusEvent(currentFocusOwner,
0N/A FocusEvent.FOCUS_LOST,
0N/A true, null, CausedFocusEvent.Cause.ACTIVATION);
0N/A } else {
0N/A return fe;
0N/A }
0N/A } else if (hwFocusRequest != null &&
0N/A (nativeOpposite == hwFocusRequest.heavyweight ||
0N/A nativeOpposite == null &&
0N/A opposite == hwFocusRequest.getFirstLightweightRequest().component))
0N/A {
0N/A if (currentFocusOwner == null) {
0N/A return fe;
0N/A }
0N/A // Focus change as a result of a known call to requestFocus(),
0N/A // or click on a peer focusable heavyweight Component.
0N/A // If a focus transfer is made across top-levels, then the
0N/A // FOCUS_LOST event is always temporary, and the FOCUS_GAINED
0N/A // event is always permanent. Otherwise, the stored temporary
0N/A // value is honored.
0N/A
0N/A LightweightFocusRequest lwFocusRequest =
0N/A hwFocusRequest.lightweightRequests.getFirst();
0N/A
0N/A boolean temporary = isTemporary(opposite, currentFocusOwner)
0N/A ? true
0N/A : lwFocusRequest.temporary;
0N/A
0N/A return new CausedFocusEvent(currentFocusOwner, FocusEvent.FOCUS_LOST,
0N/A temporary, lwFocusRequest.component, lwFocusRequest.cause);
0N/A } else if (focusedWindowChanged(opposite, currentFocusOwner)) {
0N/A // If top-level changed there might be no focus request in a list
0N/A // But we know the opposite, we now it is temporary - dispatch the event.
0N/A if (!fe.isTemporary() && currentFocusOwner != null) {
0N/A // Create copy of the event with only difference in temporary parameter.
0N/A fe = new CausedFocusEvent(currentFocusOwner, FocusEvent.FOCUS_LOST,
0N/A true, opposite, CausedFocusEvent.Cause.ACTIVATION);
0N/A }
0N/A return fe;
0N/A }
0N/A
0N/A return retargetUnexpectedFocusEvent(fe);
0N/A } // end synchronized(heavyweightRequests)
0N/A }
0N/A
0N/A static AWTEvent retargetFocusEvent(AWTEvent event) {
0N/A if (clearingCurrentLightweightRequests) {
0N/A return event;
0N/A }
0N/A
0N/A KeyboardFocusManager manager = getCurrentKeyboardFocusManager();
1979N/A if (focusLog.isLoggable(PlatformLogger.FINER)) {
0N/A if (event instanceof FocusEvent || event instanceof WindowEvent) {
1979N/A focusLog.finer(">>> {0}", String.valueOf(event));
0N/A }
1979N/A if (focusLog.isLoggable(PlatformLogger.FINER) && event instanceof KeyEvent) {
1979N/A focusLog.finer(" focus owner is {0}",
1979N/A String.valueOf(manager.getGlobalFocusOwner()));
1979N/A focusLog.finer(">>> {0}", String.valueOf(event));
0N/A }
0N/A }
0N/A
0N/A synchronized(heavyweightRequests) {
0N/A /*
0N/A * This code handles FOCUS_LOST event which is generated by
0N/A * DefaultKeyboardFocusManager for FOCUS_GAINED.
0N/A *
0N/A * This code based on knowledge of DefaultKeyboardFocusManager's
0N/A * implementation and might be not applicable for another
0N/A * KeyboardFocusManager.
0N/A *
0N/A * Fix for 4472032
0N/A */
0N/A if (newFocusOwner != null &&
0N/A event.getID() == FocusEvent.FOCUS_LOST)
0N/A {
0N/A FocusEvent fe = (FocusEvent)event;
0N/A
0N/A if (manager.getGlobalFocusOwner() == fe.getComponent() &&
0N/A fe.getOppositeComponent() == newFocusOwner)
0N/A {
0N/A newFocusOwner = null;
0N/A return event;
0N/A }
0N/A }
0N/A }
0N/A
0N/A processCurrentLightweightRequests();
0N/A
0N/A switch (event.getID()) {
0N/A case FocusEvent.FOCUS_GAINED: {
0N/A event = retargetFocusGained((FocusEvent)event);
0N/A break;
0N/A }
0N/A case FocusEvent.FOCUS_LOST: {
0N/A event = retargetFocusLost((FocusEvent)event);
0N/A break;
0N/A }
0N/A default:
0N/A /* do nothing */
0N/A }
0N/A return event;
0N/A }
0N/A
0N/A /**
0N/A * Clears markers queue
0N/A * This method is not intended to be overridden by KFM's.
0N/A * Only DefaultKeyboardFocusManager can implement it.
0N/A * @since 1.5
0N/A */
0N/A void clearMarkers() {
0N/A }
0N/A
0N/A static boolean removeFirstRequest() {
0N/A KeyboardFocusManager manager =
0N/A KeyboardFocusManager.getCurrentKeyboardFocusManager();
0N/A
0N/A synchronized(heavyweightRequests) {
0N/A HeavyweightFocusRequest hwFocusRequest = getFirstHWRequest();
0N/A
0N/A if (hwFocusRequest != null) {
0N/A heavyweightRequests.removeFirst();
0N/A if (hwFocusRequest.lightweightRequests != null) {
0N/A for (Iterator lwIter = hwFocusRequest.lightweightRequests.
0N/A iterator();
0N/A lwIter.hasNext(); )
0N/A {
0N/A manager.dequeueKeyEvents
0N/A (-1, ((LightweightFocusRequest)lwIter.next()).
0N/A component);
0N/A }
0N/A }
0N/A }
0N/A // Fix for 4799136 - clear type-ahead markers if requests queue is empty
0N/A // We do it here because this method is called only when problems happen
0N/A if (heavyweightRequests.size() == 0) {
0N/A manager.clearMarkers();
0N/A }
0N/A return (heavyweightRequests.size() > 0);
0N/A }
0N/A }
0N/A static void removeLastFocusRequest(Component heavyweight) {
1979N/A if (log.isLoggable(PlatformLogger.FINE)) {
0N/A if (heavyweight == null) {
1979N/A log.fine("Assertion (heavyweight != null) failed");
0N/A }
0N/A }
0N/A
0N/A KeyboardFocusManager manager =
0N/A KeyboardFocusManager.getCurrentKeyboardFocusManager();
0N/A synchronized(heavyweightRequests) {
0N/A HeavyweightFocusRequest hwFocusRequest = getLastHWRequest();
0N/A if (hwFocusRequest != null &&
0N/A hwFocusRequest.heavyweight == heavyweight) {
0N/A heavyweightRequests.removeLast();
0N/A }
0N/A // Fix for 4799136 - clear type-ahead markers if requests queue is empty
0N/A // We do it here because this method is called only when problems happen
0N/A if (heavyweightRequests.size() == 0) {
0N/A manager.clearMarkers();
0N/A }
0N/A }
0N/A }
0N/A
0N/A private static boolean focusedWindowChanged(Component to, Component from) {
1045N/A Window wto = SunToolkit.getContainingWindow(to);
1045N/A Window wfrom = SunToolkit.getContainingWindow(from);
0N/A if (wto == null && wfrom == null) {
0N/A return true;
0N/A }
0N/A if (wto == null) {
0N/A return true;
0N/A }
0N/A if (wfrom == null) {
0N/A return true;
0N/A }
0N/A return (wto != wfrom);
0N/A }
0N/A
0N/A private static boolean isTemporary(Component to, Component from) {
1045N/A Window wto = SunToolkit.getContainingWindow(to);
1045N/A Window wfrom = SunToolkit.getContainingWindow(from);
0N/A if (wto == null && wfrom == null) {
0N/A return false;
0N/A }
0N/A if (wto == null) {
0N/A return true;
0N/A }
0N/A if (wfrom == null) {
0N/A return false;
0N/A }
0N/A return (wto != wfrom);
0N/A }
0N/A
0N/A static Component getHeavyweight(Component comp) {
0N/A if (comp == null || comp.getPeer() == null) {
0N/A return null;
0N/A } else if (comp.getPeer() instanceof LightweightPeer) {
0N/A return comp.getNativeContainer();
0N/A } else {
0N/A return comp;
0N/A }
0N/A }
0N/A
0N/A static Field proxyActive;
0N/A // Accessor to private field isProxyActive of KeyEvent
0N/A private static boolean isProxyActiveImpl(KeyEvent e) {
0N/A if (proxyActive == null) {
0N/A proxyActive = (Field) AccessController.doPrivileged(new PrivilegedAction() {
0N/A public Object run() {
0N/A Field field = null;
0N/A try {
0N/A field = KeyEvent.class.getDeclaredField("isProxyActive");
0N/A if (field != null) {
0N/A field.setAccessible(true);
0N/A }
0N/A } catch (NoSuchFieldException nsf) {
0N/A assert(false);
0N/A }
0N/A return field;
0N/A }
0N/A });
0N/A }
0N/A
0N/A try {
0N/A return proxyActive.getBoolean(e);
0N/A } catch (IllegalAccessException iae) {
0N/A assert(false);
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A // Returns the value of this KeyEvent's field isProxyActive
0N/A static boolean isProxyActive(KeyEvent e) {
0N/A if (!GraphicsEnvironment.isHeadless()) {
0N/A return isProxyActiveImpl(e);
0N/A } else {
0N/A return false;
0N/A }
0N/A }
0N/A
0N/A private static HeavyweightFocusRequest getLastHWRequest() {
0N/A synchronized(heavyweightRequests) {
0N/A return (heavyweightRequests.size() > 0)
0N/A ? heavyweightRequests.getLast()
0N/A : null;
0N/A }
0N/A }
0N/A
0N/A private static HeavyweightFocusRequest getFirstHWRequest() {
0N/A synchronized(heavyweightRequests) {
0N/A return (heavyweightRequests.size() > 0)
0N/A ? heavyweightRequests.getFirst()
0N/A : null;
0N/A }
0N/A }
4743N/A
4743N/A private void checkCurrentKFMSecurity() {
4743N/A if (this != getCurrentKeyboardFocusManager()) {
4743N/A if (focusLog.isLoggable(PlatformLogger.FINER)) {
4743N/A focusLog.finer("This manager is " + this +
4743N/A ", current is " + getCurrentKeyboardFocusManager());
4743N/A }
4743N/A throw new SecurityException(notPrivileged);
4743N/A }
4743N/A }
0N/A}