GradientPaintpublic class GradientPaint extends Object implements PaintThe GradientPaint class defines a way to fill a Shape with a linear color
gradient pattern.
The GradientPaint's fill pattern is determined by two points and two colors,
plus the cyclic mode option. Each of the two points is painted with its
corresponding color, and on the line segment connecting the two points, the
color is proportionally changed between the two colors. For points on the
same line which are not between the two specified points (outside of the
connecting segment) their color is determined by the cyclic mode option. If
the mode is cyclic, then the rest of the line repeats the color pattern of
the connecting segment, cycling back and forth between the two colors. If
not, the mode is acyclic which means that all points on the line outside the
connecting line segment are given the same color as the closest of the two
specified points.
The color of points that are not on the line connecting the two specified
points are given by perpendicular projection: by taking the set of lines
perpendicular to the connecting line and for each one, the whole line is
colored with the same color. |
Fields Summary |
---|
Color | color1The start point color. | Color | color2The end color point. | Point2D | point1The location of the start point. | Point2D | point2The location of the end point. | boolean | cyclicThe indicator of cycle filling. If TRUE filling repeated outside points
stripe, if FALSE solid color filling outside. |
Constructors Summary |
---|
public GradientPaint(Point2D point1, Color color1, Point2D point2, Color color2, boolean cyclic)Instantiates a new GradientPaint with cyclic or acyclic mode.
if (point1 == null || point2 == null) {
// awt.6D=Point is null
throw new NullPointerException(Messages.getString("awt.6D")); //$NON-NLS-1$
}
if (color1 == null || color2 == null) {
// awt.6E=Color is null
throw new NullPointerException(Messages.getString("awt.6E")); //$NON-NLS-1$
}
this.point1 = point1;
this.point2 = point2;
this.color1 = color1;
this.color2 = color2;
this.cyclic = cyclic;
| public GradientPaint(float x1, float y1, Color color1, float x2, float y2, Color color2, boolean cyclic)Instantiates a new GradientPaint with cyclic or acyclic mode; points are
specified by coordinates.
this(new Point2D.Float(x1, y1), color1, new Point2D.Float(x2, y2), color2, cyclic);
| public GradientPaint(float x1, float y1, Color color1, float x2, float y2, Color color2)Instantiates a new acyclic GradientPaint; points are specified by
coordinates.
this(x1, y1, color1, x2, y2, color2, false);
| public GradientPaint(Point2D point1, Color color1, Point2D point2, Color color2)Instantiates a new acyclic GradientPaint.
this(point1, color1, point2, color2, false);
|
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 t, java.awt.RenderingHints hints)Creates PaintContext for a color pattern generating.
return new GradientPaintContext(cm, t, point1, color1, point2, color2, cyclic);
| public java.awt.Color | getColor1()Gets the color of the first point.
return color1;
| public java.awt.Color | getColor2()Gets the color of the second point.
return color2;
| public java.awt.geom.Point2D | getPoint1()Gets the first point.
return point1;
| public java.awt.geom.Point2D | getPoint2()Gets the second point.
return point2;
| public int | getTransparency()Gets the transparency mode for the GradientPaint.
int a1 = color1.getAlpha();
int a2 = color2.getAlpha();
return (a1 == 0xFF && a2 == 0xFF) ? OPAQUE : TRANSLUCENT;
| public boolean | isCyclic()Returns the GradientPaint mode: true for cyclic mode, false for acyclic
mode.
return cyclic;
|
|