swingx
Version 2005-08-19

org.jdesktop.swingx.painter.gradient
Class BasicGradientPainter

java.lang.Object
  extended by org.jdesktop.swingx.JavaBean
      extended by org.jdesktop.swingx.painter.AbstractPainter
          extended by org.jdesktop.swingx.painter.gradient.AbstractGradientPainter
              extended by org.jdesktop.swingx.painter.gradient.BasicGradientPainter
All Implemented Interfaces:
Painter

public class BasicGradientPainter
extends AbstractGradientPainter

A Gradient based Painter that uses GradientPaint to paint the gradient. Simply specify the GradientPaint to use.

In order for resizing to work properly with GradientPaint it is necessary that the various control points used in these paints be specified in such a manner that they can be reliably resized. For example, BasicGradientPainter takes GradientPaints who's point1 and point2 properties are specified between 0 and 1, representing at what percentage of the distance from the origin the gradient begins and ends. Thus, if I created a GradientPaint like this:


  GradientPaint gp = new GradientPaint(
      new Point2D.Double(.2d, 0),
      Color.BLUE,
      new Point2D.Double(.8d, 0),
      Color.WHITE);
 
then when painted, the gradient will start with a BLUE at 20% of the width of the component, and finish with WHITE at 80% of the width of the component.

Various built in gradients also exist as public static final properties. They are defined as GradientPaints rather than BasicGradientPainters because BasicGradientPainter is mutable and thus don't make very reliable public static final defaults. To use:


  panel.setBackgroundPainter(new BasicGradientPainter(BasicGradientPainter.BLUE_EXPERIENCE));
 


Field Summary
static GradientPaint AERITH
           
static GradientPaint BLUE_EXPERIENCE
           
static GradientPaint GRAY
           
static GradientPaint MAC_OSX
           
static GradientPaint MAC_OSX_SELECTED
           
static GradientPaint NIGHT_GRAY
           
static GradientPaint NIGHT_GRAY_LIGHT
           
static GradientPaint RED_XP
           
 
Constructor Summary
BasicGradientPainter()
          Creates a new instance of BasicGradientPainter
BasicGradientPainter(float x1, float y1, Color startColor, float x2, float y2, Color endColor)
          Constructs a simple acyclic BasicGradientPainter object.
BasicGradientPainter(float x1, float y1, Color startColor, float x2, float y2, Color endColor, boolean cyclic)
          Constructs either a cyclic or acyclic BasicGradientPainter object depending on the boolean parameter.
BasicGradientPainter(GradientPaint paint)
          Creates a new instance of BasicGradientPainter
BasicGradientPainter(Point2D startPoint, Color startColor, Point2D endPoint, Color endColor)
          Constructs a simple acyclic BasicGradientPainter object.
BasicGradientPainter(Point2D startPoint, Color startColor, Point2D endPoint, Color endColor, boolean cyclic)
          Constructs either a cyclic or acyclic BasicGradientPainter object depending on the boolean parameter.
 
Method Summary
protected  Paint calculateSizedPaint(int width, int height)
           
 GradientPaint getGradientPaint()
           
 void setGradientPaint(GradientPaint paint)
          Set the gradient paint to use.
 
Methods inherited from class org.jdesktop.swingx.painter.gradient.AbstractGradientPainter
getResize, isResizeHorizontal, isResizeVertical, paintBackground, setResize
 
Methods inherited from class org.jdesktop.swingx.painter.AbstractPainter
getAlphaInterpolation, getAntialiasing, getClip, getColorRendering, getComposite, getDithering, getEffects, getFractionalMetrics, getInterpolation, getRendering, getRenderingHint, getRenderingHints, getResizeClip, getStrokeControl, getTextAntialiasing, isUseCache, paint, restoreState, saveState, setAlphaInterpolation, setAntialiasing, setClip, setColorRendering, setComposite, setDithering, setEffects, setEffects, setFractionalMetrics, setInterpolation, setRendering, setRenderingHint, setRenderingHints, setResizeClip, setStrokeControl, setTextAntialiasing, setUseCache
 
Methods inherited from class org.jdesktop.swingx.JavaBean
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, getPropertyChangeListeners, hasListeners, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BLUE_EXPERIENCE

public static final GradientPaint BLUE_EXPERIENCE

MAC_OSX_SELECTED

public static final GradientPaint MAC_OSX_SELECTED

MAC_OSX

public static final GradientPaint MAC_OSX

AERITH

public static final GradientPaint AERITH

GRAY

public static final GradientPaint GRAY

RED_XP

public static final GradientPaint RED_XP

NIGHT_GRAY

public static final GradientPaint NIGHT_GRAY

NIGHT_GRAY_LIGHT

public static final GradientPaint NIGHT_GRAY_LIGHT
Constructor Detail

BasicGradientPainter

public BasicGradientPainter()
Creates a new instance of BasicGradientPainter


BasicGradientPainter

public BasicGradientPainter(GradientPaint paint)
Creates a new instance of BasicGradientPainter


BasicGradientPainter

public BasicGradientPainter(float x1,
                            float y1,
                            Color startColor,
                            float x2,
                            float y2,
                            Color endColor)
Constructs a simple acyclic BasicGradientPainter object.

Parameters:
x1 - x coordinate of the first specified Point in user space
y1 - y coordinate of the first specified Point in user space
startColor - Color at the first specified Point
x2 - x coordinate of the second specified Point in user space
y2 - y coordinate of the second specified Point in user space
endColor - Color at the second specified Point
Throws:
NullPointerException - if either one of colors is null

BasicGradientPainter

public BasicGradientPainter(Point2D startPoint,
                            Color startColor,
                            Point2D endPoint,
                            Color endColor)
Constructs a simple acyclic BasicGradientPainter object.

Parameters:
startPoint - the first specified Point in user space
startColor - Color at the first specified Point
endPoint - the second specified Point in user space
endColor - Color at the second specified Point
Throws:
NullPointerException - if either one of colors or points is null

BasicGradientPainter

public BasicGradientPainter(float x1,
                            float y1,
                            Color startColor,
                            float x2,
                            float y2,
                            Color endColor,
                            boolean cyclic)
Constructs either a cyclic or acyclic BasicGradientPainter object depending on the boolean parameter.

Parameters:
x1 - x coordinate of the first specified Point in user space
y1 - y coordinate of the first specified Point in user space
startColor - Color at the first specified Point
x2 - x coordinate of the second specified Point in user space
y2 - y coordinate of the second specified Point in user space
endColor - Color at the second specified Point
cyclic - true if the gradient pattern should cycle repeatedly between the two colors; false otherwise

BasicGradientPainter

public BasicGradientPainter(Point2D startPoint,
                            Color startColor,
                            Point2D endPoint,
                            Color endColor,
                            boolean cyclic)
Constructs either a cyclic or acyclic BasicGradientPainter object depending on the boolean parameter.

Parameters:
startPoint - the first specified Point in user space
startColor - Color at the first specified Point
endPoint - the second specified Point in user space
endColor - 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

setGradientPaint

public void setGradientPaint(GradientPaint paint)
Set the gradient paint to use. This may be null. If null, nothing is painted

Parameters:
paint - the GradientPaint to use

getGradientPaint

public GradientPaint getGradientPaint()
Returns:
the GradientPaint used for painting. This may be null

calculateSizedPaint

protected Paint calculateSizedPaint(int width,
                                    int height)
Specified by:
calculateSizedPaint in class AbstractGradientPainter
Parameters:
width - the width used to calculate the new paint size
height - the height used to calculate the new paint size
Returns:
a calculated Paint that fits within the given width/height. May be null.

swingx
Version 2005-08-19