Class TypedValue

All Implemented Interfaces:
CSSPrimitiveValue, CSSTypedValue, CSSValue, Serializable, Cloneable
Direct Known Subclasses:
ColorValue, ExpressionValue, FunctionValue, IdentifierValue, NumberValue, RatioValue, RectValue, StringValue, SystemDefaultValue, UnicodeRangeValue, UnicodeValue, UnicodeWildcardValue, UnknownValue

public abstract class TypedValue extends PrimitiveValue implements CSSTypedValue
Base implementation for CSS typed values.
See Also:
  • Constructor Details

  • Method Details

    • getCssValueType

      public CSSValue.CssType getCssValueType()
      Description copied from interface: CSSValue
      Get the general category to which this value belongs.
      Specified by:
      getCssValueType in interface CSSValue
      Returns:
      the general value type.
    • setFloatValue

      public void setFloatValue(short unitType, float floatValue) throws DOMException
      Description copied from interface: CSSTypedValue
      If this value is numeric, set a float value with the given unit.
      Specified by:
      setFloatValue in interface CSSTypedValue
      Parameters:
      unitType - the unit type according to CSSUnit.
      floatValue - the float value.
      Throws:
      DOMException - INVALID_ACCESS_ERR if the unit is not a CSSUnit one, or this value is not a number.
      NO_MODIFICATION_ALLOWED_ERR if this value is unmodifiable.
    • getFloatValue

      public float getFloatValue(short unitType) throws DOMException
      Description copied from interface: CSSTypedValue
      If this is a number, get its float value in the requested unit.
      Specified by:
      getFloatValue in interface CSSTypedValue
      Parameters:
      unitType - the requested unit type. If the type is CSS_OTHER, the value shall be returned as is, regardless of the unit that was set with.
      Returns:
      the float value in the requested unit.
      Throws:
      DOMException - INVALID_ACCESS_ERR if this value is not a number value or it could not be transformed to the desired unit (for example a relative value converted to an absolute one, for which a context is needed).
    • setStringValue

      public void setStringValue(CSSValue.Type stringType, String stringValue) throws DOMException
      Description copied from interface: CSSTypedValue
      If this value is a string, identifier, URI, unicode wildcard or element reference, set its value.

      The string value has to be supplied unescaped and unquoted. If it is a unicode wildcard, it must not have the preceding U+.

      Specified by:
      setStringValue in interface CSSTypedValue
      Parameters:
      stringType - the type of value.
      stringValue - the string value.
      Throws:
      DOMException - INVALID_ACCESS_ERR if the requested type of value is different to this one, or this value does not accept strings.
      NO_MODIFICATION_ALLOWED_ERR if this value is unmodifiable.
    • getStringValue

      public String getStringValue() throws DOMException
      Description copied from interface: CSSTypedValue
      If this value represents a string value, get it.

      This method is useful for values like strings, identifiers, URIs, element references, etc. For functions, it returns the function name.

      Specified by:
      getStringValue in interface CSSTypedValue
      Returns:
      the string value.
      Throws:
      DOMException - INVALID_ACCESS_ERR if this value is not a string.
    • toRGBColor

      public RGBAColor toRGBColor() throws DOMException
      Description copied from interface: CSSTypedValue
      If this value represents a color, get it or transform to a RGB color.

      If the color does not map into the sRGB gamut, it is clamped.

      Specified by:
      toRGBColor in interface CSSTypedValue
      Returns:
      the RGBA color.
      Throws:
      DOMException - INVALID_ACCESS_ERR: if this value can't return a RGB color value (either is not a COLOR or not a typed value).
      NOT_SUPPORTED_ERR: if the conversion needs device color space information to be performed accurately.
    • isCalculatedNumber

      public boolean isCalculatedNumber()
      Description copied from interface: CSSTypedValue
      Test whether this is a numeric value that was the result of a calc() expression.
      Specified by:
      isCalculatedNumber in interface CSSTypedValue
      Returns:
      true if this is a numeric value, and it was produced as the output of a calculation (instead of declared as a plain, constant numeric value).
    • isNumberZero

      public boolean isNumberZero()
      Is this value a number set to a value of zero, or an absolute value less than 1e-5 ?
      Specified by:
      isNumberZero in interface CSSTypedValue
      Returns:
      true if this is a number and is set to zero (or equivalently small value).
    • getComponent

      public StyleValue getComponent(int index)
      Get the component at index.

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

      Parameters:
      index - the index. For colors, index 0 is always the alpha channel.
      Returns:
      the component, or null if the index is incorrect.
    • setComponent

      public void setComponent(int index, StyleValue component)
      If this value has components, set the 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).

      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 component. Cannot be a KEYWORD nor a SHORTHAND. For colors, must be a primitive value (that is, either TYPED or a PROXY).
      Throws:
      NullPointerException - if the index is valid but the component is null.
    • clone

      public abstract TypedValue clone()
      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 CSSValue
      Specified by:
      clone in class PrimitiveValue
      Returns:
      a copy of this object.