JIDE 3.5.15

com.jidesoft.chart.style
Class StripePaint

java.lang.Object
  extended by com.jidesoft.chart.style.StripePaint
All Implemented Interfaces:
Paint, Transparency

public class StripePaint
extends Object
implements Paint

StripePaint is a class for creating striped patterns. These patterns can be used for filling other shapes; in particular, they are excellent for filling the bars of a bar chart.

The basic idea is that you create a stripe by specifying an angle for a line (either as an int for degrees or as a double for radians), along with the size of the tile in the repeated pattern. The class then constructs the tile that is used in the Paint fill. You can specify the foreground color for the line and the background color for the rest of the tile. You can also specify a Stroke to use for the line to give a dotted stripe effect.

For more complex patterns you can use a Paint as the background of the tile instead of a Color. This means you can use a StripePaint as the background to a StripePaint and build up a layered stripe pattern. By careful use of this feature you can create zig-zag patterns, cross-hatches, crosses, and multi-coloured stripes. Finally, you can also create a polka-dot paint effect by setting the dashes of your BasicStroke to have a length of zero and a round cap. The diameter of the dots is the same as the line width. This too, can be used as part of a layered effect - in the example below the background polka-dot layer has larger dots than the foreground layer, allowing us to create a polka-dot effect with concentric circles.

Here are some sample paint patterns generated using StripePaint:

The number labels on the patterns indicate which of the code fragments from the table (below) can be used to generate it:

Pattern Code to Generate It
1 new StripePaint(0, 10, 2f)
2 StripePaint paint = new StripePaint(-45, 20, 2f);
paint.setForeground(Color.green.darker());
3 StripePaint paint = new StripePaint(20, 20, 1f);
paint.setForeground(Color.blue);
4 StripePaint paint = new StripePaint(90, 10, 2f);
paint.setBackground(Color.yellow);
paint.setForeground(Color.red);
5 StripePaint background = new StripePaint(0, 10, 2f);
StripePaint paint = new StripePaint(90, 10, 2f);
paint.setBackground(background);
6 StripePaint background = new StripePaint(-45, 20, 2f);
background.setForeground(Color.green.darker());
StripePaint paint = new StripePaint(45, 20, 2f);
paint.setBackground(background);
paint.setForeground(Color.green.darker());
7 new StripePaint(45, 20, new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10f, new float[] {10f, 10f}, 0f));
8 StripePaint background = new StripePaint(45, 20, new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10f, new float[] {10f, 10f}, 0f));
StripePaint paint = new StripePaint(-45, 20, new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10f, new float[] {10f, 10f}, 10f));
paint.setBackground(background);
9 StripePaint background = new StripePaint(45, 20, new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10f, new float[] {10f, 10f}, 0f));
StripePaint paint = new StripePaint(-45, 20, new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10f, new float[] {10f, 10f}, 0f));
paint.setBackground(background);
10 StripePaint background = new StripePaint(45, 20, new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10f, new float[] {10f, 10f}, 5f));
StripePaint paint = new StripePaint(-45, 20, new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10f, new float[] {10f, 10f}, 5f));
paint.setBackground(background);
11 StripePaint background = new StripePaint(30, 20, 6f);
background.setForeground(Color.blue);
StripePaint paint = new StripePaint(30, 20, 3f);
paint.setBackground(background);
paint.setForeground(Color.red);
12 StripePaint background = new StripePaint(45, 30, new BasicStroke(6f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 5f, new float[] {0f, 30f}, 15f));
background.setForeground(Color.blue);
StripePaint paint = new StripePaint(45, 30, new BasicStroke(3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 5f, new float[] {0f, 30f}, 15f));
paint.setForeground(Color.red);
paint.setBackground(background);

Author:
Simon White

Field Summary
 
Fields inherited from interface java.awt.Transparency
BITMASK, OPAQUE, TRANSLUCENT
 
