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