Class HatchedIconBuilder
- All Implemented Interfaces:
AutoCloseable
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration for the different pattern types. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbackgroundColor(android.graphics.Color backgroundColor) Sets the background color.build()Returns a newly created hatchedIIcon, based on the properties set on this builder.voidclose()protected voidfinalize()lineColor(android.graphics.Color lineColor) Sets the line color.lineWidth(double lineWidth) Sets the line width.static HatchedIconBuilderCreates a new builder to construct a hatched icon.patterns(List<@NotNull HatchedIconBuilder.Pattern> patterns) Sets the patterns.patternSize(double width, double height) Sets the pixel size of the filling pattern.tileCount(long columns, long rows) Sets the number of times to repeat the pattern.
-
Constructor Details
-
HatchedIconBuilder
Copy constructor.- Parameters:
other- the builder to copy.
-
-
Method Details
-
finalize
protected void finalize() -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
newBuilder
Creates a new builder to construct a hatched icon.- Returns:
- a new builder to construct a hatched icon.
-
backgroundColor
Sets the background color.By default, the background color is transparent.
- Parameters:
backgroundColor- the background color.- Returns:
- this builder.
-
lineColor
Sets the line color.By default, the line color is opaque red.
- Parameters:
lineColor- the line color.- Returns:
- this builder.
-
lineWidth
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
patternSizeas 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 slashpattern 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
lineWidthas 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
Imagefor 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
Returns a newly created hatchedIIcon, based on the properties set on this builder.- Returns:
- a newly created hatched
IIcon.
-