Class Utilities


  • public final class Utilities
    extends Object
    Sets of methods used as common utilities.
    Author:
    Andrea "Stock" Stocchero
    • Method Detail

      • toCSSBackgroundProperty

        public static String toCSSBackgroundProperty​(Pattern pattern)
        Returns the CSS syntax to represent the pattern.
        The dimension of canvas pattern image will be the dimension of pattern.
        Parameters:
        pattern - object to export in the CSS
        Returns:
        the CSS syntax to represent the pattern
      • toCSSBackgroundProperty

        public static String toCSSBackgroundProperty​(Pattern pattern,
                                                     int squareSize)
        Returns the CSS syntax to represent the pattern.
        The dimension of canvas pattern image is unique then the image of pattern is a square.
        Parameters:
        pattern - object to export in the CSS
        squareSize - size of image applied to canvasPattern to be a square
        Returns:
        the CSS syntax to represent the pattern
      • toCSSBackgroundProperty

        public static String toCSSBackgroundProperty​(Pattern pattern,
                                                     int width,
                                                     int height)
        Returns the CSS syntax to represent the pattern.
        Parameters:
        pattern - object to export in the CSS
        width - width of image applied to canvasPattern
        height - height of image applied to canvasPattern
        Returns:
        the CSS syntax to represent the pattern
      • toCSSBackgroundProperty

        public static String toCSSBackgroundProperty​(String dataUrl)
        Returns a URL CSS property for the data URL for the current content of the canvas element.
        Parameters:
        dataUrl - the data URL for the current content of the canvas element
        Returns:
        a URL CSS property for the current content of the canvas element
      • toCSSBackgroundProperty

        public static String toCSSBackgroundProperty​(String dataUrl,
                                                     Repetition repetition)
        Returns a URL CSS property for the data URL for the current content of the canvas element.
        Parameters:
        dataUrl - the data URL for the current content of the canvas element
        repetition - repetition of image
        Returns:
        a URL CSS property for the current content of the canvas element
      • toCSSBackgroundProperty

        public static String toCSSBackgroundProperty​(Img image)
        Returns a URL CSS property for the current content of an image element instance.
        Parameters:
        image - image element instance to fet as CSS property
        Returns:
        a URL CSS property for the current content of the image
      • toCSSBorderRadiusProperty

        public static String toCSSBorderRadiusProperty​(BorderRadiusItem borderRadius)
        Builds the border radius string (shorthand property of CSS font) to use in the canvas object or in DOM element.
        The format is [top-left | top-right | bottom-right | bottom-left].
        Parameters:
        borderRadius - border radius item to use
        Returns:
        the border radius string to use in the canvas object or in DOM element.
      • getImageURLFromCanvasPattern

        public static String getImageURLFromCanvasPattern​(CanvasPatternItem pattern,
                                                          int width,
                                                          int height)
        Returns a data URL for the current content of a canvas pattern instance.
        Parameters:
        pattern - canvas pattern instance
        width - width of canvas applied to canvasPattern
        height - height of image applied to canvasPattern
        Returns:
        a data URL for the current content of the canvas pattern
      • toCSSBackgroundProperty

        public static String toCSSBackgroundProperty​(Gradient gradient)
        Returns the CSS syntax to represent the gradient.
        The dimension of canvas pattern image will be the dimension of pattern.
        Parameters:
        gradient - object to export in the CSS
        Returns:
        the CSS syntax to represent the gradient
      • toImageElement

        public static Img toImageElement​(String url)
        Creates a image element by a data URL which is a URI scheme that provides a way to in-line data in a document, and it's commonly used to embed images in HTML and CSS.
        Parameters:
        url - a URI scheme that provides a way to in-line data
        Returns:
        a image element or null if argument is not consistent
      • toImageElement

        public static Img toImageElement​(String url,
                                         int width,
                                         int height)
        Creates a image element by a data URL which is a URI scheme that provides a way to in-line data in a document, and it's commonly used to embed images in HTML and CSS, forcing the size.
        Parameters:
        url - a URI scheme that provides a way to in-line data
        width - width of image
        height - height of image
        Returns:
        a image element or null if argument is not consistent
      • getCursorOfChart

        public static CursorType getCursorOfChart​(IsChart chart)
        Returns the cursor currently set in the chart.
        Parameters:
        chart - chart instance
        Returns:
        the cursor currently set in the chart.
      • applyTemplate

        public static String applyTemplate​(String template,
                                           Object... values)
        Creates a string in order to change a template filling with the replacements.
        The replacement must be set as following:
         {0} ... {1} ... {n}
         
        where the value in the brackets represents the index of the obecjt in the array, passed as argument.
        Parameters:
        template - template of message
        values - values to apply in the template
        Returns:
        a string with the template filled by values
      • applyPrecision

        public static String applyPrecision​(double value,
                                            int precision)
        Converts a double in the a string setting the decimals places to maintain.
        Parameters:
        value - value to convert. If is Double.NaN, return Constants.NULL_STRING
        precision - decimals places to apply. If less than 0, uses 0
        Returns:
        a string which represents the double value