Class GradientBuilder
- java.lang.Object
-
- org.pepstock.charba.client.colors.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 beLinear
orRadial
.
Can be created using the size ofCANVAS
orCHART
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 Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description GradientBuilder
addColorsStartStop(String start, String stop)
Sets the start and stop color of gradient, when the gradient will have only 2 colors.GradientBuilder
addColorsStartStop(IsColor start, IsColor stop)
Sets the start and stop color of gradient, when the gradient will have only 2 colors.GradientBuilder
addColorStop(double offset, String color)
Adds a stopping color with its offsetGradientBuilder
addColorStop(double offset, IsColor color)
Adds a stopping color with its offsetGradientBuilder
addColorStop(GradientColor color)
Adds a stopping color with its offsetGradient
build()
Builds and returns a gradient instance.static Gradient
build(NativeObject nativeObject)
Creates a gradient, previously stored in the a native java script object.static GradientBuilder
create()
Creates a LINEAR gradient, withtopDown
orientation andchart
scope.static GradientBuilder
create(GradientType type)
Creates a gradient by a type, withchart
scope.static GradientBuilder
create(GradientType type, GradientOrientation orientation)
Creates a gradient by a type and an orientation, withchart
scope.static GradientBuilder
create(GradientType type, GradientOrientation orientation, GradientScope scope)
Creates a gradient by a type, an orientation and a scope.static GradientBuilder
create(GradientType type, GradientScope scope)
Creates a gradient by a type and a scope.static Gradient
retrieve(CanvasGradientItem canvasGradient)
Retrieves a cached pattern by aCanvasGradientItem
instance.
If the pattern doesn't exist, returnsnull
.GradientBuilder
setColors(List<IsColor> colors)
Sets the list of colors.GradientBuilder
setColors(IsColor... colors)
Sets an array of colors to the gradient.
-
-
-
Method Detail
-
create
public static GradientBuilder create()
Creates a LINEAR gradient, withtopDown
orientation andchart
scope.- Returns:
- gradient builder instance
-
create
public static GradientBuilder create(GradientType type)
Creates a gradient by a type, withchart
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, withchart
scope.- Parameters:
type
- gradient typeorientation
- 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 typescope
- 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 typeorientation
- orientation of gradientscope
- 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 0stop
- 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 0stop
- 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 colorcolor
- 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 colorcolor
- 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 aCanvasGradientItem
instance.
If the pattern doesn't exist, returnsnull
.- Parameters:
canvasGradient
- the canvas gradient to use for searching- Returns:
- a cached pattern by a
CanvasGradientItem
instance.
If the pattern doesn't exist, returnsnull
-
-