summaryrefslogtreecommitdiff
path: root/javax/swing
diff options
context:
space:
mode:
authorRoman Kennke <roman@kennke.org>2007-01-17 09:19:35 +0000
committerRoman Kennke <roman@kennke.org>2007-01-17 09:19:35 +0000
commitd9fe5d7a9b8a0a889399d97822ad986421a121f0 (patch)
tree6867147149478c39224f9bc35e9e9edab7277f30 /javax/swing
parente6bd50e5161e5574dcbd9795abd0e32715c44580 (diff)
downloadclasspath-d9fe5d7a9b8a0a889399d97822ad986421a121f0.tar.gz
2007-01-17 Roman Kennke <kennke@aicas.com>
* 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.
Diffstat (limited to 'javax/swing')
-rw-r--r--javax/swing/plaf/basic/BasicRadioButtonUI.java97
1 files changed, 58 insertions, 39 deletions
diff --git a/javax/swing/plaf/basic/BasicRadioButtonUI.java b/javax/swing/plaf/basic/BasicRadioButtonUI.java
index bfb9e98db..3cea0d926 100644
--- a/javax/swing/plaf/basic/BasicRadioButtonUI.java
+++ b/javax/swing/plaf/basic/BasicRadioButtonUI.java
@@ -149,57 +149,24 @@ public class BasicRadioButtonUI extends BasicToggleButtonUI
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)
@@ -218,6 +185,58 @@ public class BasicRadioButtonUI extends BasicToggleButtonUI
}
}
+ /**
+ * 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