Class ColorValue

All Implemented Interfaces:
CSSColorValue, CSSPrimitiveValue, CSSTypedValue, CSSValue, Serializable, Cloneable
Direct Known Subclasses:
HSLColorValue, HWBColorValue, LABColorValue, LCHColorValue, RGBColorValue

public abstract class ColorValue extends TypedValue implements CSSColorValue
Color value.
See Also:
  • Method Details

    • setSystemDefault

      public void setSystemDefault()
    • isSystemDefault

      public boolean isSystemDefault()
      Description copied from class: StyleValue
      Is this value a wildcard for a system-dependent default?

      If that is the case, it cannot be used to compute values.

      Overrides:
      isSystemDefault in class StyleValue
      Returns:
      true if this is a placeholder for a system-dependent default, false otherwise.
    • setCssText

      public void setCssText(String cssText) throws DOMException
      Description copied from class: StyleValue
      Attempts to change this value to match the supplied css text.

      In css4j, it is not recommended to set property values using this method.

      Specified by:
      setCssText in interface CSSValue
      Overrides:
      setCssText in class StyleValue
      Parameters:
      cssText - the text value.
      Throws:
      DOMException - SYNTAX_ERR: Raised if the specified CSS string value has a syntax error (according to the attached property) or is unparsable.
      INVALID_MODIFICATION_ERR: Raised if the specified CSS string value represents a different type of values than the values allowed by the CSS property.
      NO_MODIFICATION_ALLOWED_ERR: Raised if this value is read-only.
    • getCssText

      public String getCssText()
      Description copied from class: StyleValue
      Get a string representation of the current value.
      Specified by:
      getCssText in interface CSSValue
      Specified by:
      getCssText in class StyleValue
      Returns:
      the css text representing the value of this property.
    • getMinifiedCssText

      public String getMinifiedCssText(String propertyValue)
      Description copied from interface: CSSValue
      Gives a minified version of the css text of the property.

      It may be customized for the given property name.

      Specified by:
      getMinifiedCssText in interface CSSValue
      Overrides:
      getMinifiedCssText in class StyleValue
      Parameters:
      propertyValue - the property name.
      Returns:
      the minified css text.
    • writeCssText

      public void writeCssText(io.sf.carte.util.SimpleWriter wri) throws IOException
      Description copied from interface: CSSValue
      Serialize this value to a SimpleWriter.
      Specified by:
      writeCssText in interface CSSValue
      Parameters:
      wri - the SimpleWriter.
      Throws:
      IOException - if an error happened while writing.
    • deltaE2000

      public float deltaE2000(CSSColorValue color)
      Description copied from interface: CSSColorValue
      Compute the difference to the given color, according to CIE Delta E 2000.
      Specified by:
      deltaE2000 in interface CSSColorValue
      Parameters:
      color - the color to compute the delta from.
      Returns:
      the CIE Delta E 2000.
    • setComponent

      public void setComponent(int index, StyleValue component)
      Set the color component at index.

      This method allows to access the components regardless of them being formally indexed or not. It is convenient to perform common tasks at the components (like when computing values).

      Overrides:
      setComponent in class TypedValue
      Parameters:
      index - the index. For colors, index 0 is always the alpha channel. Setting a component at an index that does not exist has no effect.
      component - the new color component. Must be a primitive value (that is, either TYPED or a PROXY).
      Throws:
      NullPointerException - if the index is valid but the component is null.
    • getComponent

      public abstract PrimitiveValue getComponent(int index)
      Get the color component at index.

      This method allows to access the color components like if they were indexed. It is convenient to perform common tasks at the components (like when computing values).

      Overrides:
      getComponent in class TypedValue
      Parameters:
      index - the index. Index 0 is always the alpha channel.
      Returns:
      the color component, or null if the index is incorrect.
    • clone

      public abstract ColorValue clone()
      Description copied from class: TypedValue
      Creates and returns a copy of this object.

      The object will be the same except for the subproperty flag, that will be disabled in the clone object.

      Specified by:
      clone in interface CSSColorValue
      Specified by:
      clone in interface CSSValue
      Specified by:
      clone in class TypedValue
      Returns:
      a copy of this object.
    • toHSLColorValue

      public HSLColorValue toHSLColorValue() throws DOMException
      Convert this value to a HSLColorValue, if possible.
      Returns:
      the converted HSLColorValue.
      Throws:
      DOMException - INVALID_STATE_ERR if the components cannot be converted.
    • toLABColorValue

      public LABColorValue toLABColorValue() throws DOMException
      Convert this value to a LABColorValue, if possible.
      Specified by:
      toLABColorValue in interface CSSColorValue
      Returns:
      the converted LABColorValue.
      Throws:
      DOMException - INVALID_STATE_ERR if the components cannot be converted.
    • toLCHColorValue

      public LCHColorValue toLCHColorValue() throws DOMException
      Description copied from interface: CSSColorValue
      Convert this value to a LCHColorValue, if possible.
      Specified by:
      toLCHColorValue in interface CSSColorValue
      Returns:
      the converted LCHColorValue.
      Throws:
      DOMException - INVALID_STATE_ERR if the components cannot be converted.