summaryrefslogtreecommitdiffstats
path: root/libjava/classpath/javax/swing/plaf/metal/MetalUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/javax/swing/plaf/metal/MetalUtils.java')
-rw-r--r--libjava/classpath/javax/swing/plaf/metal/MetalUtils.java164
1 files changed, 140 insertions, 24 deletions
diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalUtils.java b/libjava/classpath/javax/swing/plaf/metal/MetalUtils.java
index b9d5ea76434..03617aa4099 100644
--- a/libjava/classpath/javax/swing/plaf/metal/MetalUtils.java
+++ b/libjava/classpath/javax/swing/plaf/metal/MetalUtils.java
@@ -91,7 +91,7 @@ class MetalUtils
Color light, Color dark)
{
if (g instanceof Graphics2D
- && SystemProperties.getProperty("gnu.javax.swing.noGraphics2D") != null)
+ && SystemProperties.getProperty("gnu.javax.swing.noGraphics2D") == null)
fillMetalPattern2D((Graphics2D) g, x, y, w, h, light, dark);
else
{
@@ -161,14 +161,35 @@ class MetalUtils
/**
* Paints the typical Metal gradient. See {@link #paintGradient(Graphics,
- * int, int, int, int, double, double, Color, Color, Color, int)}
+ * int, int, int, int, float, float, Color, Color, Color, int, int[][])}
+ * for more details.
+ *
+ * This variant paints a gradient without a mask.
+ *
+ * @param g the graphics context to use
+ * @param x the X coordinate of the upper left corner of the rectangle
+ * @param y the Y coordinate of the upper left corner of the rectangle
+ * @param w the width of the rectangle
+ * @param h the height of the rectangle
+ * @param dir the direction of the gradient, either
+ * @param uiProp the key of the UIManager property that has the parameters
+ */
+ static void paintGradient(Graphics g, int x, int y, int w, int h,
+ int dir, String uiProp)
+ {
+ paintGradient(g, x, y, w, h, dir, uiProp, null);
+ }
+
+ /**
+ * Paints the typical Metal gradient. See {@link #paintGradient(Graphics,
+ * int, int, int, int, float, float, Color, Color, Color, int, int[][])}
* for more details.
*
* The parameters are fetched from the UIManager using the key
* <code>uiProp</code>. The value is expected to be a {@link List} that
* contains 4 values: two {@link Double}s and 3 {@link Color} object that
* together make up the parameters passed to the painting method.
- *
+ *
* @param g the graphics context to use
* @param x the X coordinate of the upper left corner of the rectangle
* @param y the Y coordinate of the upper left corner of the rectangle
@@ -176,17 +197,19 @@ class MetalUtils
* @param h the height of the rectangle
* @param dir the direction of the gradient, either
* @param uiProp the key of the UIManager property that has the parameters
+ * @param mask the mask that should be used when painting the gradient as
+ * described above
*/
static void paintGradient(Graphics g, int x, int y, int w, int h,
- int dir, String uiProp)
+ int dir, String uiProp, int[][] mask)
{
List params = (List) UIManager.get(uiProp);
- double g1 = ((Double) params.get(0)).doubleValue();
- double g2 = ((Double) params.get(1)).doubleValue();
+ float g1 = ((Float) params.get(0)).floatValue();
+ float g2 = ((Float) params.get(1)).floatValue();
Color c1 = (Color) params.get(2);
Color c2 = (Color) params.get(3);
Color c3 = (Color) params.get(4);
- paintGradient(g, x, y, w, h, g1, g2, c1, c2, c3, dir);
+ paintGradient(g, x, y, w, h, g1, g2, c1, c2, c3, dir, mask);
}
/**
@@ -209,6 +232,33 @@ class MetalUtils
* <li>A gradient from color 2 to color 1 with the relative width specified
* by <code>g1</code></li>
*
+ * The <code>mask</code> parameter is an array if int arrays, where the first
+ * index specifies the row (in the gradient direction), and the second index
+ * is the starting and end offset of that line. This way you can specify a
+ * mask that should be laid over the gradient for paintint non-rectangular
+ * gradients. The following example should demonstrate this for painting
+ * a circular shaped gradient (note that the first and last line should not
+ * be drawn at all, they are only here to show the circular shape more
+ * clearly). Everything <em>inside</code> the surrounded area is filled by
+ * the gradient:
+ *
+ * <pre>
+ * 012345678
+ * xxx
+ * 0 x x { {4, 7},
+ * 1 x x {3, 8},
+ * 2 x x {3, 8},
+ * 3 x x {3, 8},
+ * 4 x x {4, 7} }
+ * xxx
+ * </pre>
+ *
+ * The <code>mask</code> array is expected to have <code>w</code> or
+ * <code>h</code> array elements, depending on the direction.
+ *
+ * If the <code>mask</code> parameter is null, then the gradient is painted
+ * without a mask.
+ *
* @param g the graphics context to use
* @param x the X coordinate of the upper left corner of the rectangle
* @param y the Y coordinate of the upper left corner of the rectangle
@@ -221,19 +271,23 @@ class MetalUtils
* @param c3 the color 3
* @param dir the direction of the gradient, either
* {@link SwingConstants#HORIZONTAL} or {@link SwingConstants#VERTICAL}
+ * @param mask the mask that should be used when painting the gradient as
+ * described above
*/
- static void paintGradient(Graphics g, int x, int y, int w, int h, double g1,
- double g2, Color c1, Color c2, Color c3, int dir)
+ static void paintGradient(Graphics g, int x, int y, int w, int h, float g1,
+ float g2, Color c1, Color c2, Color c3, int dir,
+ int[][] mask)
{
if (dir == SwingConstants.HORIZONTAL)
- paintHorizontalGradient(g, x, y, w, h, g1, g2, c1, c2, c3);
+ paintHorizontalGradient(g, x, y, w, h, g1, g2, c1, c2, c3, mask);
else
- paintVerticalGradient(g, x, y, w, h, g1, g2, c1, c2, c3);
+ paintVerticalGradient(g, x, y, w, h, g1, g2, c1, c2, c3, mask);
}
/**
* Paints a horizontal gradient. See {@link #paintGradient(Graphics, int,
- * int, int, int, double, double, Color, Color, Color, int)} for details.
+ * int, int, int, float, float, Color, Color, Color, int, int[][])}
+ * for details.
*
* @param x the X coordinate of the upper left corner of the rectangle
* @param y the Y coordinate of the upper left corner of the rectangle
@@ -244,12 +298,16 @@ class MetalUtils
* @param c1 the color 1
* @param c2 the color 2
* @param c3 the color 3
+ * @param mask the mask that should be used when painting the gradient as
+ * described above
*/
static void paintHorizontalGradient(Graphics g, int x, int y, int w, int h,
- double g1, double g2, Color c1, Color c2,
- Color c3)
+ float g1, float g2, Color c1, Color c2,
+ Color c3, int[][] mask)
{
// Calculate the coordinates.
+ int y0 = y;
+ int y1 = y + h;
// The size of the first gradient area (c1->2).
int w1 = (int) (w * g1);
// The size of the solid c2 area.
@@ -276,11 +334,28 @@ class MetalUtils
+ c1.getBlue());
Color interpolated = new Color(rInt, gInt, bInt);
g.setColor(interpolated);
- g.drawLine(xc, y, xc, y + h);
+ if (mask != null)
+ {
+ y0 = mask[xc - x0][0] + y;
+ y1 = mask[xc - x0][1] + y;
+ }
+ g.drawLine(xc, y0, xc, y1);
}
// Paint solid c2 area.
g.setColor(c2);
- g.fillRect(x1, y, x2 - x1, h);
+ if (mask == null)
+ {
+ g.fillRect(x1, y, x2 - x1, h);
+ }
+ else
+ {
+ for (xc = x1; xc < x2; xc++)
+ {
+ y0 = mask[xc - x0][0] + y;
+ y1 = mask[xc - x0][1] + y;
+ g.drawLine(xc, y0, xc, y1);
+ }
+ }
// Paint second gradient area (c2->c1).
for (xc = x2; xc < x3; xc++)
@@ -297,7 +372,12 @@ class MetalUtils
+ c2.getBlue());
Color interpolated = new Color(rInt, gInt, bInt);
g.setColor(interpolated);
- g.drawLine(xc, y, xc, y + h);
+ if (mask != null)
+ {
+ y0 = mask[xc - x0][0] + y;
+ y1 = mask[xc - x0][1] + y;
+ }
+ g.drawLine(xc, y0, xc, y1);
}
// Paint third gradient area (c1->c3).
@@ -315,13 +395,18 @@ class MetalUtils
+ c1.getBlue());
Color interpolated = new Color(rInt, gInt, bInt);
g.setColor(interpolated);
- g.drawLine(xc, y, xc, y + h);
+ if (mask != null)
+ {
+ y0 = mask[xc - x0][0] + y;
+ y1 = mask[xc - x0][1] + y;
+ }
+ g.drawLine(xc, y0, xc, y1);
}
}
/**
* Paints a vertical gradient. See {@link #paintGradient(Graphics, int, int,
- * int, int, double, double, Color, Color, Color, int)} for details.
+ * int, int, float, float, Color, Color, Color, int, int[][])} for details.
*
* @param x the X coordinate of the upper left corner of the rectangle
* @param y the Y coordinate of the upper left corner of the rectangle
@@ -332,12 +417,16 @@ class MetalUtils
* @param c1 the color 1
* @param c2 the color 2
* @param c3 the color 3
+ * @param mask the mask that should be used when painting the gradient as
+ * described above
*/
static void paintVerticalGradient(Graphics g, int x, int y, int w, int h,
double g1, double g2, Color c1, Color c2,
- Color c3)
+ Color c3, int[][] mask)
{
// Calculate the coordinates.
+ int x0 = x;
+ int x1 = x + w;
// The size of the first gradient area (c1->2).
int w1 = (int) (h * g1);
// The size of the solid c2 area.
@@ -364,11 +453,28 @@ class MetalUtils
+ c1.getBlue());
Color interpolated = new Color(rInt, gInt, bInt);
g.setColor(interpolated);
- g.drawLine(x, yc, x + w, yc);
+ if (mask != null)
+ {
+ x0 = mask[yc - y0][0] + x;
+ x1 = mask[yc - y0][1] + x;
+ }
+ g.drawLine(x0, yc, x1, yc);
}
// Paint solid c2 area.
g.setColor(c2);
- g.fillRect(x, y1, w, y2 - y1);
+ if (mask == null)
+ {
+ g.fillRect(x, y1, w, y2 - y1);
+ }
+ else
+ {
+ for (yc = y1; yc < y2; yc++)
+ {
+ x0 = mask[yc - y0][0] + x;
+ x1 = mask[yc - y0][1] + x;
+ g.drawLine(x0, yc, x1, yc);
+ }
+ }
// Paint second gradient area (c2->c1).
for (yc = y2; yc < y3; yc++)
@@ -385,7 +491,12 @@ class MetalUtils
+ c2.getBlue());
Color interpolated = new Color(rInt, gInt, bInt);
g.setColor(interpolated);
- g.drawLine(x, yc, x + w, yc);
+ if (mask != null)
+ {
+ x0 = mask[yc - y0][0] + x;
+ x1 = mask[yc - y0][1] + x;
+ }
+ g.drawLine(x0, yc, x1, yc);
}
// Paint third gradient area (c1->c3).
@@ -403,7 +514,12 @@ class MetalUtils
+ c1.getBlue());
Color interpolated = new Color(rInt, gInt, bInt);
g.setColor(interpolated);
- g.drawLine(x, yc, x + w, yc);
+ if (mask != null)
+ {
+ x0 = mask[yc - y0][0] + x;
+ x1 = mask[yc - y0][1] + x;
+ }
+ g.drawLine(x0, yc, x1, yc);
}
}
}
OpenPOWER on IntegriCloud