com.miginfocom.util.gfx
Class ShapeGradientPaint

java.lang.Object
  extended by com.miginfocom.util.gfx.ShapeGradientPaint
All Implemented Interfaces:
java.awt.Paint, java.awt.Transparency, java.io.Serializable

public class ShapeGradientPaint
extends java.lang.Object
implements java.awt.Paint, java.io.Serializable

An implementation that uses a GradientPaint that is better suited to fill a generic shape. The constructors are also a lot more flexible, giving the choice to enter absolute or relative values as well as angles, length and alignment rather than coordinates.

The main difference to GradientPaint is that the coordinates are scaled to the bounds of the painted shape for every paint context returned.

See Also:
Serialized Form

Field Summary
static int MODE_ANGLE
          Angle mode.
static int MODE_COORD
          Coordinate mode, relative or absolute.
 
Fields inherited from interface java.awt.Transparency
BITMASK, OPAQUE, TRANSLUCENT
 
Constructor Summary
ShapeGradientPaint(AtRefRangeNumber x1, AtRefRangeNumber y1, java.awt.Color color1, AtRefRangeNumber x2, AtRefRangeNumber y2, java.awt.Color color2, boolean cyclic)
          Constructor that intercepts the values to GradientPaint.
ShapeGradientPaint(java.awt.Color color1, java.awt.Color color2, float gradingAngle, boolean cyclic)
          Creates a gradient with absolute colors
ShapeGradientPaint(java.awt.Color color1, java.awt.Color color2, float gradingAngle, float length, float alignment, boolean cyclic)
          Creates a gradient with absolute colors
ShapeGradientPaint(java.awt.Color color, float ligtnessFactor, float gradingAngle, boolean cyclic)
          Creates a gradient with a base color and a ligtnessFactor to this color
ShapeGradientPaint(java.awt.Color color, float ligtnessFactor, float gradingAngle, float length, float alignment, boolean cyclic)
          Creates a gradient with a base color and a ligtnessFactor to this color
 
Method Summary
 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)
           
 boolean equals(java.lang.Object o)
           
 float getAlignment()
          The alignment of the line.
 float getAngle()
          The direction of the grading.
 java.awt.Color getColor1()
          The start color
 java.awt.Color getColor2()
          The end color
 float getLength()
          The distance between the points in the gradinet
 int getMode()
          Returns the mode is which this object has been created.
 java.awt.geom.Point2D getPoint1()
          Returns a copy of the point P1 that anchors the first color.
 java.awt.geom.Point2D getPoint2()
          Returns a copy of the point P2 which anchors the second color.
 int getTransparency()
          Returns the transparency.
 AtRefRangeNumber getX1()
          Returns the x1 value or null if not in coordinate mode.
 AtRefRangeNumber getX2()
          Returns the x2 value or null if not in coordinate mode.
 AtRefRangeNumber getY1()
          Returns the y1 value or null if not in coordinate mode.
 AtRefRangeNumber getY2()
          Returns the y2 value or null if not in coordinate mode.
 boolean isCyclic()
          Returns if the grading should restart or fade out
 void scaleToBounds(java.awt.Rectangle bounds)
          Scales this gradient paint to some bounds, normally bounds from a shape.
protected  java.awt.GradientPaint scaleToBoundsAngleMode(java.awt.Rectangle bounds)
          Impl.
protected  java.awt.GradientPaint scaleToBoundsCoordMode(java.awt.Rectangle bounds)
          Impl.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MODE_ANGLE

public static final int MODE_ANGLE
Angle mode.

See Also:
Constant Field Values

MODE_COORD

public static final int MODE_COORD
Coordinate mode, relative or absolute.

See Also:
Constant Field Values
Constructor Detail

ShapeGradientPaint

public ShapeGradientPaint(java.awt.Color color1,
                          java.awt.Color color2,
                          float gradingAngle,
                          float length,
                          float alignment,
                          boolean cyclic)
Creates a gradient with absolute colors

Parameters:
color1 - The first color
color2 - The second color
gradingAngle - The angle of the grading in degrees. For example, 0 is to the right, 90 point up, 180 points left and 270 points down, 360 points right and so on. Not negative but for instance 720 equals 360.
length - The distance between th epoints in the gradinet.
If <= 1.0 it's the percentage (1.0f == 100%) of the painted shape that the gradient should span over.
If > 1.0 it's interpreted as an absolute distance between the points.
Must be more than 0.0f.
alignment - The alignment of the line if the length is < 1f. Value should be from 0 to 1, inclusive.
cyclic - If the color should "restart" when reaching the end point.

ShapeGradientPaint

public ShapeGradientPaint(AtRefRangeNumber x1,
                          AtRefRangeNumber y1,
                          java.awt.Color color1,
                          AtRefRangeNumber x2,
                          AtRefRangeNumber y2,
                          java.awt.Color color2,
                          boolean cyclic)
Constructor that intercepts the values to GradientPaint. Works in exaclty the same way as GradientPaint(...) except that the coordinates are a bit more customizable.

Parameters:
x1 - x coordinate of the first specified Point in user space. If null a static AtStart(0) is used.
y1 - y coordinate of the first specified Point in user space. If null a static AtStart(0) is used.
color1 - Color at the first specified Point
x2 - x coordinate of the second specified Point in user space. If null a static AtEnd(0) is used.
y2 - y coordinate of the second specified Point in user space. If null a static AtEnd(0) is used.
color2 - Color at the second specified Point
cyclic - If the color should "restart" when reaching the end point.
See Also:
AtStart, AtEnd, AtFraction

ShapeGradientPaint

