Class AbstractModeledColor<C extends Enum<C> & ModeledColor.Component>

java.lang.Object
io.guise.framework.style.AbstractModeledColor<C>
Type Parameters:
C - The type of color component for this color space.
All Implemented Interfaces:
Color, ModeledColor<C>
Direct Known Subclasses:
HSLColor, RGBColor

public abstract class AbstractModeledColor<C extends Enum<C> & ModeledColor.Component> extends Object implements ModeledColor<C>
Abstract representation of a color value in a color space.
Author:
Garret Wilson
See Also:
  • Constructor Details

    • AbstractModeledColor

      public AbstractModeledColor(double... values)
      Constructs a color with the given components.
      Parameters:
      values - The values of components of the color in the correct color space, each within the range (0.0-1.0), in the order of the component ordinals.
      Throws:
      NullPointerException - if the components is null. TODO fix @throws IllegalArgumentException if the number of component values do not equal the number of components.
  • Method Details

    • getValues

      public double[] getValues()
      Returns:
      The color component values, each within the range (0.0-1.0).
    • checkComponentValue

      protected static double checkComponentValue(double value)
      Checks the range of a given color component.
      Parameters:
      value - The value to check.
      Returns:
      The checked value.
      Throws:
      IllegalArgumentException - if the given component is outside the range (0.0-1.0).
    • getComponent

      public double getComponent(C component)
      Description copied from interface: ModeledColor
      Determines the value of the given color component.
      Specified by:
      getComponent in interface ModeledColor<C extends Enum<C> & ModeledColor.Component>
      Parameters:
      component - The color component for which a value should be retrieved.
      Returns:
      The value of the requested color component.
    • getAbsoluteComponent

      public long getAbsoluteComponent(C component, int bitDepth)
      Description copied from interface: ModeledColor
      Determines the absolute value of the given color component with the given bit depth. For example, retrieving a component with value 0.5 and a bit depth of 16 would produce 128 or 0x80.
      Specified by:
      getAbsoluteComponent in interface ModeledColor<C extends Enum<C> & ModeledColor.Component>
      Parameters:
      component - The color component for which a value should be retrieved.
      bitDepth - The number of bits to use for the given color component.
      Returns:
      The absolute value of the requested color component at the given bit depth.
      See Also:
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object object)

      This implementation returns whether the objects are of the same class with identical color component values.

      Overrides:
      equals in class Object
    • valueOf

      public static Color valueOf(CharSequence charSequence)
      Creates a color from a string representation. This representation can be in one of the following forms:
      • colorname, one of the HTML color names, which must be in all lowercase without delimiters, such as "aliceblue".
      • #rgb, with hexadecimal representation of RGB color components without regard to case.
      • #rrggbb, with hexadecimal representation of RGB color components without regard to case.
      • rgb(red,green,blue), with decimal representation with a depth of eight bits (0-255).
      • rgb(red%,green%,blue%), with decimal component values multiplied by 100 (0.0-100.0%).
      • rgba(red,green,blue,alpha), with decimal representation with a depth of eight bits (0-255).
      • rgba(red%,green%,blue%,alpha%), with decimal component values multiplied by 100 (0.0%-100.0%).
      • hsl(hue,saturation,lightness), with decimal representation with a depth of eight bits (0-255).
      • hsl(hue%,saturation%,lightness%), with decimal component values multiplied by 100 (0.0-100.0%).
      This method also recognizes the transparent color name as equivalent to rgba(0, 0, 0, 0), or black with zero alpha.
      Parameters:
      charSequence - The character sequence representation of a color.
      Returns:
      A color object representing the color represented by the given string.
      Throws:
      NullPointerException - if the given string is null.
      IllegalArgumentException - if a color cannot be determined from the given string.
      See Also: