Class GradientBuilder


  • public final class GradientBuilder
    extends Object
    The gradient builder is the entry point to create a canvas gradient.
    A gradient is an image consisting of a progressive transition between two or more colors.
    Could be Linear or Radial.
    Can be created using the size of CANVAS or CHART area.
    The orientation to have a progressive transition, is defined by an enumeration in order to creates the gradient using the right coordinates and dimension, based on existing items (canvas and chart).
    Author:
    Andrea "Stock" Stocchero
    • Method Detail

      • create

        public static GradientBuilder create()
        Creates a LINEAR gradient, with topDown orientation and chart scope.
        Returns:
        gradient builder instance
      • create

        public static GradientBuilder create​(GradientType type)
        Creates a gradient by a type, with chart scope.
        Parameters:
        type - gradient type
        Returns:
        gradient builder instance
      • create

        public static GradientBuilder create​(GradientType type,
                                             GradientOrientation orientation)
        Creates a gradient by a type and an orientation, with chart scope.
        Parameters:
        type - gradient type
        orientation - orientation of gradient
        Returns:
        gradient builder instance
      • create

        public static GradientBuilder create​(GradientType type,
                                             GradientScope scope)
        Creates a gradient by a type and a scope.
        Parameters:
        type - gradient type
        scope - scope of gradient
        Returns:
        gradient builder instance
      • create

        public static GradientBuilder create​(GradientType type,
                                             GradientOrientation orientation,
                                             GradientScope scope)
        Creates a gradient by a type, an orientation and a scope.
        Parameters:
        type - gradient type
        orientation - orientation of gradient
        scope - scope of gradient
        Returns:
        gradient builder instance
      • addColorsStartStop

        public GradientBuilder addColorsStartStop​(IsColor start,
                                                  IsColor stop)
        Sets the start and stop color of gradient, when the gradient will have only 2 colors.
        Parameters:
        start - starting color, with offset 0
        stop - stopping color, with offset 1
        Returns:
        gradient builder instance
      • addColorsStartStop

        public GradientBuilder addColorsStartStop​(String start,
                                                  String stop)
        Sets the start and stop color of gradient, when the gradient will have only 2 colors.
        Parameters:
        start - starting color, with offset 0
        stop - stopping color, with offset 1
        Returns:
        gradient builder instance
      • addColorStop

        public GradientBuilder addColorStop​(double offset,
                                            IsColor color)
        Adds a stopping color with its offset
        Parameters:
        offset - offset of color
        color - color instance
        Returns:
        gradient builder instance
      • addColorStop

        public GradientBuilder addColorStop​(double offset,
                                            String color)
        Adds a stopping color with its offset
        Parameters:
        offset - offset of color
        color - color instance
        Returns:
        gradient builder instance
      • addColorStop

        public GradientBuilder addColorStop​(GradientColor color)
        Adds a stopping color with its offset
        Parameters:
        color - color instance
        Returns:
        gradient builder instance
      • setColors

        public GradientBuilder setColors​(IsColor... colors)
        Sets an array of colors to the gradient.
        Parameters:
        colors - colors array to set
        Returns:
        gradient builder instance
      • setColors

        public GradientBuilder setColors​(List<IsColor> colors)
        Sets the list of colors.
        Parameters:
        colors - colors list to set
        Returns:
        gradient builder instance
      • build

        public Gradient build()
        Builds and returns a gradient instance.
        Returns:
        a gradient instance, built by the builder.
      • build

        public static Gradient build​(NativeObject nativeObject)
        Creates a gradient, previously stored in the a native java script object.
        Parameters:
        nativeObject - native java script object wrapped by gradient.
        Returns:
        a gradient instance, built by the builder.
      • retrieve

        public static Gradient retrieve​(CanvasGradientItem canvasGradient)
        Retrieves a cached pattern by a CanvasGradientItem instance.
        If the pattern doesn't exist, returns null.
        Parameters:
        canvasGradient - the canvas gradient to use for searching
        Returns:
        a cached pattern by a CanvasGradientItem instance.
        If the pattern doesn't exist, returns null