Hi,
I finally fixed the Swing/AWT FocusManager compatibility problem. The
problem was that Swing used to define a FocusManager, that was obsoleted
in Java 1.4 and replaced by the AWT FocusManager. Now the static method
getCurrentManager in the Swing FocusManager must return a Swing
FocusManager, but the AWT DefaultFocusManager is only a superclass of
this. The solution until now has been the gnu.java.awt.FocusManager that
could be used when compatibility was needed using a system property. The
solution now is more generic and returns a Swing FocusManager that wraps
the current AWT focus manager completely.
2005-10-28 Roman Kennke <[EMAIL PROTECTED]>
* java/awt/KeyboardFocusManager.java
(setCurrentKeyboardFocusManager): Create a
DefaultKeyboardFocusManager
directly.
(createFocusManager): Removed.
* gnu/java/awt/FocusManager.java: Removed.
* javax/swing/FocusManager.java
(DisabledFocusManager): Removed inner class.
(WrappingFocusManager): New inner class.
(getCurrentManager): Return WrappingKeyboardFocusManager instance.
/Roman
Index: gnu/java/awt/FocusManager.java
===================================================================
RCS file: gnu/java/awt/FocusManager.java
diff -N gnu/java/awt/FocusManager.java
--- gnu/java/awt/FocusManager.java 7 Jul 2005 12:37:04 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,52 +0,0 @@
-/* FocusManager.java -- Provide Swing FocusManager API compatibility
- Copyright (C) 2005 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-package gnu.java.awt;
-
-/**
- * This is a subclass of the otherwise abstract class
- * [EMAIL PROTECTED] javax.swing.FocusManager}. Its sole purpose is to make the Swing
- * FocusManager usable as a FocusManager in AWT, so that we can provide both
- * the new (1.4) KeyboardFocusManager API and still support the older
- * Swing FocusManager.
- *
- * @author Roman Kennke
- */
-public class FocusManager
- extends javax.swing.FocusManager
-{
-}
Index: java/awt/KeyboardFocusManager.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/KeyboardFocusManager.java,v
retrieving revision 1.16
diff -u -r1.16 KeyboardFocusManager.java
--- java/awt/KeyboardFocusManager.java 3 Oct 2005 17:21:06 -0000 1.16
+++ java/awt/KeyboardFocusManager.java 28 Oct 2005 16:37:01 -0000
@@ -288,51 +288,11 @@
KeyboardFocusManager manager;
if (m == null)
- manager = createFocusManager();
+ manager = new DefaultKeyboardFocusManager();
else
manager = m;
currentKeyboardFocusManagers.put (currentGroup, manager);
- }
-
- /**
- * Creates a KeyboardFocusManager. The exact class is determined by the
- * system property 'gnu.java.awt.FocusManager'. If this is not set,
- * we default to DefaultKeyboardFocusManager.
- */
- private static KeyboardFocusManager createFocusManager()
- {
- String fmClassName = System.getProperty("gnu.java.awt.FocusManager",
- "java.awt.DefaultKeyboardFocusManager");
- try
- {
- Class fmClass = Class.forName(fmClassName);
- KeyboardFocusManager fm = (KeyboardFocusManager) fmClass.newInstance();
- return fm;
- }
- catch (ClassNotFoundException ex)
- {
- System.err.println("The class " + fmClassName + " cannot be found.");
- System.err.println("Check the setting of the system property");
- System.err.println("gnu.java.awt.FocusManager");
- return null;
- }
- catch (InstantiationException ex)
- {
- System.err.println("The class " + fmClassName + " cannot be");
- System.err.println("instantiated.");
- System.err.println("Check the setting of the system property");
- System.err.println("gnu.java.awt.FocusManager");
- return null;
- }
- catch (IllegalAccessException ex)
- {
- System.err.println("The class " + fmClassName + " cannot be");
- System.err.println("accessed.");
- System.err.println("Check the setting of the system property");
- System.err.println("gnu.java.awt.FocusManager");
- return null;
- }
}
/**
Index: javax/swing/FocusManager.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/FocusManager.java,v
retrieving revision 1.9
diff -u -r1.9 FocusManager.java
--- javax/swing/FocusManager.java 27 Jul 2005 12:41:33 -0000 1.9
+++ javax/swing/FocusManager.java 28 Oct 2005 16:37:01 -0000
@@ -38,10 +38,19 @@
package javax.swing;
+import java.awt.AWTEvent;
import java.awt.Component;
+import java.awt.Container;
import java.awt.DefaultKeyboardFocusManager;
+import java.awt.FocusTraversalPolicy;
+import java.awt.KeyEventDispatcher;
+import java.awt.KeyEventPostProcessor;
import java.awt.KeyboardFocusManager;
+import java.awt.Window;
import java.awt.event.KeyEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.VetoableChangeListener;
+import java.util.Set;
/**
* This class has been obsoleted by the new
@@ -54,46 +63,409 @@
extends DefaultKeyboardFocusManager
{
/**
- * DisabledFocusManager
+ * A FocusManager that wraps an AWT KeyboardFocusManager and forwards all
+ * method calls to it. This is used for compatibility with the new focus
+ * system.
+ *
+ * @author Roman Kennke ([EMAIL PROTECTED])
*/
- static class DisabledFocusManager
+ private static class WrappingFocusManager
extends FocusManager
{
+ /**
+ * The wrapped KeyboardFocusManager.
+ */
+ private KeyboardFocusManager wrapped;
+
+ /**
+ * Creates a new instance of WrappedFocusManager.
+ *
+ * @param fm the focus manager to wrap
+ */
+ WrappingFocusManager(KeyboardFocusManager fm)
+ {
+ wrapped = fm;
+ }
+
+ /**
+ * Wraps [EMAIL PROTECTED] DefaultKeyboardFocusManager#dispatchEvent(AWTEvent)}.
+ *
+ * @param ev the event to dispatch
+ *
+ * @return <code>true</code> if the event has been dispatched,
+ * <code>false</code> otherwise
+ */
+ public boolean dispatchEvent(AWTEvent ev)
+ {
+ return wrapped.dispatchEvent(ev);
+ }
+
+ /**
+ * Wraps [EMAIL PROTECTED] DefaultKeyboardFocusManager#dispatchKeyEvent(KeyEvent)}.
+ *
+ * @param ev the event to dispatch
+ *
+ * @return <code>true</code> if the event has been dispatched,
+ * <code>false</code> otherwise
+ */
+ public boolean dispatchKeyEvent(KeyEvent ev)
+ {
+ return wrapped.dispatchKeyEvent(ev);
+ }
+
+ /**
+ * Wraps [EMAIL PROTECTED] DefaultKeyboardFocusManager#downFocusCycle(Container)}.
+ *
+ * @param c the container
+ */
+ public void downFocusCycle(Container c)
+ {
+ wrapped.downFocusCycle(c);
+ }
+
+ /**
+ * Wraps [EMAIL PROTECTED] DefaultKeyboardFocusManager#upFocusCycle(Container)}.
+ *
+ * @param c the container
+ */
+ public void upFocusCycle(Container c)
+ {
+ wrapped.upFocusCycle(c);
+ }
+
+ /**
+ * Wraps [EMAIL PROTECTED] DefaultKeyboardFocusManager#focusNextComponent(Component)}.
+ *
+ * @param c the component
+ */
+ public void focusNextComponent(Component c)
+ {
+ wrapped.focusNextComponent(c);
+ }
+
+ /**
+ * Wraps
+ * [EMAIL PROTECTED] DefaultKeyboardFocusManager#focusPreviousComponent(Component)}.
+ *
+ * @param c the component
+ */
+ public void focusPreviousComponent(Component c)
+ {
+ wrapped.focusPreviousComponent(c);
+ }
+
+ /**
+ * Wraps [EMAIL PROTECTED] DefaultKeyboardFocusManager#postProcessKeyEvent(KeyEvent)}.
+ *
+ * @param e the key event
+ *
+ * @return a boolead
+ */
+ public boolean postProcessKeyEvent(KeyEvent e)
+ {
+ return wrapped.postProcessKeyEvent(e);
+ }
+
+ /**
+ * Wraps
+ * [EMAIL PROTECTED] DefaultKeyboardFocusManager#processKeyEvent(Component, KeyEvent)}.
+ *
+ * @param c the component
+ * @param e the key event
+ */
+ public void processKeyEvent(Component c, KeyEvent e)
+ {
+ wrapped.processKeyEvent(c, e);
+ }
+
+ /**
+ * Wraps
+ * [EMAIL PROTECTED] KeyboardFocusManager#addKeyEventDispatcher(KeyEventDispatcher)}.
+ *
+ * @param d the dispatcher
+ */
+ public void addKeyEventDispatcher(KeyEventDispatcher d)
+ {
+ wrapped.addKeyEventDispatcher(d);
+ }
+
+ /**
+ * Wraps
+ * [EMAIL PROTECTED] KeyboardFocusManager#addKeyEventPostProcessor(KeyEventPostProcessor)}.
+ *
+ * @param p the post processor
+ */
+ public void addKeyEventPostProcessor(KeyEventPostProcessor p)
+ {
+ wrapped.addKeyEventPostProcessor(p);
+ }
+
+ /**
+ * Wraps [EMAIL PROTECTED] KeyboardFocusManager#addPropertyChangeListener(PropertyChangeListener)}.
+ *
+ * @param l the property change listener
+ */
+ public void addPropertyChangeListener(PropertyChangeListener l)
+ {
+ wrapped.addPropertyChangeListener(l);
+ }
+
+ /**
+ * Wraps [EMAIL PROTECTED] KeyboardFocusManager#addPropertyChangeListener(String, PropertyChangeListener)}.
+ *
+ * @param p the property name
+ * @param l the property change listener
+ */
+ public void addPropertyChangeListener(String p, PropertyChangeListener l)
+ {
+ wrapped.addPropertyChangeListener(p, l);
+ }
+
+ /**
+ * Wraps [EMAIL PROTECTED] KeyboardFocusManager#addVetoableChangeListener(String, VetoableChangeListener)}.
+ *
+ * @param p the property name
+ * @param l the vetoable change listener
+ */
+ public void addVetoableChangeListener(String p, VetoableChangeListener l)
+ {
+ wrapped.addVetoableChangeListener(p, l);
+ }
+
+ /**
+ * Wraps [EMAIL PROTECTED] KeyboardFocusManager#addVetoableChangeListener(VetoableChangeListener)}.
+ *
+ * @param l the vetoable change listener
+ */
+ public void addVetoableChangeListener(VetoableChangeListener l)
+ {
+ wrapped.addVetoableChangeListener(l);
+ }
+
+ /**
+ * Wraps [EMAIL PROTECTED] KeyboardFocusManager#clearGlobalFocusOwner()}.
+ */
+ public void clearGlobalFocusOwner()
+ {
+ wrapped.clearGlobalFocusOwner();
+ }
+
+ /**
+ * Wraps [EMAIL PROTECTED] KeyboardFocusManager#getActiveWindow()}.
+ *
+ * @return the active window
+ */
+ public Window getActiveWindow()
+ {
+ return wrapped.getActiveWindow();
+ }
+
+ /**
+ * Wraps [EMAIL PROTECTED] KeyboardFocusManager#getCurrentFocusCycleRoot()}.
+ *
+ * @return the focus cycle root
+ */
+ public Container getCurrentFocusCycleRoot()
+ {
+ return wrapped.getCurrentFocusCycleRoot();
+ }
+
+ /**
+ * Wraps [EMAIL PROTECTED] KeyboardFocusManager#getDefaultFocusTraversalKeys(int)}.
+ *
+ * @param i the ID
+ *
+ * @return the focus traversal keys
+ */
+ public Set getDefaultFocusTraversalKeys(int i)
+ {
+ return wrapped.getDefaultFocusTraversalKeys(i);
+ }
+
+ /**
+ * Wraps [EMAIL PROTECTED] KeyboardFocusManager#getDefaultFocusTraversalPolicy()}.
+ *
+ * @return the focus traversal policy
+ */
+ public FocusTraversalPolicy getDefaultFocusTraversalPolicy()
+ {
+ return wrapped.getDefaultFocusTraversalPolicy();
+ }
+
+ /**
+ * Wraps [EMAIL PROTECTED] KeyboardFocusManager#getFocusedWindow()}.
+ *
+ * @return the focused window
+ */
+ public Window getFocusedWindow()
+ {
+ return wrapped.getFocusedWindow();
+ }
+
+ /**
+ * Wraps [EMAIL PROTECTED] KeyboardFocusManager#getFocusOwner()}.
+ *
+ * @return the focus owner
+ */
+ public Component getFocusOwner()
+ {
+ return wrapped.getFocusOwner();
+ }
+
+ /**
+ * Wraps [EMAIL PROTECTED] KeyboardFocusManager#getPermanentFocusOwner()}.
+ *
+ * @return the focus owner
+ */
+ public Component getPermanentFocusOwner()
+ {
+ return wrapped.getPermanentFocusOwner();
+ }
+
+ /**
+ * Wraps [EMAIL PROTECTED] KeyboardFocusManager#getPropertyChangeListeners()}.
+ *
+ * @return the property change listeners
+ */
+ public PropertyChangeListener[] getPropertyChangeListeners()
+ {
+ return wrapped.getPropertyChangeListeners();
+ }
+
+ /**
+ * Wraps [EMAIL PROTECTED] KeyboardFocusManager#getPropertyChangeListeners(String)}.
+ *
+ * @param n the property name
+ *
+ * @return the property change listeners
+ */
+ public PropertyChangeListener[] getPropertyChangeListeners(String n)
+ {
+ return wrapped.getPropertyChangeListeners(n);
+ }
+
+ /**
+ * Wraps [EMAIL PROTECTED] KeyboardFocusManager#getVetoableChangeListeners()}.
+ *
+ * @return the vetoable change listeners
+ */
+ public VetoableChangeListener[] getVetoableChangeListeners()
+ {
+ return wrapped.getVetoableChangeListeners();
+ }
+
+ /**
+ * Wraps [EMAIL PROTECTED] KeyboardFocusManager#getVetoableChangeListeners(String)}.
+ *
+ * @param n the property name
+ *
+ * @return the vetoable change listeners
+ */
+ public VetoableChangeListener[] getVetoableChangeListeners(String n)
+ {
+ return wrapped.getVetoableChangeListeners(n);
+ }
+
+
+ /**
+ * Wraps
+ * [EMAIL PROTECTED] KeyboardFocusManager#removeKeyEventDispatcher(KeyEventDispatcher)}.
+ *
+ * @param d the key event dispatcher to remove
+ */
+ public void removeKeyEventDispatcher(KeyEventDispatcher d)
+ {
+ wrapped.removeKeyEventDispatcher(d);
+ }
+
+ /**
+ * Wraps
+ * [EMAIL PROTECTED] KeyboardFocusManager#removeKeyEventPostProcessor(KeyEventPostProcessor)}.
+ *
+ * @param p the post processor
+ */
+ public void removeKeyEventPostProcessor(KeyEventPostProcessor p)
+ {
+ wrapped.removeKeyEventPostProcessor(p);
+ }
+
+ /**
+ * Wraps
+ * [EMAIL PROTECTED] KeyboardFocusManager#removePropertyChangeListener(PropertyChangeListener)}.
+ *
+ * @param l the listener
+ */
+ public void removePropertyChangeListener(PropertyChangeListener l)
+ {
+ wrapped.removePropertyChangeListener(l);
+ }
+
+ /**
+ * Wraps
+ * [EMAIL PROTECTED] KeyboardFocusManager#removePropertyChangeListener(String, PropertyChangeListener)}.
+ *
+ * @param n the property name
+ * @param l the listener
+ */
+ public void removePropertyChangeListener(String n, PropertyChangeListener l)
+ {
+ wrapped.removePropertyChangeListener(n, l);
+ }
+
+ /**
+ * Wraps
+ * [EMAIL PROTECTED] KeyboardFocusManager#removeVetoableChangeListener(VetoableChangeListener)}.
+ *
+ * @param l the listener
+ */
+ public void removeVetoableChangeListener(VetoableChangeListener l)
+ {
+ wrapped.removeVetoableChangeListener(l);
+ }
/**
- * Constructor DisabledFocusManager
+ * Wraps
+ * [EMAIL PROTECTED] KeyboardFocusManager#removeVetoableChangeListener(String, VetoableChangeListener)}.
+ *
+ * @param n the property name
+ * @param l the listener
*/
- DisabledFocusManager()
+ public void removeVetoableChangeListener(String n, VetoableChangeListener l)
{
- // TODO
+ wrapped.removeVetoableChangeListener(n, l);
}
/**
- * processKeyEvent
- * @param component TODO
- * @param event TODO
+ * Wraps
+ * [EMAIL PROTECTED] KeyboardFocusManager#setDefaultFocusTraversalKeys(int, Set)}.
+ *
+ * @param id the ID
+ * @param k the keystrokes
*/
- public void processKeyEvent(Component component, KeyEvent event)
+ public void setDefaultFocusTraversalKeys(int id, Set k)
{
- // TODO
+ wrapped.setDefaultFocusTraversalKeys(id, k);
}
/**
- * focusNextComponent
- * @param component TODO
+ * Wraps [EMAIL PROTECTED] KeyboardFocusManager#setDefaultFocusTraversalPolicy(FocusTraversalPolicy)}.
+ *
+ * @param p the focus traversal policy
*/
- public void focusNextComponent(Component component)
+ public void setDefaultFocusTraversalPolicy(FocusTraversalPolicy p)
{
- // TODO
+ wrapped.setDefaultFocusTraversalPolicy(p);
}
/**
- * focusPreviousComponent
- * @param value0 TODO
+ * Wraps
+ * [EMAIL PROTECTED] KeyboardFocusManager#setGlobalCurrentFocusCycleRoot(Container)}.
+ *
+ * @param r the focus cycle root
*/
- public void focusPreviousComponent(Component value0)
+ public void setGlobalCurrentFocusCycleRoot(Container r)
{
- // TODO
+ wrapped.setGlobalCurrentFocusCycleRoot(r);
}
}
@@ -117,20 +489,9 @@
*/
public static FocusManager getCurrentManager()
{
- KeyboardFocusManager fm =
- KeyboardFocusManager.getCurrentKeyboardFocusManager();
- if (fm instanceof FocusManager)
- return (FocusManager) fm;
- else
- {
- System.err.println("The Swing FocusManager API has been obsoleted by");
- System.err.println("the new KeyboardFocusManager system.");
- System.err.println("You should either not use the Swing FocusManager");
- System.err.println("API or set the system property");
- System.err.println
- ("gnu.java.awt.FocusManager=javax.swing.FocusManager");
- }
- return null;
+ KeyboardFocusManager m =
+ KeyboardFocusManager.getCurrentKeyboardFocusManager();
+ return new WrappingFocusManager(m);
}
/**
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches