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.
    • 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.
      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).
    • 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) throws DOMException
      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:
      DOMException - TYPE_MISMATCH_ERR if the value is of the wrong type.
      NullPointerException - if the index is valid but the component cannot be null.
    • getComponentCount

      public int getComponentCount()
      Get the number of components of this value.
      Returns:
      the number of components, 0 if none.
    • 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 CSSTypedValue
      Specified by:
      clone in interface CSSValue
      Specified by:
      clone in class PrimitiveValue
      Returns:
      a copy of this object.