Top Description Constructors Methods
com.dlsc.gemsfx.util

public Class Utils

extends Object
Class Inheritance
Imports
javafx.geometry.BoundingBox, .Bounds, .HPos, .NodeOrientation, .Point2D, .Rectangle2D, .VPos, javafx.scene.Node, .Scene, javafx.scene.paint.Color, .Stop, javafx.stage.Screen, .Stage, .Window, java.util.List

Some basic utilities which need to be in java (for shifting operations or other reasons), which are not toolkit dependent.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static double
calculateBrightness(Color color)

Calculates a perceptual brightness for a color between 0.0 black and 1.0 while

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.

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.

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.

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.

public static int
clampMax(int value, int max)

Simple utility function which clamps the given value to be strictly under the max value.

public static double
clampMin(double value, double min)

Simple utility function which clamps the given value to be strictly above the min value.

public static boolean
contains(String src, String s)

Because mobile doesn't have string.contains(s) function, this function was written.

public static Color
convertLinearRGBtoSRGB(Color color)

Helper function to convert a color in linear RGB space to SRGB space.

public static Color
convertSRGBtoLinearRGB(Color color)

Helper function to convert a color in sRGB space to linear RGB space.

public static Color
deriveColor(Color
The color to derive from
c
,
double
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
brightness
)

Derives a lighter or darker of a given color.

private static Bounds
getBounds(Object obj)

To facilitate multiple types of parent object, we unfortunately must allow for Objects to be passed in. This method handles determining the bounds of the given Object.

private static HPos
private static double
getIntersectionLength(double a0, double a1, double b0, double b1)

private static double
getIntersectionLengthImpl(double v0, double v1, double v)

private static double
getOuterDistance(double a0, double a1, double b0, double b1)

private static double
getOuterDistance(double v0, double v1, double v)

public static 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.

public static Screen
getScreenForPoint(double x, double y)

public static Screen
private static VPos
public static boolean
public static double[]
HSBtoRGB(double hue, double saturation, double brightness)

private static Color
interpolateLinear(double position, Color color1, Color color2)

interpolate at a set position between two colors color1 and color2.

public static boolean
private static Color
ladder(double position, Stop[] stops)

Get the color at the give position in the ladder of color stops

public static Color
ladder(Color color, Stop[] stops)

Get the color at the give position in the ladder of color stops

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.

public static Point2D
pointRelativeTo(Node parent, Node node, HPos hpos, VPos vpos, double dx, double dy, boolean reposition)

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

public static Point2D
pointRelativeTo(Object parent, double width, double height, double screenX, double screenY, HPos hpos, VPos vpos)

This is the fallthrough function that most other functions fall into.

private static double
positionX(Bounds parentBounds, double width, HPos hpos)

Utility function that returns the x-axis position that an object should be positioned at, given the parents screen bounds, the width of the object, and the required HPos.

private static double
positionY(Bounds parentBounds, double height, VPos vpos)

Utility function that returns the y-axis position that an object should be positioned at, given the parents screen bounds, the height of the object, and the required VPos.

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

public static String[]
split(String str, String separator)

Because mobile doesn't have string.split(s) function, this function was written.

public static String
stripQuotes(String str)

Helper to remove leading and trailing quotes from a string.

public static double
sum(double[] values)

helper function for calculating the sum of a series of numbers

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Utilsback to summary
public Utils()

Method Detail

calculateBrightnessback to summary
public static double calculateBrightness(Color color)

Calculates a perceptual brightness for a color between 0.0 black and 1.0 while

clampback to summary
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.

clampback to summary
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.

clampback to summary
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.

clampback to summary
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.

clampMaxback to summary
public static int clampMax(int value, int max)

Simple utility function which clamps the given value to be strictly under the max value.

clampMinback to summary
public static double clampMin(double value, double min)

Simple utility function which clamps the given value to be strictly above the min value.

containsback to summary
public static boolean contains(String src, String s)

