Class ColorParm

java.lang.Object
org.bzdev.obnaming.misc.ColorParm
Direct Known Subclasses:
ColorParm.BLACK, ColorParm.BLUE, ColorParm.GREEN, ColorParm.RED, ColorParm.WHITE

public class ColorParm extends Object
Factory support class for defining colors. If no color is provided in a constructor and no color component is set, the createColor method will return null. If a default color is desired, use the constructor that takes an instance of Color as its argument. The factory 'set' methods will not allow a color component to be set to null - instead one must clear the field to restore the default (whether null or a specific color).

Parameter names will be compound names, typically using a period as a separator. When this class is used, multiple parameters will be defined, and the last component of the parameter name will be the following:

  • css - a string giving a color in a format acceptable to CSS as specified in a W3C recommendation for CSS level 3; null if CSS is not used.
  • red - an integer in the range [0,255] giving the red component of the color (overrides the red component of the css option when the css parametercss is not null).
  • green - an integer in the range [0,255] giving the green component of the color (overrides the green component of the css option when the css parametercss is not null).
  • blue - an integer in the range [0,255] giving the blue component of the color (overrides the blue component of the css option when the css parametercss is not null).
  • alpha - an integer in the range [0,255] giving the alpha component of the color. If null, the value will be 255 unless the css parameter specifies a value of alpha, in which case that value will be used.
If all of these parameters are null, a default color will be used (which may be null).
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    An instance of ColorParm whose default constructor returns an object initialized to the CSS color specification "black".
    static final class 
    An instance of ColorParm whose default constructor returns an object initialized to the CSS color specification "blue".
    static final class 
    An instance of ColorParm whose default constructor returns an object initialized to the CSS color specification "green".
    static final class 
    An instance of ColorParm whose default constructor returns an object initialized to the CSS color specification "red".
    static final class 
    An instance of ColorParm whose default constructor returns an object initialized to the CSS color specification "WHITE".
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    The alpha component of a color.
    The blue component of a color.
    A CSS specification for a color.
    The green component of a color.
    The red component of a color.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor.
    Constructor given a color.
    Constructor given a CSS color specification This constructor should not be used to initialize the value of a variable annotated with a @CompoundParm annotation.
  • Method Summary

    Modifier and Type
    Method
    Description
    Create the color specified by this object.
    Get the alpha component for a colorParm.
    Get the blue component for a colorParm.
    Get the green component for a colorParm.
    Get the red component for a colorParm.

    Methods inherited from class java.lang.Object

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

    • css

      public String css
      A CSS specification for a color.
    • red

      public Integer red
      The red component of a color.
    • green

      public Integer green
      The green component of a color.
    • blue

      public Integer blue
      The blue component of a color.
    • alpha

      public Integer alpha
      The alpha component of a color.
  • Constructor Details

    • ColorParm

      public ColorParm()
      Constructor. Note: unless the fields are modified, a call to createColor() will return null. To initialize a variable annotated with a @CompoundParm annotation, use one the inner classes or create a subclass with a zero-argument constructor that will create the desired color.
    • ColorParm

      public ColorParm(Color c)
      Constructor given a color. The color provided can be changed by setting the red, green, blue, or css fields. This constructor should not be used to initialize the value of a variable annotated with a @CompoundParm annotation. To initialize a variable annotated with a @CompoundParm annotation, use one the inner classes or create a subclass with a zero-argument constructor that will create the desired color.
      Parameters:
      c - the color used to configure this object
    • ColorParm

      public ColorParm(String spec) throws IllegalArgumentException
      Constructor given a CSS color specification This constructor should not be used to initialize the value of a variable annotated with a @CompoundParm annotation. To initialize a variable annotated with a @CompoundParm annotation, use one the inner classes or create a subclass with a zero-argument constructor that will create the desired color.
      Parameters:
      spec - the CSS color specification
      Throws:
      IllegalArgumentException - if the specification was ill formed
  • Method Details

    • getRed

      public Integer getRed()
      Get the red component for a colorParm. If other color components are non-null and the red component is null, a default value of 0 is returned. Otherwise if the CSS component is non-null, the red component of that color is returned. Otherwise if a default was provided in a constructor, the red component of that color is returned.
      Returns:
      the red component of the color; null if no color components were provided either explicitly or by specifying a default color in a constructor.
    • getGreen

      public Integer getGreen()
      Get the green component for a colorParm. If other color components are non-null and the green component is null, a default value of 0 is returned. Otherwise if the CSS component is non-null, the red component of that color is returned. Otherwise if a default was provided in a constructor, the green component of that color is returned.
      Returns:
      the green component of the color; null if no color components were provided either explicitly or by specifying a default color in a constructor.
    • getBlue

      public Integer getBlue()
      Get the blue component for a colorParm. If other color components are non-null and the blue component is null, a default value of 0 is returned. Otherwise if the CSS component is non-null, the blue component of that color is returned. Otherwise if a default was provided in a constructor, the red component of that color is returned.
      Returns:
      the blue component of the color; null if no color components were provided either explicitly or by specifying a default color in a constructor.
    • getAlpha

      public Integer getAlpha()
      Get the alpha component for a colorParm. If other color components are non-null and the alpha component is null, a default value of 255 is returned. Otherwise if a default alpha component was provided, that is returned, but if a default alpha component was not provided (i.e., was null), but other defaults were provided, 255 is returned.
      Returns:
      the alpha component of the color; null if no color components were provided either explicitly or by specifying a default value in a constructor.
    • createColor

      public Color createColor()
      Create the color specified by this object.
      Returns:
      the color; null if no color was specified in a constructor and no parameter was set to a non-null value