Class Color

All Implemented Interfaces:
IElement, IColor

public final class Color extends AbstractElement implements IColor
A Color is not mutable.
Author:
Silvan Wyss
  • Field Details

  • Method Details

    • createAverageFrom

      public static Color createAverageFrom(IColor color, IColor... colors)
    • createAverageFrom

      public static Color createAverageFrom(IContainer<IColor> colors)
    • fromColor

      public static Color fromColor(IColor color)
      Parameters:
      color -
      Returns:
      a new Color from the given color.
      Throws:
      NullPointerException - if the given color is null.
    • fromLong

      public static Color fromLong(long pLong)
      Parameters:
      pLong -
      Returns:
      a new Color from the given pLong.
      Throws:
      RuntimeException - if the given pLong does not represent a Color.
    • fromSpecification

      public static Color fromSpecification(INode<?> specification)
      Parameters:
      specification -
      Returns:
      a new Color from the given specification
      Throws:
      RuntimeException - if the given specification is not valid.
    • fromString

      public static Color fromString(String string)
      Parameters:
      string -
      Returns:
      a new Color from the given string.
      Throws:
      RuntimeException - if the given string does not represent a Color.
    • withRedValueAndGreenValueAndBlueValue

      public static Color withRedValueAndGreenValueAndBlueValue(int redValue, int greenValue, int blueValue)
      Parameters:
      redValue -
      greenValue -
      blueValue -
      Returns:
      a new Color with the given redValue, greenValue and blueValue.
      Throws:
      RuntimeException - if the given blueValue is not a true color component (in [0, 255]).
      RuntimeException - if the given greenValue is not a true color component (in [0, 255]).
      RuntimeException - if the given blueValue is not a true color component (in [0, 255]).
    • withRedValueAndGreenValueAndBlueValueAndAlphaValue

      public static Color withRedValueAndGreenValueAndBlueValueAndAlphaValue(int redValue, int greenValue, int blueValue, int alphaValue)
      Parameters:
      redValue -
      greenValue -
      blueValue -
      alphaValue -
      Returns:
      a new Color with the given redValue, greenValue, blueValue and alphaValue.
      Throws:
      RuntimeException - if the given blueValue is not a true color component (in [0, 255]).
      RuntimeException - if the given greenValue is not a true color component (in [0, 255]).
      RuntimeException - if the given blueValue is not a true color component (in [0, 255]).
      RuntimeException - if the given alphaValue is not a true color component (in [0, 255]).
    • getAlphaPercentage

      public double getAlphaPercentage()
      Specified by:
      getAlphaPercentage in interface IColor
      Returns:
      the alpha value of the current IColor as percentage. A percentage is a number in the range [0.0, 1.0].
    • getAlphaValue

      public int getAlphaValue()
      Specified by:
      getAlphaValue in interface IColor
      Returns:
      the alpha value of the current IColor.
    • getAttributes

      public IContainer<INode<?>> getAttributes()
      Specified by:
      getAttributes in interface IElement
      Returns:
      the attributes of the current IElement.
    • getBluePercentage

      public double getBluePercentage()
      Specified by:
      getBluePercentage in interface IColor
      Returns:
      the blue value of the current IColor as percentage. A percentage is a number in the range [0.0, 1.0].
    • getBlueValue

      public int getBlueValue()
      Specified by:
      getBlueValue in interface IColor
      Returns:
      the blue value of the current IColor.
    • getColorNameOrHexadecimalString

      public String getColorNameOrHexadecimalString()
      Specified by:
      getColorNameOrHexadecimalString in interface IColor
      Returns:
      the color name or a hexadecimal String representation of the current IColor.
    • getGreenPercentage

      public double getGreenPercentage()
      Specified by:
      getGreenPercentage in interface IColor
      Returns:
      the green value of the current IColor as percentage. A percentage is a number in the range [0.0, 1.0].
    • getGreenValue

      public int getGreenValue()
      Specified by:
      getGreenValue in interface IColor
      Returns:
      the green value of the current IColor.
    • getInvertedColor

      public Color getInvertedColor()
      The inverted IColor of a IColor has the same alpha value.
      Specified by:
      getInvertedColor in interface IColor
      Returns:
      the inverted IColor of the current IColor.
    • getRedPercentage

      public double getRedPercentage()
      Specified by:
      getRedPercentage in interface IColor
      Returns:
      the red value of the current IColor as percentage. A percentage is a number in the range [0.0, 1.0].
    • getRedValue

      public int getRedValue()
      Specified by:
      getRedValue in interface IColor
      Returns:
      the red value of the current IColor.
    • hasFullAlphaValue

      public boolean hasFullAlphaValue()
      Specified by:
      hasFullAlphaValue in interface IColor
      Returns:
      true if the current IColor has a full alpha value, false otherwise.
    • hasFullBlueValue

      public boolean hasFullBlueValue()
      Specified by:
      hasFullBlueValue in interface IColor
      Returns:
      true if the current IColor has a full blue value, false otherwise.
    • hasFullGreenValue

      public boolean hasFullGreenValue()
      Specified by:
      hasFullGreenValue in interface IColor
      Returns:
      true if the current IColor has a full green value, false otherwise.
    • hasFullRedValue

      public boolean hasFullRedValue()
      Specified by:
      hasFullRedValue in interface IColor
      Returns:
      true if the current IColor has a full red value, false otherwise.
    • toAlphaRedGreenBlueInt

      public int toAlphaRedGreenBlueInt()
      Specified by:
      toAlphaRedGreenBlueInt in interface IColor
      Returns:
      an integer representation of the current IColor with the schema alpha-red-green-blue.
    • toHexadecimalString

      public String toHexadecimalString()
      Specified by:
      toHexadecimalString in interface IColor
      Returns:
      a hexadecimal String representation of the current IColor.
    • toHexadecimalStringWithAlphaValue

      public String toHexadecimalStringWithAlphaValue()
      Specified by:
      toHexadecimalStringWithAlphaValue in interface IColor
      Returns:
      a hexadecimal with alpha value String representation of the current IColor.
    • toLong

      public long toLong()
      Specified by:
      toLong in interface IColor
      Returns:
      a long representation of the current IColor.
    • withFloatingPointAlphaValue

      public IColor withFloatingPointAlphaValue(double floatingPointAlphaValue)
      Specified by:
      withFloatingPointAlphaValue in interface IColor
      Parameters:
      floatingPointAlphaValue -
      Returns:
      a new IColor from the current IColor with the given floatingPointAlphaValue.
    • withFullAlphaValue

      public Color withFullAlphaValue()
      Specified by:
      withFullAlphaValue in interface IColor
      Returns:
      a new IColor from the current IColor with a full alpha value.
    • withAlphaValue

      public Color withAlphaValue(int alphaValue)
      Specified by:
      withAlphaValue in interface IColor
      Parameters:
      alphaValue -
      Returns:
      a new IColor from the current IColor with the given alphaValue.