java.lang.Object
org.bzdev.obnaming.misc.ColorParm
- Direct Known Subclasses:
ColorParm.BLACK
,ColorParm.BLUE
,ColorParm.GREEN
,ColorParm.RED
,ColorParm.WHITE
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic 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 -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
css
A CSS specification for a color. -
red
The red component of a color. -
green
The green component of a color. -
blue
The blue component of a color. -
alpha
The alpha component of a color.
-
-
Constructor Details
-
ColorParm
public ColorParm()Constructor. Note: unless the fields are modified, a call tocreateColor()
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
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
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
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
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
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
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
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
-