Constructor Summary
StripePaint(double angleRadians, int segmentLength)
          Creates a stripe paint that can be used to fill shapes
StripePaint(double angleRadians, int segmentLength, BasicStroke stroke)
          Creates a Stripe paint that can be used to fill shapes
StripePaint(double angleRadians, int segmentLength, float lineWidth)
          Creates a stripe paint that can be used to fill shapes
StripePaint(int angleDegrees, int segmentLength)
          Creates a stripe paint that can be used to fill shapes
StripePaint(int angleDegrees, int segmentLength, BasicStroke stroke)
          Creates a stripe paint that can be used to fill shapes
StripePaint(int angleDegrees, int segmentLength, float lineWidth)
          Creates a stripe paint that can be used to fill shapes
 
Method Summary
 PaintContext createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform transform, RenderingHints hints)
          
 Paint getBackground()
          Returns the background colour of the paint
 Color getForeground()
          Returns the foreground colour of the paint
 int getTransparency()
          
 void setBackground(Paint background)
          Specify the background colour of the paint
 void setForeground(Color foreground)
          Specify the foreground colour to use in the paint
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StripePaint

public StripePaint(double angleRadians,
                   int segmentLength)
Creates a stripe paint that can be used to fill shapes

Parameters:
angleRadians - the angle in radians of the line of the stripe
segmentLength - the length of the line segment, used to calculate the size of the paint tile and therefore also the separation between the stripes

StripePaint

public StripePaint(int angleDegrees,
                   int segmentLength)
Creates a stripe paint that can be used to fill shapes

Parameters:
angleDegrees - the angle in degrees of the line of the stripe
segmentLength - the length of the line segment, used to calculate the size of the paint tile

StripePaint

public StripePaint(int angleDegrees,
                   int segmentLength,
                   float lineWidth)
Creates a stripe paint that can be used to fill shapes

Parameters:
angleDegrees - the angle in degrees of the line of the stripe
segmentLength - the length of the line segment, used to calculate the size of the paint tile
lineWidth - the width of the line

StripePaint

public StripePaint(double angleRadians,
                   int segmentLength,
                   float lineWidth)
Creates a stripe paint that can be used to fill shapes

Parameters:
angleRadians - the angle in radians of the line of the stripe
segmentLength - the length of the line segment, used to calculate the size of the paint tile
lineWidth - the width of the line

StripePaint

public StripePaint(int angleDegrees,
                   int segmentLength,
                   BasicStroke stroke)
Creates a stripe paint that can be used to fill shapes

Parameters:
angleDegrees - the angle in degrees of the line of the stripe
segmentLength - the length of the line segment, used to calculate the size of the paint tile
stroke - the stroke of the line

StripePaint

public StripePaint(double angleRadians,
                   int segmentLength,
                   BasicStroke stroke)
Creates a Stripe paint that can be used to fill shapes

Parameters:
angleRadians - the angle in radians
segmentLength - the length of the line segment, used to calculate the size of the paint tile and therefore also the separation between the stripes
stroke - the stroke to use when painting the line
Method Detail

getBackground

public Paint getBackground()
Returns the background colour of the paint

Returns:
the background colour of the paint

setBackground

public void setBackground(Paint background)
Specify the background colour of the paint

Parameters:
background - the background colour of the paint

getForeground

public Color getForeground()
Returns the foreground colour of the paint

Returns:
the foreground colour of the paint

setForeground

public void setForeground(Color foreground)
Specify the foreground colour to use in the paint

Parameters:
foreground - the foreground colour of the paint

getTransparency

public int getTransparency()

Specified by:
getTransparency in interface Transparency

createContext

public PaintContext createContext(ColorModel cm,
                                  Rectangle deviceBounds,
                                  Rectangle2D userBounds,
                                  AffineTransform transform,
                                  RenderingHints hints)

Specified by:
createContext in interface Paint

JIDE 3.5.15