Class 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
The AbstractAreaPainter also provides support for path effects like dropshadows and glows.
  • Field Details

    • stretchPaint

      private boolean stretchPaint
    • areaEffects

      private AreaEffect[] areaEffects
    • style

    • borderWidth

      private float borderWidth
      The stroke width to use when painting. If null, the default Stroke for the Graphics2D is used
    • fillPaint

      private Paint fillPaint
      The paint to use when filling the shape
    • borderPaint

      private Paint 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

      public AbstractAreaPainter(Paint paint)
      Creates a new instance of AbstractAreaPainter
      Parameters:
      paint - the default paint to fill this area painter with
  • Method Details

    • getFillPaint

      public 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(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(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 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

      Paint calculateSnappedPaint(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 Shape provideShape(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 - graphics
      comp - The Object this painter will be painted on.
      width - the width to paint
      height - 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