I completed the OceanTheme support for the JSlider, which should be the
last component that lacked that support. While doing so I found a fixed
some bugs in the gradient painting code.
2006-03-14 Roman Kennke <[EMAIL PROTECTED]>
* javax/swing/plaf/metal/MetalIconFactory.java
(HorizontalSliderThumbIcon.gradientMask): New field
(HorizontalSliderThumbIcon.paintIcon): Added support for the
OceanTheme.
(VerticalSliderThumbIcon.gradientMask): New field
(VerticalSliderThumbIcon.paintIcon): Added support for the
OceanTheme.
* javax/swing/plaf/metal/MetalUtils.java
(paintHorizontalGradient): Fixed painting of 'masked' gradients.
(paintVerticalGradient): Fixed painting of 'masked' gradients.
/Roman
Index: javax/swing/plaf/metal/MetalIconFactory.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalIconFactory.java,v
retrieving revision 1.23
diff -u -r1.23 MetalIconFactory.java
--- javax/swing/plaf/metal/MetalIconFactory.java 14 Mar 2006 14:39:14 -0000 1.23
+++ javax/swing/plaf/metal/MetalIconFactory.java 14 Mar 2006 20:03:26 -0000
@@ -963,6 +963,14 @@
{
/**
+ * This mask is used to paint the gradient in the shape of the thumb.
+ */
+ int[][] gradientMask = new int[][] { {0, 12}, {0, 12}, {0, 12}, {0, 12},
+ {0, 12}, {0, 12}, {0, 12}, {1, 12},
+ {2, 10}, {3, 9}, {4, 8}, {5, 7},
+ {6, 6}};
+
+ /**
* Creates a new instance.
*/
public HorizontalSliderThumbIcon()
@@ -1020,21 +1028,37 @@
g.drawLine(x + 6, y + 14, x, y + 8);
g.drawLine(x, y + 7, x, y + 1);
- // fill the icon
- if (focus)
- g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
+ // Fill the icon.
+ if (MetalLookAndFeel.getCurrentTheme() instanceof OceanTheme
+ && enabled)
+ {
+ String gradient;
+ if (focus)
+ gradient = "Slider.focusGradient";
+ else
+ gradient = "Slider.gradient";
+ MetalUtils.paintGradient(g, x + 1, y + 2, 12, 13,
+ SwingConstants.VERTICAL, gradient,
+ gradientMask);
+ }
else
- g.setColor(MetalLookAndFeel.getControl());
- g.fillRect(x + 1, y + 2, 13, 7);
- g.drawLine(x + 2, y + 9, x + 12, y + 9);
- g.drawLine(x + 3, y + 10, x + 11, y + 10);
- g.drawLine(x + 4, y + 11, x + 10, y + 11);
- g.drawLine(x + 5, y + 12, x + 9, y + 12);
- g.drawLine(x + 6, y + 13, x + 8, y + 13);
- g.drawLine(x + 7, y + 14, x + 7, y + 14);
-
- // if the slider is enabled, draw dots and highlights
- if (c.isEnabled())
+ {
+ if (focus)
+ g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
+ else
+ g.setColor(MetalLookAndFeel.getControl());
+ g.fillRect(x + 1, y + 2, 13, 7);
+ g.drawLine(x + 2, y + 9, x + 12, y + 9);
+ g.drawLine(x + 3, y + 10, x + 11, y + 10);
+ g.drawLine(x + 4, y + 11, x + 10, y + 11);
+ g.drawLine(x + 5, y + 12, x + 9, y + 12);
+ g.drawLine(x + 6, y + 13, x + 8, y + 13);
+ g.drawLine(x + 7, y + 14, x + 7, y + 14);
+ }
+
+ // If the slider is enabled, draw dots and highlights.
+ if (c.isEnabled()
+ && !(MetalLookAndFeel.getCurrentTheme() instanceof OceanTheme))
{
if (focus)
g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
@@ -1051,7 +1075,7 @@
g.drawLine(x + 7, y + 7, x + 7, y + 7);
g.drawLine(x + 11, y + 7, x + 11, y + 7);
- // draw highlights
+ // Draw highlights
if (focus)
g.setColor(MetalLookAndFeel.getPrimaryControl());
else
@@ -1595,6 +1619,14 @@
private static class VerticalSliderThumbIcon implements Icon, Serializable
{
/**
+ * This mask is used to paint the gradient in the shape of the thumb.
+ */
+ int[][] gradientMask = new int[][] { {0, 12}, {0, 12}, {0, 12}, {0, 12},
+ {0, 12}, {0, 12}, {0, 12}, {1, 12},
+ {2, 10}, {3, 9}, {4, 8}, {5, 7},
+ {6, 6}};
+
+ /**
* Creates a new instance.
*/
public VerticalSliderThumbIcon()
@@ -1653,21 +1685,37 @@
g.drawLine(x + 8, y + 14, x + 1, y + 14);
g.drawLine(x, y + 13, x, y + 1);
- // fill the icon
- if (focus)
- g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
+ // Fill the icon.
+ if (MetalLookAndFeel.getCurrentTheme() instanceof OceanTheme
+ && enabled)
+ {
+ String gradient;
+ if (focus)
+ gradient = "Slider.focusGradient";
+ else
+ gradient = "Slider.gradient";
+ MetalUtils.paintGradient(g, x + 2, y + 1, 13, 12,
+ SwingConstants.HORIZONTAL, gradient,
+ gradientMask);
+ }
else
- g.setColor(MetalLookAndFeel.getControl());
- g.fillRect(x + 2, y + 1, 7, 13);
- g.drawLine(x + 9, y + 2, x + 9, y + 12);
- g.drawLine(x + 10, y + 3, x + 10, y + 11);
- g.drawLine(x + 11, y + 4, x + 11, y + 10);
- g.drawLine(x + 12, y + 5, x + 12, y + 9);
- g.drawLine(x + 13, y + 6, x + 13, y + 8);
- g.drawLine(x + 14, y + 7, x + 14, y + 7);
-
+ {
+ if (focus)
+ g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
+ else
+ g.setColor(MetalLookAndFeel.getControl());
+ g.fillRect(x + 2, y + 1, 7, 13);
+ g.drawLine(x + 9, y + 2, x + 9, y + 12);
+ g.drawLine(x + 10, y + 3, x + 10, y + 11);
+ g.drawLine(x + 11, y + 4, x + 11, y + 10);
+ g.drawLine(x + 12, y + 5, x + 12, y + 9);
+ g.drawLine(x + 13, y + 6, x + 13, y + 8);
+ g.drawLine(x + 14, y + 7, x + 14, y + 7);
+ }
+
// if the slider is enabled, draw dots and highlights
- if (enabled)
+ if (enabled
+ && ! (MetalLookAndFeel.getCurrentTheme() instanceof OceanTheme))
{
if (focus)
g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
Index: javax/swing/plaf/metal/MetalUtils.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalUtils.java,v
retrieving revision 1.11
diff -u -r1.11 MetalUtils.java
--- javax/swing/plaf/metal/MetalUtils.java 14 Mar 2006 14:39:14 -0000 1.11
+++ javax/swing/plaf/metal/MetalUtils.java 14 Mar 2006 20:03:26 -0000
@@ -336,8 +336,8 @@
g.setColor(interpolated);
if (mask != null)
{
- y0 = mask[xc - x0][0];
- y1 = mask[xc - x0][1];
+ y0 = mask[xc - x0][0] + y;
+ y1 = mask[xc - x0][1] + y;
}
g.drawLine(xc, y0, xc, y1);
}
@@ -349,10 +349,10 @@
}
else
{
- for (xc = x1; xc < x2 - x1; xc++)
+ for (xc = x1; xc < x2; xc++)
{
- y0 = mask[xc - x0][0];
- y1 = mask[xc - x0][1];
+ y0 = mask[xc - x0][0] + y;
+ y1 = mask[xc - x0][1] + y;
g.drawLine(xc, y0, xc, y1);
}
}
@@ -374,10 +374,10 @@
g.setColor(interpolated);
if (mask != null)
{
- y0 = mask[xc - x0][0];
- y1 = mask[xc - x0][1];
+ y0 = mask[xc - x0][0] + y;
+ y1 = mask[xc - x0][1] + y;
}
- g.drawLine(xc, y, xc, y + h);
+ g.drawLine(xc, y0, xc, y1);
}
// Paint third gradient area (c1->c3).
@@ -397,10 +397,10 @@
g.setColor(interpolated);
if (mask != null)
{
- y0 = mask[xc - x0][0];
- y1 = mask[xc - x0][1];
+ y0 = mask[xc - x0][0] + y;
+ y1 = mask[xc - x0][1] + y;
}
- g.drawLine(xc, y, xc, y + h);
+ g.drawLine(xc, y0, xc, y1);
}
}
@@ -455,8 +455,8 @@
g.setColor(interpolated);
if (mask != null)
{
- x0 = mask[yc - y0][0];
- x1 = mask[yc - y0][1];
+ x0 = mask[yc - y0][0] + x;
+ x1 = mask[yc - y0][1] + x;
}
g.drawLine(x0, yc, x1, yc);
}
@@ -468,10 +468,10 @@
}
else
{
- for (yc = y1; yc < y2 - y1; yc++)
+ for (yc = y1; yc < y2; yc++)
{
- x0 = mask[yc - y0][0];
- x1 = mask[yc - y0][1];
+ x0 = mask[yc - y0][0] + x;
+ x1 = mask[yc - y0][1] + x;
g.drawLine(x0, yc, x1, yc);
}
}
@@ -493,8 +493,8 @@
g.setColor(interpolated);
if (mask != null)
{
- x0 = mask[yc - y0][0];
- x1 = mask[yc - y0][1];
+ x0 = mask[yc - y0][0] + x;
+ x1 = mask[yc - y0][1] + x;
}
g.drawLine(x0, yc, x1, yc);
}
@@ -516,8 +516,8 @@
g.setColor(interpolated);
if (mask != null)
{
- x0 = mask[yc - y0][0];
- x1 = mask[yc - y0][1];
+ x0 = mask[yc - y0][0] + x;
+ x1 = mask[yc - y0][1] + x;
}
g.drawLine(x0, yc, x1, yc);
}