java.awt
Class GradientPaint

java.lang.Object
  |
  +--java.awt.GradientPaint
All Implemented Interfaces:
Paint, Transparency

public class GradientPaint
extends Object
implements Paint

Safe: The GradientPaint class provides a way to fill a Shape with a linear color gradient pattern. If Point P1 with 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.

Version:
10 Feb 1997
See Also:
Paint, Graphics2D.setPaint(java.awt.Paint)

Field Summary
(package private)  Color color1
           
(package private)  Color color2
           
(package private)  boolean cyclic
           
(package private)  java.awt.geom.Point2D.Float p1
           
(package private)  java.awt.geom.Point2D.Float p2
           
 
Fields inherited from interface java.awt.Transparency
BITMASK, OPAQUE, TRANSLUCENT
 
Constructor Summary
GradientPaint(float x1, float y1, Color color1, float x2, float y2, Color color2)
          Enabled: Constructs a simple acyclic GradientPaint object.
GradientPaint(float x1, float y1, Color color1, float x2, float y2, Color color2, boolean cyclic)
          Enabled: Constructs either a cyclic or acyclic GradientPaint object depending on the boolean parameter.
GradientPaint(java.awt.geom.Point2D pt1, Color color1, java.awt.geom.Point2D pt2, Color color2)
          Suppressed: Constructs a simple acyclic GradientPaint object.
GradientPaint(java.awt.geom.Point2D pt1, Color color1, java.awt.geom.Point2D pt2, Color color2, boolean cyclic)
          Suppressed: Constructs either a cyclic or acyclic GradientPaint object depending on the boolean parameter.
 
Method Summary
 PaintContext createContext(java.awt.image.ColorModel cm, Rectangle deviceBounds, java.awt.geom.Rectangle2D userBounds, java.awt.geom.AffineTransform xform, RenderingHints hints)
          Enabled: Creates and returns a context used to generate the color pattern.
 Color getColor1()
          Enabled: Returns the color C1 anchored by the point P1.
 Color getColor2()
          Enabled: Returns the color C2 anchored by the point P2.
 java.awt.geom.Point2D getPoint1()
          Enabled: Returns a copy of the point P1 that anchors the first color.
 java.awt.geom.Point2D getPoint2()
          Enabled: Returns a copy of the point P2 which anchors the second color.
 int getTransparency()
          Enabled: Returns the transparency mode for this GradientPaint.
 boolean isCyclic()
          Enabled: Returns true if the gradient cycles repeatedly between the two colors C1 and C2.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

p1

java.awt.geom.Point2D.Float p1

p2

java.awt.geom.Point2D.Float p2

color1

Color color1

color2

Color color2

cyclic

boolean cyclic
Constructor Detail

GradientPaint

public GradientPaint(float x1,
                     float y1,
                     Color color1,
                     float x2,
                     float y2,
                     Color color2)
Enabled: Constructs a simple acyclic GradientPaint object.

Parameters:
color1 - Color at the first specified Point
color2 - Color at the second specified Point
Throws:
NullPointerException - if either one of colors is null

GradientPaint

public GradientPaint(java.awt.geom.Point2D pt1,
                     Color color1,
                     java.awt.geom.Point2D pt2,
                     Color color2)
Suppressed: Constructs a simple acyclic GradientPaint object.

Parameters:
pt1 - the first specified Point in user space
color1 - Color at the first specified Point
pt2 - the second specified Point in user space
color2 - Color at the second specified Point
Throws:
NullPointerException - if either one of colors or points is null

GradientPaint

public GradientPaint(float x1,
                     float y1,
                     Color color1,
                     float x2,
                     float y2,
                     Color color2,
                     boolean cyclic)
Enabled: Constructs either a cyclic or acyclic GradientPaint object depending on the boolean parameter.

Parameters:
color1 - Color at the first specified Point
color2 - Color at the second specified Point
cyclic - true if the gradient pattern should cycle repeatedly between the two colors; false otherwise

GradientPaint

public GradientPaint(java.awt.geom.Point2D pt1,
                     Color color1,
                     java.awt.geom.Point2D pt2,
                     Color color2,
                     boolean cyclic)
Suppressed: Constructs either a cyclic or acyclic GradientPaint object depending on the boolean parameter.

Parameters:
pt1 - the first specified Point in user space
color1 - Color at the first specified Point
pt2 - the second specified Point in user space
color2 - Color at the second specified Point
cyclic - true if the gradient pattern should cycle repeatedly between the two colors; false otherwise
Throws:
NullPointerException - if either one of colors or points is null
Method Detail

getPoint1

public java.awt.geom.Point2D getPoint1()
Enabled: Returns a copy of the point P1 that anchors the first color.

Returns:
a Point2D object that is a copy of the point that anchors the first color of this GradientPaint.

getColor1

public Color getColor1()
Enabled: Returns the color C1 anchored by the point P1.

Returns:
a Color object that is the color anchored by P1.

getPoint2

public java.awt.geom.Point2D getPoint2()
Enabled: Returns a copy of the point P2 which anchors the second color.

Returns:
a Point2D object that is a copy of the point that anchors the second color of this GradientPaint.

getColor2

public Color getColor2()
Enabled: Returns the color C2 anchored by the point P2.

Returns:
a Color object that is the color anchored by P2.

isCyclic

public boolean isCyclic()
Enabled: Returns true if the gradient cycles repeatedly between the two colors C1 and C2.

Returns:
true if the gradient cycles repeatedly between the two colors; false otherwise.

createContext

public PaintContext createContext(java.awt.image.ColorModel cm,
                                  Rectangle deviceBounds,
                                  java.awt.geom.Rectangle2D userBounds,
                                  java.awt.geom.AffineTransform xform,
                                  RenderingHints hints)
Enabled: Creates and returns a context used to generate the color pattern.

Specified by:
createContext in interface Paint
Parameters:
cm - ColorModel that receives the Paint data. This is used only as a hint.
deviceBounds - the device space bounding box of the graphics primitive being rendered
userBounds - the user space bounding box of the graphics primitive being rendered
xform - the AffineTransform from user space into device space
hints - the hints that the context object uses to choose between rendering alternatives
Returns:
the PaintContext that generates color patterns.
See Also:
PaintContext

getTransparency

public int getTransparency()
Enabled: Returns the transparency mode for this GradientPaint.

Specified by:
getTransparency in interface Transparency
Returns:
an integer value representing this GradientPaint object's transparency mode.
See Also:
Transparency


comments?