Class ScriptableUtil
- java.lang.Object
-
- org.pepstock.charba.client.callbacks.ScriptableUtil
-
public final class ScriptableUtil extends Object
Sets of common methods as utilities to manage scriptable options by callback and java interfaces.- Author:
- Andrea "Stock" Stocchero
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T,C extends ChartContext>
TgetOptionValue(C context, Scriptable<T,C> callback)
Returns the value of the property as result of callback (the same type).static <T,C extends ChartContext>
TgetOptionValue(C context, Scriptable<T,C> callback, T defaultValue)
Returns the value of the property as result of callback (the same type), passing a default value.static <C extends ChartContext>
ObjectgetOptionValueAsColor(C context, Scriptable<?,C> callback, String defaultValue)
Returns a color value of property by a callback, checking all different types of object which can be used as value of the property in color ones.
By defaults, is able to manage alsoPattern
orCanvasPatternItem
.static <C extends ChartContext>
ObjectgetOptionValueAsColor(C context, Scriptable<?,C> callback, String defaultValue, boolean hasPattern)
Returns a color value of property by a callback, checking all different types of object which can be used as value of the property in color ones.static <C extends ChartContext>
FontItemgetOptionValueAsFont(C context, Scriptable<FontItem,C> callback, IsDefaultFont defaultValue)
Returns the font item value as value of the property by invoking a callback which is typed to a font item.static <T extends Number,C extends ChartContext>
TgetOptionValueAsNumber(C context, Scriptable<T,C> callback, T defaultValue)
Returns the value, asNumber
, of the property as result of callback (the same type), passing a default value.static <T extends Number,C extends ChartContext>
TgetOptionValueAsNumber(C context, Scriptable<T,C> callback, T defaultValue, ScriptableResultChecker<T> checker)
Returns the value, asNumber
, of the property as result of callback (the same type), passing a default value and aScriptableResultChecker
to check the consistency of the result.static <C extends ChartContext>
PaddingItemgetOptionValueAsPadding(C context, Scriptable<PaddingItem,C> callback, IsDefaultPadding defaultValue)
Returns the padding item value as value of the property by invoking a callback which is typed to a paddng item.static <T extends Key,C extends ChartContext>
TgetOptionValueAsString(C context, Scriptable<T,C> callback)
Returns the enumeration value as value of the property by invoking a callback which is typed to a key.static <T extends Key,C extends ChartContext>
TgetOptionValueAsString(C context, Scriptable<T,C> callback, T defaultValue)
Returns the enumeration value of the property by invoking a callback which is typed to a key, passing a default value.static <C extends ChartContext>
ObjecthandleCallbackResultAsColor(C context, Object result, String defaultValue, boolean hasPattern)
Returns a color value of property by a callback, checking all different types of object which can be used as value of the property in color ones.static boolean
isContextConsistent(ChartContext context)
Returnstrue
if context is consistent, otherwisefalse
.static Object
parseCallbackResult(Object result, String defaultValue)
Parses the result of aTickCallback
orPointLabelCallback
callbacks, checking if it's a string or a list of strings.static IsChart
retrieveChart(ChartContext context)
Returns the chart instance, contained in the context if context is consistent.
-
-
-
Method Detail
-
isContextConsistent
public static boolean isContextConsistent(ChartContext context)
Returnstrue
if context is consistent, otherwisefalse
.- Parameters:
context
- scriptable context- Returns:
true
if context is consistent, otherwisefalse
-
retrieveChart
public static IsChart retrieveChart(ChartContext context)
Returns the chart instance, contained in the context if context is consistent.- Parameters:
context
- scriptable context- Returns:
- the chart instance, contained in the context if context is consistent
-
getOptionValueAsPadding
public static <C extends ChartContext> PaddingItem getOptionValueAsPadding(C context, Scriptable<PaddingItem,C> callback, IsDefaultPadding defaultValue)
Returns the padding item value as value of the property by invoking a callback which is typed to a paddng item.- Type Parameters:
C
- type of context to pass to the callback- Parameters:
context
- native object as contextcallback
- padding callback to executedefaultValue
- default padding if the callback returns an inconsistent value- Returns:
- a value of property related to the padding value
-
getOptionValueAsFont
public static <C extends ChartContext> FontItem getOptionValueAsFont(C context, Scriptable<FontItem,C> callback, IsDefaultFont defaultValue)
Returns the font item value as value of the property by invoking a callback which is typed to a font item.- Type Parameters:
C
- type of context to pass to the callback- Parameters:
context
- native object as contextcallback
- font callback to executedefaultValue
- default font if the callback returns an inconsistent value- Returns:
- a value of property related to the font value
-
getOptionValueAsString
public static <T extends Key,C extends ChartContext> T getOptionValueAsString(C context, Scriptable<T,C> callback)
Returns the enumeration value as value of the property by invoking a callback which is typed to a key.- Type Parameters:
T
- type of result of the callback which extends a keyC
- type of context to pass to the callback- Parameters:
context
- scriptable contextcallback
- callback to invoke- Returns:
- a value of property related to the enumeration value
-
getOptionValueAsString
public static <T extends Key,C extends ChartContext> T getOptionValueAsString(C context, Scriptable<T,C> callback, T defaultValue)
Returns the enumeration value of the property by invoking a callback which is typed to a key, passing a default value. as argument.- Type Parameters:
T
- type of callback which extends a keyC
- type of context to pass to the callback- Parameters:
context
- scriptable contextcallback
- callback to invokedefaultValue
- default value to return in case of chart, callback or result of callback are not consistent.- Returns:
- a value of property related to the enumeration value
-
getOptionValueAsNumber
public static <T extends Number,C extends ChartContext> T getOptionValueAsNumber(C context, Scriptable<T,C> callback, T defaultValue)
Returns the value, asNumber
, of the property as result of callback (the same type), passing a default value.- Type Parameters:
T
- type of callback result, asNumber
C
- type of context to pass to the callback- Parameters:
context
- scriptable contextcallback
- callback to invokedefaultValue
- default value to return in case of chart, callback or result of callback are not consistent.- Returns:
- a value of property as result of callback invocation
-
getOptionValueAsNumber
public static <T extends Number,C extends ChartContext> T getOptionValueAsNumber(C context, Scriptable<T,C> callback, T defaultValue, ScriptableResultChecker<T> checker)
Returns the value, asNumber
, of the property as result of callback (the same type), passing a default value and aScriptableResultChecker
to check the consistency of the result.- Type Parameters:
T
- type of callback result, asNumber
C
- type of context to pass to the callback- Parameters:
context
- scriptable contextcallback
- callback to invokedefaultValue
- default value to return in case of chart, callback or result of callback are not consistent.checker
-ScriptableResultChecker
to check the consistency of the value- Returns:
- a value of property as result of callback invocation
-
getOptionValue
public static <T,C extends ChartContext> T getOptionValue(C context, Scriptable<T,C> callback)
Returns the value of the property as result of callback (the same type).- Type Parameters:
T
- type of callback resultC
- type of context to pass to the callback- Parameters:
context
- scriptable contextcallback
- callback to invoke- Returns:
- a value of property as result of callback invocation
-
getOptionValue
public static <T,C extends ChartContext> T getOptionValue(C context, Scriptable<T,C> callback, T defaultValue)
Returns the value of the property as result of callback (the same type), passing a default value.- Type Parameters:
T
- type of callback resultC
- type of context to pass to the callback- Parameters:
context
- scriptable contextcallback
- callback to invokedefaultValue
- default value to return in case of chart, callback or result of callback are not consistent.- Returns:
- a value of property as result of callback invocation
-
getOptionValueAsColor
public static <C extends ChartContext> Object getOptionValueAsColor(C context, Scriptable<?,C> callback, String defaultValue)
Returns a color value of property by a callback, checking all different types of object which can be used as value of the property in color ones.
By defaults, is able to manage alsoPattern
orCanvasPatternItem
.- Type Parameters:
C
- type of context to pass to the callback- Parameters:
context
- scriptable contextcallback
- callback to invokedefaultValue
- default value to return in case of chart, callback or result of callback are not consistent.- Returns:
- a value of property as color
-
getOptionValueAsColor
public static <C extends ChartContext> Object getOptionValueAsColor(C context, Scriptable<?,C> callback, String defaultValue, boolean hasPattern)
Returns a color value of property by a callback, checking all different types of object which can be used as value of the property in color ones.- Type Parameters:
C
- type of context to pass to the callback- Parameters:
context
- scriptable contextcallback
- callback to invokedefaultValue
- default value to return in case of chart, callback or result of callback are not consistent.hasPattern
- iftrue
is able to manage alsoPattern
orCanvasPatternItem
, otherwise it skips them.- Returns:
- a value of property as color
-
handleCallbackResultAsColor
public static <C extends ChartContext> Object handleCallbackResultAsColor(C context, Object result, String defaultValue, boolean hasPattern)
Returns a color value of property by a callback, checking all different types of object which can be used as value of the property in color ones.- Type Parameters:
C
- type of context to pass to the callback- Parameters:
context
- scriptable contextresult
- result of callback invocationdefaultValue
- default value to return in case of chart, callback or result of callback are not consistent.hasPattern
- iftrue
is able to manage alsoPattern
orCanvasPatternItem
, otherwise it skips them.- Returns:
- a value of property as color
-
parseCallbackResult
public static Object parseCallbackResult(Object result, String defaultValue)
Parses the result of aTickCallback
orPointLabelCallback
callbacks, checking if it's a string or a list of strings.- Parameters:
result
- the result of callback to checkdefaultValue
- default value to return if the result fo callback is not consistent.- Returns:
- return a string or a list of strings (multiline) or
default
if result is not consistent
-
-