Package com.day.image

Class LineStyle

java.lang.Object
com.day.image.LineStyle
All Implemented Interfaces:
Paint, Stroke, Transparency

public final class LineStyle extends Object implements Paint, Stroke
The 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

    Fields
    Modifier and Type
    Field
    Description
    static final LineStyle
    The default line style is a solid black line, 1px wide
    static 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
    Constructor
    Description
    Creates a line style for a line with the given color.
    LineStyle(Paint paint, float mark, float blank, float width)
    Creates a new line style with the given paint and stroking attributes.
  • Method Summary

    Modifier and Type
    Method
    Description
    createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform xform, RenderingHints hints)
    Creates and returns a PaintContext used to generate the color pattern.
    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
    Returns the blank length of this line style.
    float
    Returns the mark length of this line style.
    int
    Returns the style of this line style which is one of the predefined style constants.
    int
    Returns the type of this Transparency.
    float
    Returns the width of the line according to the line style.
    Returns a String representation of the LineStyle

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • STYLE_SOLID

      public static final int STYLE_SOLID
      Style code for a solid line.
      See Also:
    • 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:
    • 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:
    • 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:
    • DEFAULT

      public static final LineStyle DEFAULT
      The default line style is a solid black line, 1px wide
  • Constructor Details

    • LineStyle

      public LineStyle(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 - The Paint value to set. If this is null, the line color is defined to be black.
    • LineStyle

      public LineStyle(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_DOTTEDDotted stroke with mark=1, blank=1
      STYLE_DASHEDDashed stroke with mark=3, blank=2
      elseSolid 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 == nullblack 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 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.
  • 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 a PaintContext used to generate the color pattern.
      Specified by:
      createContext in interface Paint
      Parameters:
      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 invalid input: '<'being rendered
      userBounds - the user space bounding box of the graphics primitive being rendered
      xform - the AffineTransform from user space into device space
      hints - 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 this Transparency.
      Specified by:
      getTransparency in interface Transparency
      Returns:
      the field type of this Transparency, which is either OPAQUE, BITMASK or TRANSLUCENT.
    • createStrokedShape

      public Shape createStrokedShape(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.
      Specified by:
      createStrokedShape in interface Stroke
      Parameters:
      p - a Shape to be stroked
      Returns:
      the stroked outline Shape.
    • toString

      public String toString()
      Returns a String representation of the LineStyle
      Overrides:
      toString in class Object
      Returns:
      a String representation of the LineStyle