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
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 ClassesModifier and TypeClassDescriptionstatic enum
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
FieldsModifier and TypeFieldDescriptionprivate AreaEffect[]
private Paint
The Paint to use when stroking the shape (drawing the outline).private float
The stroke width to use when painting.private Paint
The paint to use when filling the shapeprivate boolean
private AbstractAreaPainter.Style
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance of AbstractAreaPainterAbstractAreaPainter
(Paint paint) Creates a new instance of AbstractAreaPainter -
Method Summary
Modifier and TypeMethodDescription(package private) Paint
calculateSnappedPaint
(Paint p, int width, int height) Resizes the given Paint.Gets the current set of path effects applied to this painter.Gets the current Paint to use for stroking the shape (painting the outline).float
Gets the current border width.Gets the current fill paint.getStyle()
Gets the current Style.boolean
Indicates if the paint will be snapped.protected abstract Shape
provideShape
(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
The Paint to use for stroking the shape (painting the outline).void
setBorderWidth
(float s) Sets the border width to use for painting.void
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
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 Details
-
stretchPaint
private boolean stretchPaint -
areaEffects
-
style
-
borderWidth
private float borderWidthThe stroke width to use when painting. If null, the default Stroke for the Graphics2D is used -
fillPaint
The paint to use when filling the shape -
borderPaint
The Paint to use when stroking the shape (drawing the outline). If null, then the component foreground color is used
-
-
Constructor Details
-
AbstractAreaPainter
public AbstractAreaPainter()Creates a new instance of AbstractAreaPainter -
AbstractAreaPainter
Creates a new instance of AbstractAreaPainter- Parameters:
paint
- the default paint to fill this area painter with
-
-
Method Details
-
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
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
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
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
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
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
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
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
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
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
-