This fixes some minor issues with the BasicRadioButtonUI. See ChangeLog
for details.

2007-01-17  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/plaf/basic/BasicRadioButtonUI.java
        (paint): Use helper method to figure out icon. Don't override
        the icon field in that class. Check for null icons.
        (getCurrentIcon): New helper function to determine icon to be
        painted.

/Roman

Index: javax/swing/plaf/basic/BasicRadioButtonUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicRadioButtonUI.java,v
retrieving revision 1.22
diff -u -1 -5 -r1.22 BasicRadioButtonUI.java
--- javax/swing/plaf/basic/BasicRadioButtonUI.java	12 Oct 2006 12:24:43 -0000	1.22
+++ javax/swing/plaf/basic/BasicRadioButtonUI.java	17 Jan 2007 09:18:56 -0000
@@ -137,99 +137,118 @@
     textR.width = 0;
     textR.height = 0;
     iconR.x = 0;
     iconR.y = 0;
     iconR.width = 0;
     iconR.height = 0;
     viewR.x = i.left;
     viewR.y = i.right;
     viewR.width = size.width - i.left - i.right;
     viewR.height = size.height - i.top - i.bottom;
 
     Font f = c.getFont();
 
     g.setFont(f);
 
-    ButtonModel m = b.getModel();
-
     // This is the icon that we use for layout.
     Icon icon = b.getIcon();
     if (icon == null)
       icon = getDefaultIcon();
 
+    // Figure out the correct icon.
+    Icon currentIcon = getCurrentIcon(b);
+
     // Do the layout.
     String text = SwingUtilities.layoutCompoundLabel(c, g.getFontMetrics(f), 
-       b.getText(), icon,
+       b.getText(), currentIcon == null ? getDefaultIcon() : currentIcon,
        b.getVerticalAlignment(), b.getHorizontalAlignment(),
        b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
        viewR, iconR, textR, b.getIconTextGap());
 
-    // Figure out the correct icon.
-    icon = b.getIcon();
-    if (icon == null)
-      icon = getDefaultIcon();
-    else
-      {
-        if (! m.isEnabled())
-          {
-            if (m.isSelected())
-              icon = b.getDisabledSelectedIcon();
-            else
-              icon = b.getDisabledIcon();
-          }
-        else if (m.isArmed() && m.isPressed())
-          {
-            icon = b.getPressedIcon();
-            if (icon == null)
-              icon = b.getSelectedIcon();
-          }
-        else if (m.isSelected())
-          {
-            if (b.isRolloverEnabled() && m.isRollover())
-              {
-                icon = b.getRolloverSelectedIcon();
-                if (icon == null)
-                  icon = b.getSelectedIcon();
-              }
-            else
-              icon = b.getSelectedIcon();
-          }
-        else if (b.isRolloverEnabled() && m.isRollover())
-          icon = b.getRolloverIcon();
-        if (icon == null)
-          icon = b.getIcon();
-      }
     // .. and paint it.
-    icon.paintIcon(c, g, iconR.x, iconR.y);
+    if (currentIcon != null)
+      currentIcon.paintIcon(c, g, iconR.x, iconR.y);
 
     // Paint text and focus indicator.
     if (text != null)
       {
         // Maybe render HTML in the radio button.
         View v = (View) c.getClientProperty(BasicHTML.propertyKey);
         if (v != null)
           v.paint(g, textR);
         else
           paintText(g, b, textR, text);
 
         // Paint focus indicator if necessary.
         if (b.hasFocus() && b.isFocusPainted()
             && textR.width > 0 && textR.height > 0)
           paintFocus(g, textR, size);
       }
   }
   
+  /**                                                                                  
+   * Determines the icon to be displayed for the specified radio button.               
+   *                                                                                   
+   * @param b the radio button                                                         
+   *                                                                                   
+   * @return the icon                                                                  
+   */
+  private Icon getCurrentIcon(AbstractButton b)
+  {
+    ButtonModel m = b.getModel();
+    Icon currentIcon = b.getIcon();
+
+    if (currentIcon == null)
+      {
+        currentIcon = getDefaultIcon();
+      }
+    else
+      {
+        if (! m.isEnabled())
+          {
+            if (m.isSelected())
+              currentIcon = b.getDisabledSelectedIcon();
+            else
+              currentIcon = b.getDisabledIcon();
+          }
+        else if (m.isPressed() && m.isArmed())
+          {
+            currentIcon = b.getPressedIcon();
+            if (currentIcon == null)
+              currentIcon = b.getSelectedIcon();
+          }
+        else if (m.isSelected())
+          {
+            if (b.isRolloverEnabled() && m.isRollover())
+              {
+                currentIcon = b.getRolloverSelectedIcon();
+                if (currentIcon == null)
+                  currentIcon = b.getSelectedIcon();
+              }
+            else
+              currentIcon = b.getSelectedIcon();
+          }
+        else if (b.isRolloverEnabled() && m.isRollover())
+          {
+            currentIcon = b.getRolloverIcon();
+          }
+        if (currentIcon == null)
+          currentIcon = b.getIcon();
+      }
+    return currentIcon;
+  }
+
   public Dimension getPreferredSize(JComponent c)
   {
     // This is basically the same code as in
     // BasicGraphicsUtils.getPreferredButtonSize() but takes the default icon
     // property into account. JRadioButton and subclasses always have an icon:
     // the check box. If the user explicitly changes it with setIcon() that
     // one will be used for layout calculations and painting instead.
     // The other icon properties are ignored.
     AbstractButton b = (AbstractButton) c;
     
     Insets insets = b.getInsets();
 
     String text = b.getText();
     Icon i = b.getIcon();
     if (i == null)

Reply via email to