summaryrefslogtreecommitdiff
path: root/javax/swing/plaf/metal/MetalButtonUI.java
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2006-05-20 22:55:00 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2006-05-20 22:55:00 +0000
commit5418bfcd1dcd18878b4d0910610513c6247632ec (patch)
treec7e274af46c60dab1174c0b7dc6aedf45a5df6f6 /javax/swing/plaf/metal/MetalButtonUI.java
parent7eab2896e4bc891612450c50a41d99e1804fc940 (diff)
downloadclasspath-5418bfcd1dcd18878b4d0910610513c6247632ec.tar.gz
2006-05-20 Andrew John Hughes <gnu_andrew@member.fsf.org>
* Merge of HEAD to generics for 0.91 to 2006/05/20.
Diffstat (limited to 'javax/swing/plaf/metal/MetalButtonUI.java')
-rw-r--r--javax/swing/plaf/metal/MetalButtonUI.java67
1 files changed, 58 insertions, 9 deletions
diff --git a/javax/swing/plaf/metal/MetalButtonUI.java b/javax/swing/plaf/metal/MetalButtonUI.java
index 83cd33662..d6cc1bc07 100644
--- a/javax/swing/plaf/metal/MetalButtonUI.java
+++ b/javax/swing/plaf/metal/MetalButtonUI.java
@@ -39,6 +39,7 @@ exception statement from your version. */
package javax.swing.plaf.metal;
import java.awt.Color;
+import java.awt.Container;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
@@ -48,7 +49,9 @@ import javax.swing.AbstractButton;
import javax.swing.ButtonModel;
import javax.swing.JButton;
import javax.swing.JComponent;
+import javax.swing.JToolBar;
import javax.swing.SwingConstants;
+import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
@@ -121,7 +124,8 @@ public class MetalButtonUI
*
* @return A new instance of <code>MetalButtonUI</code>.
*/
- public static ComponentUI createUI(JComponent c) {
+ public static ComponentUI createUI(JComponent c)
+ {
return new MetalButtonUI();
}
@@ -187,7 +191,8 @@ public class MetalButtonUI
* @param iconRect the icon bounds.
*/
protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect,
- Rectangle textRect, Rectangle iconRect) {
+ Rectangle textRect, Rectangle iconRect)
+ {
if (b.isEnabled() && b.hasFocus() && b.isFocusPainted())
{
Color savedColor = g.getColor();
@@ -235,19 +240,63 @@ public class MetalButtonUI
public void update(Graphics g, JComponent c)
{
AbstractButton b = (AbstractButton) c;
- ButtonModel m = b.getModel();
if (b.isContentAreaFilled()
&& (UIManager.get(getPropertyPrefix() + "gradient") != null)
- && ! m.isPressed() && ! m.isArmed()
&& b.isEnabled()
&& (b.getBackground() instanceof UIResource))
+ updateWidthGradient(g, b, b.getParent());
+ else
+ super.update(g, c);
+ }
+
+ private void updateWidthGradient(Graphics g, AbstractButton b, Container parent)
+ {
+ ButtonModel m = b.getModel();
+ String gradientPropertyName = getPropertyPrefix() + "gradient";
+
+ // Gradient painting behavior depends on whether the button is part of a
+ // JToolBar.
+ if (parent instanceof JToolBar)
+ {
+ if (! m.isPressed() && ! m.isArmed())
+ {
+ if (m.isRollover())
+ {
+ // Paint the gradient when the mouse cursor hovers over the
+ // button but is not pressed down.
+ MetalUtils.paintGradient(g, 0, 0, b.getWidth(), b.getHeight(),
+ SwingConstants.VERTICAL,
+ gradientPropertyName);
+ }
+ else
+ {
+ // If mouse does not hover over the button let the JToolBar
+ // paint itself at the location where the button is (the button
+ // is transparent).
+
+ // There where cases where the button was not repainted and
+ // therefore showed its old state. With this statement it does
+ // not happen.
+ b.repaint();
+
+ Rectangle area = new Rectangle();
+ SwingUtilities.calculateInnerArea(b, area);
+ SwingUtilities.convertRectangle(b, area, b.getParent());
+ b.getParent().repaint(area.x, area.y, area.width, area.height);
+ }
+ }
+
+ }
+ else if (! m.isPressed() && ! m.isArmed())
{
- MetalUtils.paintGradient(g, 0, 0, c.getWidth(), c.getHeight(),
+ // When the button is not part of a JToolBar just paint itself with a
+ // gradient and everything is fine.
+ MetalUtils.paintGradient(g, 0, 0, b.getWidth(), b.getHeight(),
SwingConstants.VERTICAL,
- getPropertyPrefix() + "gradient");
- paint(g, c);
+ gradientPropertyName);
}
- else
- super.update(g, c);
+
+ paint(g, b);
}
+
}