APIdia Launch Partner
Top Description Constructors Methods
com.sun.javafx.util

public Class Utils

extends Object
Class Inheritance
Imports
javafx.application.Platform, javafx.geometry.BoundingBox, .Bounds, .HPos, .NodeOrientation, .Point2D, .Rectangle2D, .VPos, javafx.scene.Node, .Scene, javafx.scene.paint.Color, .Stop, javafx.stage.Screen, .Stage, .Window, java.math.BigDecimal, java.util.List, com.sun.javafx.PlatformUtil, com.sun.glass.utils.NativeLibLoader, com.sun.prism.impl.PrismSettings

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 boolean
assertionEnabled()

Returns: true if and only if assertions are enabled at runtime.

public static double
calculateBrightness(Color color)

Calculates a perceptual brightness for a color between 0.0 (black) and 1.0 (white).

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 BigDecimal
clamp(BigDecimal min, BigDecimal value, BigDecimal 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 String
convertUnicode(String src)

* Unicode-related utilities * *

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.

public static void
forceInit(final Class<?> classToInit)

To force initialization of a class

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(final double a0, final double a1, final double b0, final double b1)

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

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

private static double
getOuterDistance(final double v0, final double v1, final 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(final double x, final double y)

public static Screen
private static VPos
public static boolean
hasFullScreenStage(final Screen screen)

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
isMac()

Returns true if the operating system is a form of Mac OS.

public static boolean
public static boolean
isUnix()

Returns true if the operating system is a form of Unix, including Linux.

public static boolean
isWindows()

Returns true if the operating system is a form of Windows.

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

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

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

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

public static synchronized void
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 void
runOnFxThread(Runnable
a Runnable encapsulating the code
runnable
)

Ensures that a code segment is run on the FX thread.

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

assertionEnabledback to summary
public static boolean assertionEnabled()
Returns:boolean

true if and only if assertions are enabled at runtime.

calculateBrightnessback to summary
public static double calculateBrightness(Color color)

Calculates a perceptual brightness for a color between 0.0 (black) and 1.0 (white).

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.

clampback to summary
public static BigDecimal clamp(BigDecimal min, BigDecimal value, BigDecimal 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.

convertUnicodeback to summary
public static String convertUnicode(String src)

* Unicode-related utilities * *

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

forceInitback to summary
public static void forceInit(final Class<?> classToInit)

To force initialization of a class

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(final double a0, final double a1, final double b0, final double b1)
getIntersectionLengthImplback to summary
private static double getIntersectionLengthImpl(final double v0, final double v1, final double v)
getOuterDistanceback to summary
private static double getOuterDistance(final double a0, final double a1, final double b0, final double b1)
getOuterDistanceback to summary
private static double getOuterDistance(final double v0, final double v1, final 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(final double x, final double y)
getScreenForRectangleback to summary
public static Screen getScreenForRectangle(final Rectangle2D rect)
getVPosOppositeback to summary
private static VPos getVPosOpposite(HPos hpos, VPos vpos)
hasFullScreenStageback to summary
public static boolean hasFullScreenStage(final 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.

isMacback to summary
public static boolean isMac()

Returns true if the operating system is a form of Mac OS.

isQVGAScreenback to summary
public static boolean isQVGAScreen()
isUnixback to summary
public static boolean isUnix()

Returns true if the operating system is a form of Unix, including Linux.

isWindowsback to summary
public static boolean isWindows()

Returns true if the operating system is a form of Windows.

ladderback to summary
private static Color ladder(final double position, final Stop[] stops)

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

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

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

loadNativeSwingLibraryback to summary
public static synchronized void loadNativeSwingLibrary()
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 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.

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)
runOnFxThreadback to summary
public static void runOnFxThread(Runnable runnable)

Ensures that a code segment is run on the FX thread.

Parameters
runnable:Runnable

a Runnable encapsulating the code

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