Class BasicStrokeParm

java.lang.Object
org.bzdev.obnaming.misc.BasicStrokeParm
Direct Known Subclasses:
BasicStrokeParm.FOUR, BasicStrokeParm.NULL_WHEN_ZERO, BasicStrokeParm.ONE, BasicStrokeParm.THREE, BasicStrokeParm.TWO, BasicStrokeParm.ZERO

public class BasicStrokeParm extends Object
Obnaming factory support class for java.awt.BasicStroke.

Parameter names will be compound names, typically using a period as a separator. When this class is used, multiple parameter-name components will be defined, and the last component of the parameter name will be the following:

  • "cap" - an enumeration constant specified by the enumeration BasicStrokeParm.Cap whose values are BUTT, ROUND, and SQUARE
  • "join" - an enumeration constant specified by the enumeration BasicStrokeParm.Join whose values are BEVEL, MITER, and ROUND.
  • "width" - the line width.
  • "miterLimit" - the limit such that a line join is trimmed when the ratio of miter length to stroke width is greater than this value. The miter length is the diagonal length of the miter, which is the distance between the inside corner and the outside corner of the intersection. The smaller the angle formed by two line segments, the longer the miter length and the sharper the angle of intersection. The default miterlimit value of 10.0 causes all angles less than 11 degrees to be trimmed. Trimming miters converts the decoration of the line join to a bevel. This value applies only to a line join that has a MITER join decoration and must be larger than or equal to 1.0
  • "dashPhase" - the offset to start the dashing pattern.
  • "dashIncrement" - the length corresponding to a space ' ' or minus sign '-' in a dash pattern.
  • "dashPattern" - the dash pattern, represented by a string. If the string has a length of zero, the line is solid. Otherwise the pattern should be represented by a sequence of "-" or " " giving the length of dashes or empty space respectively as multiples of the value of dashIncrement. Each "-" and each " " represents a component of a segment whose length is dashIncrement. Thus, if dashIncrement is 10.0, then the pattern "-- - " will consist of a dash of length 20.0, a space of length 10.0, a dash of length 10.0, and a space of length 10.0, with the pattern repeating as needed. Unless the string is empty, it must start with a "-". Note that a dash phase can be used to make it look like the pattern started with a blank: spaces may appear at the end of the string.
  • "gcsMode" - a boolean that, when true, indicates that the width, dashPhase, and dashIncrement are provided in graph coordinate space, not user space. The default is 'false'.
  • Field Details

    • cap

      public BasicStrokeParm.Cap cap
      Specification for how lines or line segments are capped.
      See Also:
    • width

      public double width
      The line width.
    • join

      public BasicStrokeParm.Join join
      Specification for how lines or line segments are joined.
      See Also:
    • miterLimit

      public double miterLimit
      The limit so that line joins are trimmed when the ratio of miter length to stroke width is greater than this value. The miter length is the diagonal length of the miter, which is the distance between the inside corner and the outside corner of the intersection. The smaller the angle formed by two line segments, the longer the miter length and the sharper the angle of intersection. The default miterlimit value of 10.0 causes all angles less than 11 degrees to be trimmed. Trimming miters converts the decoration of the line join to a bevel. This values applies only to a line join that has a MITER join decoration. The miter limit, if provided, must have a value no smaller than or equal to 1.0.
      See Also:
    • dashPhase

      public double dashPhase
      The offset to start the dashing pattern.
    • dashIncrement

      public double dashIncrement
      The length corresponding to a "-" or " " in a dashPattern.
    • dashPattern

      public String dashPattern
      The dash pattern. If null or of zero length, the line is solid. Otherwise the pattern should be represented by a sequence of "-" or " " giving the length of dashes or empty space respectively as multiples of the value of dashIncrement. Each "-" and each " " represents a component of a segment whose length is dashIncrement. Unless the pattern is empty or all dashes, the pattern must start with a dash and end with a space. Thus, if dashIncrement is 10.0, then the pattern "--  - " will consist of a dash of length 20.0, a space of length 20.0, a dash of length 10.0, and a space of length 10.0, with the pattern repeating as needed.
    • gcsMode

      public boolean gcsMode
      Flag to indicate if widths or lengths are provided in graph-coordinate-space units. If true, the stroke created should be used for a graphic context that includes a transform from graph coordinate space to user space.
  • Constructor Details

    • BasicStrokeParm

      public BasicStrokeParm()
      Constructor. The default stroke width is 1.0.
    • BasicStrokeParm

      public BasicStrokeParm(boolean zeroWidth)
      Construct specifying handling of zero width strokes.
      Parameters:
      zeroWidth - true if the width should be zero and if createBasicStroke() should return null for zero-width strokes; false otherwise, in which case the width will have an initial value of 1.0
    • BasicStrokeParm

      public BasicStrokeParm(double width)
      Constructor given a line width.
      Parameters:
      width - the line width
  • Method Details

    • getGcsMode

      public boolean getGcsMode()
      Indicate if widths or lengths are provided in graph-coordinate-space units. If true, the stroke created should be used for a graphic context that includes a transform from graph coordinate space to user space.
      Returns:
      true if the basic stroke created is intended for graph coordinate space; false if it is intended for user space
    • getDashArray

      public static float[] getDashArray(String dashPattern, double dashIncrement) throws IllegalArgumentException
      Get an array that represents a dash pattern. A dash pattern consists of a string whose characters are either a minus sign ("-") or a space (" "), starting with a "-". An empty string, a string of zero length, or a string containing only "-" characters is ignored and a null value will be returned. Otherwise a dash pattern must start with a '-' and end with a space. A pattern ending with a '-' is not necessary as the dashPhase parameter can be used to create the same effect. A sequence of "-" characters represents a dash whose length is the number of characters in that sequence multiplied by the dash increment. Similarly, a sequence of " " characters represents a gap whose length is the number of characters in that sequence multiplied by the dash increment. The array returned provides the pattern of alternating opaque and transparent segments used by classes such as BasicStroke.
      Parameters:
      dashPattern - the dash pattern
      dashIncrement - the length corresponding to a character in a dash pattern
      Returns:
      an array representing a dash pattern
      Throws:
      IllegalArgumentException - the dashInrement argument was not positive or the dashPattern argument was illegal
    • createBasicStroke

      public BasicStroke createBasicStroke()
      Create a basic stroke. The basic stroke will use the parameters defined by the fields width, cap, join, miterLimit, dashPhase, dashIncrement, and dashPattern.
      Returns:
      the stroke; null if the width is 0.0 and this class is configured to return null in that case