Because mobile doesn't have string.contains(s) function, this function was written.

convertLinearRGBtoSRGBback to summary
public static Color convertLinearRGBtoSRGB(Color color)

Helper function to convert a color in linear RGB space to SRGB space.

convertSRGBtoLinearRGBback to summary
public static Color convertSRGBtoLinearRGB(Color color)

Helper function to convert a color in sRGB space to linear RGB space.

deriveColorback to summary
public static Color deriveColor(Color c, double brightness)

Derives a lighter or darker of a given color.

Parameters
c:Color

The color to derive from

brightness:double

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

getBoundsback to summary
private static Bounds getBounds(Object obj)

To facilitate multiple types of parent object, we unfortunately must allow for Objects to be passed in. This method handles determining the bounds of the given Object. If the Object type is not supported, a default Bounds will be returned.

getHPosOppositeback to summary
private static HPos getHPosOpposite(HPos hpos, VPos vpos)
getIntersectionLengthback to summary
private static double getIntersectionLength(double a0, double a1, double b0, double b1)
getIntersectionLengthImplback to summary
private static double getIntersectionLengthImpl(double v0, double v1, double v)
getOuterDistanceback to summary
private static double getOuterDistance(double a0, double a1, double b0, double b1)
getOuterDistanceback to summary
private static double getOuterDistance(double v0, double v1, double v)
getScreenback to summary
public static 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.

getScreenForPointback to summary
public static Screen getScreenForPoint(double x, double y)
getScreenForRectangleback to summary
public static Screen getScreenForRectangle(Rectangle2D rect)
getVPosOppositeback to summary
private static VPos getVPosOpposite(HPos hpos, VPos vpos)
hasFullScreenStageback to summary
public static boolean hasFullScreenStage(Screen screen)
HSBtoRGBback to summary
public static double[] HSBtoRGB(double hue, double saturation, double brightness)
interpolateLinearback to summary
private static Color interpolateLinear(double position, Color color1, Color color2)

interpolate at a set position between two colors color1 and color2. The interpolation is done is linear RGB color space not the default sRGB color space.

isQVGAScreenback to summary
public static boolean isQVGAScreen()
ladderback to summary
private static Color ladder(double position, Stop[] stops)

Get the color at the give position in the ladder of color stops

ladderback to summary
public static Color ladder(Color color, Stop[] stops)

Get the color at the give position in the ladder of color stops

nearestback to summary
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.

pointRelativeToback to summary
public static Point2D pointRelativeTo(Node parent, Node node, HPos hpos, VPos vpos, double dx, double dy, boolean reposition)
pointRelativeToback to summary
public static Point2D pointRelativeTo(Node parent, double anchorWidth, double anchorHeight, HPos hpos, VPos vpos, double dx, double dy, boolean reposition)
pointRelativeToback to summary
public static Point2D pointRelativeTo(Object parent, double width, double height, double screenX, double screenY, HPos hpos, 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 its 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 a wrong result.

positionXback to summary
private static double positionX(Bounds parentBounds, double width, HPos hpos)

Utility function that returns the x-axis position that an object should be positioned at, given the parents screen bounds, the width of the object, and the required HPos.

positionYback to summary
private static double positionY(Bounds parentBounds, double height, VPos vpos)

Utility function that returns the y-axis position that an object should be positioned at, given the parents screen bounds, the height of the object, and the required VPos.

The BASELINE vpos doesn't make sense here, 0 is returned for it.

RGBtoHSBback to summary
public static double[] RGBtoHSB(double r, double g, double b)
splitback to summary
public static String[] split(String str, String separator)

Because mobile doesn't have string.split(s) function, this function was written.

stripQuotesback to summary
public static String stripQuotes(String str)

Helper to remove leading and trailing quotes from a string. Works with single or double quotes.

sumback to summary
public static double sum(double[] values)

helper function for calculating the sum of a series of numbers