Class Utils
java.lang.Object
com.dlsc.gemsfx.util.Utils
Some basic utilities which need to be in java (for shifting operations or
other reasons), which are not toolkit dependent.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doublecalculateBrightness(javafx.scene.paint.Color color) Calculates a perceptual brightness for a color between0.0and1.0.static doubleclamp(double min, double value, double max) Clamps the given value to the inclusive range betweenminandmax.static floatclamp(float min, float value, float max) Clamps the given value to the inclusive range betweenminandmax.static intclamp(int min, int value, int max) Clamps the given value to the inclusive range betweenminandmax.static longclamp(long min, long value, long max) Clamps the given value to the inclusive range betweenminandmax.static intclampMax(int value, int max) Clamps the given value to be at mostmax.static doubleclampMin(double value, double min) Clamps the given value to be at leastmin.static booleanChecks whether the source string contains the given substring.static javafx.scene.paint.ColorconvertLinearRGBtoSRGB(javafx.scene.paint.Color color) Converts a color from linear RGB space to sRGB space.static javafx.scene.paint.ColorconvertSRGBtoLinearRGB(javafx.scene.paint.Color color) Converts a color from sRGB space to linear RGB space.static javafx.scene.paint.ColorderiveColor(javafx.scene.paint.Color c, double brightness) Derives a lighter or darker version of a given color.static javafx.stage.ScreenDetermines the best screen for the given object.static javafx.stage.ScreengetScreenForPoint(double x, double y) Determines the best screen for the given point.static javafx.stage.ScreengetScreenForRectangle(javafx.geometry.Rectangle2D rect) Determines the best screen for the given rectangle.static booleanhasFullScreenStage(javafx.stage.Screen screen) Checks whether the given screen currently shows a full-screen stage.static double[]HSBtoRGB(double hue, double saturation, double brightness) Converts HSB values to RGB values.static booleanReturns whether the primary screen has QVGA dimensions.static javafx.scene.paint.Colorladder(javafx.scene.paint.Color color, javafx.scene.paint.Stop[] stops) Returns the ladder color for the given base color and stops.static doublenearest(double less, double value, double more) Returns eitherlessormore, depending on which one is closer tovalue.static javafx.geometry.Point2DpointRelativeTo(Object parent, double width, double height, double screenX, double screenY, javafx.geometry.HPos hpos, javafx.geometry.VPos vpos) Repositions an item relative to its parent while keeping it on screen whenever possible.static javafx.geometry.Point2DpointRelativeTo(javafx.scene.Node parent, double anchorWidth, double anchorHeight, javafx.geometry.HPos hpos, javafx.geometry.VPos vpos, double dx, double dy, boolean reposition) Computes a point for positioning content relative to its parent.static javafx.geometry.Point2DpointRelativeTo(javafx.scene.Node parent, javafx.scene.Node node, javafx.geometry.HPos hpos, javafx.geometry.VPos vpos, double dx, double dy, boolean reposition) Computes a point for positioning a node relative to its parent.static double[]RGBtoHSB(double r, double g, double b) Converts RGB values to HSB values.static String[]Splits the given string using the specified separator.static StringstripQuotes(String str) Removes leading and trailing quotes from a string.static doublesum(double[] values) Calculates the average of the given values.
-
Constructor Details
-
Utils
public Utils()
-
-
Method Details
-
clamp
public static float clamp(float min, float value, float max) Clamps the given value to the inclusive range betweenminandmax.- Parameters:
min- the minimum allowed valuevalue- the value to clampmax- the maximum allowed value- Returns:
- the clamped value
-
clamp
public static int clamp(int min, int value, int max) Clamps the given value to the inclusive range betweenminandmax.- Parameters:
min- the minimum allowed valuevalue- the value to clampmax- the maximum allowed value- Returns:
- the clamped value
-
clamp
public static double clamp(double min, double value, double max) Clamps the given value to the inclusive range betweenminandmax.- Parameters:
min- the minimum allowed valuevalue- the value to clampmax- the maximum allowed value- Returns:
- the clamped value
-
clamp
public static long clamp(long min, long value, long max) Clamps the given value to the inclusive range betweenminandmax.- Parameters:
min- the minimum allowed valuevalue- the value to clampmax- the maximum allowed value- Returns:
- the clamped value
-
clampMin
public static double clampMin(double value, double min) Clamps the given value to be at leastmin.- Parameters:
value- the value to clampmin- the minimum allowed value- Returns:
- the clamped value
-
clampMax
public static int clampMax(int value, int max) Clamps the given value to be at mostmax.- Parameters:
value- the value to clampmax- the maximum allowed value- Returns:
- the clamped value
-
nearest
public static double nearest(double less, double value, double more) Returns eitherlessormore, depending on which one is closer tovalue.- Parameters:
less- the lower candidate valuevalue- the value to compare againstmore- the upper candidate value- Returns:
- the nearest candidate value
-
stripQuotes
-
split
-
contains
-
calculateBrightness
public static double calculateBrightness(javafx.scene.paint.Color color) Calculates a perceptual brightness for a color between0.0and1.0.- Parameters:
color- the color to analyze- Returns:
- the calculated brightness
-
deriveColor
public static javafx.scene.paint.Color deriveColor(javafx.scene.paint.Color c, double brightness) Derives a lighter or darker version of a given color.- Parameters:
c- the color to derive frombrightness- the brightness difference, where-1.0is black,0.0means no change, and1.0is white- Returns:
- the derived color
-
ladder
public static javafx.scene.paint.Color ladder(javafx.scene.paint.Color color, javafx.scene.paint.Stop[] stops) Returns the ladder color for the given base color and stops.- Parameters:
color- the base colorstops- the ladder stops- Returns:
- the ladder color
-
HSBtoRGB
public static double[] HSBtoRGB(double hue, double saturation, double brightness) Converts HSB values to RGB values.- Parameters:
hue- the hue valuesaturation- the saturation valuebrightness- the brightness value- Returns:
- the RGB values
-
RGBtoHSB
public static double[] RGBtoHSB(double r, double g, double b) Converts RGB values to HSB values.- Parameters:
r- the red componentg- the green componentb- the blue component- Returns:
- the HSB values
-
convertSRGBtoLinearRGB
public static javafx.scene.paint.Color convertSRGBtoLinearRGB(javafx.scene.paint.Color color) Converts a color from sRGB space to linear RGB space.- Parameters:
color- the color to convert- Returns:
- the converted color
-
convertLinearRGBtoSRGB
public static javafx.scene.paint.Color convertLinearRGBtoSRGB(javafx.scene.paint.Color color) Converts a color from linear RGB space to sRGB space.- Parameters:
color- the color to convert- Returns:
- the converted color
-
sum
public static double sum(double[] values) Calculates the average of the given values.- Parameters:
values- the values to average- Returns:
- the calculated average
-
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) Computes a point for positioning a node relative to its parent.- Parameters:
parent- the parent nodenode- the node to positionhpos- the horizontal positionvpos- the vertical positiondx- the horizontal offsetdy- the vertical offsetreposition- whether the point should be adjusted to remain on screen- Returns:
- the computed point
-
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) Computes a point for positioning content relative to its parent.- Parameters:
parent- the parent nodeanchorWidth- the width of the content to positionanchorHeight- the height of the content to positionhpos- the horizontal positionvpos- the vertical positiondx- the horizontal offsetdy- the vertical offsetreposition- whether the point should be adjusted to remain on screen- Returns:
- the computed point
-
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) Repositions an item relative to its parent while keeping it on screen whenever possible.- Parameters:
parent- the parent objectwidth- the width of the item to positionheight- the height of the item to positionscreenX- the initial x coordinatescreenY- the initial y coordinatehpos- the horizontal positionvpos- the vertical position- Returns:
- the computed point
-
hasFullScreenStage
public static boolean hasFullScreenStage(javafx.stage.Screen screen) Checks whether the given screen currently shows a full-screen stage.- Parameters:
screen- the screen to inspect- Returns:
trueif a full-screen stage is shown on the screen
-
isQVGAScreen
public static boolean isQVGAScreen()Returns whether the primary screen has QVGA dimensions.- Returns:
trueif the primary screen uses QVGA dimensions
-
getScreen
Determines the best screen for the given object.- Parameters:
obj- the object to inspect- Returns:
- the best matching screen
-
getScreenForRectangle
public static javafx.stage.Screen getScreenForRectangle(javafx.geometry.Rectangle2D rect) Determines the best screen for the given rectangle.- Parameters:
rect- the rectangle to inspect- Returns:
- the best matching screen
-
getScreenForPoint
public static javafx.stage.Screen getScreenForPoint(double x, double y) Determines the best screen for the given point.- Parameters:
x- the x coordinatey- the y coordinate- Returns:
- the best matching screen
-