Class CustomColorHandle


public class CustomColorHandle extends StructureHandle
Represents the handle of custom color. The developer can define a set of custom color names as part of the design. The developer can then reference these names within properties.

Every custom color has three parts: a display name, an internal name and a color value.

Name
a custom color has a unique and required name, so the user can use the color name to identify a custom color.
color
The color value of the color, it is preserved as the user typed in.
Resource Key
a custom color has an optional display name ID to localize the display name.

The color value can contain any of the valid color representations:

  • INT_FORMAT: An integer with a valid RGB color value.
  • HTML_FORMAT: ( #RRGGBB or #RGB )
  • JAVA_FORMAT: ( 0xRRGGBB )
  • CSS_ABSOLUTE_FORMAT: ( RGB(r,g,b) )
  • CSS_RELATIVE_FORMAT: ( RGB(r%,g%,b%) )

If the color value is in one of the format, then it is meaningful to retrieve it as integer RGB value. Otherwise the color value is treat just as what the user has entered, and can not be converted into an RGB value.

Use ColorUtil.format(int, int)and ColorUtil.format(String, int)to do the formatting work on a color value.

See Also:
  • Constructor Details

    • CustomColorHandle

      public CustomColorHandle(SimpleValueHandle valueHandle, int index)
      Constructs the handle of custom color.
      Parameters:
      valueHandle - the value handle for custom color list of one property
      index - the position of this custom color in the list
  • Method Details

    • getDisplayName

      public String getDisplayName()
      Returns the internal display name.
      Returns:
      the internal display name
    • setDisplayName

      public void setDisplayName(String displayName)
      Sets the display name.
      Parameters:
      displayName - the display name to set
    • getDisplayNameID

      public String getDisplayNameID()
      Returns the resource key for display name.
      Returns:
      the resource key for display name.
    • setDisplayNameID

      public void setDisplayNameID(String displayNameID)
      Sets the resource key for display name.
      Parameters:
      displayNameID - the resource key for display name
    • getName

      public String getName()
      Returns the custom color name.
      Returns:
      the custom color name
    • getColor

      public String getColor()
      Returns the color value as what the user has input.
      Returns:
      the color value as what the user has input.
    • setColor

      public void setColor(String colorValue) throws SemanticException
      Sets the color value.
      Parameters:
      colorValue - the color value to be set.
      Throws:
      SemanticException - value required exception
    • setName

      public void setName(String name) throws SemanticException
      Sets the custom color name.
      Parameters:
      name - the custom color name to set
      Throws:
      SemanticException - value required exception
    • getRGB

      public int getRGB()
      Returns the color value as an integer RGB value. If the color value is of a valid color representation, then return its numeric RGB value as integer. Otherwise, return -1 indicates that the value is not valid.

      The color value can contain any of the valid color representations:

      • INT_FORMAT: An integer with a valid RGB color value.
      • HTML_FORMAT: ( #RRGGBB or #RGB )
      • JAVA_FORMAT: ( 0xRRGGBB )
      • CSS_ABSOLUTE_FORMAT: ( RGB(r,g,b) )
      • CSS_RELATIVE_FORMAT: ( RGB(r%,g%,b%) )
      Returns:
      the color value as an integer RGB value. Return -1 if the color value is not valid or the color value is null.
    • getQualifiedName

      public String getQualifiedName()
      Returns the qualified name of this element. The qualified name is the name of this element if this element is in module user is editing.
      Returns:
      the qualified name of thie element.