classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: Reworked Swing FocusManager


From: Roman Kennke
Subject: [cp-patches] FYI: Reworked Swing FocusManager
Date: Thu, 07 Jul 2005 14:44:06 +0200
User-agent: Mozilla Thunderbird 1.0.2 (X11/20050317)

I have finally gotten to fix the javax.swing.FocusManager. This class is officially obsoleted, and replaced by the new java.awt.KeyboardFocusManager stuff. We should support it nevertheless. (at least I have an app here that uses the old API).

In order to achieve this we actually have to use the Swing FocusManager in AWT instead of the DefaultKeyboardFocusManager (javax.swing.FocusManager is a subclass of the DefaultKeyboardFocusManager). In order to not add dependencies into Swing in AWT, I created a subclass of javax.swing.FocusManager in gnu.java.awt (no, we cannot use FocusManager directly because it is abstract - thanks to the great design of the JDK), and let the KeyboardManager create its instance of the FocusManager based on the value of the new system property gnu.java.awt.FocusManager. So at least I did not have to hardcode the Swing dependency. And in case a VM vendor does not need/want Swing, this is easily changed to java.awt.DefaultFocusManager.

2005-07-07  Roman Kennke  <address@hidden>

       * gnu/java/awt/FocusManager.java: New class. Provides a concrete
       implementation of javax.swing.FocusManager so that we can support
       the old-style FocusManager in Swing and AWT.
       * gnu/classpath/SystemProperties.java: Add new system property
       gnu.java.awt.FocusManager that sets the class that should be used
       as the default FocusManager in AWT and Swing.
       * java/awt/KeyboardFocusManager.java
       (setCurrentKeyboardFocusManager): Use createFocusManager instead
       of creating the instance directly.
       (createFocusManager): New method. Instantiate a KeyboardFocusManager
       that is set by the system property gnu.java.awt.FocusManager.
       * javax/swing.FocusManager.java
       (constructor): Call super() here.
       (getCurrentManager): Return the current AWT KeyboardFocusManager
       here.
       (setCurrentManager): Set the current AWT KeyboardFocusManager
       here.
       (processKeyEvent): Removed method. This is no longer in the
       API.
       (focusNextComponent): Removed method. This is no longer in the
       API.
       (focusPreviousComponent): Removed method. This is no longer in the
       API.

/Roman

? lib/META-INF
Index: gnu/classpath/SystemProperties.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/classpath/SystemProperties.java,v
retrieving revision 1.8
diff -u -r1.8 SystemProperties.java
--- gnu/classpath/SystemProperties.java 2 Jul 2005 20:32:10 -0000       1.8
+++ gnu/classpath/SystemProperties.java 7 Jul 2005 12:27:47 -0000
@@ -106,6 +106,12 @@
     if (defaultProperties.get("file.encoding") == null)
       defaultProperties.put("file.encoding", "8859_1");
 
+    // Default to the Swing FocusManager so that the old-style Swing API
+    // for FocusManager can be supported without hardcoding it in AWT.
+    if (defaultProperties.get("gnu.java.awt.FocusManager") == null)
+      defaultProperties.put("gnu.java.awt.FocusManager",
+                            "gnu.java.awt.FocusManager");
+
     // XXX FIXME - Temp hack for old systems that set the wrong property
     if (defaultProperties.get("java.io.tmpdir") == null)
       defaultProperties.put("java.io.tmpdir",
Index: gnu/java/awt/FocusManager.java
===================================================================
RCS file: gnu/java/awt/FocusManager.java
diff -N gnu/java/awt/FocusManager.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ gnu/java/awt/FocusManager.java      7 Jul 2005 12:27:47 -0000
@@ -0,0 +1,52 @@
+/* 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
+ * address@hidden 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.14
diff -u -r1.14 KeyboardFocusManager.java
--- java/awt/KeyboardFocusManager.java  6 Jul 2005 08:15:17 -0000       1.14
+++ java/awt/KeyboardFocusManager.java  7 Jul 2005 12:27:47 -0000
@@ -287,7 +287,7 @@
     KeyboardFocusManager manager;
 
     if (m == null)
-      manager = new DefaultKeyboardFocusManager ();
+      manager = createFocusManager();
     else
       manager = m;
 
@@ -295,6 +295,46 @@
   }
 
   /**
+   * 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;
+      }
+  }
+
+  /**
    * Retrieve the address@hidden Component} that has the keyboard focus, or
    * null if the focus owner was not set by a thread in the current
    * address@hidden java.lang.ThreadGroup}.
Index: javax/swing/FocusManager.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/FocusManager.java,v
retrieving revision 1.7
diff -u -r1.7 FocusManager.java
--- javax/swing/FocusManager.java       2 Jul 2005 20:32:47 -0000       1.7
+++ javax/swing/FocusManager.java       7 Jul 2005 12:27:48 -0000
@@ -40,6 +40,7 @@
 
 import java.awt.Component;
 import java.awt.DefaultKeyboardFocusManager;
+import java.awt.KeyboardFocusManager;
 import java.awt.event.KeyEvent;
 
 /**
@@ -50,7 +51,6 @@
 public abstract class FocusManager
   extends DefaultKeyboardFocusManager
 {
-
   /**
    * DisabledFocusManager
    */
@@ -106,7 +106,7 @@
    */
   public FocusManager()
   {
-    // TODO
+    super();
   }
 
   /**
@@ -115,7 +115,20 @@
    */
   public static FocusManager getCurrentManager()
   {
-    return null; // TODO
+    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;
   }
 
   /**
@@ -124,7 +137,7 @@
    */
   public static void setCurrentManager(FocusManager manager)
   {
-    // TODO
+    KeyboardFocusManager.setCurrentKeyboardFocusManager(manager);
   }
 
   /**
@@ -145,24 +158,4 @@
   {
     return false; // TODO
   }
-
-  /**
-   * processKeyEvent
-   * @param component TODO
-   * @param event TODO
-   */
-  public abstract void processKeyEvent(Component component, KeyEvent event);
-
-  /**
-   * focusNextComponent
-   * @param component TODO
-   */
-  public abstract void focusNextComponent(Component component);
-
-  /**
-   * focusPreviousComponent
-   * @param component TODO
-   */
-  public abstract void focusPreviousComponent(Component component);
-
 }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]