summaryrefslogtreecommitdiffstats
path: root/libjava/classpath/javax/swing/plaf/basic/BasicRadioButtonUI.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/javax/swing/plaf/basic/BasicRadioButtonUI.java')
-rw-r--r--libjava/classpath/javax/swing/plaf/basic/BasicRadioButtonUI.java78
1 files changed, 57 insertions, 21 deletions
diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicRadioButtonUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicRadioButtonUI.java
index a7da21c4f6e..aed4d69d6d5 100644
--- a/libjava/classpath/javax/swing/plaf/basic/BasicRadioButtonUI.java
+++ b/libjava/classpath/javax/swing/plaf/basic/BasicRadioButtonUI.java
@@ -42,6 +42,7 @@ import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
+import java.awt.Insets;
import java.awt.Rectangle;
import javax.swing.AbstractButton;
@@ -92,14 +93,6 @@ public class BasicRadioButtonUI extends BasicToggleButtonUI
protected void installDefaults(AbstractButton b)
{
super.installDefaults(b);
- if (b.getIcon() == null)
- b.setIcon(icon);
- if (b.getSelectedIcon() == null)
- b.setSelectedIcon(icon);
- if (b.getDisabledIcon() == null)
- b.setDisabledIcon(icon);
- if (b.getDisabledSelectedIcon() == null)
- b.setDisabledSelectedIcon(icon);
}
/**
@@ -145,16 +138,17 @@ public class BasicRadioButtonUI extends BasicToggleButtonUI
g.setFont(f);
ButtonModel m = b.getModel();
- Icon currentIcon = null;
- if (m.isSelected() && m.isEnabled())
- currentIcon = b.getSelectedIcon();
- else if (! m.isSelected() && m.isEnabled())
- currentIcon = b.getIcon();
- else if (m.isSelected() && ! m.isEnabled())
- currentIcon = b.getDisabledSelectedIcon();
- else // (!m.isSelected() && ! m.isEnabled())
- currentIcon = b.getDisabledIcon();
+ // FIXME: Do a filtering on any customized icon if the following property
+ // is set.
+ boolean enabled = b.isEnabled();
+
+ Icon currentIcon = b.getIcon();
+ if (currentIcon == null)
+ {
+ currentIcon = getDefaultIcon();
+ }
+
SwingUtilities.calculateInnerArea(b, vr);
String text = SwingUtilities.layoutCompoundLabel(c, g.getFontMetrics(f),
b.getText(), currentIcon,
@@ -162,15 +156,57 @@ public class BasicRadioButtonUI extends BasicToggleButtonUI
b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
vr, ir, tr, b.getIconTextGap() + defaultTextShiftOffset);
- if (currentIcon != null)
- {
- currentIcon.paintIcon(c, g, ir.x, ir.y);
- }
+ currentIcon.paintIcon(c, g, ir.x, ir.y);
+
if (text != null)
paintText(g, b, tr, text);
if (b.hasFocus() && b.isFocusPainted() && m.isEnabled())
paintFocus(g, tr, c.getSize());
}
+
+ 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;
+
+ Rectangle contentRect;
+ Rectangle viewRect;
+ Rectangle iconRect = new Rectangle();
+ Rectangle textRect = new Rectangle();
+ Insets insets = b.getInsets();
+
+ Icon i = b.getIcon();
+ if (i == null)
+ i = getDefaultIcon();
+
+ viewRect = new Rectangle();
+
+ SwingUtilities.layoutCompoundLabel(
+ b, // for the component orientation
+ b.getFontMetrics(b.getFont()),
+ b.getText(),
+ i,
+ b.getVerticalAlignment(),
+ b.getHorizontalAlignment(),
+ b.getVerticalTextPosition(),
+ b.getHorizontalTextPosition(),
+ viewRect, iconRect, textRect,
+ defaultTextIconGap + defaultTextShiftOffset);
+
+ contentRect = textRect.union(iconRect);
+
+ return new Dimension(insets.left
+ + contentRect.width
+ + insets.right + b.getHorizontalAlignment(),
+ insets.top
+ + contentRect.height
+ + insets.bottom);
+ }
/**
* Paints the focus indicator for JRadioButtons.
OpenPOWER on IntegriCloud