public ShapeGradientPaint(java.awt.Color color,
                          float ligtnessFactor,
                          float gradingAngle,
                          boolean cyclic)
Creates a gradient with a base color and a ligtnessFactor to this color

Parameters:
color - The first color
ligtnessFactor - The relative (-1f .. 1f) ligtness factor to tint color with. Calls: GfxUtil.createHSLModifiedColor(color, 0, 0, 0, 0, 0, ligtnessFactor) to get the second color.
gradingAngle - The angle of the grading in degrees. For example, 0 is to the right, 90 point up, 180 points left and 270 points down, 360 points right and so on. Not negative but for instance 720 equals 360 (wraps)
cyclic - If the color should "restart" when reaching the end point. Not used for now.

ShapeGradientPaint

public ShapeGradientPaint(java.awt.Color color,
                          float ligtnessFactor,
                          float gradingAngle,
                          float length,
                          float alignment,
                          boolean cyclic)
Creates a gradient with a base color and a ligtnessFactor to this color

Parameters:
color - The first color
ligtnessFactor - The relative (-1..1) ligtness factor to tint color with. Calls: GfxUtil.tintColor(color, ligtnessFactor) to get the second color.
gradingAngle - The angle of the grading in degrees. For example, 0 is to the right, 90 point up, 180 points left and 270 points down, 360 points right and so on. Not negative but for instance 720 equals 360 (wraps)
length - The distance between th epoints in the gradinet.
If <= 1.0f it's the percentage (1.0f == 100%) of the pained shape that the gradient should span over.
If > 1.0f it's interpreted as an absolute distance between the points.
Must be more than 0.0f.
alignment - The alignment of the line if the length is < 1f. Value should be from 0 to 1, inclusive.
cyclic - If the color should "restart" when reaching the end point. Not used for now.

ShapeGradientPaint

public ShapeGradientPaint(java.awt.Color color1,
                          java.awt.Color color2,
                          float gradingAngle,
                          boolean cyclic)
Creates a gradient with absolute colors

Parameters:
color1 - The first color
color2 - The second color
gradingAngle - The angle of the grading in degrees. For example, 0 is to the right, 90 point up, 180 points left and 270 points down, 360 points right and so on. Not negative but for instance 720 equals 360 (wraps)
cyclic - If the color should "restart" when reaching the end point. Not used for now.
Method Detail

scaleToBounds

public void scaleToBounds(java.awt.Rectangle bounds)
Scales this gradient paint to some bounds, normally bounds from a shape.

Parameters:
bounds - The bounds to scale the grading to. The grading will start with color c1 and the point at the current angle so that the grading will start in one of the corners, or two corners if one of the main angles (0, 90, 180, 270) is used.

scaleToBoundsAngleMode

protected java.awt.GradientPaint scaleToBoundsAngleMode(java.awt.Rectangle bounds)
Impl. of scaleToBounds(java.awt.Rectangle) for ANGLE mode

Parameters:
bounds - The bounds to sale to
Returns:
The resulting gradient paint

scaleToBoundsCoordMode

protected java.awt.GradientPaint scaleToBoundsCoordMode(java.awt.Rectangle bounds)
Impl. of scaleToBounds(java.awt.Rectangle) for COORD mode

Parameters:
bounds - The bounds to sale to
Returns:
The resulting gradient paint

getPoint1

public java.awt.geom.Point2D getPoint1()
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

getPoint2

public java.awt.geom.Point2D getPoint2()
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

getColor1

public java.awt.Color getColor1()
The start color

Returns:
The start color

getColor2

public java.awt.Color getColor2()
The end color

Returns:
The end color

getAngle

public float getAngle()
The direction of the grading.

Returns:
The direction of the grading. Calculated from the first point to the second.

getLength

public float getLength()
The distance between the points in the gradinet

Returns:
The distance between the points in the gradinet.
If <= 1.0 it's the percentage (1.0f == 100%) of the pained shape that the gradient should span over.
If > 1.0 it's interpreted as an absolute distance between the points.
Must be more than 0.0f.

getAlignment

public float getAlignment()
The alignment of the line.

Returns:
The alignment of the line. Value should be 0 to 1, inclusive. 0.5f is in the middle (normal)

getX1

public AtRefRangeNumber getX1()
Returns the x1 value or null if not in coordinate mode. Mode is depending in which constructor was used.

Returns:
The x1 value or null if not in coordinate mode.

getY1

public AtRefRangeNumber getY1()
Returns the y1 value or null if not in coordinate mode. Mode is depending in which constructor was used.

Returns:
The y1 value or null if not in coordinate mode.

getX2

public AtRefRangeNumber getX2()
Returns the x2 value or null if not in coordinate mode. Mode is depending in which constructor was used.

Returns:
The x2 value or null if not in coordinate mode.

getY2

public AtRefRangeNumber getY2()
Returns the y2 value or null if not in coordinate mode. Mode is depending in which constructor was used.

Returns:
The y2 value or null if not in coordinate mode.

getMode

public int getMode()
Returns the mode is which this object has been created.

Returns:
The mode is which this object has been created. MODE_ANGLE or MODE_COORD)

isCyclic

public boolean isCyclic()
Returns if the grading should restart or fade out

Returns:
If the grading should restart or fade out

getTransparency

public int getTransparency()
Returns the transparency. Either OPAQUE or TRANSLUCENT depending on wheter both colors have alpha 255 (OPAQUE)

Specified by:
getTransparency in interface java.awt.Transparency
Returns:
Transparency.OPAQUE or Transparency.TRANSLUCENT
See Also:
Transparency.TRANSLUCENT, Transparency.OPAQUE

createContext

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)
Specified by:
createContext in interface java.awt.Paint

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.