Class SFColorRGBA

java.lang.Object
org.web3d.x3d.jsail.fields.X3DConcreteField
org.web3d.x3d.jsail.fields.SFColorRGBA
All Implemented Interfaces:
SFColorRGBA, X3DField

public class SFColorRGBA extends X3DConcreteField implements SFColorRGBA
This utility class provides a concrete implementation corresponding to SFColorRGBA X3D field type.


Note that SFColor provides a variety of color constants.

Package hint: This specification class is defined by the X3D Java Language Binding Specification for the Scene Authoring Interface (SAI). SFColorRGBA specifies one RGBA (red-green-blue-alpha) color 4-tuple, where each color value is an RGBA 4-tuple of floating point numbers in range [0,1]. Alpha (opacity) values = (1 - transparency). The default value of an uninitialized SFColorRGBA field is (0 0 0 0). Warning: comma characters within singleton values do not pass strict XML validation.

Related field object: MFColorRGBA
See Also:
X3D Tooltips: type SFColorRGBA, SAI Java Specification: B.4.11 X3DFieldTypes, SAI Abstract Specification: 5.2.15 SAIFieldType, X3D Abstract Specification: SFColorRGBAAndMFColorRGBA, X3D Tooltips, X3D Tooltips: field, X3D Tooltips: fieldValue, X3D Scene Authoring Hints * @see CSS Color Module Level 3, 4.3. Extended color keywords
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static float[]
    Default value for this field type is 0 0 0 0.
    static String
    Default string value for this field type is "0 0 0 0".
    static String
    String constant NAME provides name of this element: SFColorRGBA
    static Pattern
    Precompiled regular expression (regex) pattern for this field type using default REGEX value.
    static String
    Default regular expression (regex) pattern for this field type is (\s)*(([+-]?
    static int
    Default tuple size for this field type is 4 (i.e. number of component values making up a single-field SF object).

    Fields inherited from class org.web3d.x3d.jsail.fields.X3DConcreteField

    validationResult
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor for SFColorRGBA performs value initialization.
    SFColorRGBA​(double[] newValue)
    Utility constructor for SFColorRGBA using an alternatively typed Java double[] array as new initial value.
    SFColorRGBA​(double red, double green, double blue, double alpha)
    Constructor using individual double types as new initial value (which must pass validation checks).
    SFColorRGBA​(float[] newValue)
    Constructor for SFColorRGBA using a corresponding Java primitive float[] array as new initial value.
    SFColorRGBA​(float red, float green, float blue, float alpha)
    Constructor using individual float types as new initial value (which must pass validation checks).
    SFColorRGBA​(int hexColorValue, float alpha)
    Constructor using single HTML-style 0xRRGGBB hex value as new initial value.
    SFColorRGBA​(SFColorRGBA newValue)
    Constructor to copy an SFColorRGBA value as initial value for this new field object.
  • Method Summary

    Modifier and Type
    Method
    Description
    Complement alpha value by subtracting it from 1, note transparency = (1 - alpha).
    Complement all color values in RGB space (i.e. subtract each component from 1), with no change in alpha.
    boolean
    equals​(SFColorRGBA comparisonSFColorRGBA)
    Determine whether two objects contain equal values.
    float[]
    Provides current value of the field as a Java primitive type.
    void
    getValue​(float[] valueDestination)
    Get the current value of this SFColorRGBA by copying it into the valueDestination array, leaving the current object unchanged.
    void
    Initialization for SFColorRGBA applies default initial value.
    static boolean
    Whether or not this field type is an array (false)
    boolean
    Determine whether current value matches DEFAULT_VALUE
    boolean
    Test PATTERN match via regular expression (regex) check of current object's toString() value.
    static boolean
    matches​(String value)
    Test PATTERN match with regular expression (regex) of provided value.
    Ensure all component color values are within range [0-1] by clipping as necessary.
    setTransparency​(double newTransparency)
    Utility method to modify transparency
    setTransparency​(float newTransparency)
    Utility method to modify transparency
    setValue​(double[] newValue)
    Assign a new value to this field.
    setValue​(double red, double green, double blue, double alpha)
    Assign a new value to this field.
    void
    setValue​(float[] newValue)
    Assign a new value to this field.
    setValue​(float red, float green, float blue, float alpha)
    Assign a new value to this field.
    setValue​(int hexColorValue, float alpha)
    Public utility accessor method setting single HTML-style 0xRRGGBB hex value as new value.
    setValue​(SFColorRGBA newValue)
    Apply an SFColorRGBA value to this field.
    setValueArray​(float[] newValue)
    Assign a new array value to this field, pipelined.
    setValueByString​(String newValue)
    Utility accessor for SFColorRGBA using String value (which must pass parsing validation checks).
    float[]
    Provide float array for this field type.
    Provides current value as a String.
    static String
    toString​(float[] value)
    Static utility method to provide String representation of a correctly typed input value.
    Validate current value via get/set comparison tests
    Validate current value via regular expression (regex) check of current object's toString() value, reporting errors only if found.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • SFColorRGBA

      public SFColorRGBA()
      Constructor for SFColorRGBA performs value initialization.
    • SFColorRGBA

      public SFColorRGBA(SFColorRGBA newValue)
      Constructor to copy an SFColorRGBA value as initial value for this new field object.
      Parameters:
      newValue - The newValue to apply
    • SFColorRGBA

      public SFColorRGBA(float[] newValue)
      Constructor for SFColorRGBA using a corresponding Java primitive float[] array as new initial value.
      Parameters:
      newValue - is new value to assign Warning: newValue array length must correspond to tuple size for base type SFColorRGBA tuple size of 4. setContainerFieldOverride(containerFieldName); // apply checksConcreteField#getTupleSize(String)
    • SFColorRGBA

      public SFColorRGBA(float red, float green, float blue, float alpha)
      Constructor using individual float types as new initial value (which must pass validation checks).
      Parameters:
      red - first component [0..1]
      green - second component [0..1]
      blue - third component [0..1]
      alpha - fourth component for opaqueness (1 - transparency) [0..1]
    • SFColorRGBA

      public SFColorRGBA(double red, double green, double blue, double alpha)
      Constructor using individual double types as new initial value (which must pass validation checks).
      Parameters:
      red - first component [0..1]
      green - second component [0..1]
      blue - third component [0..1]
      alpha - fourth component for opaqueness (1 - transparency) [0..1]
    • SFColorRGBA

      public SFColorRGBA(int hexColorValue, float alpha)
      Constructor using single HTML-style 0xRRGGBB hex value as new initial value.
      Parameters:
      hexColorValue - HTML color value (such as 0xAA2288)
      alpha - fourth component for opaqueness (1 - transparency)
    • SFColorRGBA

      public SFColorRGBA(double[] newValue)
      Utility constructor for SFColorRGBA using an alternatively typed Java double[] array as new initial value.
      Parameters:
      newValue - is new value to assign
  • Method Details

    • isArray

      public static final boolean isArray()
      Whether or not this field type is an array (false)
      Returns:
      true if array type
    • initialize

      public final void initialize()
      Initialization for SFColorRGBA applies default initial value. Static initializer also provided to verify that the regex pattern compiles and matches that default value.
      Specified by:
      initialize in class X3DConcreteField
      See Also:
      Stack Overflow: How to check if a given Regex is valid?, DEFAULT_VALUE
    • equals

      public boolean equals(SFColorRGBA comparisonSFColorRGBA)
      Determine whether two objects contain equal values.
      Parameters:
      comparisonSFColorRGBA - field type to compare
      Returns:
      true if equivalent, false otherwise
    • validate

      public final String validate()
      Validate current value via get/set comparison tests
      Returns:
      empty string if get/set testing passes, warning otherwise
      See Also:
      validate(), validateRegex()
    • validateRegex

      public final String validateRegex()
      Validate current value via regular expression (regex) check of current object's toString() value, reporting errors only if found.
      Returns:
      empty string if PATTERN matches, warning otherwise
      See Also:
      REGEX, PATTERN, matches(), matches(String), validate(), validate(), java.util.regex.Pattern
    • matches

      public final boolean matches()
      Test PATTERN match via regular expression (regex) check of current object's toString() value.
      Returns:
      true if PATTERN matches, false otherwise
      See Also:
      REGEX, PATTERN, matches(), matches(String), validate(), java.util.regex.Pattern
    • matches

      public static final boolean matches(String value)
      Test PATTERN match with regular expression (regex) of provided value.
      Parameters:
      value - String to check against regex pattern for successful match
      Returns:
      true if PATTERN matches, false otherwise
      See Also:
      REGEX, PATTERN, matches(), matches(String), validate(), java.util.regex.Pattern
    • setValueByString

      public SFColorRGBA setValueByString(String newValue) throws InvalidFieldValueException
      Utility accessor for SFColorRGBA using String value (which must pass parsing validation checks).

      Warning: this method is not type safe at compile time! Best practice for X3DJSAIL programmers is to use strongly typed methods instead, in order to avoid potential for run-time errors.
      Parameters:
      newValue - is new value to assign, if empty then assign DEFAULT_VALUE
      Returns:
      MFMatrix4d - namely this same object to allow sequential method pipelining (i.e. consecutive method invocations on the same node object).
      Throws:
      InvalidFieldValueException
      See Also:
      X3DLoaderDOM.toX3dModelInstance(org.w3c.dom.Node)
    • setValue

      public SFColorRGBA setValue(int hexColorValue, float alpha)
      Public utility accessor method setting single HTML-style 0xRRGGBB hex value as new value.
      Parameters:
      hexColorValue - HTML color value (such as 0xAA2288)
      alpha - fourth component for opaqueness (1 - transparency)
      Returns:
      SFColorRGBA - namely this same object to allow sequential method pipelining (i.e. consecutive method invocations on the same object).
    • complementRGB

      public SFColorRGBA complementRGB()
      Complement all color values in RGB space (i.e. subtract each component from 1), with no change in alpha.
      Returns:
      SFColorRGBA - namely this same object to allow sequential method pipelining (i.e. consecutive method invocations on the same object).
      See Also:
      Wikipedia: Negative (photography), Wikipedia: Complementary colors
    • complementAlpha

      public SFColorRGBA complementAlpha()
      Complement alpha value by subtracting it from 1, note transparency = (1 - alpha).
      Returns:
      SFColorRGBA - namely this same object to allow sequential method pipelining (i.e. consecutive method invocations on the same object).
      See Also:
      Wikipedia: Negative (photography), Wikipedia: Complementary colors
    • normalizeClip

      public SFColorRGBA normalizeClip()
      Ensure all component color values are within range [0-1] by clipping as necessary.
      Returns:
      SFColorRGBA - namely this same object to allow sequential method pipelining (i.e. consecutive method invocations on the same object).
      See Also:
      X3D Scene Authoring Hints: Color
    • setValue

      public SFColorRGBA setValue(double[] newValue)
      Assign a new value to this field. Warning: newValue array length must correspond to tuple size for base type SFColorRGBA tuple size of 4.
      Parameters:
      newValue - The replacement value to assign.
      Returns:
      SFColorRGBA - namely this same object to allow sequential method pipelining (i.e. consecutive method invocations on the same object).
      See Also:
      X3DConcreteField.getTupleSize(String)
    • toString

      public static String toString(float[] value)
      Static utility method to provide String representation of a correctly typed input value.
      Parameters:
      value - The value to convert to a String
      Returns:
      String version of the provided value, with trailing zeroes and decimal points omitted.
      See Also:
      X3D Tooltips: type, SFFloat.stripTrailingZeroes(float)
    • getValue

      public void getValue(float[] valueDestination)
      Get the current value of this SFColorRGBA by copying it into the valueDestination array, leaving the current object unchanged.
      Specified by:
      getValue in interface SFColorRGBA
      Parameters:
      valueDestination - The array to be filled in with current field values.
    • getPrimitiveValue

      public float[] getPrimitiveValue()
      Provides current value of the field as a Java primitive type.
      Returns:
      current value
    • toString

      public String toString()
      Provides current value as a String.
      Overrides:
      toString in class Object
      Returns:
      String version of the provided value, with trailing zeroes and decimal points omitted.
      See Also:
      X3D Tooltips: type SFColorRGBA, SFFloat.stripTrailingZeroes(float)
    • setValue

      public void setValue(float[] newValue)
      Assign a new value to this field. Warning: newValue array length must correspond to tuple size for base type SFColorRGBA tuple size of 4.
      Specified by:
      setValue in interface SFColorRGBA
      Parameters:
      newValue - The replacement value to assign.
      See Also:
      X3DConcreteField.getTupleSize(String)
    • setValueArray

      public SFColorRGBA setValueArray(float[] newValue)
      Assign a new array value to this field, pipelined. This is an alternate utility method since primary method returns void and cannot be overridden. Warning: newValue array length must correspond to tuple size for base type SFColorRGBA tuple size of 4.
      Parameters:
      newValue - The replacement value to assign.
      Returns:
      SFColorRGBA - namely this same object to allow sequential method pipelining (i.e. consecutive method invocations on the same object).
      See Also:
      X3DConcreteField.getTupleSize(String)
    • setValue

      public SFColorRGBA setValue(float red, float green, float blue, float alpha)
      Assign a new value to this field.
      Parameters:
      red - first component [0..1]
      green - second component [0..1]
      blue - third component [0..1]
      alpha - fourth component for opaqueness (1 - transparency) [0..1]
      Returns:
      SFColorRGBA - namely this same object to allow sequential method pipelining (i.e. consecutive method invocations on the same object).
    • setValue

      public SFColorRGBA setValue(double red, double green, double blue, double alpha)
      Assign a new value to this field.
      Parameters:
      red - first component [0..1]
      green - second component [0..1]
      blue - third component [0..1]
      alpha - fourth component for opaqueness (1 - transparency) [0..1]
      Returns:
      SFColorRGBA - namely this same object to allow sequential method pipelining (i.e. consecutive method invocations on the same object).
    • setTransparency

      public SFColorRGBA setTransparency(float newTransparency)
      Utility method to modify transparency
      Parameters:
      newTransparency - value [0..1]
      Returns:
      SFColorRGBA - namely this same object to allow sequential method pipelining (i.e. consecutive method invocations on the same object).
    • setTransparency

      public SFColorRGBA setTransparency(double newTransparency)
      Utility method to modify transparency
      Parameters:
      newTransparency - value [0..1]
      Returns:
      SFColorRGBA - namely this same object to allow sequential method pipelining (i.e. consecutive method invocations on the same object).
    • toFloatArray

      public float[] toFloatArray()
      Provide float array for this field type.
      Returns:
      Array of floats in this field array.
    • setValue

      public SFColorRGBA setValue(SFColorRGBA newValue)
      Apply an SFColorRGBA value to this field.
      Parameters:
      newValue - The newValue to apply
      Returns:
      SFColorRGBA - namely this same object to allow sequential method pipelining (i.e. consecutive method invocations on the same object).
    • isDefaultValue

      public boolean isDefaultValue()
      Determine whether current value matches DEFAULT_VALUE
      Returns:
      whether current value matches DEFAULT_VALUE
      See Also:
      DEFAULT_VALUE