GradientPaintpublic class GradientPaint extends Object implements PaintThe GradientPaint class provides a way to fill
a {@link Shape} with a linear color gradient pattern.
If {@link Point} P1 with {@link Color} C1 and Point P2 with
Color C2 are specified in user space, the
Color on the P1, P2 connecting line is proportionally
changed from C1 to C2. Any point P not on the extended P1, P2
connecting line has the color of the point P' that is the perpendicular
projection of P on the extended P1, P2 connecting line.
Points on the extended line outside of the P1, P2 segment can be colored
in one of two ways.
-
If the gradient is cyclic then the points on the extended P1, P2
connecting line cycle back and forth between the colors C1 and C2.
-
If the gradient is acyclic then points on the P1 side of the segment
have the constant
Color C1 while points on the P2 side
have the constant Color C2.
|
Fields Summary |
---|
Point2D$Float | p1 | Point2D$Float | p2 | Color | color1 | Color | color2 | boolean | cyclic |
Constructors Summary |
---|
public GradientPaint(float x1, float y1, Color color1, float x2, float y2, Color color2)Constructs a simple acyclic GradientPaint object.
if ((color1 == null) || (color2 == null)) {
throw new NullPointerException("Colors cannot be null");
}
p1 = new Point2D.Float(x1, y1);
p2 = new Point2D.Float(x2, y2);
this.color1 = color1;
this.color2 = color2;
| public GradientPaint(Point2D pt1, Color color1, Point2D pt2, Color color2)Constructs a simple acyclic GradientPaint object.
if ((color1 == null) || (color2 == null) ||
(pt1 == null) || (pt2 == null)) {
throw new NullPointerException("Colors and points should be non-null");
}
p1 = new Point2D.Float((float)pt1.getX(), (float)pt1.getY());
p2 = new Point2D.Float((float)pt2.getX(), (float)pt2.getY());
this.color1 = color1;
this.color2 = color2;
| public GradientPaint(float x1, float y1, Color color1, float x2, float y2, Color color2, boolean cyclic)Constructs either a cyclic or acyclic GradientPaint
object depending on the boolean parameter.
this (x1, y1, color1, x2, y2, color2);
this.cyclic = cyclic;
| public GradientPaint(Point2D pt1, Color color1, Point2D pt2, Color color2, boolean cyclic)Constructs either a cyclic or acyclic GradientPaint
object depending on the boolean parameter.
this (pt1, color1, pt2, color2);
this.cyclic = cyclic;
|
Methods Summary |
---|
public java.awt.PaintContext | createContext(java.awt.image.ColorModel cm, java.awt.Rectangle deviceBounds, java.awt.geom.Rectangle2D userBounds, java.awt.geom.AffineTransform xform, java.awt.RenderingHints hints)Creates and returns a context used to generate the color pattern.
return new GradientPaintContext(cm, p1, p2, xform,
color1, color2, cyclic);
| public java.awt.Color | getColor1()Returns the color C1 anchored by the point P1.
return color1;
| public java.awt.Color | getColor2()Returns the color C2 anchored by the point P2.
return color2;
| public java.awt.geom.Point2D | getPoint1()Returns a copy of the point P1 that anchors the first color.
return new Point2D.Float(p1.x, p1.y);
| public java.awt.geom.Point2D | getPoint2()Returns a copy of the point P2 which anchors the second color.
return new Point2D.Float(p2.x, p2.y);
| public int | getTransparency()Returns the transparency mode for this GradientPaint .
int a1 = color1.getAlpha();
int a2 = color2.getAlpha();
return (((a1 & a2) == 0xff) ? OPAQUE : TRANSLUCENT);
| public boolean | isCyclic()Returns true if the gradient cycles repeatedly
between the two colors C1 and C2.
return cyclic;
|
|