001/* FocusManager.java --
002   Copyright (C) 2002, 2004  Free Software Foundation, Inc.
003
004This file is part of GNU Classpath.
005
006GNU Classpath is free software; you can redistribute it and/or modify
007it under the terms of the GNU General Public License as published by
008the Free Software Foundation; either version 2, or (at your option)
009any later version.
010
011GNU Classpath is distributed in the hope that it will be useful, but
012WITHOUT ANY WARRANTY; without even the implied warranty of
013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014General Public License for more details.
015
016You should have received a copy of the GNU General Public License
017along with GNU Classpath; see the file COPYING.  If not, write to the
018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
01902110-1301 USA.
020
021Linking this library statically or dynamically with other modules is
022making a combined work based on this library.  Thus, the terms and
023conditions of the GNU General Public License cover the whole
024combination.
025
026As a special exception, the copyright holders of this library give you
027permission to link this library with independent modules to produce an
028executable, regardless of the license terms of these independent
029modules, and to copy and distribute the resulting executable under
030terms of your choice, provided that you also meet, for each linked
031independent module, the terms and conditions of the license of that
032module.  An independent module is a module which is not derived from
033or based on this library.  If you modify this library, you may extend
034this exception to your version of the library, but you are not
035obligated to do so.  If you do not wish to do so, delete this
036exception statement from your version. */
037
038
039package javax.swing;
040
041import java.awt.AWTEvent;
042import java.awt.Component;
043import java.awt.Container;
044import java.awt.DefaultKeyboardFocusManager;
045import java.awt.FocusTraversalPolicy;
046import java.awt.KeyEventDispatcher;
047import java.awt.KeyEventPostProcessor;
048import java.awt.KeyboardFocusManager;
049import java.awt.Window;
050import java.awt.event.KeyEvent;
051import java.beans.PropertyChangeListener;
052import java.beans.VetoableChangeListener;
053import java.util.Set;
054
055/**
056 * This class has been obsoleted by the new
057 * {@link java.awt.KeyboardFocusManager} and
058 * {@link java.awt.DefaultKeyboardFocusManager} API.
059 *
060 * @author Andrew Selkirk
061 */
062public abstract class FocusManager
063  extends DefaultKeyboardFocusManager
064{
065  /**
066   * A FocusManager that wraps an AWT KeyboardFocusManager and forwards all
067   * method calls to it. This is used for compatibility with the new focus
068   * system.
069   *
070   * @author Roman Kennke (kennke@aicas.com)
071   */
072  private static class WrappingFocusManager
073    extends FocusManager
074  {
075    /**
076     * The wrapped KeyboardFocusManager.
077     */
078    private KeyboardFocusManager wrapped;
079
080    /**
081     * Creates a new instance of WrappedFocusManager.
082     *
083     * @param fm the focus manager to wrap
084     */
085    WrappingFocusManager(KeyboardFocusManager fm)
086    {
087      wrapped = fm;
088    }
089
090    /**
091     * Wraps {@link DefaultKeyboardFocusManager#dispatchEvent(AWTEvent)}.
092     *
093     * @param ev the event to dispatch
094     *
095     * @return <code>true</code> if the event has been dispatched,
096     *         <code>false</code> otherwise
097     */
098    public boolean dispatchEvent(AWTEvent ev)
099    {
100      return wrapped.dispatchEvent(ev);
101    }
102
103    /**
104     * Wraps {@link DefaultKeyboardFocusManager#dispatchKeyEvent(KeyEvent)}.
105     *
106     * @param ev the event to dispatch
107     *
108     * @return <code>true</code> if the event has been dispatched,
109     *         <code>false</code> otherwise
110     */
111    public boolean dispatchKeyEvent(KeyEvent ev)
112    {
113      return wrapped.dispatchKeyEvent(ev);
114    }
115
116    /**
117     * Wraps {@link DefaultKeyboardFocusManager#downFocusCycle(Container)}.
118     *
119     * @param c the container
120     */
121    public void downFocusCycle(Container c)
122    {
123      wrapped.downFocusCycle(c);
124    }
125
126    /**
127     * Wraps {@link DefaultKeyboardFocusManager#upFocusCycle(Container)}.
128     *
129     * @param c the container
130     */
131    public void upFocusCycle(Container c)
132    {
133      wrapped.upFocusCycle(c);
134    }
135
136    /**
137     * Wraps {@link DefaultKeyboardFocusManager#focusNextComponent(Component)}.
138     *
139     * @param c the component
140     */
141    public void focusNextComponent(Component c)
142    {
143      wrapped.focusNextComponent(c);
144    }
145
146    /**
147     * Wraps
148     * {@link DefaultKeyboardFocusManager#focusPreviousComponent(Component)}.
149     *
150     * @param c the component
151     */
152    public void focusPreviousComponent(Component c)
153    {
154      wrapped.focusPreviousComponent(c);
155    }
156
157    /**
158     * Wraps {@link DefaultKeyboardFocusManager#postProcessKeyEvent(KeyEvent)}.
159     *
160     * @param e the key event
161     *
162     * @return a boolead
163     */
164    public boolean postProcessKeyEvent(KeyEvent e)
165    {
166      return wrapped.postProcessKeyEvent(e);
167    }
168
169    /**
170     * Wraps
171     * {@link DefaultKeyboardFocusManager#processKeyEvent(Component, KeyEvent)}.
172     *
173     * @param c the component
174     * @param e the key event
175     */
176    public void processKeyEvent(Component c, KeyEvent e)
177    {
178      wrapped.processKeyEvent(c, e);
179    }
180
181    /**
182     * Wraps
183     * {@link KeyboardFocusManager#addKeyEventDispatcher(KeyEventDispatcher)}.
184     *
185     * @param d the dispatcher
186     */
187    public void addKeyEventDispatcher(KeyEventDispatcher d)
188    {
189      wrapped.addKeyEventDispatcher(d);
190    }
191
192    /**
193     * Wraps
194     * {@link KeyboardFocusManager#addKeyEventPostProcessor(KeyEventPostProcessor)}.
195     *
196     * @param p the post processor
197     */
198    public void addKeyEventPostProcessor(KeyEventPostProcessor p)
199    {
200      wrapped.addKeyEventPostProcessor(p);
201    }
202
203    /**
204     * Wraps {@link KeyboardFocusManager#addPropertyChangeListener(PropertyChangeListener)}.
205     *
206     * @param l the property change listener
207     */
208    public void addPropertyChangeListener(PropertyChangeListener l)
209    {
210      wrapped.addPropertyChangeListener(l);
211    }
212
213    /**
214     * Wraps {@link KeyboardFocusManager#addPropertyChangeListener(String, PropertyChangeListener)}.
215     *
216     * @param p the property name
217     * @param l the property change listener
218     */
219    public void addPropertyChangeListener(String p, PropertyChangeListener l)
220    {
221      wrapped.addPropertyChangeListener(p, l);
222    }
223
224    /**
225     * Wraps {@link KeyboardFocusManager#addVetoableChangeListener(String, VetoableChangeListener)}.
226     *
227     * @param p the property name
228     * @param l the vetoable change listener
229     */
230    public void addVetoableChangeListener(String p, VetoableChangeListener l)
231    {
232      wrapped.addVetoableChangeListener(p, l);
233    }
234
235    /**
236     * Wraps {@link KeyboardFocusManager#addVetoableChangeListener(VetoableChangeListener)}.
237     *
238     * @param l the vetoable change listener
239     */
240    public void addVetoableChangeListener(VetoableChangeListener l)
241    {
242      wrapped.addVetoableChangeListener(l);
243    }
244
245    /**
246     * Wraps {@link KeyboardFocusManager#clearGlobalFocusOwner()}.
247     */
248    public void clearGlobalFocusOwner()
249    {
250      wrapped.clearGlobalFocusOwner();
251    }
252
253    /**
254     * Wraps {@link KeyboardFocusManager#getActiveWindow()}.
255     *
256     * @return the active window
257     */
258    public Window getActiveWindow()
259    {
260      return wrapped.getActiveWindow();
261    }
262
263    /**
264     * Wraps {@link KeyboardFocusManager#getCurrentFocusCycleRoot()}.
265     *
266     * @return the focus cycle root
267     */
268    public Container getCurrentFocusCycleRoot()
269    {
270      return wrapped.getCurrentFocusCycleRoot();
271    }
272
273    /**
274     * Wraps {@link KeyboardFocusManager#getDefaultFocusTraversalKeys(int)}.
275     *
276     * @param i the ID
277     *
278     * @return the focus traversal keys
279     */
280    public Set getDefaultFocusTraversalKeys(int i)
281    {
282      return wrapped.getDefaultFocusTraversalKeys(i);
283    }
284
285    /**
286     * Wraps {@link KeyboardFocusManager#getDefaultFocusTraversalPolicy()}.
287     *
288     * @return the focus traversal policy
289     */
290    public FocusTraversalPolicy getDefaultFocusTraversalPolicy()
291    {
292      return wrapped.getDefaultFocusTraversalPolicy();
293    }
294
295    /**
296     * Wraps {@link KeyboardFocusManager#getFocusedWindow()}.
297     *
298     * @return the focused window
299     */
300    public Window getFocusedWindow()
301    {
302      return wrapped.getFocusedWindow();
303    }
304
305    /**
306     * Wraps {@link KeyboardFocusManager#getFocusOwner()}.
307     *
308     * @return the focus owner
309     */
310    public Component getFocusOwner()
311    {
312      return wrapped.getFocusOwner();
313    }
314
315    /**
316     * Wraps {@link KeyboardFocusManager#getPermanentFocusOwner()}.
317     *
318     * @return the focus owner
319     */
320    public Component getPermanentFocusOwner()
321    {
322      return wrapped.getPermanentFocusOwner();
323    }
324
325    /**
326     * Wraps {@link KeyboardFocusManager#getPropertyChangeListeners()}.
327     *
328     * @return the property change listeners
329     */
330    public PropertyChangeListener[] getPropertyChangeListeners()
331    {
332      return wrapped.getPropertyChangeListeners();
333    }
334
335    /**
336     * Wraps {@link KeyboardFocusManager#getPropertyChangeListeners(String)}.
337     *
338     * @param n the property name
339     *
340     * @return the property change listeners
341     */
342    public PropertyChangeListener[] getPropertyChangeListeners(String n)
343    {
344      return wrapped.getPropertyChangeListeners(n);
345    }
346
347    /**
348     * Wraps {@link KeyboardFocusManager#getVetoableChangeListeners()}.
349     *
350     * @return the vetoable change listeners
351     */
352    public VetoableChangeListener[] getVetoableChangeListeners()
353    {
354      return wrapped.getVetoableChangeListeners();
355    }
356
357    /**
358     * Wraps {@link KeyboardFocusManager#getVetoableChangeListeners(String)}.
359     *
360     * @param n the property name
361     *
362     * @return the vetoable change listeners
363     */
364    public VetoableChangeListener[] getVetoableChangeListeners(String n)
365    {
366      return wrapped.getVetoableChangeListeners(n);
367    }
368
369
370    /**
371     * Wraps
372     * {@link KeyboardFocusManager#removeKeyEventDispatcher(KeyEventDispatcher)}.
373     *
374     * @param d the key event dispatcher to remove
375     */
376    public void removeKeyEventDispatcher(KeyEventDispatcher d)
377    {
378      wrapped.removeKeyEventDispatcher(d);
379    }
380
381    /**
382     * Wraps
383     * {@link KeyboardFocusManager#removeKeyEventPostProcessor(KeyEventPostProcessor)}.
384     *
385     * @param p the post processor
386     */
387    public void removeKeyEventPostProcessor(KeyEventPostProcessor p)
388    {
389      wrapped.removeKeyEventPostProcessor(p);
390    }
391
392    /**
393     * Wraps
394     * {@link KeyboardFocusManager#removePropertyChangeListener(PropertyChangeListener)}.
395     *
396     * @param l the listener
397     */
398    public void removePropertyChangeListener(PropertyChangeListener l)
399    {
400      wrapped.removePropertyChangeListener(l);
401    }
402
403    /**
404     * Wraps
405     * {@link KeyboardFocusManager#removePropertyChangeListener(String, PropertyChangeListener)}.
406     *
407     * @param n the property name
408     * @param l the listener
409     */
410    public void removePropertyChangeListener(String n, PropertyChangeListener l)
411    {
412      wrapped.removePropertyChangeListener(n, l);
413    }
414
415    /**
416     * Wraps
417     * {@link KeyboardFocusManager#removeVetoableChangeListener(VetoableChangeListener)}.
418     *
419     * @param l the listener
420     */
421    public void removeVetoableChangeListener(VetoableChangeListener l)
422    {
423      wrapped.removeVetoableChangeListener(l);
424    }
425
426    /**
427     * Wraps
428     * {@link KeyboardFocusManager#removeVetoableChangeListener(String, VetoableChangeListener)}.
429     *
430     * @param n the property name
431     * @param l the listener
432     */
433    public void removeVetoableChangeListener(String n, VetoableChangeListener l)
434    {
435      wrapped.removeVetoableChangeListener(n, l);
436    }
437
438    /**
439     * Wraps
440     * {@link KeyboardFocusManager#setDefaultFocusTraversalKeys(int, Set)}.
441     *
442     * @param id the ID
443     * @param k the keystrokes
444     */
445    public void setDefaultFocusTraversalKeys(int id, Set k)
446    {
447      wrapped.setDefaultFocusTraversalKeys(id, k);
448    }
449
450    /**
451     * Wraps {@link KeyboardFocusManager#setDefaultFocusTraversalPolicy(FocusTraversalPolicy)}.
452     *
453     * @param p the focus traversal policy
454     */
455    public void setDefaultFocusTraversalPolicy(FocusTraversalPolicy p)
456    {
457      wrapped.setDefaultFocusTraversalPolicy(p);
458    }
459
460    /**
461     * Wraps
462     * {@link KeyboardFocusManager#setGlobalCurrentFocusCycleRoot(Container)}.
463     *
464     * @param r the focus cycle root
465     */
466    public void setGlobalCurrentFocusCycleRoot(Container r)
467    {
468      wrapped.setGlobalCurrentFocusCycleRoot(r);
469    }
470  }
471
472  /**
473   * FOCUS_MANAGER_CLASS_PROPERTY
474   */
475  public static final String FOCUS_MANAGER_CLASS_PROPERTY =
476    "FocusManagerClassName";
477
478  /**
479   * Constructor FocusManager
480   */
481  public FocusManager()
482  {
483    super();
484  }
485
486  /**
487   * getCurrentManager
488   * @return FocusManager
489   */
490  public static FocusManager getCurrentManager()
491  {
492    KeyboardFocusManager m =
493      KeyboardFocusManager.getCurrentKeyboardFocusManager();
494    return new WrappingFocusManager(m);
495  }
496
497  /**
498   * setCurrentManager
499   * @param manager TODO
500   */
501  public static void setCurrentManager(FocusManager manager)
502  {
503    KeyboardFocusManager.setCurrentKeyboardFocusManager(manager);
504  }
505
506  /**
507   * disableSwingFocusManager
508   * @deprecated 1.4
509   */
510  public static void disableSwingFocusManager()
511  {
512    // TODO
513  }
514
515  /**
516   * isFocusManagerEnabled
517   * @return boolean
518   * @deprecated 1.4
519   */
520  public static boolean isFocusManagerEnabled()
521  {
522    return false; // TODO
523  }
524}