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 beLinearorRadial.
Can be created using the size ofCANVASorCHARTarea.
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 GradientBuilderaddColorsStartStop(String start, String stop)Sets the start and stop color of gradient, when the gradient will have only 2 colors.GradientBuilderaddColorsStartStop(IsColor start, IsColor stop)Sets the start and stop color of gradient, when the gradient will have only 2 colors.GradientBuilderaddColorStop(double offset, String color)Adds a stopping color with its offsetGradientBuilderaddColorStop(double offset, IsColor color)Adds a stopping color with its offsetGradientBuilderaddColorStop(GradientColor color)Adds a stopping color with its offsetGradientbuild()Builds and returns a gradient instance.static Gradientbuild(NativeObject nativeObject)Creates a gradient, previously stored in the a native java script object.static GradientBuildercreate()Creates a LINEAR gradient, withtopDownorientation andchartscope.static GradientBuildercreate(GradientType type)Creates a gradient by a type, withchartscope.static GradientBuildercreate(GradientType type, GradientOrientation orientation)Creates a gradient by a type and an orientation, withchartscope.static GradientBuildercreate(GradientType type, GradientOrientation orientation, GradientScope scope)Creates a gradient by a type, an orientation and a scope.static GradientBuildercreate(GradientType type, GradientScope scope)Creates a gradient by a type and a scope.static Gradientretrieve(CanvasGradientItem canvasGradient)Retrieves a cached pattern by aCanvasGradientIteminstance.
If the pattern doesn't exist, returnsnull.GradientBuildersetColors(List<IsColor> colors)Sets the list of colors.GradientBuildersetColors(IsColor... colors)Sets an array of colors to the gradient.
-
-
-
Method Detail
-
create
public static GradientBuilder create()
Creates a LINEAR gradient, withtopDownorientation andchartscope.- Returns:
- gradient builder instance
-
create
public static GradientBuilder create(GradientType type)
Creates a gradient by a type, withchartscope.- 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, withchartscope.- 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 aCanvasGradientIteminstance.
If the pattern doesn't exist, returnsnull.- Parameters:
canvasGradient- the canvas gradient to use for searching- Returns:
- a cached pattern by a
CanvasGradientIteminstance.
If the pattern doesn't exist, returnsnull
-
-