StrategyBasedLinearGradientBuilder extends AbstractLinearGradientBuilder { public StrategyBasedLinearGradientBuilder setGradientDirectionAsStrategy(GradientStrategy gradientStrategy) { this.gradientStrategy = gradientStrategy != null ? gradientStrategy : GradientStrategy.TO_BOTTOM; this.isCentralRotationAngleStrategy = false; return this; } StrategyBasedLinearGradientBuilder(); StrategyBasedLinearGradientBuilder setGradientDirectionAsCentralRotationAngle(double radians); StrategyBasedLinearGradientBuilder setGradientDirectionAsStrategy(GradientStrategy gradientStrategy); double getRotateVectorAngle(); GradientStrategy getGradientStrategy(); boolean isCentralRotationAngleStrategy();  }
@Test public void builderToRightTest() throws IOException, InterruptedException { AbstractLinearGradientBuilder gradientBuilder = new StrategyBasedLinearGradientBuilder() .setGradientDirectionAsStrategy(StrategyBasedLinearGradientBuilder.GradientStrategy.TO_RIGHT) .addColorStop(new GradientColorStop(ColorConstants.RED.getColorValue(), 0d, OffsetType.RELATIVE)) .addColorStop(new GradientColorStop(ColorConstants.GREEN.getColorValue(), 0.5, OffsetType.RELATIVE)) .addColorStop(new GradientColorStop(ColorConstants.BLUE.getColorValue(), 1d, OffsetType.RELATIVE)); generateAndComparePdfs("builderToRightTest.pdf", null, gradientBuilder); }
@Test public void builderToLeftTest() throws IOException, InterruptedException { AbstractLinearGradientBuilder gradientBuilder = new StrategyBasedLinearGradientBuilder() .setGradientDirectionAsStrategy(StrategyBasedLinearGradientBuilder.GradientStrategy.TO_LEFT) .addColorStop(new GradientColorStop(ColorConstants.RED.getColorValue(), 0d, OffsetType.RELATIVE)) .addColorStop(new GradientColorStop(ColorConstants.GREEN.getColorValue(), 0.5, OffsetType.RELATIVE)) .addColorStop(new GradientColorStop(ColorConstants.BLUE.getColorValue(), 1d, OffsetType.RELATIVE)); generateAndComparePdfs("builderToLeftTest.pdf", null, gradientBuilder); }
@Test public void builderToBottomTest() throws IOException, InterruptedException { AbstractLinearGradientBuilder gradientBuilder = new StrategyBasedLinearGradientBuilder() .setGradientDirectionAsStrategy(StrategyBasedLinearGradientBuilder.GradientStrategy.TO_BOTTOM) .addColorStop(new GradientColorStop(ColorConstants.RED.getColorValue(), 0d, OffsetType.RELATIVE)) .addColorStop(new GradientColorStop(ColorConstants.GREEN.getColorValue(), 0.5, OffsetType.RELATIVE)) .addColorStop(new GradientColorStop(ColorConstants.BLUE.getColorValue(), 1d, OffsetType.RELATIVE)); generateAndComparePdfs("builderToBottomTest.pdf", null, gradientBuilder); }
@Test public void builderToBottomRightTest() throws IOException, InterruptedException { AbstractLinearGradientBuilder gradientBuilder = new StrategyBasedLinearGradientBuilder() .setGradientDirectionAsStrategy(StrategyBasedLinearGradientBuilder.GradientStrategy.TO_BOTTOM_RIGHT) .addColorStop(new GradientColorStop(ColorConstants.RED.getColorValue(), 0d, OffsetType.RELATIVE)) .addColorStop(new GradientColorStop(ColorConstants.GREEN.getColorValue(), 0.5, OffsetType.RELATIVE)) .addColorStop(new GradientColorStop(ColorConstants.BLUE.getColorValue(), 1d, OffsetType.RELATIVE)); generateAndComparePdfs("builderToBottomRightTest.pdf", null, gradientBuilder); }
@Test public void builderToBottomLeftTest() throws IOException, InterruptedException { AbstractLinearGradientBuilder gradientBuilder = new StrategyBasedLinearGradientBuilder() .setGradientDirectionAsStrategy(StrategyBasedLinearGradientBuilder.GradientStrategy.TO_BOTTOM_LEFT) .addColorStop(new GradientColorStop(ColorConstants.RED.getColorValue(), 0d, OffsetType.RELATIVE)) .addColorStop(new GradientColorStop(ColorConstants.GREEN.getColorValue(), 0.5, OffsetType.RELATIVE)) .addColorStop(new GradientColorStop(ColorConstants.BLUE.getColorValue(), 1d, OffsetType.RELATIVE)); generateAndComparePdfs("builderToBottomLeftTest.pdf", null, gradientBuilder); }
@Test public void builderToTopTest() throws IOException, InterruptedException { AbstractLinearGradientBuilder gradientBuilder = new StrategyBasedLinearGradientBuilder() .setGradientDirectionAsStrategy(StrategyBasedLinearGradientBuilder.GradientStrategy.TO_TOP) .addColorStop(new GradientColorStop(ColorConstants.RED.getColorValue(), 0d, OffsetType.RELATIVE)) .addColorStop(new GradientColorStop(ColorConstants.GREEN.getColorValue(), 0.5, OffsetType.RELATIVE)) .addColorStop(new GradientColorStop(ColorConstants.BLUE.getColorValue(), 1d, OffsetType.RELATIVE)); generateAndComparePdfs("builderToTopTest.pdf", null, gradientBuilder); }
@Test public void builderToTopRightTest() throws IOException, InterruptedException { AbstractLinearGradientBuilder gradientBuilder = new StrategyBasedLinearGradientBuilder() .setGradientDirectionAsStrategy(StrategyBasedLinearGradientBuilder.GradientStrategy.TO_TOP_RIGHT) .addColorStop(new GradientColorStop(ColorConstants.RED.getColorValue(), 0d, OffsetType.RELATIVE)) .addColorStop(new GradientColorStop(ColorConstants.GREEN.getColorValue(), 0.5, OffsetType.RELATIVE)) .addColorStop(new GradientColorStop(ColorConstants.BLUE.getColorValue(), 1d, OffsetType.RELATIVE)); generateAndComparePdfs("builderToTopRightTest.pdf", null, gradientBuilder); }
@Test public void builderToTopLeftTest() throws IOException, InterruptedException { AbstractLinearGradientBuilder gradientBuilder = new StrategyBasedLinearGradientBuilder() .setGradientDirectionAsStrategy(StrategyBasedLinearGradientBuilder.GradientStrategy.TO_TOP_LEFT) .addColorStop(new GradientColorStop(ColorConstants.RED.getColorValue(), 0d, OffsetType.RELATIVE)) .addColorStop(new GradientColorStop(ColorConstants.GREEN.getColorValue(), 0.5, OffsetType.RELATIVE)) .addColorStop(new GradientColorStop(ColorConstants.BLUE.getColorValue(), 1d, OffsetType.RELATIVE)); generateAndComparePdfs("builderToTopLeftTest.pdf", null, gradientBuilder); }
@Test public void builderWithNoneSpreadingAndCanvasTransformTest() throws IOException, InterruptedException { AbstractLinearGradientBuilder gradientBuilder = new StrategyBasedLinearGradientBuilder() .setGradientDirectionAsStrategy(StrategyBasedLinearGradientBuilder.GradientStrategy.TO_RIGHT) .setSpreadMethod(GradientSpreadMethod.NONE) .addColorStop(new GradientColorStop(ColorConstants.RED.getColorValue(), 0d, OffsetType.RELATIVE)) .addColorStop(new GradientColorStop(ColorConstants.GREEN.getColorValue(), 0.5, OffsetType.RELATIVE)) .addColorStop(new GradientColorStop(ColorConstants.BLUE.getColorValue(), 1d, OffsetType.RELATIVE)); AffineTransform canvasTransform = AffineTransform.getTranslateInstance(50, -50); canvasTransform.scale(0.8, 1.1); canvasTransform.rotate(Math.PI/3, 400f, 550f); generateAndComparePdfs("builderWithNoneSpreadingAndCanvasTransformTest.pdf", canvasTransform, gradientBuilder); }
@Test public void builderWithToCornerAndInnerStopsAndNoneSpreadingTest() throws IOException, InterruptedException { AbstractLinearGradientBuilder gradientBuilder = new StrategyBasedLinearGradientBuilder() .setGradientDirectionAsStrategy(StrategyBasedLinearGradientBuilder.GradientStrategy.TO_TOP_RIGHT) .setSpreadMethod(GradientSpreadMethod.NONE) .addColorStop(new GradientColorStop(ColorConstants.RED.getColorValue(), 0.3d, OffsetType.RELATIVE)) .addColorStop(new GradientColorStop(ColorConstants.GREEN.getColorValue(), 0.4, OffsetType.RELATIVE)) .addColorStop(new GradientColorStop(ColorConstants.BLUE.getColorValue(), 0.5d, OffsetType.RELATIVE)); generateAndComparePdfs("builderWithToCornerAndInnerStopsAndNoneSpreadingTest.pdf", null, gradientBuilder); }
@Test public void builderWithToCornerAndInnerStopsAndPadSpreadingTest() throws IOException, InterruptedException { AbstractLinearGradientBuilder gradientBuilder = new StrategyBasedLinearGradientBuilder() .setGradientDirectionAsStrategy(StrategyBasedLinearGradientBuilder.GradientStrategy.TO_TOP_RIGHT) .setSpreadMethod(GradientSpreadMethod.PAD) .addColorStop(new GradientColorStop(ColorConstants.RED.getColorValue(), 0.3d, OffsetType.RELATIVE)) .addColorStop(new GradientColorStop(ColorConstants.GREEN.getColorValue(), 0.4, OffsetType.RELATIVE)) .addColorStop(new GradientColorStop(ColorConstants.BLUE.getColorValue(), 0.5d, OffsetType.RELATIVE)); generateAndComparePdfs("builderWithToCornerAndInnerStopsAndPadSpreadingTest.pdf", null, gradientBuilder); }
@Test public void builderWithToCornerAndInnerStopsAndReflectSpreadingTest() throws IOException, InterruptedException { AbstractLinearGradientBuilder gradientBuilder = new StrategyBasedLinearGradientBuilder() .setGradientDirectionAsStrategy(StrategyBasedLinearGradientBuilder.GradientStrategy.TO_TOP_RIGHT) .setSpreadMethod(GradientSpreadMethod.REFLECT) .addColorStop(new GradientColorStop(ColorConstants.RED.getColorValue(), 0.3d, OffsetType.RELATIVE)) .addColorStop(new GradientColorStop(ColorConstants.GREEN.getColorValue(), 0.4, OffsetType.RELATIVE)) .addColorStop(new GradientColorStop(ColorConstants.BLUE.getColorValue(), 0.5d, OffsetType.RELATIVE)); generateAndComparePdfs("builderWithToCornerAndInnerStopsAndReflectSpreadingTest.pdf", null, gradientBuilder); }
@Test public void builderWithToCornerAndInnerStopsAndRepeatSpreadingTest() throws IOException, InterruptedException { AbstractLinearGradientBuilder gradientBuilder = new StrategyBasedLinearGradientBuilder() .setGradientDirectionAsStrategy(StrategyBasedLinearGradientBuilder.GradientStrategy.TO_TOP_RIGHT) .setSpreadMethod(GradientSpreadMethod.REPEAT) .addColorStop(new GradientColorStop(ColorConstants.RED.getColorValue(), 0.3d, OffsetType.RELATIVE)) .addColorStop(new GradientColorStop(ColorConstants.GREEN.getColorValue(), 0.4, OffsetType.RELATIVE)) .addColorStop(new GradientColorStop(ColorConstants.BLUE.getColorValue(), 0.5d, OffsetType.RELATIVE)); generateAndComparePdfs("builderWithToCornerAndInnerStopsAndRepeatSpreadingTest.pdf", null, gradientBuilder); }