Class HatchedIconBuilder

java.lang.Object
com.luciad.drawing.HatchedIconBuilder
All Implemented Interfaces:
AutoCloseable

public final class HatchedIconBuilder extends Object implements AutoCloseable
Builder for creating a hatched icon with a given line width and color.

A typical use case of such a hatched icon is as a fill pattern in a FillStyle.

By default, the generated icon will only contain one line in every configured direction (horizontal, vertical, forward- and/or backslash) on top of the background color. When used in a FillStyle, this icon will be tiled to the required area, resulting in a hatched fill.

If you want to use this icon to generate an Image for other purposes where the pattern is not automatically tiled, you can use the tileCount method to force the pattern to repeat a number of times.

Since:
2026.0
  • Constructor Details

    • HatchedIconBuilder

      public HatchedIconBuilder(@NotNull HatchedIconBuilder other)
      Copy constructor.
      Parameters:
      other - the builder to copy.
  • Method Details

    • finalize

      protected void finalize()
      Overrides:
      finalize in class Object
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • newBuilder

      @NotNull public static HatchedIconBuilder newBuilder()
      Creates a new builder to construct a hatched icon.
      Returns:
      a new builder to construct a hatched icon.
    • backgroundColor

      @NotNull public HatchedIconBuilder backgroundColor(@NotNull android.graphics.Color backgroundColor)
      Sets the background color.

      By default, the background color is transparent.

      Parameters:
      backgroundColor - the background color.
      Returns:
      this builder.
    • lineColor

      @NotNull public HatchedIconBuilder lineColor(@NotNull android.graphics.Color lineColor)
      Sets the line color.

      By default, the line color is opaque red.

      Parameters:
      lineColor - the line color.
      Returns:
      this builder.
    • lineWidth

      @NotNull public HatchedIconBuilder lineWidth(double lineWidth) throws IllegalArgumentException
      Sets the line width.

      By default, the line width is 2.0.

      The line width is interpreted as device independent pixels.

      Note that increasing the line width might require to increase the patternSize as well to obtain the desired result.

      Parameters:
      lineWidth - the line width.
      Returns:
      this builder.
      Throws:
      IllegalArgumentException - if the line width is not strictly positive.
    • patterns

      @NotNull public HatchedIconBuilder patterns(@NotNull List<@NotNull HatchedIconBuilder.Pattern> patterns) throws IllegalArgumentException
      Sets the patterns.

      By default, the forward slash pattern is used.

      Parameters:
      patterns - the patterns.
      Returns:
      this builder.
      Throws:
      IllegalArgumentException - if no patterns were given.
    • patternSize

      @NotNull public HatchedIconBuilder patternSize(double width, double height) throws IllegalArgumentException
      Sets the pixel size of the filling pattern.

      By default, this is 16x16.

      The size is interpreted as device independent pixels.

      The pattern is created by drawing one line in every configured direction (horizontal, vertical, forward- and/or backslash). This pattern is then tiled to fill the required area. Changing the size of this pattern allows to define the spacing between adjacent lines. Defining a non-square pattern size for slanted patterns (forward- and backslash) allows to change the angle of the slanted lines. For example, a slash pattern with a pattern size of 20x10 results in 26.6 degree lines (Math.atan(10/20)).

      The values should be small for performance reasons, for example 10x10 or 20x10 pixels.

      Note that decreasing the pattern size might require to decrease lineWidth as well to obtain the desired result.

      Parameters:
      width - the pattern width.
      height - the pattern height.
      Returns:
      this builder.
      Throws:
      IllegalArgumentException - if the width or height are not strictly positive.
    • tileCount

      @NotNull public HatchedIconBuilder tileCount(long columns, long rows) throws IllegalArgumentException
      Sets the number of times to repeat the pattern.

      By default, this is 1x1.

      When using this hatched icon in combination with a FillStyle, it is not needed to increase the tile count, as the icon will be tiled to cover the area automatically either way.

      If you want to use this icon to generate an Image for other purposes where the pattern is not automatically tiled, you can use this option to force the pattern to repeat a number of times.

      Parameters:
      columns - the number of columns.
      rows - the number of rows.
      Returns:
      this builder.
      Throws:
      IllegalArgumentException - if the column or row count are zero.
    • build

      @NotNull public IIcon build()
      Returns a newly created hatched IIcon, based on the properties set on this builder.
      Returns:
      a newly created hatched IIcon.