Path: blob/master/src/java.desktop/share/classes/javax/swing/DelegatingDefaultFocusManager.java
41153 views
/*1* Copyright (c) 2001, 2004, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package javax.swing;2526import java.awt.*;27import java.awt.event.*;28import java.beans.*;29import java.util.Set;303132/**33* Provides a javax.swing.DefaultFocusManager view onto an arbitrary34* java.awt.KeyboardFocusManager. We subclass DefaultFocusManager instead of35* FocusManager because it seems more backward-compatible. It is likely that36* some pre-1.4 code assumes that the object returned by37* FocusManager.getCurrentManager is an instance of DefaultFocusManager unless38* set explicitly.39*/40final class DelegatingDefaultFocusManager extends DefaultFocusManager {41private final KeyboardFocusManager delegate;4243DelegatingDefaultFocusManager(KeyboardFocusManager delegate) {44this.delegate = delegate;45setDefaultFocusTraversalPolicy(gluePolicy);46}4748KeyboardFocusManager getDelegate() {49return delegate;50}5152// Legacy methods which first appeared in javax.swing.FocusManager.53// Client code is most likely to invoke these methods.5455public void processKeyEvent(Component focusedComponent, KeyEvent e) {56delegate.processKeyEvent(focusedComponent, e);57}58public void focusNextComponent(Component aComponent) {59delegate.focusNextComponent(aComponent);60}61public void focusPreviousComponent(Component aComponent) {62delegate.focusPreviousComponent(aComponent);63}6465// Make sure that we delegate all new methods in KeyboardFocusManager66// as well as the legacy methods from Swing. It is theoretically possible,67// although unlikely, that a client app will treat this instance as a68// new-style KeyboardFocusManager. We might as well be safe.69//70// The JLS won't let us override the protected methods in71// KeyboardFocusManager such that they invoke the corresponding methods on72// the delegate. However, since client code would never be able to call73// those methods anyways, we don't have to worry about that problem.7475public Component getFocusOwner() {76return delegate.getFocusOwner();77}78public void clearGlobalFocusOwner() {79delegate.clearGlobalFocusOwner();80}81public Component getPermanentFocusOwner() {82return delegate.getPermanentFocusOwner();83}84public Window getFocusedWindow() {85return delegate.getFocusedWindow();86}87public Window getActiveWindow() {88return delegate.getActiveWindow();89}90public FocusTraversalPolicy getDefaultFocusTraversalPolicy() {91return delegate.getDefaultFocusTraversalPolicy();92}93public void setDefaultFocusTraversalPolicy(FocusTraversalPolicy94defaultPolicy) {95if (delegate != null) {96// Will be null when invoked from supers constructor.97delegate.setDefaultFocusTraversalPolicy(defaultPolicy);98}99}100public void101setDefaultFocusTraversalKeys(int id,102Set<? extends AWTKeyStroke> keystrokes)103{104delegate.setDefaultFocusTraversalKeys(id, keystrokes);105}106public Set<AWTKeyStroke> getDefaultFocusTraversalKeys(int id) {107return delegate.getDefaultFocusTraversalKeys(id);108}109public Container getCurrentFocusCycleRoot() {110return delegate.getCurrentFocusCycleRoot();111}112public void setGlobalCurrentFocusCycleRoot(Container newFocusCycleRoot) {113delegate.setGlobalCurrentFocusCycleRoot(newFocusCycleRoot);114}115public void addPropertyChangeListener(PropertyChangeListener listener) {116delegate.addPropertyChangeListener(listener);117}118public void removePropertyChangeListener(PropertyChangeListener listener) {119delegate.removePropertyChangeListener(listener);120}121public void addPropertyChangeListener(String propertyName,122PropertyChangeListener listener) {123delegate.addPropertyChangeListener(propertyName, listener);124}125public void removePropertyChangeListener(String propertyName,126PropertyChangeListener listener) {127delegate.removePropertyChangeListener(propertyName, listener);128}129public void addVetoableChangeListener(VetoableChangeListener listener) {130delegate.addVetoableChangeListener(listener);131}132public void removeVetoableChangeListener(VetoableChangeListener listener) {133delegate.removeVetoableChangeListener(listener);134}135public void addVetoableChangeListener(String propertyName,136VetoableChangeListener listener) {137delegate.addVetoableChangeListener(propertyName, listener);138}139public void removeVetoableChangeListener(String propertyName,140VetoableChangeListener listener) {141delegate.removeVetoableChangeListener(propertyName, listener);142}143public void addKeyEventDispatcher(KeyEventDispatcher dispatcher) {144delegate.addKeyEventDispatcher(dispatcher);145}146public void removeKeyEventDispatcher(KeyEventDispatcher dispatcher) {147delegate.removeKeyEventDispatcher(dispatcher);148}149public boolean dispatchEvent(AWTEvent e) {150return delegate.dispatchEvent(e);151}152public boolean dispatchKeyEvent(KeyEvent e) {153return delegate.dispatchKeyEvent(e);154}155public void upFocusCycle(Component aComponent) {156delegate.upFocusCycle(aComponent);157}158public void downFocusCycle(Container aContainer) {159delegate.downFocusCycle(aContainer);160}161}162163164