public class Utils
extends java.lang.Object
Constructor and Description |
---|
Utils() |
Modifier and Type | Method and Description |
---|---|
static boolean |
assertionEnabled()
*
Miscellaneous utilities *
*
|
static double |
calculateBrightness(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 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 |
contains(java.lang.String src,
java.lang.String s)
Because mobile doesn't have string.contains(s) function, this function
was written.
|
static Color |
convertLinearRGBtoSRGB(Color color)
Helper function to convert a color in linear RGB space to SRGB space.
|
static Color |
convertSRGBtoLinearRGB(Color color)
Helper function to convert a color in sRGB space to linear RGB space.
|
static java.lang.String |
convertUnicode(java.lang.String src)
*
Unicode-related utilities *
*
|
static Color |
deriveColor(Color c,
double brightness)
Derives a lighter or darker of a given color.
|
private static Bounds |
getBounds(java.lang.Object obj)
To facilitate multiple types of parent object, we unfortunately must allow for
Objects to be passed in.
|
private static HPos |
getHPosOpposite(HPos hpos,
VPos vpos) |
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 v0,
double v1,
double v) |
private static double |
getOuterDistance(double a0,
double a1,
double b0,
double b1) |
static Screen |
getScreen(java.lang.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.
|
static Screen |
getScreenForPoint(double x,
double y) |
static Screen |
getScreenForRectangle(Rectangle2D rect) |
private static VPos |
getVPosOpposite(HPos hpos,
VPos vpos) |
static boolean |
hasFullScreenStage(Screen screen) |
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 . |
static boolean |
isMac()
Returns true if the operating system is a form of Mac OS.
|
static boolean |
isQVGAScreen() |
static boolean |
isUnix()
Returns true if the operating system is a form of Unix, including Linux.
|
static boolean |
isWindows()
Returns true if the operating system is a form of Windows.
|
static Color |
ladder(Color color,
Stop[] stops)
Get the color at the give
position in the ladder of color stops |
private static Color |
ladder(double position,
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 Point2D |
pointRelativeTo(Node parent,
double anchorWidth,
double anchorHeight,
HPos hpos,
VPos vpos,
double dx,
double dy,
boolean reposition) |
static Point2D |
pointRelativeTo(Node parent,
Node node,
HPos hpos,
VPos vpos,
double dx,
double dy,
boolean reposition) |
static Point2D |
pointRelativeTo(java.lang.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.
|
static double[] |
RGBtoHSB(double r,
double g,
double b) |
static java.lang.String[] |
split(java.lang.String str,
java.lang.String separator)
Because mobile doesn't have string.split(s) function, this function
was written.
|
static java.lang.String |
stripQuotes(java.lang.String str)
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
|
public static float clamp(float min, float value, float max)
public static int clamp(int min, int value, int max)
public static double clamp(double min, double value, double max)
public static double clampMin(double value, double min)
public static int clampMax(int value, int max)
public static double nearest(double less, double value, double more)
less
or more
depending on which value
is closer to. If value
is perfectly between them, then either may be returned.public static java.lang.String stripQuotes(java.lang.String str)
public static java.lang.String[] split(java.lang.String str, java.lang.String separator)
public static boolean contains(java.lang.String src, java.lang.String s)
public static double calculateBrightness(Color color)
public static Color deriveColor(Color c, double brightness)
c
- The color to derive frombrightness
- 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 whiteprivate static Color interpolateLinear(double position, Color color1, Color color2)
position
between two colors color1
and color2
.
The interpolation is done is linear RGB color space not the default sRGB color space.private static Color ladder(double position, Stop[] stops)
position
in the ladder of color stopspublic static Color ladder(Color color, Stop[] stops)
position
in the ladder of color stopspublic static double[] HSBtoRGB(double hue, double saturation, double brightness)
public static double[] RGBtoHSB(double r, double g, double b)
public static Color convertSRGBtoLinearRGB(Color color)
public static Color convertLinearRGBtoSRGB(Color color)
public static double sum(double[] values)
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(java.lang.Object parent, double width, double height, double screenX, double screenY, HPos hpos, VPos vpos)
width
and private static double positionX(Bounds parentBounds, double width, HPos hpos)
private static double positionY(Bounds parentBounds, double height, VPos vpos)
private static Bounds getBounds(java.lang.Object obj)
public static boolean hasFullScreenStage(Screen screen)
public static boolean isQVGAScreen()
public static Screen getScreen(java.lang.Object obj)
public static Screen getScreenForRectangle(Rectangle2D rect)
public static Screen getScreenForPoint(double x, double y)
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 boolean assertionEnabled()
public static boolean isWindows()
public static boolean isMac()
public static boolean isUnix()
public static java.lang.String convertUnicode(java.lang.String src)