Package org.testfx.util
Class ColorUtils
- java.lang.Object
-
- org.testfx.util.ColorUtils
-
public final class ColorUtils extends java.lang.Object
ContainsColor
utility methods.- See Also:
- Named Colors
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.List<javafx.util.Pair<java.lang.String,javafx.scene.paint.Color>>
NAMED_COLORS
-
Constructor Summary
Constructors Modifier Constructor Description private
ColorUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static double
calculateColorDistSq(javafx.scene.paint.Color color0, javafx.scene.paint.Color color1)
Calculates and returns the distance between twoColor
s, using a simple Euclidean metric.private static void
checkColorTriple(int r, int g, int b)
private static java.lang.String
getClosestNamedColor(int r, int g, int b)
Returns the named color that is closest to the given color, supplied as an RGB color value.static java.lang.String
getClosestNamedColor(java.lang.Integer hexColor)
Returns the named color that is closest to the given hex code color value.static javafx.scene.paint.Color
getClosestNamedColor(javafx.scene.paint.Color color)
Returns the named color that is closest to the givencolor
.private static java.util.Optional<java.lang.String>
getNamedColor(int r, int g, int b)
Returns anOptional
with a value of the named color that has exactly the given RGB color value, if it exists.static java.util.Optional<java.lang.String>
getNamedColor(java.lang.Integer hexColor)
Returns the named color that is exactly equal to the given hex code color value.static java.util.Optional<javafx.scene.paint.Color>
getNamedColor(java.lang.String name)
Returns anOptional
with a value of the namedColor
that has the givenname
, if it exists.static java.util.Optional<javafx.scene.paint.Color>
getNamedColor(javafx.scene.paint.Color color)
Returns anOptional
with a value of the namedColor
that is equal to the givencolor
, if it exists.
-
-
-
Method Detail
-
getClosestNamedColor
private static java.lang.String getClosestNamedColor(int r, int g, int b)
Returns the named color that is closest to the given color, supplied as an RGB color value.- Parameters:
r
- the red component of the color (0 - 255)g
- the green component of the color (0 - 255)b
- the blue component of the color (0 - 255)- Returns:
- the named color that is closest to the given RGB color value
-
getClosestNamedColor
public static java.lang.String getClosestNamedColor(java.lang.Integer hexColor)
Returns the named color that is closest to the given hex code color value.Only the first 6 bytes of
hexColor
are taken into account. That is two bytes for each red, blue, and green component.- Parameters:
hexColor
- theInteger
hex color value of the named color to return- Returns:
- the named color that is closest to the given
hexString
color
-
getClosestNamedColor
public static javafx.scene.paint.Color getClosestNamedColor(javafx.scene.paint.Color color)
Returns the named color that is closest to the givencolor
.- Parameters:
color
- the color to find the closest named color for- Returns:
- the named color that is closest to the given
color
-
getNamedColor
private static java.util.Optional<java.lang.String> getNamedColor(int r, int g, int b)
Returns anOptional
with a value of the named color that has exactly the given RGB color value, if it exists. Otherwise returns an emptyOptional
.- Parameters:
r
- the red component of the color (0 - 255)g
- the green component of the color (0 - 255)b
- the blue component of the color (0 - 255)- Returns:
- an
Optional<String>
that either contains the name of the color with the exact same color value or nothing (i.e. an emptyOptional
if no such named color exists
-
getNamedColor
public static java.util.Optional<javafx.scene.paint.Color> getNamedColor(java.lang.String name)
Returns anOptional
with a value of the namedColor
that has the givenname
, if it exists. Otherwise returns an emptyOptional
.- Parameters:
name
- the name of the namedColor
to return- Returns:
- an
Optional<Color>
that either contains the named color with the givenname
or nothing (i.e. an emptyOptional
if no such named color exists
-
getNamedColor
public static java.util.Optional<javafx.scene.paint.Color> getNamedColor(javafx.scene.paint.Color color)
Returns anOptional
with a value of the namedColor
that is equal to the givencolor
, if it exists. Otherwise returns an emptyOptional
.- Parameters:
color
- the color of the named color to return- Returns:
- an
Optional<Color>
that either contains the named color that is equal to the givencolor
or nothing (i.e. an emptyOptional
) if no such named color exists
-
getNamedColor
public static java.util.Optional<java.lang.String> getNamedColor(java.lang.Integer hexColor)
Returns the named color that is exactly equal to the given hex code color value.Only the first 6 bytes of
hexColor
are taken into account. That is two bytes for each red, blue, and green component.- Parameters:
hexColor
- theInteger
hex color value of the named color to return- Returns:
- an
Optional<String>
that either contains the named color that equals the givenhexColor
or nothing if no such named color exists
-
calculateColorDistSq
public static double calculateColorDistSq(javafx.scene.paint.Color color0, javafx.scene.paint.Color color1)
Calculates and returns the distance between twoColor
s, using a simple Euclidean metric.- Parameters:
color0
- the first colorcolor1
- the second color- Returns:
- the distance between the two colors
-
checkColorTriple
private static void checkColorTriple(int r, int g, int b)
-
-