|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--java.util.Observable
|
+--grad.BasicGradientPainter
|
+--grad.LinearGradientPainter
GradientPainter is a class that accepts parameters defining a gradient, and can also paint the gradient into a Shape (actually, into the Shape's bounding box).
This implementation can only paint two simple kinds of gradients: linear gradients horizontal and vertical. This is because the current implementation uses a very stupid but easy approach of drawing a bunch of 1-pixel lines in different colors. This is easy and fast for small areas and avoids using gobs of memory for large areas, but it is totally impractical for more sophisticated or complicated gradients. [Note: for fancies gradients, you must use an algorithms that renders pixels into some kind of buffer, computing the RGB of each pixel based on it's position in the gradient. That's easy for some gradient shapes but complicated for others. It also requires a buffer big enough to hold all the pixels and computation enough to set all the pixels.]
A gradient can be a simple gradient, defined by a start and end color, or it can be a multi-part gradient composed of several GradientSegments.
The usual sequence for using this class is:
Internally, the GradientPainter holds its list of segments on a Vector and uses them in sequence. It is the responsibility of the caller to ensure that the segments link up correctly. Regions of the range [0.0..1.0] that have no segment corresponding to them will not be painted. Regions that overlap will be painted with the lowest-numbered segment that applies to them.
GradientSegment,
GradientPainter, Serialized Form| Field Summary | |
static int |
BOTTOM_TO_TOP
Linear gradient paint from bottom to top |
static int |
LEFT_TO_RIGHT
Linear gradient paint from left to right. |
static int |
RIGHT_TO_LEFT
Linear gradient paint from left to right. |
static int |
TOP_TO_BOTTOM
Linear gradient paint from top to bottom |
| Fields inherited from class grad.BasicGradientPainter |
DEFAULT_MODE, master, segments |
| Constructor Summary | |
LinearGradientPainter()
Create a new GradientPainter with 0 segments. |
|
LinearGradientPainter(BasicGradientPainter src)
Create a new LinearGradientPainter with a copy of the segments of some other gradient painter |
|
LinearGradientPainter(java.awt.Color c1,
java.awt.Color c2)
Create a simple GradientPainter with 1 simple RGB segment. |
|
| Method Summary | |
void |
paint(java.awt.Graphics g,
int x,
int y,
int w,
int h,
int mode)
Paint a gradient into a given rectangular area using a given Graphics. |
void |
paint(java.awt.Graphics g,
java.awt.Shape s,
int mode)
Paint a gradient into a given Shape using a given Graphics. |
protected void |
paintSimpleLinear(java.awt.Graphics g,
int bval,
int fval,
int min,
int max,
int incr,
boolean h)
|
| Methods inherited from class grad.BasicGradientPainter |
addSegment, countSegments, flipSegment, getSegment, gradientsChanged, removeSegment, setSegment, slaveTo, splitSegment, swapAt, toCodeFragment, toString, update |
| Methods inherited from class java.util.Observable |
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final int LEFT_TO_RIGHT
public static final int RIGHT_TO_LEFT
public static final int TOP_TO_BOTTOM
public static final int BOTTOM_TO_TOP
| Constructor Detail |
public LinearGradientPainter(java.awt.Color c1,
java.awt.Color c2)
public LinearGradientPainter()
public LinearGradientPainter(BasicGradientPainter src)
| Method Detail |
public void paint(java.awt.Graphics g,
java.awt.Shape s,
int mode)
paint in class BasicGradientPaintergrad.BasicGradientPainterg - Graphics to paint intos - Shape to fill (usually a Rectangle)mode - Gradient generation mode (defined per subclass)
public void paint(java.awt.Graphics g,
int x,
int y,
int w,
int h,
int mode)
protected void paintSimpleLinear(java.awt.Graphics g,
int bval,
int fval,
int min,
int max,
int incr,
boolean h)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||