Class Utils

java.lang.Object
com.dlsc.gemsfx.util.Utils

public class Utils extends Object
Some basic utilities which need to be in java (for shifting operations or other reasons), which are not toolkit dependent.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    calculateBrightness(javafx.scene.paint.Color color)
    Calculates a perceptual brightness for a color between 0.0 black and 1.0 while
    static double
    clamp(double min, double value, double max)
    Simple utility function which clamps the given value to be strictly between the min and max values.
    static float
    clamp(float min, float value, float max)
    Simple utility function which clamps the given value to be strictly between the min and max values.
    static int
    clamp(int min, int value, int max)
    Simple utility function which clamps the given value to be strictly between the min and max values.
    static long
    clamp(long min, long value, long max)
    Simple utility function which clamps the given value to be strictly between the min and max values.
    static int
    clampMax(int value, int max)
    Simple utility function which clamps the given value to be strictly under the max value.
    static double
    clampMin(double value, double min)
    Simple utility function which clamps the given value to be strictly above the min value.
    static boolean
    Because mobile doesn't have string.contains(s) function, this function was written.
    static javafx.scene.paint.Color
    convertLinearRGBtoSRGB(javafx.scene.paint.Color color)
    Helper function to convert a color in linear RGB space to SRGB space.
    static javafx.scene.paint.Color
    convertSRGBtoLinearRGB(javafx.scene.paint.Color color)
    Helper function to convert a color in sRGB space to linear RGB space.
    static javafx.scene.paint.Color
    deriveColor(javafx.scene.paint.Color c, double brightness)
    Derives a lighter or darker of a given color.
    static javafx.stage.Screen
    This function attempts to determine the best screen given the parent object from which we are wanting to position another item relative to.
    static javafx.stage.Screen
    getScreenForPoint(double x, double y)
     
    static javafx.stage.Screen
    getScreenForRectangle(javafx.geometry.Rectangle2D rect)
     
    static boolean
    hasFullScreenStage(javafx.stage.Screen screen)
     
    static double[]
    HSBtoRGB(double hue, double saturation, double brightness)
     
    static boolean
     
    static javafx.scene.paint.Color
    ladder(javafx.scene.paint.Color color, javafx.scene.paint.Stop[] stops)
    Get the color at the give position in the ladder of color stops
    static double
    nearest(double less, double value, double more)
    Utility function which returns either less or more depending on which value is closer to.
    static javafx.geometry.Point2D
    pointRelativeTo(Object parent, double width, double height, double screenX, double screenY, javafx.geometry.HPos hpos, javafx.geometry.VPos vpos)
    This is the fallthrough function that most other functions fall into.
    static javafx.geometry.Point2D
    pointRelativeTo(javafx.scene.Node parent, double anchorWidth, double anchorHeight, javafx.geometry.HPos hpos, javafx.geometry.VPos vpos, double dx, double dy, boolean reposition)
     
    static javafx.geometry.Point2D
    pointRelativeTo(javafx.scene.Node parent, javafx.scene.Node node, javafx.geometry.HPos hpos, javafx.geometry.VPos vpos, double dx, double dy, boolean reposition)
     
    static double[]
    RGBtoHSB(double r, double g, double b)
     
    static String[]
    split(String str, String separator)
    Because mobile doesn't have string.split(s) function, this function was written.
    static String
    Helper to remove leading and trailing quotes from a string.
    static double
    sum(double[] values)
    helper function for calculating the sum of a series of numbers

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Utils

      public Utils()
  • Method Details

    • clamp

      public static float clamp(float min, float value, float max)
      Simple utility function which clamps the given value to be strictly between the min and max values.
    • clamp

      public static int clamp(int min, int value, int max)
      Simple utility function which clamps the given value to be strictly between the min and max values.
    • clamp

      public static double clamp(double min, double value, double max)
      Simple utility function which clamps the given value to be strictly between the min and max values.
    • clamp

      public static long clamp(long min, long value, long max)
      Simple utility function which clamps the given value to be strictly between the min and max values.
    • clampMin

      public static double clampMin(double value, double min)
      Simple utility function which clamps the given value to be strictly above the min value.
    • clampMax

      public static int clampMax(int value, int max)
      Simple utility function which clamps the given value to be strictly under the max value.
    • nearest

      public static double nearest(double less, double value, double more)
      Utility function which returns either less or more depending on which value is closer to. If value is perfectly between them, then either may be returned.
    • stripQuotes

      public static String stripQuotes(String str)
      Helper to remove leading and trailing quotes from a string. Works with single or double quotes.
    • split

      public static String[] split(String str, String separator)
      Because mobile doesn't have string.split(s) function, this function was written.
    • contains

      public static boolean contains(String src, String s)
      Because mobile doesn't have string.contains(s) function, this function was written.
    • calculateBrightness

      public static double calculateBrightness(javafx.scene.paint.Color color)
      Calculates a perceptual brightness for a color between 0.0 black and 1.0 while
    • deriveColor

      public static javafx.scene.paint.Color deriveColor(javafx.scene.paint.Color c, double brightness)
      Derives a lighter or darker of a given color.
      Parameters:
      c - The color to derive from
      brightness - The brightness difference for the new color -1.0 being 100% dark which is always black, 0.0 being no change and 1.0 being 100% lighter which is always white
    • ladder

      public static javafx.scene.paint.Color ladder(javafx.scene.paint.Color color, javafx.scene.paint.Stop[] stops)
      Get the color at the give position in the ladder of color stops
    • HSBtoRGB

      public static double[] HSBtoRGB(double hue, double saturation, double brightness)
    • RGBtoHSB

      public static double[] RGBtoHSB(double r, double g, double b)
    • convertSRGBtoLinearRGB

      public static javafx.scene.paint.Color convertSRGBtoLinearRGB(javafx.scene.paint.Color color)
      Helper function to convert a color in sRGB space to linear RGB space.
    • convertLinearRGBtoSRGB

      public static javafx.scene.paint.Color convertLinearRGBtoSRGB(javafx.scene.paint.Color color)
      Helper function to convert a color in linear RGB space to SRGB space.
    • sum

      public static double sum(double[] values)
      helper function for calculating the sum of a series of numbers
    • pointRelativeTo

      public static javafx.geometry.Point2D pointRelativeTo(javafx.scene.Node parent, javafx.scene.Node node, javafx.geometry.HPos hpos, javafx.geometry.VPos vpos, double dx, double dy, boolean reposition)
    • pointRelativeTo

      public static javafx.geometry.Point2D pointRelativeTo(javafx.scene.Node parent, double anchorWidth, double anchorHeight, javafx.geometry.HPos hpos, javafx.geometry.VPos vpos, double dx, double dy, boolean reposition)
    • pointRelativeTo

      public static javafx.geometry.Point2D pointRelativeTo(Object parent, double width, double height, double screenX, double screenY, javafx.geometry.HPos hpos, javafx.geometry.VPos vpos)
      This is the fallthrough function that most other functions fall into. It takes care specifically of the repositioning of the item such that it remains onscreen as best it can, given it's unique qualities.

      As will all other functions, this one returns a Point2D that represents an x,y location that should safely position the item onscreen as best as possible.

      Note that width and refer to the width and height of the node/popup that is needing to be repositioned, not of the parent.

      Don't use the BASELINE vpos, it doesn't make sense and would produce wrong result.

    • hasFullScreenStage

      public static boolean hasFullScreenStage(javafx.stage.Screen screen)
    • isQVGAScreen

      public static boolean isQVGAScreen()
    • getScreen

      public static javafx.stage.Screen getScreen(Object obj)
      This function attempts to determine the best screen given the parent object from which we are wanting to position another item relative to. This is particularly important when we want to keep items from going off screen, and for handling multiple monitor support.
    • getScreenForRectangle

      public static javafx.stage.Screen getScreenForRectangle(javafx.geometry.Rectangle2D rect)
    • getScreenForPoint

      public static javafx.stage.Screen getScreenForPoint(double x, double y)