Package org.jdesktop.swingx.painter
Class AbstractAreaPainter<T>
- java.lang.Object
-
- org.jdesktop.beans.AbstractBean
-
- org.jdesktop.swingx.painter.AbstractPainter<T>
-
- org.jdesktop.swingx.painter.AbstractLayoutPainter<T>
-
- org.jdesktop.swingx.painter.AbstractAreaPainter<T>
-
- All Implemented Interfaces:
Painter<T>
- Direct Known Subclasses:
ImagePainter
,MattePainter
,RectanglePainter
,ShapePainter
,TextPainter
public abstract class AbstractAreaPainter<T> extends AbstractLayoutPainter<T>
The abstract base class for all painters that fill a vector path area. This includes Shapes, Rectangles, Text, and the MattePainter which fills in the entire background of a component. The defining feature of AbstractAreaPainter subclasses is that they implement the provideShape() method which returns the outline shape of the area that this painter will fill. Subclasses must implement the provideShape() method. The AbstractAreaPainter provides support for the following common painting properties- fillPaint
- paintStretched
- borderPaint
- borderWidth
- style
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractAreaPainter.Style
Different available fill styles.-
Nested classes/interfaces inherited from class org.jdesktop.swingx.painter.AbstractLayoutPainter
AbstractLayoutPainter.HorizontalAlignment, AbstractLayoutPainter.VerticalAlignment
-
Nested classes/interfaces inherited from class org.jdesktop.swingx.painter.AbstractPainter
AbstractPainter.Interpolation
-
-
Field Summary
Fields Modifier and Type Field Description private AreaEffect[]
areaEffects
private java.awt.Paint
borderPaint
The Paint to use when stroking the shape (drawing the outline).private float
borderWidth
The stroke width to use when painting.private java.awt.Paint
fillPaint
The paint to use when filling the shapeprivate boolean
stretchPaint
private AbstractAreaPainter.Style
style
-
Constructor Summary
Constructors Constructor Description AbstractAreaPainter()
Creates a new instance of AbstractAreaPainterAbstractAreaPainter(java.awt.Paint paint)
Creates a new instance of AbstractAreaPainter
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) java.awt.Paint
calculateSnappedPaint(java.awt.Paint p, int width, int height)
Resizes the given Paint.AreaEffect[]
getAreaEffects()
Gets the current set of path effects applied to this painter.java.awt.Paint
getBorderPaint()
Gets the current Paint to use for stroking the shape (painting the outline).float
getBorderWidth()
Gets the current border width.java.awt.Paint
getFillPaint()
Gets the current fill paint.AbstractAreaPainter.Style
getStyle()
Gets the current Style.boolean
isPaintStretched()
Indicates if the paint will be snapped.protected abstract java.awt.Shape
provideShape(java.awt.Graphics2D g, T comp, int width, int height)
Returns the outline shape of this painter.void
setAreaEffects(AreaEffect... areaEffects)
Sets the path effects to be drawn on this painter.void
setBorderPaint(java.awt.Paint p)
The Paint to use for stroking the shape (painting the outline).void
setBorderWidth(float s)
Sets the border width to use for painting.void
setFillPaint(java.awt.Paint p)
Sets the Paint to use.void
setPaintStretched(boolean paintStretched)
Specifies whether this Painter should attempt to resize the Paint to fit the area being painted.void
setStyle(AbstractAreaPainter.Style s)
The shape can be filled or simply stroked (outlined), or both or none.-
Methods inherited from class org.jdesktop.swingx.painter.AbstractLayoutPainter
calculateLayout, getHorizontalAlignment, getInsets, getVerticalAlignment, isFillHorizontal, isFillVertical, setFillHorizontal, setFillVertical, setHorizontalAlignment, setInsets, setVerticalAlignment
-
Methods inherited from class org.jdesktop.swingx.painter.AbstractPainter
clearCache, configureGraphics, doPaint, getFilters, getInterpolation, isAntialiasing, isCacheable, isCacheCleared, isDirty, isInPaintContext, isVisible, paint, setAntialiasing, setCacheable, setDirty, setFilters, setInPaintContext, setInterpolation, setVisible, shouldUseCache, validate
-
Methods inherited from class org.jdesktop.beans.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, clone, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, getPropertyChangeListeners, getPropertyChangeListeners, getVetoableChangeListeners, getVetoableChangeListeners, hasPropertyChangeListeners, hasVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener
-
-
-
-
Field Detail
-
stretchPaint
private boolean stretchPaint
-
areaEffects
private AreaEffect[] areaEffects
-
style
private AbstractAreaPainter.Style style
-
borderWidth
private float borderWidth
The stroke width to use when painting. If null, the default Stroke for the Graphics2D is used
-
fillPaint
private java.awt.Paint fillPaint
The paint to use when filling the shape
-
borderPaint
private java.awt.Paint borderPaint
The Paint to use when stroking the shape (drawing the outline). If null, then the component foreground color is used
-
-
Method Detail
-
getFillPaint
public java.awt.Paint getFillPaint()
Gets the current fill paint. This is the Paint object that will be used to fill the path area.- Returns:
- Gets the Paint being used. May be null
-
setFillPaint
public void setFillPaint(java.awt.Paint p)
Sets the Paint to use. This is the Paint object that will be used to fill the path area. If null, nothing is painted- Parameters:
p
- the Paint to use
-
isPaintStretched
public boolean isPaintStretched()
Indicates if the paint will be snapped. This means that the paint will be scaled and aligned along the 4 axis of (horizontal, vertical, and both diagonals). Snapping allows the paint to be stretched across the component when it is drawn, even if the component is resized. This setting is only used for gradient paints. It will have no effect on Color or Texture paints.- Returns:
- the current value of the snapPaint property
-
setPaintStretched
public void setPaintStretched(boolean paintStretched)
Specifies whether this Painter should attempt to resize the Paint to fit the area being painted. For example, if true, then a gradient specified as (0, 0), (1, 0) would stretch horizontally such that the beginning of the gradient is on the left edge of the painted region, and the end of the gradient is at the right edge of the painted region. Specifically, if true, the resizePaint method will be called to perform the actual resizing of the Paint- Parameters:
paintStretched
- true if the paint should be stretched, false otherwise.
-
setBorderPaint
public void setBorderPaint(java.awt.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.
-
getBorderPaint
public java.awt.Paint getBorderPaint()
Gets the current 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.- Returns:
- the Paint used when stroking the shape. May be null
-
setStyle
public void setStyle(AbstractAreaPainter.Style s)
The shape can be filled or simply stroked (outlined), or both or none. 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 AbstractAreaPainter.Style getStyle()
Gets the current Style. The shape can be filled or simply stroked (outlined), or both or none. By default, the shape is both filled and stroked. This property specifies the strategy to use.- Returns:
- the Style used
-
setBorderWidth
public void setBorderWidth(float s)
Sets the border width to use for painting. If null, then the default Graphics2D stroke will be used. The stroke will be centered on the actual shape outline.- Parameters:
s
- the Stroke to fillPaint with
-
getBorderWidth
public float getBorderWidth()
Gets the current border width.- Returns:
- the Stroke to use for painting
-
calculateSnappedPaint
java.awt.Paint calculateSnappedPaint(java.awt.Paint p, int width, int height)
Resizes the given Paint. By default, only Gradients, LinearGradients, and RadialGradients are resized in this method. If you have special resizing needs, override this method. This method is mainly used to make gradient paints resize with the component this painter is attached to. This method is internal to the painter api and should not be called elsewhere. It is used by the paintStretched property and painter subclasses. In the future it may be made public for use by other classes. If this happens it should probably be turned into a static utility method.
-
provideShape
protected abstract java.awt.Shape provideShape(java.awt.Graphics2D g, T comp, int width, int height)
Returns the outline shape of this painter. Subclasses must implement this method. This shape will be used for filling, stroking, and clipping.- Parameters:
g
- graphicscomp
- The Object this painter will be painted on.width
- the width to paintheight
- the height to paint- Returns:
- the outline shape of this painter
-
setAreaEffects
public void setAreaEffects(AreaEffect... areaEffects)
Sets the path effects to be drawn on this painter. Set this to null in order to remove all installed effects.- Parameters:
areaEffects
- the effects to apply to this painter
-
getAreaEffects
public AreaEffect[] getAreaEffects()
Gets the current set of path effects applied to this painter. Returned array is guarantied to be not null.- Returns:
- the effects applied to this path painter
-
-