public final class ComplexStrokePatternFactory extends Object
patterns
that are used to create complex strokes
.Modifier and Type | Method and Description |
---|---|
static ComplexStrokePattern |
allowOverlap(ComplexStrokePattern pattern,
double overlapLeft,
double overlapRight)
Creates a pattern that allows for overlap of patterns on the left and right side of the given pattern.
|
static ComplexStrokePattern |
appendPatterns(List<ComplexStrokePattern> patterns)
Creates a pattern consisting of multiple sub-patterns appended together, painting them next to each other.
|
static ArcPatternBuilder |
arcBuilder()
Creates a builder used to make patterns with an arc, ellipse or circle shape.
|
static ArrowPatternBuilder |
arrowBuilder()
Creates a builder used to make patterns with an arrow shape.
|
static ComplexStrokePattern |
atomic(ComplexStrokePattern pattern)
Creates a pattern that ensures that sub-patterns are always painted together.
|
static ComplexStrokePattern |
combineWithFallback(ComplexStrokePattern pattern)
Creates a pattern that allows the
fallback pattern to be painted on top of the given pattern. |
static ComplexStrokePattern |
combineWithRegular(ComplexStrokePattern pattern)
Creates a pattern that allows the
regular pattern to be painted on top of the given pattern. |
static ComplexStrokePattern |
composePatterns(List<ComplexStrokePattern> patterns)
Creates a pattern consisting of multiple sub-patterns that are painted on top of each other.
|
static ComplexStrokePattern |
gapFixed(double fixedLength)
Creates a gap pattern, which does not paint anything.
|
static ComplexStrokePattern |
gapRelative(double relativeLength)
Creates a gap pattern, which does not paint anything.
|
static IconPatternBuilder |
iconBuilder()
Creates a builder used to make patterns containing an icon.
|
static LinePatternBuilder |
lineBuilder()
Creates a builder used to make patterns with a line segment shape.
|
static ParallelLinePatternBuilder |
parallelLineBuilder()
Creates a builder used to make patterns with a line segment shape that is parallel to the base line.
|
static PolylinePatternBuilder |
polylineBuilder()
Creates a builder used to make patterns with a polyline shape.
|
static RectanglePatternBuilder |
rectangleBuilder()
Creates a builder used to make patterns with a rectangle shape.
|
static ComplexStrokePattern |
repeat(ComplexStrokePattern pattern,
long count)
Creates a pattern that repeats a pattern a fixed number of times.
|
static ComplexStrokePattern |
repeatOverLengthFixed(ComplexStrokePattern pattern,
double fixedLength)
Creates a pattern that repeats a pattern over a given length.
|
static ComplexStrokePattern |
repeatOverLengthRelative(ComplexStrokePattern pattern,
double relativeLength)
Creates a pattern that repeats the given pattern over a given length.
|
static TextPatternBuilder |
textBuilder()
Creates a builder used to make patterns containing text.
|
static TrianglePatternBuilder |
triangleBuilder()
Creates a builder used to make patterns with a triangle shape.
|
static WavePatternBuilder |
waveBuilder()
Creates a builder used to make patterns with a wave shape.
|
@NotNull public static ArcPatternBuilder arcBuilder()
You can define the length and minor radius
to create an ellipse (or a circle by setting the minor radius to be half of the length), and use the angle
and startAngle
to paint only a part of the ellipse.
angle
and startAngle
work counter clockwise and a startAngle of 0 means the arc starts on the baseline on the point the furthest from the start of the baselise. On a horizontal line going from left to right, this would be the right-most point of the arc. A startAngle of 90 in this case means the arc starts above the baseline.
Sample code:
ComplexStrokePattern arc1 = ComplexStrokePatternFactory.arcBuilder().fixedLength(30).minorRadius(15).build();
ComplexStrokePattern
arc2 = ComplexStrokePatternFactory.arcBuilder().fixedLength(30).minorRadius(10).angle(200).fillColor(Color.valueOf(Color.RED)).build();
ComplexStrokePattern arc3 = ComplexStrokePatternFactory.arcBuilder()
.fixedLength(40)
.minorRadius(15)
.startAngle(new Angle(225))
.angle(270)
.lineWidth(3)
.lineColor(Color.valueOf(Color.BLUE))
.fillColor(Color.valueOf(Color.RED))
.build();
ComplexStrokeLineStyle strokeStyle = ComplexStrokeLineStyle.newBuilder()
.fallback(ComplexStrokePatternFactory.parallelLineBuilder().build())
.addDecoration(arc1, 0.2)
.addDecoration(arc2, 0.5)
.addDecoration(arc3, 0.8)
.build();
Results in:
@NotNull public static ArrowPatternBuilder arrowBuilder()
Sample code:
ComplexStrokePattern arrow = ComplexStrokePatternFactory.arrowBuilder().size(10).type(ComplexStrokePatternArrowType.PlainOutlined).build();
ComplexStrokeLineStyle strokeStyle = ComplexStrokeLineStyle.newBuilder()
.fallback(ComplexStrokePatternFactory.parallelLineBuilder().build())
.addDecoration(arrow, 0.5)
.build();
Results in:
@NotNull public static IconPatternBuilder iconBuilder()
The icon must be set by calling the icon method before calling build. All other methods are optional.
Sample code:
IIcon icon = ImageIcon.create("images/closecross.png");
ComplexStrokePattern iconPattern = ComplexStrokePatternFactory.iconBuilder().icon(icon).build();
ComplexStrokeLineStyle strokeStyle = ComplexStrokeLineStyle.newBuilder()
.fallback(ComplexStrokePatternFactory.parallelLineBuilder().build())
.addDecoration(iconPattern, 0.5)
.build();
Results in:
@NotNull public static LinePatternBuilder lineBuilder()
A line segment is defined by:
Note that the difference with a parallel line
is that a line has rounded corners, whereas a parallel line
does not have rounded corners.
Sample code:
ComplexStrokePattern lineLeft = ComplexStrokePatternFactory.lineBuilder().fixedLength(20).lineWidth(3).offset1(20).build();
ComplexStrokePattern lineRight = ComplexStrokePatternFactory.lineBuilder().fixedLength(20).lineWidth(3).offset0(20).build();
ComplexStrokePattern pattern = ComplexStrokePatternFactory.appendPatterns(List.of(lineLeft, lineRight));
ComplexStrokePattern lineLeftFilled = ComplexStrokePatternFactory.lineBuilder().fixedLength(30).fillColor(Color.valueOf(Color.RED)).offset0(20).offset1(40).build();
ComplexStrokePattern lineRightFilled = ComplexStrokePatternFactory.lineBuilder().fixedLength(30).fillColor(Color.valueOf(Color.BLUE)).offset0(40).offset1(20).build();
ComplexStrokePattern patternFilled = ComplexStrokePatternFactory.appendPatterns(List.of(lineLeftFilled, lineRightFilled));
ComplexStrokeLineStyle strokeStyle = ComplexStrokeLineStyle.newBuilder()
.fallback(ComplexStrokePatternFactory.parallelLineBuilder().build())
.addDecoration(pattern, 0.33)
.addDecoration(patternFilled, 0.66)
.build();
Results in:
@NotNull public static ParallelLinePatternBuilder parallelLineBuilder()
Note that the difference with a line
is that a line
has rounded corners, whereas a parallel line does not have rounded corners.
Sample code:
ComplexStrokePattern parallelLineLeft = ComplexStrokePatternFactory.parallelLineBuilder().fixedLength(30).lineWidth(3).offset(10).build();
ComplexStrokePattern parallelLineRight = ComplexStrokePatternFactory.parallelLineBuilder().fixedLength(30).lineWidth(3).offset(-10).build();
ComplexStrokePattern pattern = ComplexStrokePatternFactory.appendPatterns(List.of(parallelLineLeft, parallelLineRight));
ComplexStrokeLineStyle strokeStyle = ComplexStrokeLineStyle.newBuilder()
.fallback(ComplexStrokePatternFactory.parallelLineBuilder().build())
.addDecoration(pattern, 0.5)
.build();
Results in:
@NotNull public static PolylinePatternBuilder polylineBuilder()
The polyline's points must be set by calling the points method before calling build. All other methods are optional.
Sample code:
List<Coordinate> coordinates = List.of(new Coordinate(0, 10),
new Coordinate(0, -10),
new Coordinate(20, -10),
new Coordinate(30, 0),
new Coordinate(20, 10),
new Coordinate(0, 10));
ComplexStrokePattern polylinePattern = ComplexStrokePatternFactory.polylineBuilder()
.points(coordinates)
.build();
ComplexStrokeLineStyle stroke = ComplexStrokeLineStyle.newBuilder()
.fallback(ComplexStrokePatternFactory.parallelLineBuilder().build())
.addDecoration(polylinePattern, 0.5)
.build();
Results in:
@NotNull public static RectanglePatternBuilder rectangleBuilder()
Sample code:
ComplexStrokePattern rectangleSide = ComplexStrokePatternFactory.rectangleBuilder()
.lineColor(Color.valueOf(Color.RED))
.minHeight(-10)
.maxHeight(10)
.fixedLength(10)
.build();
ComplexStrokePattern rectangleCenter = ComplexStrokePatternFactory.rectangleBuilder()
.lineColor(Color.valueOf(Color.rgb(255, 163, 0)))
.minHeight(-10)
.maxHeight(0)
.fixedLength(20)
.build();
ComplexStrokePattern gap = ComplexStrokePatternFactory.gapFixed(1);
ComplexStrokePattern pattern = ComplexStrokePatternFactory.appendPatterns(List.of(rectangleSide, gap, rectangleCenter, gap, rectangleSide));
ComplexStrokePattern rectangleSideFilled = ComplexStrokePatternFactory.rectangleBuilder()
.fillColor(Color.valueOf(Color.RED))
.minHeight(-10)
.maxHeight(10)
.fixedLength(10)
.build();
ComplexStrokePattern rectangleCenterFilled = ComplexStrokePatternFactory.rectangleBuilder()
.lineColor(Color.valueOf(Color.RED))
.fillColor(Color.valueOf(Color.rgb(255, 163, 0)))
.minHeight(-9)
.maxHeight(0)
.fixedLength(20)
.build();
ComplexStrokePattern patternFilled = ComplexStrokePatternFactory.appendPatterns(List.of(rectangleSideFilled, rectangleCenterFilled, rectangleSideFilled));
ComplexStrokeLineStyle strokeStyle = ComplexStrokeLineStyle.newBuilder()
.fallback(ComplexStrokePatternFactory.parallelLineBuilder().build())
.addDecoration(pattern, 0.33)
.addDecoration(patternFilled, 0.66)
.build();
Results in:
@NotNull public static TextPatternBuilder textBuilder()
The text must be set by calling a text method
before calling build. All other methods are optional.
Sample code:
TextStyle textStyle = TextStyle.newBuilder().fontName("Arial Black").fontSize(16).haloWidth(0).build();
ComplexStrokePattern textPattern = ComplexStrokePatternFactory.textBuilder().text("Read me").textStyle(textStyle).build();
ComplexStrokeLineStyle strokeStyle = ComplexStrokeLineStyle.newBuilder()
.fallback(ComplexStrokePatternFactory.parallelLineBuilder().build())
.addDecoration(textPattern, 0.5)
.build();
Results in:
@NotNull public static TrianglePatternBuilder triangleBuilder()
Sample code:
ComplexStrokePattern triangle1 = ComplexStrokePatternFactory.triangleBuilder().lineColor(Color.valueOf(Color.BLUE)).lineWidth(2).p0(new Coordinate(0, 10)).p1(new Coordinate(0, -10)).p2(new Coordinate(16, -10)).build();
ComplexStrokePattern triangle2 = ComplexStrokePatternFactory.triangleBuilder().fillColor(Color.valueOf(Color.RED)).p0(new Coordinate(0, 10)).p1(new Coordinate(16, 10)).p2(new Coordinate(16, -10)).build();
ComplexStrokePattern pattern = ComplexStrokePatternFactory.appendPatterns(List.of(triangle1, triangle2));
ComplexStrokeLineStyle strokeStyle = ComplexStrokeLineStyle.newBuilder()
.fallback(ComplexStrokePatternFactory.parallelLineBuilder().build())
.addDecoration(pattern, 0.5)
.build();
Results in:
@NotNull public static WavePatternBuilder waveBuilder()
More specifically, the wave shape follows a sine wave. Which part of the sine wave gets painted is determined by angle
and startAngle
. The amplitude (height) is set with amplitude
. The wave is stretched over the given length.
In the first image below, we have horizontal lines going from left to right. As you see, a regular wave first goes up (or to the left of the baseline, if looking at it from the baseline's start towards the end), then back to the baseline, repeating the same shape below the baseline (i.e. to the right of the baseline when looking from the baseline's start).
The second wave is broken down in four separate colored segments each with an angle
of 90, but with different startAngles
.
Created by the following code:
ComplexStrokePattern wave = ComplexStrokePatternFactory.waveBuilder().angle(360).fixedLength(120).amplitude(20).startAngle(new Angle(0)).lineColor(Color.valueOf(Color.RED)).lineWidth(2).build();
//Blue from 0->90.
ComplexStrokePattern waveSegment1 = ComplexStrokePatternFactory.waveBuilder()
.angle(90)
.fixedLength(30)
.amplitude(20)
.startAngle(new Angle(0))
.lineColor(Color.valueOf(Color.BLUE))
.lineWidth(2)
.build();
//Green from 90->180.
ComplexStrokePattern waveSegment2 = ComplexStrokePatternFactory.waveBuilder()
.angle(90)
.fixedLength(30)
.amplitude(20)
.startAngle(new Angle(90))
.lineColor(Color.valueOf(Color.GREEN))
.lineWidth(2)
.build();
//Magenta from 180->270
ComplexStrokePattern waveSegment3 = ComplexStrokePatternFactory.waveBuilder()
.angle(90)
.fixedLength(30)
.amplitude(20)
.startAngle(new Angle(180))
.lineColor(Color.valueOf(Color.MAGENTA))
.lineWidth(2)
.build();
//Yellow from 270->360
ComplexStrokePattern waveSegment4 = ComplexStrokePatternFactory.waveBuilder()
.angle(90)
.fixedLength(30)
.amplitude(20)
.startAngle(new Angle(270))
.lineColor(Color.valueOf(Color.YELLOW))
.lineWidth(2)
.build();
ComplexStrokePattern waves = ComplexStrokePatternFactory.appendPatterns(List.of(waveSegment1, waveSegment2, waveSegment3, waveSegment4));
ComplexStrokeLineStyle strokeStyleTop = ComplexStrokeLineStyle.newBuilder()
.fallback(ComplexStrokePatternFactory.parallelLineBuilder().build())
.addDecoration(wave, 0.5)
.build();
ComplexStrokeLineStyle strokeStyleBottom = ComplexStrokeLineStyle.newBuilder()
.fallback(ComplexStrokePatternFactory.parallelLineBuilder().build())
.addDecoration(waves, 0.5)
.build();
Note that, unlike most patterns, the wave can be partially drawn even as a regular
or decoration
pattern when there is not enough space and other patterns would be omitted in full. By making the wave atomic
only the full wave pattern will be drawn.
Sample code:
ComplexStrokePattern wave1 = ComplexStrokePatternFactory.waveBuilder().relativeLength(0.25).amplitude(20).angle(720).lineWidth(2).build();
ComplexStrokePattern wave2 = ComplexStrokePatternFactory.waveBuilder().relativeLength(0.25).amplitude(20).fillColor(Color.valueOf(Color.GREEN)).lineWidth(2).build();
ComplexStrokePattern wave3 = ComplexStrokePatternFactory.waveBuilder()
.relativeLength(0.25)
.amplitude(30)
.lineColor(Color.valueOf(Color.RED))
.fillColor(Color.valueOf(Color.YELLOW))
.lineWidth(2)
.build();
ComplexStrokePattern waves = ComplexStrokePatternFactory.appendPatterns(List.of(wave1, wave2, wave3));
ComplexStrokeLineStyle strokeStyle = ComplexStrokeLineStyle.newBuilder()
.fallback(ComplexStrokePatternFactory.parallelLineBuilder().build())
.addDecoration(waves, 0.5)
.build();
Results in:
@NotNull public static ComplexStrokePattern appendPatterns(@NotNull List<ComplexStrokePattern> patterns) throws IllegalArgumentException
Sample code:
ComplexStrokePattern pattern1 = ComplexStrokePatternFactory.arcBuilder().fixedLength(40).minorRadius(20).lineWidth(2).build();
ComplexStrokePattern pattern2 = ComplexStrokePatternFactory.arcBuilder().fixedLength(40).minorRadius(20).lineWidth(2).lineColor(Color.valueOf(Color.RED)).build();
ComplexStrokePattern appendPattern = ComplexStrokePatternFactory.appendPatterns(List.of(pattern1, pattern2));
ComplexStrokeLineStyle strokeStyle = ComplexStrokeLineStyle.newBuilder()
.fallback(ComplexStrokePatternFactory.parallelLineBuilder().build())
.addDecoration(appendPattern, 0.5)
.build();
Results in:
patterns
- patterns to append, may not be empty.IllegalArgumentException
- patterns may not be empty.@NotNull public static ComplexStrokePattern composePatterns(@NotNull List<ComplexStrokePattern> patterns) throws IllegalArgumentException
If one of the strokes has a different length than the other strokes, it is aligned to the center of the largest stroke.
In the following example, a horizontal red line and half a red circle are composed.
Sample code:
ComplexStrokePattern pattern1 = ComplexStrokePatternFactory.arcBuilder().fixedLength(40).minorRadius(20).lineWidth(2).angle(180).lineColor(Color.valueOf(Color.RED)).build();
ComplexStrokePattern pattern2 = ComplexStrokePatternFactory.lineBuilder().fixedLength(40).lineWidth(2).lineColor(Color.valueOf(Color.RED)).build();
ComplexStrokePattern composedPattern = ComplexStrokePatternFactory.composePatterns(List.of(pattern1, pattern2));
ComplexStrokeLineStyle strokeStyle = ComplexStrokeLineStyle.newBuilder()
.fallback(ComplexStrokePatternFactory.parallelLineBuilder().build())
.addDecoration(composedPattern, 0.5)
.build();
Results in:
patterns
- patterns to compose, may not be empty.IllegalArgumentException
- patterns may not be empty.@NotNull public static ComplexStrokePattern atomic(@NotNull ComplexStrokePattern pattern)
By making a composed pattern (compose
, append
, repeat
,...) atomic, you ensure that the composed pattern is never broken apart during painting. The sub-patterns will always be painted together, or not at all.
In the example image, the circle patterns are appended. When they are not atomic, the sub-patterns of the appendPattern
can be dropped individually. This is what happens in the first pattern. If there is not enough room for a circle to be placed, it is dropped.
However, in an atomic pattern, all sub-patterns of the appendPattern
are dropped together if one of them does not have enough space. This is useful when you are appending multiple patterns, where it is important that all sub-patterns are always visible at the same time.
Sample code:
ComplexStrokePattern circle1 = ComplexStrokePatternFactory.arcBuilder().fixedLength(16).minorRadius(8).lineColor(Color.valueOf(Color.BLUE)).build();
ComplexStrokePattern circle2 = ComplexStrokePatternFactory.arcBuilder().fixedLength(16).minorRadius(8).lineColor(Color.valueOf(Color.RED)).build();
ComplexStrokePattern line = ComplexStrokePatternFactory.lineBuilder().fixedLength(6).build();
ComplexStrokePattern appendedPattern = ComplexStrokePatternFactory.appendPatterns(List.of(line, circle1, circle2, line));
ComplexStrokeLineStyle strokeStyle = ComplexStrokeLineStyle.newBuilder()
.fallback(ComplexStrokePatternFactory.parallelLineBuilder().build())
.regular(appendedPattern)
.build();
ComplexStrokePattern atomicPattern = ComplexStrokePatternFactory.atomic(appendedPattern);
ComplexStrokeLineStyle atomicStrokeStyle = ComplexStrokeLineStyle.newBuilder()
.fallback(ComplexStrokePatternFactory.parallelLineBuilder().build())
.regular(atomicPattern)
.build();
Results in:
pattern
- The pattern to make atomic.@NotNull public static ComplexStrokePattern combineWithFallback(@NotNull ComplexStrokePattern pattern)
fallback pattern
to be painted on top of the given pattern.
Normally, a fallback pattern
is only painted where no other pattern could be painted. This pattern wrapper adds an exception to this. When a pattern is wrapped with a combineWithFallback, this pattern can be painted in addition to a fallback pattern. This is useful when adding a non-filled arrowhead, as in the image example.
Sample code:
ComplexStrokePattern line = ComplexStrokePatternFactory.parallelLineBuilder().lineWidth(2).build();
ComplexStrokePattern arrowPattern = ComplexStrokePatternFactory.arrowBuilder().size(10).lineWidth(2).type(ComplexStrokePatternArrowType.Plain).build();
ComplexStrokeLineStyle strokeStyleTop = ComplexStrokeLineStyle.newBuilder().fallback(line).addDecoration(arrowPattern, 1.0).build();
ComplexStrokePattern combineWithFallbackPattern = ComplexStrokePatternFactory.combineWithFallback(arrowPattern);
ComplexStrokeLineStyle strokeStyleBottom = ComplexStrokeLineStyle.newBuilder().fallback(line).addDecoration(combineWithFallbackPattern, 1.0).build();
Results in:
pattern
- The pattern to combine with the fallback pattern
.fallback pattern
to be combined with this pattern.@NotNull public static ComplexStrokePattern combineWithRegular(@NotNull ComplexStrokePattern pattern)
regular pattern
to be painted on top of the given pattern.
A regular pattern
is a pattern that is repeated along the whole line. Normally, a regular pattern
is only painted where no decorations could be painted. This pattern wrapper adds an exception to this. When a pattern is wrapped with a combineWithRegular pattern, the pattern can be painted in addition to the regular pattern
. This is useful for adding a non-filled arrowhead,as in the example.
In the example there is still a small gap. This is because regular patterns
don't get cut off but get dropped instead, while fallback patterns
do get cut off.
Note that using this pattern wrapper implies that a fallback pattern
can be painted as well (if part of the regular pattern
cannot be painted).
Also note that if no regular pattern
is specified, then this pattern is combined with the fallback pattern
instead, as if you are using combineWithFallback
.
Sample code:
ComplexStrokePattern line = ComplexStrokePatternFactory.parallelLineBuilder().fixedLength(1).lineWidth(2).build();
ComplexStrokePattern arrowPattern = ComplexStrokePatternFactory.arrowBuilder().size(10).lineWidth(2).type(ComplexStrokePatternArrowType.Plain).build();
ComplexStrokeLineStyle strokeStyleTop = ComplexStrokeLineStyle.newBuilder().regular(line).addDecoration(arrowPattern, 1.0).build();
ComplexStrokePattern combineWithRegularPattern = ComplexStrokePatternFactory.combineWithRegular(arrowPattern);
ComplexStrokeLineStyle strokeStyleBottom = ComplexStrokeLineStyle.newBuilder().regular(line).addDecoration(combineWithRegularPattern, 1.0).build();
Results in:
pattern
- The pattern to combine with the regular pattern
.regular pattern
to be combined with this pattern.@NotNull public static ComplexStrokePattern gapFixed(double fixedLength) throws IllegalArgumentException
A gap pattern occupies space only. It can be used to add space in between other strokes.
Sample code:
ComplexStrokePattern gapPattern = ComplexStrokePatternFactory.gapFixed(15);
ComplexStrokePattern circle = ComplexStrokePatternFactory.arcBuilder().fixedLength(30).minorRadius(15).build();
ComplexStrokePattern pattern = ComplexStrokePatternFactory.appendPatterns(List.of(gapPattern, circle, gapPattern));
ComplexStrokeLineStyle strokeStyle = ComplexStrokeLineStyle.newBuilder()
.fallback(ComplexStrokePatternFactory.parallelLineBuilder().build())
.addDecoration(pattern, 0.5)
.build();
Results in:
fixedLength
- the length of the gap in pixels.IllegalArgumentException
- fixedLength must be >=0
.@NotNull public static ComplexStrokePattern gapRelative(double relativeLength) throws IllegalArgumentException
A gap pattern occupies space only. It can be used to add space in between other strokes.
Sample code:
ComplexStrokePattern gapPattern = ComplexStrokePatternFactory.gapRelative(0.05);
ComplexStrokePattern circle = ComplexStrokePatternFactory.arcBuilder().fixedLength(30).minorRadius(15).build();
ComplexStrokePattern pattern = ComplexStrokePatternFactory.appendPatterns(List.of(gapPattern, circle, gapPattern));
ComplexStrokeLineStyle strokeStyle = ComplexStrokeLineStyle.newBuilder()
.fallback(ComplexStrokePatternFactory.parallelLineBuilder().build())
.addDecoration(pattern, 0.5)
.build();
Results in:
relativeLength
- the length (relative to the length of the entire line, [0,1]
) of the gap.IllegalArgumentException
- relativeLength must be in range [0,1]
.@NotNull public static ComplexStrokePattern repeat(@NotNull ComplexStrokePattern pattern, long count)
Note that with this pattern, there is no guarantee that the given number of patterns is actually painted. This also depends on the line on which the complex stroke is painted. For example, if the line is too short, not all of the patterns may fit on it. If one of the repeated patterns crosses a sharp corner, it may be omitted as well. In that case, the regular
or fallback
patterns may be painted instead.
In the following example, a circular arc pattern is repeated 3 times:
Sample code:
ComplexStrokePattern circle = ComplexStrokePatternFactory.arcBuilder().minorRadius(15).fixedLength(30).build();
ComplexStrokePattern repeatedCircles = ComplexStrokePatternFactory.repeat(circle, 3);
ComplexStrokeLineStyle strokeStyle = ComplexStrokeLineStyle.newBuilder()
.fallback(ComplexStrokePatternFactory.parallelLineBuilder().build())
.addDecoration(repeatedCircles, 0.5)
.build();
Results in:
pattern
- the pattern to repeat.count
- the number of times to repeat the pattern. Must be greater than or equal to 1.@NotNull public static ComplexStrokePattern repeatOverLengthFixed(@NotNull ComplexStrokePattern pattern, double fixedLength) throws IllegalArgumentException
This length is a fixed length (in pixels).
Sample code:
ComplexStrokePattern circle = ComplexStrokePatternFactory.arcBuilder().minorRadius(8).fixedLength(16).build();
ComplexStrokePattern repeatedCircles = ComplexStrokePatternFactory.repeatOverLengthFixed(circle, 100);
ComplexStrokeLineStyle strokeStyle = ComplexStrokeLineStyle.newBuilder()
.fallback(ComplexStrokePatternFactory.parallelLineBuilder().build())
.addDecoration(repeatedCircles, 0.5)
.build();
Results in:
pattern
- the pattern to repeat.fixedLength
- the length (in pixels) over which the pattern should be repeated.IllegalArgumentException
- fixedLength must be >0
.@NotNull public static ComplexStrokePattern repeatOverLengthRelative(@NotNull ComplexStrokePattern pattern, double relativeLength) throws IllegalArgumentException
This is a length relative to the length of the line.
Sample code:
ComplexStrokePattern circle = ComplexStrokePatternFactory.arcBuilder().minorRadius(8).fixedLength(16).build();
ComplexStrokePattern repeatedCircle = ComplexStrokePatternFactory.repeatOverLengthRelative(circle, 0.5);
ComplexStrokeLineStyle strokeStyle = ComplexStrokeLineStyle.newBuilder()
.fallback(ComplexStrokePatternFactory.parallelLineBuilder().build())
.addDecoration(repeatedCircle, 0.5)
.build();
Results in:
pattern
- the pattern to repeat.relativeLength
- the length (relative to the length of the entire line, [0,1]
) over which the pattern should be repeated.IllegalArgumentException
- relativeLength must be in range [0,1]
.@NotNull public static ComplexStrokePattern allowOverlap(@NotNull ComplexStrokePattern pattern, double overlapLeft, double overlapRight) throws IllegalArgumentException
Note that the given pattern must be a pattern with a fixed (non-relative) length for the overlap to work.
In the following examples, two half circles are painted next to each other. This is done twice. The first time, no overlap is allowed. The second time, overlap is allowed:
Sample code:
ComplexStrokePattern leftArc = ComplexStrokePatternFactory.arcBuilder()
.minorRadius(20)
.fixedLength(40)
.angle(180)
.lineColor(Color.valueOf(Color.RED))
.lineWidth(2)
.build();
ComplexStrokePattern rightArc = ComplexStrokePatternFactory.arcBuilder()
.minorRadius(20)
.fixedLength(40)
.angle(180)
.startAngle(new Angle(180))
.lineColor(Color.valueOf(Color.BLUE))
.lineWidth(2)
.build();
ComplexStrokePattern arcs = ComplexStrokePatternFactory.appendPatterns(List.of(leftArc, rightArc));
ComplexStrokePattern leftArcAllowOverlap = ComplexStrokePatternFactory.allowOverlap(leftArc, 0, 8);
ComplexStrokePattern rightArcAllowOverlap = ComplexStrokePatternFactory.allowOverlap(rightArc, 8, 0);
ComplexStrokePattern arcsOverlap = ComplexStrokePatternFactory.appendPatterns(List.of(leftArcAllowOverlap, rightArcAllowOverlap));
ComplexStrokeLineStyle strokeStyle = ComplexStrokeLineStyle.newBuilder()
.fallback(ComplexStrokePatternFactory.parallelLineBuilder().build())
.addDecoration(arcs, 0.5)
.build();
ComplexStrokeLineStyle strokeStyleOverlap = ComplexStrokeLineStyle.newBuilder()
.fallback(ComplexStrokePatternFactory.parallelLineBuilder().build())
.addDecoration(arcsOverlap, 0.5)
.build();
Results in:
pattern
- the pattern to allow overlaps.overlapLeft
- The allowed overlap on the left, in pixels.overlapRight
- The allowed overlap on the right, in pixels.IllegalArgumentException
- overlapLeft and overlapRight must be >=0
.