Package com.iizix.prop
Class GColor
java.lang.Object
com.iizix.prop.GColor
- All Implemented Interfaces:
Cloneable
This is a data holder class for color, typically an RGB(A) color for a component.
- Author:
- Christopher Mindus
Field Summary
Constructor Summary
ConstructorDescriptionGColor
(int rgb) Creates an opaque RGB color object.GColor
(int argb, boolean hasAlpha) Creates an opaque [A]RGB color object.GColor
(int r, int g, int b) Creates an opaque RGB color object.GColor
(int r, int g, int b, double a) Creates an ARGB color object.GColor
(int r, int g, int b, int a) Creates an ARGB color object.Method Summary
Modifier and TypeMethodDescriptionvoid
appendColor
(SendTransaction trans) Appends the color to a transaction.static GColor
createGColor
(String string) Creates a GColor from a String.boolean
Checks if two color objects are equal.boolean
Checks if two color objects are equal.static GColor
from
(ReadTransaction trans) Creates a color from a transaction.int
getColor()
Gets the color value as ARGB.static String[]
Returns a list of all the color names sorted in alphabetical order.Gets the shortest CSS color string for this color.getName()
Returns the color name.static int
Gets a color RGB value from a CSS3 color name.Gets the color as a String in the form described below.int
hashCode()
Hash code.boolean
Returns whether the color is inherited or not.boolean
isOpaque()
Checks if this color is (100%) opaque and not a color by name or not a system color, i.e.boolean
Returns the theme color flag.boolean
Checks if this color is transparent, or no color is set.protected String
Returns the parameter string representing the state of this event.static GColor
parseGColor
(String string) Parses an HTML color String, such as "#nnn", "#123456", "rgb(r,g,b)", "rgba(r,g,b,a)" or a named color.toString()
Returns a string representation of this class instance and its values.
Field Details
NONE
The no-color, i.e. full transparent.INHERIT
The inherited color, used for CSS.namesForColors
The map of colors to name where only the first entry is taken.
Constructor Details
GColor
public GColor(int r, int g, int b) Creates an opaque RGB color object.- Parameters:
r
- The red color (0-255).g
- The green color (0-255).b
- The build color (0-255).- Throws:
IllegalArgumentException
- if any r,g,b color is not 0-255.
GColor
public GColor(int r, int g, int b, int a) Creates an ARGB color object.- Parameters:
r
- The red color (0-255).g
- The green color (0-255).b
- The build color (0-255).a
- The alpha (0-255), 0=transparent, 255=opaque.- Throws:
IllegalArgumentException
- if any r,g,b color is not 0-255.
GColor
public GColor(int r, int g, int b, double a) Creates an ARGB color object.- Parameters:
r
- The red color (0-255).g
- The green color (0-255).b
- The build color (0-255).a
- The alpha (0.0-1.0), 0.0=transparent, 1.0=opaque.- Throws:
IllegalArgumentException
- if any r,g,b color is not 0-255.
GColor
public GColor(int rgb) Creates an opaque RGB color object.- Parameters:
rgb
- The integer red, green and blue colors.- Throws:
IllegalArgumentException
- ifrgb
< 0 orrgb
> 0xFFFFFF.
GColor
public GColor(int argb, boolean hasAlpha) Creates an opaque [A]RGB color object.- Parameters:
argb
- The alpha-blended integer red, green and blue colors.hasAlpha
- If false, sets alpha-blend part to 255.- Throws:
IllegalArgumentException
- if any r,g,b color is not 0-255.
Method Details
getColorNames
Returns a list of all the color names sorted in alphabetical order.- Returns:
- The color names array.
getRGBColorFromCSS3Name
Gets a color RGB value from a CSS3 color name.- Parameters:
name
- The color name.- Returns:
- The color value matching, or -1 for none.
createGColor
Creates a GColor from a String. If the string is null or empty, GColor.NONE is returned, otherwise a new GColor as ifnew GColor(string)
was called.- Parameters:
string
- The string as 0xnnnnnnnn or decimal. It can be null or empty string for GColor.NONE, or "inherit" for GColor.INHERIT.- Throws:
IllegalArgumentException
- for errors in the string specification.NumberFormatException
- for invalid number formats.
parseGColor
Parses an HTML color String, such as "#nnn", "#123456", "rgb(r,g,b)", "rgba(r,g,b,a)" or a named color. Named colors are CSS3 names or IIZI defined names starting with "%".- Throws:
ParseException
- If parsing failed.
from
Creates a color from a transaction.- Parameters:
trans
- The transaction.- Returns:
- The color.
getName
Returns the color name.- Returns:
- The color name is either a CSS3 color name matching the value or a predefined color name, or null if the color is not mapped to a named color.
isThemeColor
public boolean isThemeColor()Returns the theme color flag.- Returns:
- true if the color is a themed color without color if no theme is selected, false for well-defined color.
appendColor
Appends the color to a transaction.- Parameters:
trans
- The transaction.
equals
Checks if two color objects are equal.equals
Checks if two color objects are equal.- Parameters:
color
- another color object. If null, the colors are not equal.- Returns:
- true if equal, false otherwise.
hashCode
public int hashCode()Hash code.isInherited
public boolean isInherited()Returns whether the color is inherited or not.- Returns:
- true for CSS "inherit" color, false otherwise.
isTransparent
public boolean isTransparent()Checks if this color is transparent, or no color is set.- Returns:
- true if transparent, false otherwise (also false when inherited).
isOpaque
public boolean isOpaque()Checks if this color is (100%) opaque and not a color by name or not a system color, i.e. is a color of RGB type or ARGB with A=0x00.- Returns:
- true if fully opaque, false otherwise (also false when inherited).
getColor
public int getColor()Gets the color value as ARGB.- Returns:
- The color value, -1 if inherited.
getString
Gets the color as a String in the form described below.- Returns:
- the String as described below.
paramString
Returns the parameter string representing the state of this event. This string is useful for debugging. Subclasses adds extra information to the string by preceding it with a comma followed by the extra information.- Returns:
- the parameter string of this event.
toString
Returns a string representation of this class instance and its values.getCSSValue
Gets the shortest CSS color string for this color.- Returns:
- E.g. #123456 for opaque colors, rgba(r,g,b,a) for (semi-)transparency colors, or "inherit" if inherited.