Class 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 Detail

      • isContextConsistent

        public static boolean isContextConsistent​(ChartContext context)
        Returns true if context is consistent, otherwise false.
        Parameters:
        context - scriptable context
        Returns:
        true if context is consistent, otherwise false
      • 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 ChartContextPaddingItem 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 context
        callback - padding callback to execute
        defaultValue - default padding if the callback returns an inconsistent value
        Returns:
        a value of property related to the padding value
      • getOptionValueAsFont

        public static <C extends ChartContextFontItem 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 context
        callback - font callback to execute
        defaultValue - 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 key
        C - type of context to pass to the callback
        Parameters:
        context - scriptable context
        callback - 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 key
        C - type of context to pass to the callback
        Parameters:
        context - scriptable context
        callback - callback to invoke
        defaultValue - 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, as Number, of the property as result of callback (the same type), passing a default value.
        Type Parameters:
        T - type of callback result, as Number
        C - type of context to pass to the callback
        Parameters:
        context - scriptable context
        callback - callback to invoke
        defaultValue - 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, as Number, of the property as result of callback (the same type), passing a default value and a ScriptableResultChecker to check the consistency of the result.
        Type Parameters:
        T - type of callback result, as Number
        C - type of context to pass to the callback
        Parameters:
        context - scriptable context
        callback - callback to invoke
        defaultValue - 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 result
        C - type of context to pass to the callback
        Parameters:
        context - scriptable context
        callback - 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 result
        C - type of context to pass to the callback
        Parameters:
        context - scriptable context
        callback - callback to invoke
        defaultValue - 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 ChartContextObject 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 also Pattern or CanvasPatternItem.
        Type Parameters:
        C - type of context to pass to the callback
        Parameters:
        context - scriptable context
        callback - callback to invoke
        defaultValue - 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 ChartContextObject 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 context
        callback - callback to invoke
        defaultValue - default value to return in case of chart, callback or result of callback are not consistent.
        hasPattern - if true is able to manage also Pattern or CanvasPatternItem, otherwise it skips them.
        Returns:
        a value of property as color
      • handleCallbackResultAsColor

        public static <C extends ChartContextObject 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 context
        result - result of callback invocation
        defaultValue - default value to return in case of chart, callback or result of callback are not consistent.
        hasPattern - if true is able to manage also Pattern or CanvasPatternItem, otherwise it skips them.
        Returns:
        a value of property as color
      • parseCallbackResult

        public static Object parseCallbackResult​(Object result,
                                                 String defaultValue)
        Parses the result of a TickCallback or PointLabelCallback callbacks, checking if it's a string or a list of strings.
        Parameters:
        result - the result of callback to check
        defaultValue - 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