summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Kennke <roman@kennke.org>2005-11-16 20:33:05 +0000
committerRoman Kennke <roman@kennke.org>2005-11-16 20:33:05 +0000
commit9e52594fcbb1bdfccab6b94658782a4bfcd12568 (patch)
treec12937827dfdafd12d0e14f43f387609e43cd43a
parentff084035d66bb089f5bf66937bad7cf693f41f6b (diff)
downloadclasspath-9e52594fcbb1bdfccab6b94658782a4bfcd12568.tar.gz
2005-11-16 Roman Kennke <kennke@aicas.com>
* javax/swing/plaf/metal/MetalBorders.java (ButtonBorder.paintBorder): Special case the OceanTheme. (ButtonBorder.paintOceanThemeBorder): New method. * javax/swing/plaf/metal/MetalButtonUI.java (installDefaults): Set the rollover flag here. Don't set a special border for rollover buttons. (uninstallDefaults): Reset the rollover flag. (update): Only paint gradient when button is enabled and not pressed. * javax/swing/plaf/metal/MetalButtonUI.java (getCurrentTheme): New method.
-rw-r--r--ChangeLog13
-rw-r--r--javax/swing/plaf/metal/MetalBorders.java133
-rw-r--r--javax/swing/plaf/metal/MetalButtonUI.java14
-rw-r--r--javax/swing/plaf/metal/MetalLookAndFeel.java9
4 files changed, 126 insertions, 43 deletions
diff --git a/ChangeLog b/ChangeLog
index 115b5c549..73c78d3e0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2005-11-16 Roman Kennke <kennke@aicas.com>
+
+ * javax/swing/plaf/metal/MetalBorders.java
+ (ButtonBorder.paintBorder): Special case the OceanTheme.
+ (ButtonBorder.paintOceanThemeBorder): New method.
+ * javax/swing/plaf/metal/MetalButtonUI.java
+ (installDefaults): Set the rollover flag here. Don't set a special
+ border for rollover buttons.
+ (uninstallDefaults): Reset the rollover flag.
+ (update): Only paint gradient when button is enabled and not pressed.
+ * javax/swing/plaf/metal/MetalButtonUI.java
+ (getCurrentTheme): New method.
+
2005-11-16 Gary Benson <gbenson@redhat.com>
* java/io/FilePermission.java (implies): Correct the sense
diff --git a/javax/swing/plaf/metal/MetalBorders.java b/javax/swing/plaf/metal/MetalBorders.java
index 94e74eca0..28143d51e 100644
--- a/javax/swing/plaf/metal/MetalBorders.java
+++ b/javax/swing/plaf/metal/MetalBorders.java
@@ -130,6 +130,82 @@ public class MetalBorders
public void paintBorder(Component c, Graphics g, int x, int y, int w,
int h)
{
+ // With the OceanTheme the button border is painted entirely different.
+ // However, I couldn't figure out how this is determined besides checking
+ // for instanceof OceanTheme. The button painting is definitely not
+ // influenced by a UI default property and it is definitely performed
+ // by the same Border class.
+ if (MetalLookAndFeel.getCurrentTheme() instanceof OceanTheme)
+ paintOceanButtonBorder(c, g, x, y, w, h);
+ else
+ {
+ ButtonModel bmodel = null;
+
+ if (c instanceof AbstractButton)
+ bmodel = ((AbstractButton) c).getModel();
+
+ Color darkShadow = MetalLookAndFeel.getControlDarkShadow();
+ Color shadow = MetalLookAndFeel.getControlShadow();
+ Color light = MetalLookAndFeel.getControlHighlight();
+ Color middle = MetalLookAndFeel.getControl();
+
+ if (c.isEnabled())
+ {
+ // draw dark border
+ g.setColor(darkShadow);
+ g.drawRect(x, y, w - 2, h - 2);
+
+ if (!bmodel.isPressed())
+ {
+ // draw light border
+ g.setColor(light);
+ g.drawRect(x + 1, y + 1, w - 2, h - 2);
+
+ // draw crossing pixels of both borders
+ g.setColor(middle);
+ g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
+ g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);
+ }
+ else
+ {
+ // draw light border
+ g.setColor(light);
+ g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
+ g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);
+
+ // draw shadow border
+ g.setColor(middle);
+ g.drawLine(x + 1, y + 1, x + w - 2, y + 1);
+ g.drawLine(x + 1, y + 1, x + 1, y + h - 2);
+
+ // draw crossing pixels of both borders
+ g.setColor(shadow);
+ g.drawRect(x + 1, y + h - 2, 0, 0);
+ g.drawRect(x + w - 2, y + 1, 0, 0);
+ }
+ }
+ else
+ {
+ // draw disabled border
+ g.setColor(MetalLookAndFeel.getInactiveControlTextColor());
+ g.drawRect(x, y, w - 2, h - 2);
+ }
+ }
+ }
+
+ /**
+ * Paints the button border for the OceanTheme.
+ *
+ * @param c the button
+ * @param g the graphics context
+ * @param x the X coordinate of the upper left corner of the painting rect
+ * @param y the Y coordinate of the upper left corner of the painting rect
+ * @param w the width of the painting rect
+ * @param h the height of the painting rect
+ */
+ private void paintOceanButtonBorder(Component c, Graphics g, int x,
+ int y, int w, int h)
+ {
ButtonModel bmodel = null;
if (c instanceof AbstractButton)
@@ -137,44 +213,31 @@ public class MetalBorders
Color darkShadow = MetalLookAndFeel.getControlDarkShadow();
Color shadow = MetalLookAndFeel.getControlShadow();
- Color light = MetalLookAndFeel.getWhite();
+ Color light = MetalLookAndFeel.getControlHighlight();
Color middle = MetalLookAndFeel.getControl();
if (c.isEnabled())
- {
- // draw dark border
- g.setColor(darkShadow);
- g.drawRect(x, y, w - 2, h - 2);
-
- if (!bmodel.isPressed())
- {
- // draw light border
- g.setColor(light);
- g.drawRect(x + 1, y + 1, w - 2, h - 2);
-
- // draw crossing pixels of both borders
- g.setColor(middle);
- g.drawRect(x + 1, y + h - 2, 0, 0);
- g.drawRect(x + w - 2, y + 1, 0, 0);
- }
- else
- {
- // draw light border
- g.setColor(light);
- g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
- g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);
-
- // draw shadow border
- g.setColor(middle);
- g.drawLine(x + 1, y + 1, x + w - 2, y + 1);
- g.drawLine(x + 1, y + 1, x + 1, y + h - 2);
-
- // draw crossing pixels of both borders
- g.setColor(shadow);
- g.drawRect(x + 1, y + h - 2, 0, 0);
- g.drawRect(x + w - 2, y + 1, 0, 0);
- }
- }
+ {
+ if (bmodel.isPressed())
+ {
+ // draw fat border
+ g.drawLine(x + 1, y + 1, x + w - 2, y + 1);
+ g.drawLine(x + 1, y + 1, x + 1, y + h - 2);
+ }
+ else if (bmodel.isRollover())
+ {
+ g.setColor(shadow);
+ g.drawRect(x, y, w - 1, h - 1);
+ g.drawRect(x + 2, y + 2, w - 5, h - 5);
+ g.setColor(darkShadow);
+ g.drawRect(x + 1, y + 1, w - 3, h - 3);
+ }
+ else
+ {
+ g.setColor(darkShadow);
+ g.drawRect(x, y, w - 1, h - 1);
+ }
+ }
else
{
// draw disabled border
diff --git a/javax/swing/plaf/metal/MetalButtonUI.java b/javax/swing/plaf/metal/MetalButtonUI.java
index d7ff2fd32..10e511173 100644
--- a/javax/swing/plaf/metal/MetalButtonUI.java
+++ b/javax/swing/plaf/metal/MetalButtonUI.java
@@ -134,11 +134,8 @@ public class MetalButtonUI
public void installDefaults(AbstractButton button)
{
super.installDefaults(button);
- if (button.isRolloverEnabled())
- {
- if (button.getBorder() instanceof UIResource)
- button.setBorder(MetalBorders.getRolloverBorder());
- }
+ button.setRolloverEnabled(UIManager.getBoolean(
+ getPropertyPrefix() + "rollover"));
}
/**
@@ -147,8 +144,7 @@ public class MetalButtonUI
public void uninstallDefaults(AbstractButton button)
{
super.uninstallDefaults(button);
- if (button.getBorder() instanceof UIResource)
- button.setBorder(null);
+ button.setRolloverEnabled(false);
}
/**
@@ -237,7 +233,9 @@ public class MetalButtonUI
*/
public void update(Graphics g, JComponent c)
{
- if (c.isOpaque() && UIManager.get(getPropertyPrefix() + "gradient") != null)
+ AbstractButton b = (AbstractButton) c;
+ if (b.isOpaque() && UIManager.get(getPropertyPrefix() + "gradient") != null
+ && !b.getModel().isPressed() && b.isEnabled())
{
MetalUtils.paintGradient(g, 0, 0, c.getWidth(), c.getHeight(),
SwingConstants.VERTICAL,
diff --git a/javax/swing/plaf/metal/MetalLookAndFeel.java b/javax/swing/plaf/metal/MetalLookAndFeel.java
index d9c0cd013..da019379b 100644
--- a/javax/swing/plaf/metal/MetalLookAndFeel.java
+++ b/javax/swing/plaf/metal/MetalLookAndFeel.java
@@ -1202,4 +1202,13 @@ public class MetalLookAndFeel extends BasicLookAndFeel
defaults.putDefaults(uiDefaults);
}
+ /**
+ * Returns the current theme setting for the Metal L&amp;F.
+ *
+ * @return the current theme setting for the Metal L&amp;F
+ */
+ public static MetalTheme getCurrentTheme()
+ {
+ return theme;
+ }
}