Class LineStyle
- java.lang.Object
-
- com.day.image.LineStyle
-
- All Implemented Interfaces:
java.awt.Paint
,java.awt.Stroke
,java.awt.Transparency
public final class LineStyle extends java.lang.Object implements java.awt.Paint, java.awt.Stroke
TheLineStyle
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 thePaint
of the Java2DGraphics2D
and you would get the stroke to set theStroke
.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
Fields Modifier and Type Field Description static LineStyle
DEFAULT
The default line style is a solid black line, 1px widestatic int
STYLE_DASHED
Style code for a dashed line, where the mark length is 3 points and the blank length is 2 points.static int
STYLE_DOTTED
Style code for a dotted line, where both the mark and the blank length are one point.static int
STYLE_FANCY
Style code for a fancy dashed line, where both the mark and the blank lentghs are specified with the constructor.static int
STYLE_SOLID
Style code for a solid line.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.awt.PaintContext
createContext(java.awt.image.ColorModel cm, java.awt.Rectangle deviceBounds, java.awt.geom.Rectangle2D userBounds, java.awt.geom.AffineTransform xform, java.awt.RenderingHints hints)
Creates and returns aPaintContext
used to generate the color pattern.java.awt.Shape
createStrokedShape(java.awt.Shape p)
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
getTransparency()
Returns the type of thisTransparency
.float
getWidth()
Returns the width of the line according to the line style.java.lang.String
toString()
Returns a String representation of the LineStyle
-
-
-
Field Detail
-
STYLE_SOLID
public static final int STYLE_SOLID
Style code for a solid line.- See Also:
- Constant Field Values
-
STYLE_DOTTED
public static final int STYLE_DOTTED
Style code for a dotted line, where both the mark and the blank length are one point.- See Also:
- Constant Field Values
-
STYLE_DASHED
public static final int STYLE_DASHED
Style code for a dashed line, where the mark length is 3 points and the blank length is 2 points.- See Also:
- Constant Field Values
-
STYLE_FANCY
public static final int STYLE_FANCY
Style 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:
- Constant Field Values
-
DEFAULT
public static final LineStyle DEFAULT
The default line style is a solid black line, 1px wide
-
-
Constructor Detail
-
LineStyle
public LineStyle(java.awt.Paint paint)
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
public LineStyle(java.awt.Paint paint, float mark, float blank, float width)
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 Detail
-
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 java.awt.PaintContext createContext(java.awt.image.ColorModel cm, java.awt.Rectangle deviceBounds, java.awt.geom.Rectangle2D userBounds, java.awt.geom.AffineTransform xform, java.awt.RenderingHints hints)
Creates and returns aPaintContext
used to generate the color pattern.- Specified by:
createContext
in interfacejava.awt.Paint
- Parameters:
cm
- theColorModel
that receives thePaint
data. This is used only as a hint.deviceBounds
- the device space bounding box of the graphics primitiveuserBounds
- 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:
PaintContext
-
getTransparency
public int getTransparency()
Returns the type of thisTransparency
.- Specified by:
getTransparency
in interfacejava.awt.Transparency
- Returns:
- the field type of this
Transparency
, which is either OPAQUE, BITMASK or TRANSLUCENT.
-
createStrokedShape
public java.awt.Shape createStrokedShape(java.awt.Shape p)
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 interfacejava.awt.Stroke
- Parameters:
p
- aShape
to be stroked- Returns:
- the stroked outline
Shape
.
-
toString
public java.lang.String toString()
Returns a String representation of the LineStyle- Overrides:
toString
in classjava.lang.Object
- Returns:
- a String representation of the LineStyle
-
-