Class ColorUtils

java.lang.Object
org.testfx.util.ColorUtils

public final class ColorUtils extends Object
Contains Color utility methods.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final List<javafx.util.Pair<String,javafx.scene.paint.Color>>
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    calculateColorDistSq(javafx.scene.paint.Color color0, javafx.scene.paint.Color color1)
    Calculates and returns the distance between two Colors, using a simple Euclidean metric.
    private static void
    checkColorTriple(int r, int g, int b)
     
    private static 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 String
    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 given color.
    private static Optional<String>
    getNamedColor(int r, int g, int b)
    Returns an Optional with a value of the named color that has exactly the given RGB color value, if it exists.
    Returns the named color that is exactly equal to the given hex code color value.
    static Optional<javafx.scene.paint.Color>
    Returns an Optional with a value of the named Color that has the given name, if it exists.
    static Optional<javafx.scene.paint.Color>
    getNamedColor(javafx.scene.paint.Color color)
    Returns an Optional with a value of the named Color that is equal to the given color, if it exists.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • NAMED_COLORS

      private static final List<javafx.util.Pair<String,javafx.scene.paint.Color>> NAMED_COLORS
  • Constructor Details

    • ColorUtils

      private ColorUtils()
  • Method Details

    • getClosestNamedColor

      private static 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 String getClosestNamedColor(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 - the Integer 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 given color.
      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 Optional<String> getNamedColor(int r, int g, int b)
      Returns an Optional with a value of the named color that has exactly the given RGB color value, if it exists. Otherwise returns an empty Optional.
      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 empty Optional if no such named color exists
    • getNamedColor

      public static Optional<javafx.scene.paint.Color> getNamedColor(String name)
      Returns an Optional with a value of the named Color that has the given name, if it exists. Otherwise returns an empty Optional.
      Parameters:
      name - the name of the named Color to return
      Returns:
      an Optional<Color> that either contains the named color with the given name or nothing (i.e. an empty Optional if no such named color exists
    • getNamedColor

      public static Optional<javafx.scene.paint.Color> getNamedColor(javafx.scene.paint.Color color)
      Returns an Optional with a value of the named Color that is equal to the given color, if it exists. Otherwise returns an empty Optional.
      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 given color or nothing (i.e. an empty Optional) if no such named color exists
    • getNamedColor

      public static Optional<String> getNamedColor(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 - the Integer hex color value of the named color to return
      Returns:
      an Optional<String> that either contains the named color that equals the given hexColor 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 two Colors, using a simple Euclidean metric.
      Parameters:
      color0 - the first color
      color1 - the second color
      Returns:
      the distance between the two colors
    • checkColorTriple

      private static void checkColorTriple(int r, int g, int b)