KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > DelegatingDefaultFocusManager


1 /*
2  * @(#)DelegatingDefaultFocusManager.java 1.5 04/05/05
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package javax.swing;
8
9 import java.awt.*;
10 import java.awt.event.*;
11 import java.beans.*;
12 import java.util.Set JavaDoc;
13
14
15 /**
16  * Provides a javax.swing.DefaultFocusManager view onto an arbitrary
17  * java.awt.KeyboardFocusManager. We subclass DefaultFocusManager instead of
18  * FocusManager because it seems more backward-compatible. It is likely that
19  * some pre-1.4 code assumes that the object returned by
20  * FocusManager.getCurrentManager is an instance of DefaultFocusManager unless
21  * set explicitly.
22  */

23 final class DelegatingDefaultFocusManager extends DefaultFocusManager JavaDoc {
24     private final KeyboardFocusManager delegate;
25
26     DelegatingDefaultFocusManager(KeyboardFocusManager delegate) {
27     this.delegate = delegate;
28         setDefaultFocusTraversalPolicy(gluePolicy);
29     }
30
31     KeyboardFocusManager getDelegate() {
32         return delegate;
33     }
34
35     // Legacy methods which first appeared in javax.swing.FocusManager.
36
// Client code is most likely to invoke these methods.
37

38     public void processKeyEvent(Component focusedComponent, KeyEvent e) {
39     delegate.processKeyEvent(focusedComponent, e);
40     }
41     public void focusNextComponent(Component aComponent) {
42     delegate.focusNextComponent(aComponent);
43     }
44     public void focusPreviousComponent(Component aComponent) {
45     delegate.focusPreviousComponent(aComponent);
46     }
47
48     // Make sure that we delegate all new methods in KeyboardFocusManager
49
// as well as the legacy methods from Swing. It is theoretically possible,
50
// although unlikely, that a client app will treat this instance as a
51
// new-style KeyboardFocusManager. We might as well be safe.
52
//
53
// The JLS won't let us override the protected methods in
54
// KeyboardFocusManager such that they invoke the corresponding methods on
55
// the delegate. However, since client code would never be able to call
56
// those methods anyways, we don't have to worry about that problem.
57

58     public Component getFocusOwner() {
59     return delegate.getFocusOwner();
60     }
61     public void clearGlobalFocusOwner() {
62     delegate.clearGlobalFocusOwner();
63     }
64     public Component getPermanentFocusOwner() {
65     return delegate.getPermanentFocusOwner();
66     }
67     public Window getFocusedWindow() {
68     return delegate.getFocusedWindow();
69     }
70     public Window getActiveWindow() {
71     return delegate.getActiveWindow();
72     }
73     public FocusTraversalPolicy getDefaultFocusTraversalPolicy() {
74     return delegate.getDefaultFocusTraversalPolicy();
75     }
76     public void setDefaultFocusTraversalPolicy(FocusTraversalPolicy
77                                                defaultPolicy) {
78         if (delegate != null) {
79             // Will be null when invoked from supers constructor.
80
delegate.setDefaultFocusTraversalPolicy(defaultPolicy);
81         }
82     }
83     public void
84     setDefaultFocusTraversalKeys(int id,
85                      Set JavaDoc<? extends AWTKeyStroke> keystrokes)
86     {
87     delegate.setDefaultFocusTraversalKeys(id, keystrokes);
88     }
89     public Set JavaDoc<AWTKeyStroke> getDefaultFocusTraversalKeys(int id) {
90     return delegate.getDefaultFocusTraversalKeys(id);
91     }
92     public Container getCurrentFocusCycleRoot() {
93     return delegate.getCurrentFocusCycleRoot();
94     }
95     public void setGlobalCurrentFocusCycleRoot(Container newFocusCycleRoot) {
96     delegate.setGlobalCurrentFocusCycleRoot(newFocusCycleRoot);
97     }
98     public void addPropertyChangeListener(PropertyChangeListener listener) {
99     delegate.addPropertyChangeListener(listener);
100     }
101     public void removePropertyChangeListener(PropertyChangeListener listener) {
102     delegate.removePropertyChangeListener(listener);
103     }
104     public void addPropertyChangeListener(String JavaDoc propertyName,
105                                           PropertyChangeListener listener) {
106     delegate.addPropertyChangeListener(propertyName, listener);
107     }
108     public void removePropertyChangeListener(String JavaDoc propertyName,
109                                              PropertyChangeListener listener) {
110     delegate.removePropertyChangeListener(propertyName, listener);
111     }
112     public void addVetoableChangeListener(VetoableChangeListener listener) {
113     delegate.addVetoableChangeListener(listener);
114     }
115     public void removeVetoableChangeListener(VetoableChangeListener listener) {
116     delegate.removeVetoableChangeListener(listener);
117     }
118     public void addVetoableChangeListener(String JavaDoc propertyName,
119                                           VetoableChangeListener listener) {
120     delegate.addVetoableChangeListener(propertyName, listener);
121     }
122     public void removeVetoableChangeListener(String JavaDoc propertyName,
123                                              VetoableChangeListener listener) {
124     delegate.removeVetoableChangeListener(propertyName, listener);
125     }
126     public void addKeyEventDispatcher(KeyEventDispatcher dispatcher) {
127     delegate.addKeyEventDispatcher(dispatcher);
128     }
129     public void removeKeyEventDispatcher(KeyEventDispatcher dispatcher) {
130     delegate.removeKeyEventDispatcher(dispatcher);
131     }
132     public boolean dispatchEvent(AWTEvent e) {
133     return delegate.dispatchEvent(e);
134     }
135     public boolean dispatchKeyEvent(KeyEvent e) {
136     return delegate.dispatchKeyEvent(e);
137     }
138     public void upFocusCycle(Component aComponent) {
139     delegate.upFocusCycle(aComponent);
140     }
141     public void downFocusCycle(Container aContainer) {
142     delegate.downFocusCycle(aContainer);
143     }
144 }
145
Popular Tags