swingx
Version 2005-08-19

org.jdesktop.swingx.painter
Class ShapePainter

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

public class ShapePainter
extends AbstractPainter

A Painter that paints Shapes. It uses a stroke and a fillPaint to do so. The shape is painted as is, at a specific location. If no Shape is specified, nothing will be painted. If no stroke is specified, the default for the Graphics2D will be used. If no fillPaint is specified, the component background color will be used. And if no location is specified, then the shape will be draw at the origin (0,0)

Here is an example that draws a lowly rectangle:


  Rectangle2D.Double rect = new Rectangle2D.Double(0, 0, 50, 50);
  ShapePainter p = new ShapePainter(rect);
  p.setLocation(new Point2D.Double(20, 10));
 


Nested Class Summary
static class ShapePainter.Style
          Different available fill styles.
 
Constructor Summary
ShapePainter()
          Create a new ShapePainter
ShapePainter(Shape shape)
          Create a new ShapePainter with the specified shape.
ShapePainter(Shape shape, Paint paint)
          Create a new ShapePainter with the specified shape and fillPaint.
ShapePainter(Shape shape, Paint paint, ShapePainter.Style style)
          Create a new ShapePainter with the specified shape and fillPaint.
 
Method Summary
 Paint getFillPaint()
           
 Point2D getLocation()
           
 Resize getResize()
           
 Resize getResizeLocation()
           
 Shape getShape()
           
 Stroke getStroke()
           
 Paint getStrokePaint()
           
 ShapePainter.Style getStyle()
           
 void paintBackground(Graphics2D g, JComponent component)
          Subclasses should implement this method and perform custom painting operations here.
 void setFillPaint(Paint p)
          The Paint to use for filling the shape.
 void setLocation(Point2D location)
          Specifies the location at which to place the shape prior to painting.
 void setResize(Resize r)
          Specifies the resize behavior of the shape.
 void setResizeLocation(Resize r)
          Specifies the resize behavior for the location property.
 void setShape(Shape s)
          Sets the shape to fillPaint.
 void setStroke(Stroke s)
          Sets the stroke to use for painting.
 void setStrokePaint(Paint p)
          The Paint to use for stroking the shape (painting the outline).
 void setStyle(ShapePainter.Style s)
          The shape can be filled or simply stroked (outlined), or both.
 
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

ShapePainter

public ShapePainter()
Create a new ShapePainter


ShapePainter

public ShapePainter(Shape shape)
Create a new ShapePainter with the specified shape.

Parameters:
shape - the shape to fillPaint

ShapePainter

public ShapePainter(Shape shape,
                    Paint paint)
Create a new ShapePainter with the specified shape and fillPaint.

Parameters:
shape - the shape to fillPaint
paint - the fillPaint to be used to fillPaint the shape

ShapePainter

public ShapePainter(Shape shape,
                    Paint paint,
                    ShapePainter.Style style)
Create a new ShapePainter with the specified shape and fillPaint. The shape can be filled or stroked (only the ouline is painted).

Parameters:
shape - the shape to fillPaint
paint - the fillPaint to be used to fillPaint the shape
style - specifies the ShapePainter.Style to use for painting this shape. If null, then Style.BOTH is used
Method Detail

setShape

public void setShape(Shape s)
Sets the shape to fillPaint. This shape is not resized when the component bounds are. To do that, create a custom shape that is bound to the component width/height

Parameters:
s - the Shape to fillPaint. May be null

getShape

public Shape getShape()
Returns:
the Shape to fillPaint. May be null

setStroke

public void setStroke(Stroke s)
Sets the stroke to use for painting. If null, then the default Graphics2D stroke use used

Parameters:
s - the Stroke to fillPaint with

getStroke

public Stroke getStroke()
Returns:
the Stroke to use for painting

setFillPaint

public void setFillPaint(Paint p)
The Paint to use for filling the shape. Can be a Color, GradientPaint, TexturePaint, or any other kind of Paint. If null, the component background is used.

Parameters:
p - the Paint to use for painting the shape. May be null.

getFillPaint

public Paint getFillPaint()
Returns:
the Paint used when painting the shape. May be null

setStrokePaint

public void setStrokePaint(Paint p)
The Paint to use for stroking the shape (painting the outline). Can be a Color, GradientPaint, TexturePaint, or any other kind of Paint. If null, the component foreground is used.

Parameters:
p - the Paint to use for stroking the shape. May be null.

getStrokePaint

public Paint getStrokePaint()
Returns:
the Paint used when stroking the shape. May be null

setLocation

public void setLocation(Point2D location)
Specifies the location at which to place the shape prior to painting. If null, the origin (0,0) is used

Parameters:
location - the Point2D at which to fillPaint the shape. may be null

getLocation

public Point2D getLocation()
Returns:
the Point2D location at which to fillPaint the shape. Will never be null (if it was null, new Point2D.Double(0,0) will be returned)

setStyle

public void setStyle(ShapePainter.Style s)
The shape can be filled or simply stroked (outlined), or both. By default, the shape is both filled and stroked. This property specifies the strategy to use.

Parameters:
s - the Style to use. If null, Style.BOTH is used

getStyle

public ShapePainter.Style getStyle()
Returns:
the Style used

setResizeLocation

public void setResizeLocation(Resize r)
Specifies the resize behavior for the location property. If r is Resize.HORIZONTAL or Resize.BOTH, then the x value of the location will be treated as if it were a percentage of the width of the component. Likewise, Resize.VERTICAL or Resize.BOTH will affect the y value. For example, if I had a location (.3, .8) then the X will be situated at 30% of the width and the Y will be situated at 80% of the height.

Parameters:
r - value indicating whether/how to resize the Location property when painting. If null, Resize.BOTH will be used

getResizeLocation

public Resize getResizeLocation()
Returns:
value indication whether/how to resize the location property. This will never be null

setResize

public void setResize(Resize r)
Specifies the resize behavior of the shape. As with all other properties that rely on Resize, the value of the width/height of the shape will represent a percentage of the width/height of the component, as a value between 0 and 1

Parameters:
r - value indication whether/how to resize the shape. If null, Resize.NONE will be used

getResize

public Resize getResize()
Returns:
value indication whether/how to resize the shape. Will never be null

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