Class LineStyle
- All Implemented Interfaces:
Paint
,Stroke
,Transparency
LineStyle
class implements the Communiqu� 2 line style.
This line style embraces both the stroke style (dashing, line width) and
the line color. To use this line style for line drawing, you would get the
color to set the Paint
of the Java2D Graphics2D
and you would get the stroke to set the Stroke
.
The line style is initialized using the paint only, in which case it defaults
to define a style with the given paint which is solid and has the width of
one point. The line style can also be initialized giving the paint, the line
width and the length of the dash and blank parts of a dashed line. See the
comments on the LineStyle(Paint, float, float, float)
constructor
for information on the possibilities.
The line style is immutable and final.
- Since:
- coati
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final LineStyle
The default line style is a solid black line, 1px widestatic final int
Style code for a dashed line, where the mark length is 3 points and the blank length is 2 points.static final int
Style code for a dotted line, where both the mark and the blank length are one point.static final int
Style code for a fancy dashed line, where both the mark and the blank lentghs are specified with the constructor.static final int
Style code for a solid line.Fields inherited from interface java.awt.Transparency
BITMASK, OPAQUE, TRANSLUCENT
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateContext
(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform xform, RenderingHints hints) Creates and returns aPaintContext
used to generate the color pattern.Returns an outlineShape
which encloses the area that should be painted when theShape
is stroked according to the rules defined by the object implementing theStroke
interface.float
getBlank()
Returns the blank length of this line style.float
getMark()
Returns the mark length of this line style.int
getStyle()
Returns the style of this line style which is one of the predefined style constants.int
Returns the type of thisTransparency
.float
getWidth()
Returns the width of the line according to the line style.toString()
Returns a String representation of the LineStyle
-
Field Details
-
STYLE_SOLID
public static final int STYLE_SOLIDStyle code for a solid line.- See Also:
-
STYLE_DOTTED
public static final int STYLE_DOTTEDStyle code for a dotted line, where both the mark and the blank length are one point.- See Also:
-
STYLE_DASHED
public static final int STYLE_DASHEDStyle code for a dashed line, where the mark length is 3 points and the blank length is 2 points.- See Also:
-
STYLE_FANCY
public static final int STYLE_FANCYStyle code for a fancy dashed line, where both the mark and the blank lentghs are specified with the constructor. This style code is set by the constructor in this case. If this style code is set in the constructor, when the mark length is set to zero, it has no effect and the line is styled to be solid.- See Also:
-
DEFAULT
The default line style is a solid black line, 1px wide
-
-
Constructor Details
-
LineStyle
Creates a line style for a line with the given color. The line is solid and has a width of one point.- Parameters:
paint
- ThePaint
value to set. If this isnull
, the line color is defined to be black.
-
LineStyle
Creates a new line style with the given paint and stroking attributes. The mark and blank parameters are special : If mark is zero, the blank parameters is interpreted as a generic style and the mark and blank values are reset accordingly :STYLE_DOTTED Dotted stroke with mark=1, blank=1 STYLE_DASHED Dashed stroke with mark=3, blank=2 else Solid stroke with no breaks, that is mark=1, blank=0 If the mark parameters is given as a non-zero value, the style is set to STYLE_FANCY. If any of the parameters has a value as listed in the following table, a default value is assumed :
paint == null
black color isNaN(mark)
mark=0, prompting the above algorithm isNaN(blank)
blank=STYLE_SOLID, which applies if mark is zero isNan(width)
width = 1 If mark is non-zero (or after the above listed treatment) a dashed stroke is defined, where mark defines the point length of set points and blank defines the point length of unset points, applied alternatively for the length of the line to be drawn. If on the other hand mark is non-zero but the blank length is zero, this defines a solid line.
- Parameters:
paint
- The paint value to set. If this isnull
, the line color is defined to be black.mark
- The length of the mark in points. If zero, negative or NaN the blank parameter contains a style constant.blank
- The length of the blank in points or a style constant if the length is zero, negative or NaN. If blank is negative, zero or NaN the line style is defined to be solid. The line style is also defined to be solid, if the blank parameter is not a valid style constant if mark is zero.width
- The line width. If this is zero, negative or NaN, the width defaults to 1 point.
-
-
Method Details
-
getStyle
public int getStyle()Returns the style of this line style which is one of the predefined style constants.- Returns:
- the style of this line style.
-
getMark
public float getMark()Returns the mark length of this line style. This is either the mark length used to construct the line style or the length of the mark according to the style used to create the line style.- Returns:
- the mark length of this line style.
-
getBlank
public float getBlank()Returns the blank length of this line style. This is either the blank length used to construct the line style or the length of the blank according to the style used to create the line style.- Returns:
- the blank length of this line style.
-
getWidth
public float getWidth()Returns the width of the line according to the line style.- Returns:
- the width of the line according to the line style.
-
createContext
public PaintContext createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform xform, RenderingHints hints) Creates and returns aPaintContext
used to generate the color pattern.- Specified by:
createContext
in interfacePaint
- Parameters:
cm
- theColorModel
that receives thePaint
data. This is used only as a hint.deviceBounds
- the device space bounding box of the graphics primitive invalid input: '<'being rendereduserBounds
- the user space bounding box of the graphics primitive being renderedxform
- theAffineTransform
from user space into device spacehints
- the hint that the context object uses to choose between rendering alternatives- Returns:
- the
PaintContext
for generating color patterns - See Also:
-
getTransparency
public int getTransparency()Returns the type of thisTransparency
.- Specified by:
getTransparency
in interfaceTransparency
- Returns:
- the field type of this
Transparency
, which is either OPAQUE, BITMASK or TRANSLUCENT.
-
createStrokedShape
Returns an outlineShape
which encloses the area that should be painted when theShape
is stroked according to the rules defined by the object implementing theStroke
interface.- Specified by:
createStrokedShape
in interfaceStroke
- Parameters:
p
- aShape
to be stroked- Returns:
- the stroked outline
Shape
.
-
toString
Returns a String representation of the LineStyle
-