[jsword-svn] r1275 - trunk/common-swing/src/main/java/org/crosswire/common/swing

dmsmith at www.crosswire.org dmsmith at www.crosswire.org
Thu Apr 19 11:06:12 MST 2007


Author: dmsmith
Date: 2007-04-19 11:06:11 -0700 (Thu, 19 Apr 2007)
New Revision: 1275

Modified:
   trunk/common-swing/src/main/java/org/crosswire/common/swing/LookAndFeelUtil.java
Log:
Initial code to allow one to specify a new font for the entire application.

Modified: trunk/common-swing/src/main/java/org/crosswire/common/swing/LookAndFeelUtil.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/swing/LookAndFeelUtil.java	2007-04-02 18:55:26 UTC (rev 1274)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/LookAndFeelUtil.java	2007-04-19 18:06:11 UTC (rev 1275)
@@ -21,10 +21,13 @@
  */
 package org.crosswire.common.swing;
 
+import java.util.Enumeration;
+
 import javax.swing.JOptionPane;
 import javax.swing.LookAndFeel;
 import javax.swing.UIManager;
 import javax.swing.UnsupportedLookAndFeelException;
+import javax.swing.plaf.FontUIResource;
 import javax.swing.plaf.metal.MetalLookAndFeel;
 
 import org.crosswire.common.swing.plaf.MetalLFCustoms;
@@ -94,6 +97,28 @@
     }
 
     /**
+     * Set the default font for all Swing components.
+     * E.g. <code>setUIFont(new FontUIResource("Serif", Font.ITALIC, 12));</code>
+     * <br/>Note: a single resources can be changed with:
+     *   <code>UIManager.put("Label.font", new Font("Serif", Font.ITALIC, 12));</code>
+     * @param f the font to use
+     */
+    public static void setUIFont(FontUIResource f)
+    {
+        Enumeration keys = UIManager.getDefaults().keys();
+        while (keys.hasMoreElements()) {
+          Object key = keys.nextElement();
+          Object value = UIManager.get (key);
+
+          if (value instanceof FontUIResource)
+          {
+//              System.err.println(key + " = " + value);
+              UIManager.put (key, f);
+          }
+        }
+    }    
+
+    /**
      * The current PLAF
      */
     private static Class currentLAF;




More information about the jsword-svn mailing list