public final class LineStyle
extends java.lang.Object
implements java.awt.Paint, java.awt.Stroke
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.
Modifier and Type | Field and Description |
---|---|
static LineStyle |
DEFAULT
The default line style is a solid black line, 1px wide
|
static 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.
|
Constructor and Description |
---|
LineStyle(java.awt.Paint paint)
Creates a line style for a line with the given color.
|
LineStyle(java.awt.Paint paint,
float mark,
float blank,
float width)
Creates a new line style with the given paint and stroking attributes.
|
Modifier and Type | Method and 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 a
PaintContext used to
generate the color pattern. |
java.awt.Shape |
createStrokedShape(java.awt.Shape p)
Returns an outline
Shape which encloses the area that
should be painted when the Shape is stroked according
to the rules defined by the
object implementing the Stroke 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 this
Transparency . |
float |
getWidth()
Returns the width of the line according to the line style.
|
java.lang.String |
toString()
Returns a String representation of the LineStyle
|
public static final int STYLE_SOLID
public static final int STYLE_DOTTED
public static final int STYLE_DASHED
public static final int STYLE_FANCY
public static final LineStyle DEFAULT
public LineStyle(java.awt.Paint paint)
paint
- The Paint
value to set. If this is
null
, the line color is defined to be black.public LineStyle(java.awt.Paint paint, float mark, float blank, float width)
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.
paint
- The paint value to set. If this is null
, 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.public int getStyle()
public float getMark()
public float getBlank()
public float getWidth()
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)
PaintContext
used to
generate the color pattern.createContext
in interface java.awt.Paint
cm
- the ColorModel
that receives the
Paint
data. This is used only as a hint.deviceBounds
- the device space bounding box
of the graphics primitive userBounds
- the user space bounding box
of the graphics primitive being renderedxform
- the AffineTransform
from user
space into device spacehints
- the hint that the context object uses to
choose between rendering alternativesPaintContext
for
generating color patternsPaintContext
public int getTransparency()
Transparency
.getTransparency
in interface java.awt.Transparency
Transparency
, which is
either OPAQUE, BITMASK or TRANSLUCENT.public java.awt.Shape createStrokedShape(java.awt.Shape p)
Shape
which encloses the area that
should be painted when the Shape
is stroked according
to the rules defined by the
object implementing the Stroke
interface.createStrokedShape
in interface java.awt.Stroke
p
- a Shape
to be strokedShape
.public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2010 - 2020 Adobe. All Rights Reserved