swingx
Version 2005-08-19

org.jdesktop.swingx.painter
Class PinstripePainter

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

public class PinstripePainter
extends AbstractPainter

A fun Painter that paints pinstripes. You can specify the Paint to paint those pinstripes in (could even be a texture paint!), the angle at which to paint the pinstripes, and the spacing between stripes.

The default PinstripePainter configuration will paint the pinstripes using the foreground color of the component (the default behavior if a Paint is not specified) at a 45 degree angle with 8 pixels between stripes

Here is a custom code snippet that paints Color.GRAY pinstripes at a 135 degree angle:


  PinstripePainter p = new PinstripePainter();
  p.setAngle(135);
  p.setPaint(Color.GRAY);
 


Constructor Summary
PinstripePainter()
          Create a new PinstripePainter.
PinstripePainter(double angle)
          Create a new PinstripePainter using the given angle, 8 pixel spacing, and the foreground color of the Component
PinstripePainter(Paint paint)
          Create a new PinstripePainter using an angle of 45, 8 pixel spacing, and the given Paint.
PinstripePainter(Paint paint, double angle)
          Create a new PinstripePainter using the given angle, 8 pixel spacing, and the given Paint
 
Method Summary
 double getAngle()
           
 Paint getPaint()
           
 double getSpacing()
           
 void paintBackground(Graphics2D g, JComponent component)
          Subclasses should implement this method and perform custom painting operations here.
 void setAngle(double angle)
          Sets the angle, in degrees, at which to paint the pinstripes.
 void setPaint(Paint p)
          Set the paint to use for drawing the pinstripes
 void setSpacing(double spacing)
          Sets the spacing between pinstripes
 
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

PinstripePainter

public PinstripePainter()
Create a new PinstripePainter. By default the angle with be 45 degrees, the spacing will be 8 pixels, and the color will be the Component foreground color.


PinstripePainter

public PinstripePainter(Paint paint)
Create a new PinstripePainter using an angle of 45, 8 pixel spacing, and the given Paint.

Parameters:
paint - the paint used when drawing the stripes

PinstripePainter

public PinstripePainter(Paint paint,
                        double angle)
Create a new PinstripePainter using the given angle, 8 pixel spacing, and the given Paint

Parameters:
paint - the paint used when drawing the stripes
angle - the angle, in degrees, in which to paint the pinstripes

PinstripePainter

public PinstripePainter(double angle)
Create a new PinstripePainter using the given angle, 8 pixel spacing, and the foreground color of the Component

Parameters:
angle - the angle, in degrees, in which to paint the pinstripes
Method Detail

setPaint

public void setPaint(Paint p)
Set the paint to use for drawing the pinstripes

Parameters:
p - the Paint to use. May be a Color.

getPaint

public Paint getPaint()
Returns:
the Paint to use to draw the pinstripes

setAngle

public void setAngle(double angle)
Sets the angle, in degrees, at which to paint the pinstripes. If the given angle is < 0 or > 360, it will be appropriately constrained. For example, if a value of 365 is given, it will result in 5 degrees. The conversion is not perfect, but "a man on a galloping horse won't be able to tell the difference".

Parameters:
angle - the Angle in degrees at which to paint the pinstripes

getAngle

public double getAngle()
Returns:
the angle, in degrees, at which the pinstripes are painted

setSpacing

public void setSpacing(double spacing)
Sets the spacing between pinstripes

Parameters:
spacing - spacing between pinstripes

getSpacing

public double getSpacing()
Returns:
the spacing between pinstripes

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.

swingx
Version 2005-08-19