diff options
author | Roman Kennke <roman@kennke.org> | 2006-10-12 12:24:43 +0000 |
---|---|---|
committer | Roman Kennke <roman@kennke.org> | 2006-10-12 12:24:43 +0000 |
commit | 4cd9bd1a091b99b239c84d7d8704aa6026d85ad2 (patch) | |
tree | c283ad0c04bed8df66178cdc7b8c6d779796b670 /javax/swing/plaf | |
parent | a6e51ed8246130bc7bca4e52bb65e9a9ba1acbaa (diff) | |
download | classpath-4cd9bd1a091b99b239c84d7d8704aa6026d85ad2.tar.gz |
2006-10-12 Roman Kennke <kennke@aicas.com>
PR 28057
* javax/swing/plaf/basic/BasicRadioButtonUI.java
(paint): Determine correct icon. Added support for HTML label.
Added small optimizations.
(getPreferredSize): Only consider the buttons iconTextGap, and
only when the text is not null.
* javax/swing/plaf/basic/BasicLookAndFeel.java
(initComponentDefaults): Fetch border for RadioButton from
BasicButtons.getRadioButtonBorder().
* javax/swing/plaf/metal/MetalRadioButtonUI.java
(paintFocus): Paint focus rectangle one pixel smaller.
Diffstat (limited to 'javax/swing/plaf')
-rw-r--r-- | javax/swing/plaf/basic/BasicLookAndFeel.java | 3 | ||||
-rw-r--r-- | javax/swing/plaf/basic/BasicRadioButtonUI.java | 106 | ||||
-rw-r--r-- | javax/swing/plaf/metal/MetalRadioButtonUI.java | 2 |
3 files changed, 74 insertions, 37 deletions
diff --git a/javax/swing/plaf/basic/BasicLookAndFeel.java b/javax/swing/plaf/basic/BasicLookAndFeel.java index 76d67b002..51a73e2c6 100644 --- a/javax/swing/plaf/basic/BasicLookAndFeel.java +++ b/javax/swing/plaf/basic/BasicLookAndFeel.java @@ -1062,8 +1062,7 @@ public abstract class BasicLookAndFeel extends LookAndFeel "ProgressBar.repaintInterval", new Integer(50), "ProgressBar.cycleTime", new Integer(3000), "RadioButton.background", new ColorUIResource(light), - "RadioButton.border", new BorderUIResource.CompoundBorderUIResource(null, - null), + "RadioButton.border", BasicBorders.getRadioButtonBorder(), "RadioButton.darkShadow", new ColorUIResource(shadow), "RadioButton.focusInputMap", new UIDefaults.LazyInputMap(new Object[] { KeyStroke.getKeyStroke("SPACE"), "pressed", diff --git a/javax/swing/plaf/basic/BasicRadioButtonUI.java b/javax/swing/plaf/basic/BasicRadioButtonUI.java index fb84cf443..bfb9e98db 100644 --- a/javax/swing/plaf/basic/BasicRadioButtonUI.java +++ b/javax/swing/plaf/basic/BasicRadioButtonUI.java @@ -52,6 +52,7 @@ import javax.swing.JComponent; import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; +import javax.swing.text.View; /** * The BasicLookAndFeel UI implementation for @@ -129,52 +130,92 @@ public class BasicRadioButtonUI extends BasicToggleButtonUI public void paint(Graphics g, JComponent c) { AbstractButton b = (AbstractButton) c; - + Dimension size = c.getSize(); Insets i = b.getInsets(); - Rectangle tr = textR; textR.x = 0; textR.y = 0; textR.width = 0; textR.height = 0; - Rectangle ir = iconR; iconR.x = 0; iconR.y = 0; iconR.width = 0; iconR.height = 0; - Rectangle vr = viewR; viewR.x = i.left; viewR.y = i.right; - viewR.width = b.getWidth() - i.left - i.right; - viewR.height = b.getHeight() - i.top - i.bottom; + 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(); - // 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(); - } - + // This is the icon that we use for layout. + Icon icon = b.getIcon(); + if (icon == null) + icon = getDefaultIcon(); + + // Do the layout. String text = SwingUtilities.layoutCompoundLabel(c, g.getFontMetrics(f), - b.getText(), currentIcon, + b.getText(), icon, b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), - vr, ir, tr, b.getIconTextGap() + defaultTextShiftOffset); + viewR, iconR, textR, b.getIconTextGap()); - currentIcon.paintIcon(c, g, ir.x, ir.y); - + // 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); + + // Paint text and focus indicator. if (text != null) - paintText(g, b, tr, text); - if (b.hasFocus() && b.isFocusPainted() && m.isEnabled()) - paintFocus(g, tr, c.getSize()); + { + // 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); + } } public Dimension getPreferredSize(JComponent c) @@ -207,17 +248,14 @@ public class BasicRadioButtonUI extends BasicToggleButtonUI viewR.width = Short.MAX_VALUE; viewR.height = Short.MAX_VALUE; - SwingUtilities.layoutCompoundLabel( - b, // for the component orientation - b.getFontMetrics(b.getFont()), - b.getText(), - i, - b.getVerticalAlignment(), - b.getHorizontalAlignment(), - b.getVerticalTextPosition(), - b.getHorizontalTextPosition(), - viewR, iconR, textR, - defaultTextIconGap + defaultTextShiftOffset); + SwingUtilities.layoutCompoundLabel(b, // for the component orientation + b.getFontMetrics(b.getFont()), + text, i, b.getVerticalAlignment(), + b.getHorizontalAlignment(), + b.getVerticalTextPosition(), + b.getHorizontalTextPosition(), + viewR, iconR, textR, + text == null ? 0 : b.getIconTextGap()); Rectangle r = SwingUtilities.computeUnion(textR.x, textR.y, textR.width, textR.height, iconR); diff --git a/javax/swing/plaf/metal/MetalRadioButtonUI.java b/javax/swing/plaf/metal/MetalRadioButtonUI.java index 046e4942e..57f5bbe3e 100644 --- a/javax/swing/plaf/metal/MetalRadioButtonUI.java +++ b/javax/swing/plaf/metal/MetalRadioButtonUI.java @@ -177,7 +177,7 @@ public class MetalRadioButtonUI protected void paintFocus(Graphics g, Rectangle t, Dimension d) { g.setColor(focusColor); - g.drawRect(t.x - 1, t.y - 1, t.width + 2, t.height + 2); + g.drawRect(t.x - 1, t.y - 1, t.width + 1, t.height + 1); } } |