📄 keyboardfocusmanager.java
字号:
/* KeyboardFocusManager.java -- manage component focusing via the keyboard Copyright (C) 2002 Free Software FoundationThis file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package java.awt;import java.awt.event.KeyEvent;import java.beans.PropertyChangeListener;import java.beans.PropertyChangeSupport;import java.beans.PropertyVetoException;import java.beans.VetoableChangeListener;import java.beans.VetoableChangeSupport;import java.util.ArrayList;import java.util.Collections;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Set;/** * * @author Eric Blake <ebb9@email.byu.edu> * @since 1.4 * @status partially updated to 1.4, needs documentation. */public abstract class KeyboardFocusManager implements KeyEventDispatcher, KeyEventPostProcessor{ public static final int FORWARD_TRAVERSAL_KEYS = 0; public static final int BACKWARD_TRAVERSAL_KEYS = 1; public static final int UP_CYCLE_TRAVERSAL_KEYS = 2; public static final int DOWN_CYCLE_TRAVERSAL_KEYS = 3; private static final Set DEFAULT_FORWARD_KEYS; private static final Set DEFAULT_BACKWARD_KEYS; static { Set s = new HashSet(); s.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0)); s.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, KeyEvent.CTRL_DOWN_MASK)); DEFAULT_FORWARD_KEYS = Collections.unmodifiableSet(s); s = new HashSet(); s.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_DOWN_MASK)); s.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK)); DEFAULT_BACKWARD_KEYS = Collections.unmodifiableSet(s); } private static KeyboardFocusManager current = new DefaultKeyboardFocusManager(); // XXX Not implemented correctly. I think a good implementation here may // be to have permanentFocusOwner be null, and fall back to focusOwner, // unless a temporary focus change is in effect. private static Component focusOwner; private static Component permanentFocusOwner; private static Window focusedWindow; private static Window activeWindow; private static Container focusCycleRoot; private FocusTraversalPolicy defaultPolicy; private Set[] defaultFocusKeys = new Set[] { DEFAULT_FORWARD_KEYS, DEFAULT_BACKWARD_KEYS, Collections.EMPTY_SET, Collections.EMPTY_SET }; private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); private final VetoableChangeSupport vetoableChangeSupport = new VetoableChangeSupport(this); private final ArrayList keyEventDispatchers = new ArrayList(); private final ArrayList keyEventPostProcessors = new ArrayList(); public KeyboardFocusManager() { } public static KeyboardFocusManager getCurrentKeyboardFocusManager() { // XXX Need a way to divide this into contexts. return current; } public static void setCurrentKeyboardFocusManager(KeyboardFocusManager m) { SecurityManager sm = System.getSecurityManager(); if (sm != null) sm.checkPermission(new AWTPermission("replaceKeyboardFocusManager")); // XXX Need a way to divide this into contexts. current = m == null ? new DefaultKeyboardFocusManager() : m; } public Component getFocusOwner() { // XXX Need an easy way to test if this thread is in the context of the // global focus owner, to avoid creating the exception in the first place. try { return getGlobalFocusOwner(); } catch (SecurityException e) { return null; } } protected Component getGlobalFocusOwner() { // XXX Need a way to test if this thread is in the context of the focus // owner, and throw a SecurityException if that is the case. // XXX Implement. return focusOwner; } protected void setGlobalFocusOwner(Component owner) { // XXX Should this send focus events to the components involved? if (owner == null || owner.focusable) { firePropertyChange("focusOwner", focusOwner, owner); try { fireVetoableChange("focusOwner", focusOwner, owner); focusOwner = owner; } catch (PropertyVetoException e) { } } } public void clearGlobalFocusOwner() { // XXX Is this enough? setGlobalFocusOwner(null); } public Component getPermanentFocusOwner() { // XXX Need an easy way to test if this thread is in the context of the // global focus owner, to avoid creating the exception in the first place. try { return getGlobalPermanentFocusOwner(); } catch (SecurityException e) { return null; } } protected Component getGlobalPermanentFocusOwner() { // XXX Need a way to test if this thread is in the context of the focus // owner, and throw a SecurityException if that is the case. // XXX Implement. return permanentFocusOwner == null ? focusOwner : permanentFocusOwner; } protected void setGlobalPermanentFocusOwner(Component focusOwner) { // XXX Should this send focus events to the components involved? if (focusOwner == null || focusOwner.focusable) { firePropertyChange("permanentFocusOwner", permanentFocusOwner, focusOwner); try { fireVetoableChange("permanentFocusOwner", permanentFocusOwner, focusOwner); permanentFocusOwner = focusOwner; } catch (PropertyVetoException e) { } } } public Window getFocusedWindow() { // XXX Need an easy way to test if this thread is in the context of the // global focus owner, to avoid creating the exception in the first place. try { return getGlobalFocusedWindow(); } catch (SecurityException e) { return null; } } protected Window getGlobalFocusedWindow() { // XXX Need a way to test if this thread is in the context of the focus // owner, and throw a SecurityException if that is the case. // XXX Implement. return focusedWindow; } protected void setGlobalFocusedWindow(Window window) { // XXX Should this send focus events to the windows involved? if (window == null || window.focusable) { firePropertyChange("focusedWindow", focusedWindow, window); try { fireVetoableChange("focusedWindow", focusedWindow, window); focusedWindow = window; } catch (PropertyVetoException e) { } } } public Window getActiveWindow() { // XXX Need an easy way to test if this thread is in the context of the // global focus owner, to avoid creating the exception in the first place. try { return getGlobalActiveWindow(); } catch (SecurityException e) { return null; } } protected Window getGlobalActiveWindow() { // XXX Need a way to test if this thread is in the context of the focus // owner, and throw a SecurityException if that is the case. // XXX Implement. return activeWindow; } protected void setGlobalActiveWindow(Window window)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -