classpath-patches
[Top][All Lists]
Advanced

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

[cp-patches] FYI: MetalLabelUI


From: David Gilbert
Subject: [cp-patches] FYI: MetalLabelUI
Date: Tue, 30 Aug 2005 13:50:58 +0000
User-agent: Mozilla Thunderbird 1.0.6 (X11/20050728)

I implemented a missing method in MetalLabelUI and updated the defaults in MetalLookAndFeel. This changes the appearance of disabled labels slightly to match Sun's implementation:

2005-08-30  David Gilbert  <address@hidden>

        * javax/swing/plaf/metal/MetalLabelUI.java
        (instance): renamed 'metalLabelUI' and changed from private to
        protected,
        (createUI): modified for renamed field,
        (paintDisabledText): implemented,
        * javax/swing/plaf/metal/MetalLookAndFeel.java
        (initComponentDefaults): modified Label defaults.

The patch is committed.

Regards,

Dave
Index: javax/swing/plaf/metal/MetalLabelUI.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalLabelUI.java,v
retrieving revision 1.3
diff -u -r1.3 MetalLabelUI.java
--- javax/swing/plaf/metal/MetalLabelUI.java    2 Jul 2005 20:32:51 -0000       
1.3
+++ javax/swing/plaf/metal/MetalLabelUI.java    30 Aug 2005 12:44:23 -0000
@@ -38,17 +38,26 @@
 
 package javax.swing.plaf.metal;
 
+import java.awt.Color;
+import java.awt.Graphics;
+
 import javax.swing.JComponent;
+import javax.swing.JLabel;
+import javax.swing.UIDefaults;
+import javax.swing.UIManager;
 import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.basic.BasicGraphicsUtils;
 import javax.swing.plaf.basic.BasicLabelUI;
 
+/**
+ * A UI delegate used for address@hidden JLabel}s in the address@hidden 
MetalLookAndFeel}.
+ */
 public class MetalLabelUI
   extends BasicLabelUI
 {
 
-  // FIXME: maybe replace by a Map of instances when this becomes stateful
   /** The shared UI instance for JLabels. */
-  private static MetalLabelUI instance = null;
+  protected static MetalLabelUI metalLabelUI;
 
   /**
    * Constructs a new instance of MetalLabelUI.
@@ -67,8 +76,36 @@
    */
   public static ComponentUI createUI(JComponent component)
   {
-    if (instance == null)
-      instance = new MetalLabelUI();
-    return instance;
+    if (metalLabelUI == null)
+      metalLabelUI = new MetalLabelUI();
+    return metalLabelUI;
+  }
+  
+  /**
+   * Draws the text for a disabled label, using the color defined in the 
+   * address@hidden UIDefaults} with the key 
<code>Label.disabledForeground</code>.
+   * 
+   * @param l  the label.
+   * @param g  the graphics device.
+   * @param s  the label text.
+   * @param textX  the x-coordinate for the label.
+   * @param textY  the y-coordinate for the label.
+   * 
+   * @see UIManager#getLookAndFeelDefaults()
+   */
+  protected void paintDisabledText(JLabel l, Graphics g, String s, int textX,
+                                 int textY)
+  {
+    Color savedColor = g.getColor();
+    UIDefaults defaults = UIManager.getLookAndFeelDefaults();
+    g.setColor(defaults.getColor("Label.disabledForeground"));
+    int mnemIndex = l.getDisplayedMnemonicIndex();
+    if (mnemIndex != -1)
+      BasicGraphicsUtils.drawStringUnderlineCharAt(g, s, mnemIndex, textX,
+          textY);
+    else
+      g.drawString(s, textX, textY);
+
+    g.setColor(savedColor);
   }
 }
Index: javax/swing/plaf/metal/MetalLookAndFeel.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalLookAndFeel.java,v
retrieving revision 1.44
diff -u -r1.44 MetalLookAndFeel.java
--- javax/swing/plaf/metal/MetalLookAndFeel.java        30 Aug 2005 09:42:23 
-0000      1.44
+++ javax/swing/plaf/metal/MetalLookAndFeel.java        30 Aug 2005 12:44:23 
-0000
@@ -797,8 +797,8 @@
         MetalIconFactory.getInternalFrameMinimizeIcon(16),
       "Label.background", new ColorUIResource(getControl()),
       "Label.font", getControlTextFont(),
-      "Label.disabledForeground", new ColorUIResource(getControlDisabled()),
-      "Label.foreground", new ColorUIResource(getSystemTextColor()),
+      "Label.disabledForeground", new 
ColorUIResource(getInactiveControlTextColor()),
+      "Label.foreground", new ColorUIResource(getControlTextColor()),
       "Menu.background", new ColorUIResource(getControl()),
       "Menu.border", new MetalBorders.MenuItemBorder(),
       "Menu.borderPainted", Boolean.TRUE,

reply via email to

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