1 /* FocusManager.java --
2 Copyright (C) 2002, 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
41 import java
.awt
.AWTEvent
;
42 import java
.awt
.Component
;
43 import java
.awt
.Container
;
44 import java
.awt
.DefaultKeyboardFocusManager
;
45 import java
.awt
.FocusTraversalPolicy
;
46 import java
.awt
.KeyEventDispatcher
;
47 import java
.awt
.KeyEventPostProcessor
;
48 import java
.awt
.KeyboardFocusManager
;
49 import java
.awt
.Window
;
50 import java
.awt
.event
.KeyEvent
;
51 import java
.beans
.PropertyChangeListener
;
52 import java
.beans
.VetoableChangeListener
;
56 * This class has been obsoleted by the new
57 * {@link java.awt.KeyboardFocusManager} and
58 * {@link java.awt.DefaultKeyboardFocusManager} API.
60 * @author Andrew Selkirk
62 public abstract class FocusManager
63 extends DefaultKeyboardFocusManager
66 * A FocusManager that wraps an AWT KeyboardFocusManager and forwards all
67 * method calls to it. This is used for compatibility with the new focus
70 * @author Roman Kennke (kennke@aicas.com)
72 private static class WrappingFocusManager
76 * The wrapped KeyboardFocusManager.
78 private KeyboardFocusManager wrapped
;
81 * Creates a new instance of WrappedFocusManager.
83 * @param fm the focus manager to wrap
85 WrappingFocusManager(KeyboardFocusManager fm
)
91 * Wraps {@link DefaultKeyboardFocusManager#dispatchEvent(AWTEvent)}.
93 * @param ev the event to dispatch
95 * @return <code>true</code> if the event has been dispatched,
96 * <code>false</code> otherwise
98 public boolean dispatchEvent(AWTEvent ev
)
100 return wrapped
.dispatchEvent(ev
);
104 * Wraps {@link DefaultKeyboardFocusManager#dispatchKeyEvent(KeyEvent)}.
106 * @param ev the event to dispatch
108 * @return <code>true</code> if the event has been dispatched,
109 * <code>false</code> otherwise
111 public boolean dispatchKeyEvent(KeyEvent ev
)
113 return wrapped
.dispatchKeyEvent(ev
);
117 * Wraps {@link DefaultKeyboardFocusManager#downFocusCycle(Container)}.
119 * @param c the container
121 public void downFocusCycle(Container c
)
123 wrapped
.downFocusCycle(c
);
127 * Wraps {@link DefaultKeyboardFocusManager#upFocusCycle(Container)}.
129 * @param c the container
131 public void upFocusCycle(Container c
)
133 wrapped
.upFocusCycle(c
);
137 * Wraps {@link DefaultKeyboardFocusManager#focusNextComponent(Component)}.
139 * @param c the component
141 public void focusNextComponent(Component c
)
143 wrapped
.focusNextComponent(c
);
148 * {@link DefaultKeyboardFocusManager#focusPreviousComponent(Component)}.
150 * @param c the component
152 public void focusPreviousComponent(Component c
)
154 wrapped
.focusPreviousComponent(c
);
158 * Wraps {@link DefaultKeyboardFocusManager#postProcessKeyEvent(KeyEvent)}.
160 * @param e the key event
164 public boolean postProcessKeyEvent(KeyEvent e
)
166 return wrapped
.postProcessKeyEvent(e
);
171 * {@link DefaultKeyboardFocusManager#processKeyEvent(Component, KeyEvent)}.
173 * @param c the component
174 * @param e the key event
176 public void processKeyEvent(Component c
, KeyEvent e
)
178 wrapped
.processKeyEvent(c
, e
);
183 * {@link KeyboardFocusManager#addKeyEventDispatcher(KeyEventDispatcher)}.
185 * @param d the dispatcher
187 public void addKeyEventDispatcher(KeyEventDispatcher d
)
189 wrapped
.addKeyEventDispatcher(d
);
194 * {@link KeyboardFocusManager#addKeyEventPostProcessor(KeyEventPostProcessor)}.
196 * @param p the post processor
198 public void addKeyEventPostProcessor(KeyEventPostProcessor p
)
200 wrapped
.addKeyEventPostProcessor(p
);
204 * Wraps {@link KeyboardFocusManager#addPropertyChangeListener(PropertyChangeListener)}.
206 * @param l the property change listener
208 public void addPropertyChangeListener(PropertyChangeListener l
)
210 wrapped
.addPropertyChangeListener(l
);
214 * Wraps {@link KeyboardFocusManager#addPropertyChangeListener(String, PropertyChangeListener)}.
216 * @param p the property name
217 * @param l the property change listener
219 public void addPropertyChangeListener(String p
, PropertyChangeListener l
)
221 wrapped
.addPropertyChangeListener(p
, l
);
225 * Wraps {@link KeyboardFocusManager#addVetoableChangeListener(String, VetoableChangeListener)}.
227 * @param p the property name
228 * @param l the vetoable change listener
230 public void addVetoableChangeListener(String p
, VetoableChangeListener l
)
232 wrapped
.addVetoableChangeListener(p
, l
);
236 * Wraps {@link KeyboardFocusManager#addVetoableChangeListener(VetoableChangeListener)}.
238 * @param l the vetoable change listener
240 public void addVetoableChangeListener(VetoableChangeListener l
)
242 wrapped
.addVetoableChangeListener(l
);
246 * Wraps {@link KeyboardFocusManager#clearGlobalFocusOwner()}.
248 public void clearGlobalFocusOwner()
250 wrapped
.clearGlobalFocusOwner();
254 * Wraps {@link KeyboardFocusManager#getActiveWindow()}.
256 * @return the active window
258 public Window
getActiveWindow()
260 return wrapped
.getActiveWindow();
264 * Wraps {@link KeyboardFocusManager#getCurrentFocusCycleRoot()}.
266 * @return the focus cycle root
268 public Container
getCurrentFocusCycleRoot()
270 return wrapped
.getCurrentFocusCycleRoot();
274 * Wraps {@link KeyboardFocusManager#getDefaultFocusTraversalKeys(int)}.
278 * @return the focus traversal keys
280 public Set
getDefaultFocusTraversalKeys(int i
)
282 return wrapped
.getDefaultFocusTraversalKeys(i
);
286 * Wraps {@link KeyboardFocusManager#getDefaultFocusTraversalPolicy()}.
288 * @return the focus traversal policy
290 public FocusTraversalPolicy
getDefaultFocusTraversalPolicy()
292 return wrapped
.getDefaultFocusTraversalPolicy();
296 * Wraps {@link KeyboardFocusManager#getFocusedWindow()}.
298 * @return the focused window
300 public Window
getFocusedWindow()
302 return wrapped
.getFocusedWindow();
306 * Wraps {@link KeyboardFocusManager#getFocusOwner()}.
308 * @return the focus owner
310 public Component
getFocusOwner()
312 return wrapped
.getFocusOwner();
316 * Wraps {@link KeyboardFocusManager#getPermanentFocusOwner()}.
318 * @return the focus owner
320 public Component
getPermanentFocusOwner()
322 return wrapped
.getPermanentFocusOwner();
326 * Wraps {@link KeyboardFocusManager#getPropertyChangeListeners()}.
328 * @return the property change listeners
330 public PropertyChangeListener
[] getPropertyChangeListeners()
332 return wrapped
.getPropertyChangeListeners();
336 * Wraps {@link KeyboardFocusManager#getPropertyChangeListeners(String)}.
338 * @param n the property name
340 * @return the property change listeners
342 public PropertyChangeListener
[] getPropertyChangeListeners(String n
)
344 return wrapped
.getPropertyChangeListeners(n
);
348 * Wraps {@link KeyboardFocusManager#getVetoableChangeListeners()}.
350 * @return the vetoable change listeners
352 public VetoableChangeListener
[] getVetoableChangeListeners()
354 return wrapped
.getVetoableChangeListeners();
358 * Wraps {@link KeyboardFocusManager#getVetoableChangeListeners(String)}.
360 * @param n the property name
362 * @return the vetoable change listeners
364 public VetoableChangeListener
[] getVetoableChangeListeners(String n
)
366 return wrapped
.getVetoableChangeListeners(n
);
372 * {@link KeyboardFocusManager#removeKeyEventDispatcher(KeyEventDispatcher)}.
374 * @param d the key event dispatcher to remove
376 public void removeKeyEventDispatcher(KeyEventDispatcher d
)
378 wrapped
.removeKeyEventDispatcher(d
);
383 * {@link KeyboardFocusManager#removeKeyEventPostProcessor(KeyEventPostProcessor)}.
385 * @param p the post processor
387 public void removeKeyEventPostProcessor(KeyEventPostProcessor p
)
389 wrapped
.removeKeyEventPostProcessor(p
);
394 * {@link KeyboardFocusManager#removePropertyChangeListener(PropertyChangeListener)}.
396 * @param l the listener
398 public void removePropertyChangeListener(PropertyChangeListener l
)
400 wrapped
.removePropertyChangeListener(l
);
405 * {@link KeyboardFocusManager#removePropertyChangeListener(String, PropertyChangeListener)}.
407 * @param n the property name
408 * @param l the listener
410 public void removePropertyChangeListener(String n
, PropertyChangeListener l
)
412 wrapped
.removePropertyChangeListener(n
, l
);
417 * {@link KeyboardFocusManager#removeVetoableChangeListener(VetoableChangeListener)}.
419 * @param l the listener
421 public void removeVetoableChangeListener(VetoableChangeListener l
)
423 wrapped
.removeVetoableChangeListener(l
);
428 * {@link KeyboardFocusManager#removeVetoableChangeListener(String, VetoableChangeListener)}.
430 * @param n the property name
431 * @param l the listener
433 public void removeVetoableChangeListener(String n
, VetoableChangeListener l
)
435 wrapped
.removeVetoableChangeListener(n
, l
);
440 * {@link KeyboardFocusManager#setDefaultFocusTraversalKeys(int, Set)}.
443 * @param k the keystrokes
445 public void setDefaultFocusTraversalKeys(int id
, Set k
)
447 wrapped
.setDefaultFocusTraversalKeys(id
, k
);
451 * Wraps {@link KeyboardFocusManager#setDefaultFocusTraversalPolicy(FocusTraversalPolicy)}.
453 * @param p the focus traversal policy
455 public void setDefaultFocusTraversalPolicy(FocusTraversalPolicy p
)
457 wrapped
.setDefaultFocusTraversalPolicy(p
);
462 * {@link KeyboardFocusManager#setGlobalCurrentFocusCycleRoot(Container)}.
464 * @param r the focus cycle root
466 public void setGlobalCurrentFocusCycleRoot(Container r
)
468 wrapped
.setGlobalCurrentFocusCycleRoot(r
);
473 * FOCUS_MANAGER_CLASS_PROPERTY
475 public static final String FOCUS_MANAGER_CLASS_PROPERTY
=
476 "FocusManagerClassName";
479 * Constructor FocusManager
481 public FocusManager()
488 * @return FocusManager
490 public static FocusManager
getCurrentManager()
492 KeyboardFocusManager m
=
493 KeyboardFocusManager
.getCurrentKeyboardFocusManager();
494 return new WrappingFocusManager(m
);
499 * @param manager TODO
501 public static void setCurrentManager(FocusManager manager
)
503 KeyboardFocusManager
.setCurrentKeyboardFocusManager(manager
);
507 * disableSwingFocusManager
510 public static void disableSwingFocusManager()
516 * isFocusManagerEnabled
520 public static boolean isFocusManagerEnabled()
522 return false; // TODO