Interface Color


public interface Color
A numeric model of an RGB color. The components of the color instance are presented in the arithmetic notation. This means that each component accepts any fractional value from 0 to 1.

If all the components except alpha are at zero and the alpha is at 1, the result is black. If all are at 1, the result is the brightest representable white.

Important: the component values out of the 0..1 range are not allowed and should not be used.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static final class 
    A builder of Color.
  • Method Summary

    Modifier and Type
    Method
    Description
    default float
    Returns the opacity channel value in the 0..1 range.
    default float
    Returns the blue channel value in the 0..1 range.
    default float
    Returns the green channel value in the 0..1 range.
    default boolean
    Returns true if this color is a valid color.
    Creates a new Color builder with the given required parameters.
    default float
    red()
    Returns the red channel value in the 0..1 range.
    static Color
    rgb(float red, float green, float blue)
    Creates a new Color instance from the passed RGB values with opacity (alpha) channel set to 1 (non-transparent).
    static Color
    rgba(float red, float green, float blue, float alpha)
    Creates a new Color instance from the passed RGBA values.
    default String
    Returns a string representation for this color in the #RGB hex format.
    default String
    Returns a string representation for this color in the #RGBA hex format.
  • Method Details

    • newBuilder

      static Color.Builder newBuilder()
      Creates a new Color builder with the given required parameters.
      Returns:
      a new Color.Builder instance
    • rgba

      static Color rgba(float red, float green, float blue, float alpha)
      Creates a new Color instance from the passed RGBA values.
      Parameters:
      red - the red channel value in the 0..1 range
      green - the green channel value in the 0..1 range
      blue - the blue channel value in the 0..1 range
      alpha - the opacity channel value in the 0..1 range
      Returns:
      a new Color instance
      Throws:
      IllegalArgumentException - if any of the passed values is out of the 0..1 range
    • rgb

      static Color rgb(float red, float green, float blue)
      Creates a new Color instance from the passed RGB values with opacity (alpha) channel set to 1 (non-transparent).
      Parameters:
      red - the red channel value in the 0..1 range
      green - the green channel value in the 0..1 range
      blue - the blue channel value in the 0..1 range
      Returns:
      a new Color instance
      Throws:
      IllegalArgumentException - if any of the passed values is out of the 0..1 range
    • isValid

      default boolean isValid()
      Returns true if this color is a valid color. The color is valid only if its channel values are in the 0..1 range.
    • toHexRGBA

      default String toHexRGBA()
      Returns a string representation for this color in the #RGBA hex format.
      Throws:
      IllegalArgumentException - when this color is invalid
    • toHexRGB

      default String toHexRGB()
      Returns a string representation for this color in the #RGB hex format.
      Throws:
      IllegalArgumentException - when this color is invalid
    • alpha

      default float alpha()
      Returns the opacity channel value in the 0..1 range. When the value is 1, the color is 100% opaque. When 0, the color is 100% transparent.
    • blue

      default float blue()
      Returns the blue channel value in the 0..1 range.
    • green

      default float green()
      Returns the green channel value in the 0..1 range.
    • red

      default float red()
      Returns the red channel value in the 0..1 range.