This fixes the handling of the swing.boldMetal property. It also allows
the use of the system property with the same name.

2006-09-20  Roman Kennke  <[EMAIL PROTECTED]>

        PR 29036
        * javax/swing/plaf/metal/DefaultMetalTheme.java
        (PLAIN_CONTROL_TEXT_FONT): New constant field.
        (BOLD_CONTROL_TEXT_FONT): New constant field.
        (PLAIN_MENU_TEXT_FONT): New constant field.
        (BOLD_MENU_TEXT_FONT): New constant field.
        (controlTextFont): Removed.
        (menuTextFont): Removed.
        (CONTROL_TEXT_FONT): New constant field.
        (MENU_TEXT_FONT): New constant field.
        (getControlTextFont): Use getFont() helper method for fetching
        the correct font.
        (getMenuTextFont): Use getFont() helper method for fetching
        the correct font.
        (getFont): New helper method.
        (isBoldMetal): New helper method.

/Roman

Index: javax/swing/plaf/metal/DefaultMetalTheme.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/DefaultMetalTheme.java,v
retrieving revision 1.5
diff -u -1 -5 -r1.5 DefaultMetalTheme.java
--- javax/swing/plaf/metal/DefaultMetalTheme.java	12 Sep 2006 14:30:53 -0000	1.5
+++ javax/swing/plaf/metal/DefaultMetalTheme.java	20 Sep 2006 15:33:44 -0000
@@ -26,30 +26,32 @@
 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 javax.swing.plaf.metal;
 
