swingx
Version 2005-08-19

org.jdesktop.swingx.painter.gradient
Class AbstractGradientPainter

java.lang.Object
  extended by org.jdesktop.swingx.JavaBean
      extended by org.jdesktop.swingx.painter.AbstractPainter
          extended by org.jdesktop.swingx.painter.gradient.AbstractGradientPainter
All Implemented Interfaces:
Painter
Direct Known Subclasses:
BasicGradientPainter, LinearGradientPainter, RadialGradientPainter

public abstract class AbstractGradientPainter
extends AbstractPainter

An abstract base class from which the various gradient oriented painter classes extend. Gradient based painters perform an important task beyond what a MattePainter with a GradientPaint will do -- they resize the gradient to fit the Component regardless of its dimensions.

AbstractGradientPainter has a resize property of type Resize that specifies whether the gradient should be resized horizontally, vertically, in both directions or not at all (in which case you should really probably be using MattePainter). Subclasses must implement calculateSizedPaint to return a new gradient paint instance that is resized in the proper ways. If no Paint is returned from this method call, then nothing is painted.

By default, the resize property is set to BOTH.

In order for resizing to work properly with GradientPaint, LinearGradientPaint, and RadialGradientPaint, 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.

See the various subclasses for more detailed examples.


Constructor Summary
AbstractGradientPainter()
          Creates a new instance of AbstractGradientPainter
 
Method Summary
protected abstract  Paint calculateSizedPaint(int width, int height)
           
 Resize getResize()
           
protected  boolean isResizeHorizontal()
           
protected  boolean isResizeVertical()
           
 void paintBackground(Graphics2D g, JComponent component)
          Subclasses should implement this method and perform custom painting operations here.
 void setResize(Resize resize)
          Specifies how the paint will be resized based on the component dimensions.
 
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
 

Constructor Detail

AbstractGradientPainter

public AbstractGradientPainter()
Creates a new instance of AbstractGradientPainter

Method Detail

paintBackground

public void paintBackground(Graphics2D g,
                            JComponent component)
Description copied from class: AbstractPainter
Subclasses should implement this method and perform custom painting operations here. Common behavior, such as setting the clip and composite, saving and restoring state, is performed in the "paint" method automatically, and then delegated here.

Specified by:
paintBackground in class AbstractPainter
Parameters:
g - The Graphics2D object in which to paint
component - The JComponent that the Painter is delegate for.

calculateSizedPaint

protected abstract Paint calculateSizedPaint(int width,
                                             int height)
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.

getResize

public Resize getResize()
Returns:
a value indicating how the paint will be resized to fit the component dimensions. Never returns null.

setResize

public void setResize(Resize resize)
Specifies how the paint will be resized based on the component dimensions.

Parameters:
resize - the new Resize value. May be null. If null, set to Resize.BOTH.

isResizeHorizontal

protected boolean isResizeHorizontal()
Returns:
true if getResize() returns BOTH or HORIZONTAL.

isResizeVertical

protected boolean isResizeVertical()
Returns:
true if getResize() returns BOTH or VERTICAL.

swingx
Version 2005-08-19