+import gnu.classpath.SystemProperties;
+
 import java.awt.Font;
 
 import javax.swing.UIManager;
 import javax.swing.plaf.ColorUIResource;
 import javax.swing.plaf.FontUIResource;
 
 /**
  * The default theme for the [EMAIL PROTECTED] MetalLookAndFeel}.
  * 
  * @see MetalLookAndFeel#setCurrentTheme(MetalTheme)
  */
 public class DefaultMetalTheme extends MetalTheme
 {
   private static final ColorUIResource PRIMARY1 =
     new ColorUIResource(102, 102, 153);
@@ -61,35 +63,63 @@
     new ColorUIResource(102, 102, 102);
   private static final ColorUIResource SECONDARY2 = 
     new ColorUIResource(153, 153, 153);
   private static final ColorUIResource SECONDARY3 = 
     new ColorUIResource(204, 204, 204);
   
   private static final FontUIResource SUB_TEXT_FONT =
     new FontUIResource("Dialog", Font.PLAIN, 10);
   private static final FontUIResource SYSTEM_TEXT_FONT =
     new FontUIResource("Dialog", Font.PLAIN, 12);
   private static final FontUIResource USER_TEXT_FONT =
     new FontUIResource("Dialog", Font.PLAIN, 12);
   private static final FontUIResource WINDOW_TITLE_FONT =
     new FontUIResource("Dialog", Font.BOLD, 12);
   
-  /** The control text font. */
-  private FontUIResource controlTextFont;
+  /**
+   * The control text font for swing.boldMetal=false.
+   */
+  private static final FontUIResource PLAIN_CONTROL_TEXT_FONT =
+    new FontUIResource("Dialog", Font.PLAIN, 12);
 
-  /** The menu text font. */
-  private FontUIResource menuTextFont;
+  /**
+   * The standard control text font.
+   */
+  private static final FontUIResource BOLD_CONTROL_TEXT_FONT =
+    new FontUIResource("Dialog", Font.BOLD, 12);
+
+  /**
+   * The menu text font for swing.boldMetal=false.
+   */
+  private static final FontUIResource PLAIN_MENU_TEXT_FONT =
+    new FontUIResource("Dialog", Font.PLAIN, 12);
+
+  /**
+   * The menu control text font.
+   */
+  private static final FontUIResource BOLD_MENU_TEXT_FONT =
+    new FontUIResource("Dialog", Font.BOLD, 12);
+
+  /**
+   * Indicates the control text font.
+   */
+  static final int CONTROL_TEXT_FONT = 1;
+
+  /**
+   * Indicates the menu text font.
+   */
+  static final int MENU_TEXT_FONT = 2;
   
   /**
    * Creates a new instance of this theme.
    */
   public DefaultMetalTheme()
   {
     // Do nothing here.
   }
 
   /**
    * Returns the name of the theme.
    * 
    * @return <code>"Steel"</code>.
    */
   public String getName()
@@ -155,58 +185,44 @@
   protected ColorUIResource getSecondary3()
   {
     return SECONDARY3;
   }
 
   /**
    * Returns the font used for text on controls.  In this case, the font is
    * <code>FontUIResource("Dialog", Font.BOLD, 12)</code>, unless the
    * <code>swing.boldMetal</code> UI default is set to [EMAIL PROTECTED] Boolean#FALSE} 
    * in which case it is <code>FontUIResource("Dialog", Font.PLAIN, 12)</code>.
    * 
    * @return The font.
    */
   public FontUIResource getControlTextFont()
   {
-    if (controlTextFont == null)
-      {
-        if (Boolean.FALSE.equals(UIManager.get("swing.boldMetal")))
-          controlTextFont = new FontUIResource("Dialog", Font.PLAIN, 12);
-        else
-          controlTextFont = new FontUIResource("Dialog", Font.BOLD, 12);
-      }
-    return controlTextFont;
+    return getFont(CONTROL_TEXT_FONT);
   }
   
   /**
    * Returns the font used for text in menus.  In this case, the font is
    * <code>FontUIResource("Dialog", Font.BOLD, 12)</code>, unless the
    * <code>swing.boldMetal</code> UI default is set to [EMAIL PROTECTED] Boolean#FALSE} 
    * in which case it is <code>FontUIResource("Dialog", Font.PLAIN, 12)</code>.
    * 
    * @return The font used for text in menus.
    */
   public FontUIResource getMenuTextFont()
   {
-    if (menuTextFont == null)
-      {
-        if (Boolean.FALSE.equals(UIManager.get("swing.boldMetal")))
-          menuTextFont = new FontUIResource("Dialog", Font.PLAIN, 12);
-        else
-          menuTextFont = new FontUIResource("Dialog", Font.BOLD, 12);
-      }
-    return menuTextFont;
+    return getFont(MENU_TEXT_FONT);
   }
   
   /**
    * Returns the font used for sub text.  In this case, the font is
    * <code>FontUIResource("Dialog", Font.PLAIN, 10)</code>.
    * 
    * @return The font used for sub text.
    */
   public FontUIResource getSubTextFont()
   {
     return SUB_TEXT_FONT;
   }
   
   /**
    * Returns the font used for system text.  In this case, the font is
@@ -228,16 +244,62 @@
   public FontUIResource getUserTextFont()
   {
     return USER_TEXT_FONT;
   }
   
   /**
    * Returns the font used for window titles.  In this case, the font is 
    * <code>FontUIResource("Dialog", Font.BOLD, 12)</code>.
    * 
    * @return The font used for window titles.
    */
   public FontUIResource getWindowTitleFont()
   {
     return WINDOW_TITLE_FONT;
   }
+
+  /**
+   * Returns the appropriate font. The font type to return is identified
+   * by the specified id.
+   *
+   * @param id the font type to return
+   *
+   * @return the correct font
+   */
+  private FontUIResource getFont(int id)
+  {
+    FontUIResource font = null;
+    switch (id)
+      {
+      case CONTROL_TEXT_FONT:
+        if (isBoldMetal())
+          font = BOLD_CONTROL_TEXT_FONT;
+        else
+          font = PLAIN_CONTROL_TEXT_FONT;
+        break;
+      case MENU_TEXT_FONT:
+        if (isBoldMetal())
+          font = BOLD_MENU_TEXT_FONT;
+        else
+          font = PLAIN_MENU_TEXT_FONT;
+      break;
+      // TODO: Add other font types and their mapping here.
+      }
+    return font;
+  }
+
+  /**
+   * Determines if the theme should be bold or not. The theme is bold by
+   * default, this can be turned off by setting the system property
+   * swing.boldMetal to true, or by putting the property with the same name
+   * into the current UIManager's defaults.
+   *
+   * @return <code>true</code>, when the theme is bold, <code>false</code>
+   *         otherwise
+   */
+  private boolean isBoldMetal()
+  {
+    Object boldMetal = UIManager.get("swing.boldMetal");
+    return (boldMetal == null || ! Boolean.FALSE.equals(boldMetal))
+        && ! ("false".equals(SystemProperties.getProperty("swing.boldMetal")));
+  }
 }

Reply via email to