Class GColor
- All Implemented Interfaces:
Cloneable
The class is FINAL and its instances are immutable value objects. A color is in one of three STATES: a literal ARGB value, the CSS inherit keyword, or a REFERENCE to a palette color by name (ofRef(String), persisted as %<reference>). The state is carried by discriminator fields (isInherited, ref), never by a subclass and never by a reserved value smuggled into value - a sentinel inside the payload can always collide with a real payload, a separate tag cannot. The precedent is INHERIT, which is identified by its flag and not by its value, precisely because its value -1 is also opaque white.
A referenced color carries NO resolved value: what it means depends on the palette and on the active scheme at run time, so equals(GColor) and hashCode() compare the reference and never a resolved value, and getColor() reports the unresolved magenta until something resolves it (ColorResolver). On the wire (appendColor(SendTransaction,GColor)) the reference travels as its name plus a fallback color computed at send time. The role names a component asks for are ColorRoles.
Being final is what keeps equals(GColor) honest. Java binds overloads on the STATIC type, so with a subclass in play a.equals(b) and ((Object)a).equals(b) could return different answers for the same two values depending only on how the variables were declared - invisible, and unexplainable from any log. No subclass, one dispatch, no asymmetry.
- Author:
- Christopher Mindus
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final GColorThe inherited color, used for CSS.The map of colors to name where only the first entry is taken.static final GColorThe no-color, i.e.static final charThe character that starts the persisted form of a referenced color:%<reference>.static final GColorThe unresolved color as a literal: what a referenced color paints as when nothing resolves it.static final intThe ARGB value a referenced color reports while unresolved: opaque magenta, the missing-texture color that no designer chooses and that stays violently wrong under the common color-vision deficiencies (ruled 2026-09-12, "The fallback, corrected").Constructor Summary
ConstructorsConstructorDescriptionGColor(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 TypeMethodDescriptionvoidappendColor(SendTransaction trans) Appends the color to a transaction.voidappendColor(SendTransaction trans, GColor fallback) Appends the color to a transaction, with the fallback a referenced color carries on the wire.static GColorcreateGColor(String string) Creates a GColor from a String.booleanChecks if two color objects are equal.booleanChecks if two color objects are equal.static GColorfrom(ReadTransaction trans) Creates a color from a transaction, the wire formappendColor(SendTransaction,GColor)writes: a tag byte, 0 literal, 1 inherit, 2 reference.static longGets an opaque ARGB color value from a CSS3 color name.intgetColor()Gets the color value as ARGB.static String[]Returns an array copy of all the color names sorted in alphabetical order.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.getRef()Gets the palette reference of a referenced color.static intGets a color RGB value from a CSS3 color name, WITHOUT the alpha component.Gets the color as a String in the form described below:0xaarrggbbfor a literal,inherit, or%<reference>for a referenced color - the persisted form, read back bycreateGColor(String).inthashCode()Hash code.booleanReturns whether the color is inherited or not.booleanisOpaque()Checks if this color is (100%) opaque and not a color by name or not a system color, i.e.booleanReturns whether this color is a reference to a palette color.booleanChecks if this color is transparent, or no color is set.static GColorCreates a referenced color: a color that names a palette color instead of holding a value.protected StringReturns the parameter string representing the state of this event.static GColorparseGColor(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.REF_PREFIX
public static final char REF_PREFIXThe character that starts the persisted form of a referenced color:%<reference>.- See Also:
UNRESOLVED_ARGB
public static final int UNRESOLVED_ARGBThe ARGB value a referenced color reports while unresolved: opaque magenta, the missing-texture color that no designer chooses and that stays violently wrong under the common color-vision deficiencies (ruled 2026-09-12, "The fallback, corrected").- See Also:
UNRESOLVED
The unresolved color as a literal: what a referenced color paints as when nothing resolves it.namesForColors
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,a value 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, or if a is NaN or not 0.0-1.0.
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 hasAlpha is false andargb< 0 orargb> 0xFFFFFF.
Method Details
getColorNames
Returns an array copy of all the color names sorted in alphabetical order. To avoid cloning, use the methodgetColorNamesList()instead.- Returns:
- A cloned array of the color names.
getColorNamesList
getRGBColorFromCSS3Name
Gets a color RGB value from a CSS3 color name, WITHOUT the alpha component.The returned value is
0x00RRGGBB, in the range 0 to 0xFFFFFF, so the-1returned for an unknown name cannot be mistaken for a color. The mask is applied even though the backing map holds no alpha today: it makes the contract true by construction rather than by coincidence, so a change to the map cannot silently turn this into an ARGB method.Use
getARGBColorFromCSS3Name(String)when an opaque ARGB value is wanted. It cannot return anintfor the reason this method can: opaque ARGB values occupy the whole 32-bit range, so-1would be 0xFFFFFFFF, which is opaque white - a real color, and a common one. That is the same collision documented onequals(GColor)forINHERIT.- Parameters:
name- The color name, case-insensitive.- Returns:
- The RGB color value 0 to 0xFFFFFF matching the name, or -1 for none.
- Throws:
NullPointerException- ifnameis null.
getARGBColorFromCSS3Name
Gets an opaque ARGB color value from a CSS3 color name.The returned value is
0xFFRRGGBBas along, which is what every GColor constructor taking an RGB value produces. Alongis used deliberately: as anintthe natural error value-1is 0xFFFFFFFF, i.e. opaque white, so noint-returning version of this method can report "not a color name" without also being unable to report white. As alongthe color values occupy 0x00000000L to 0xFFFFFFFFL and-1Llies outside that range.- Parameters:
name- The color name, case-insensitive.- Returns:
- The opaque ARGB color value 0xFF000000L to 0xFFFFFFFFL matching the name, or -1L for none.
- Throws:
NullPointerException- ifnameis null.
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, "inherit" for GColor.INHERIT, or "%" followed by a palette reference for a referenced color (ofRef(String)).- Throws:
IllegalArgumentException- for errors in the string specification, including an empty reference after "%".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 palette references starting with "%", which keep their case: a reference is a property path andBrand/Primaryis notbrand/primary.- Throws:
ParseException- If parsing failed.
ofRef
Creates a referenced color: a color that names a palette color instead of holding a value.The reference is a property reference string, e.g.
MyModule:/style/Brand/Primary, a module-relative/style/Brand/Primary, or a bare role name such asAccentthat is resolved against the module's palette and then the platform roles (ColorRoles); seeColorResolver. It is kept exactly as given, case included. Persisted as%<reference>(getString()) and created back bycreateGColor(String).- Parameters:
ref- The reference, never null or blank, without the leading%.- Returns:
- A new referenced color.
- Throws:
IllegalArgumentException- Ifrefis null or blank.
from
Creates a color from a transaction, the wire formappendColor(SendTransaction,GColor)writes: a tag byte, 0 literal, 1 inherit, 2 reference.For a reference the name is read and the fallback the sender computed is read and DISCARDED: the receiver holds the reference and resolves it against its own palette. A resolved value is never part of a referenced color.
- Parameters:
trans- The transaction.- Returns:
- The color.
- Throws:
IllegalArgumentException- If the tag byte is not 0, 1 or 2.
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. A referenced color has no CSS3 name (its reference is
getRef()): the unresolved magenta it reports must not come back as "fuchsia".
isReference
public boolean isReference()Returns whether this color is a reference to a palette color.- Returns:
- true for a referenced color (
ofRef(String)), false for a literal or inherited color.
getRef
Gets the palette reference of a referenced color.- Returns:
- The reference without the leading
%, or null for a literal or inherited color.
appendColor
Appends the color to a transaction.The wire form is a tag byte:
0literal, then the 32-bit ARGB value;1inherit, nothing follows;2reference, then the reference name, then the fallback color computed at send time as a literal-or-inherit (a boolean, then the ARGB value when not inherited). The tag replaced a boolean on 2026-09-26 (ruling R16): client and server are always the same build, so there is no version to negotiate, and a separate tag is what makes a third state impossible to confuse with a value.A referenced color appended through THIS method has no resolver, so its fallback is the
UNRESOLVEDmagenta and a warning is logged; a holder that can resolve the reference against its tree callsappendColor(SendTransaction,GColor)instead (ColorProp,Color4Prop).- Parameters:
trans- The transaction.
appendColor
Appends the color to a transaction, with the fallback a referenced color carries on the wire.For a literal or inherited color the fallback is ignored and the form is that of
appendColor(SendTransaction). For a referenced color the tag2is written, then the reference name, thenfallbackas a boolean (inherited) and, when not inherited, its ARGB value: the color the client paints until something resolves the name.- Parameters:
trans- The transaction.fallback- The resolved color to carry as the fallback, a literal orINHERIT;UNRESOLVEDwhen the reference did not resolve.- Throws:
IllegalArgumentException- Iffallbackis itself a referenced color.NullPointerException- Iffallbackis null and this color is a reference.
equals
equals
Checks if two color objects are equal.The inherited color is equal only to itself: the flag is the discriminator, not the value.
INHERITcarries the value -1, which is also the value of opaque white (0xFFFFFFFF), so a comparison that looked only at the value would call the two equal.A referenced color is equal only to a color with the same reference, and never to a literal, whatever it currently resolves to: resolution changes with the active scheme at run time and equality must not, or a color used as a map key becomes unfindable after a scheme switch (ruled 2026-09-12, Q12: compare the reference, never what it currently means).
- Parameters:
color- another color object. If null, the colors are not equal.- Returns:
- true if equal, false otherwise.
hashCode
public int hashCode()Hash code.The discriminator is mixed in for the same reason
equals(GColor)tests it: two colors that are never equal must not hash equally, or they collide in every bucket. The class itself is no longer part of this - the class is final, so it is a constant. A referenced color hashes on its reference alone, as it compares.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, and false for a referenced color, which reports its unresolved opaque magenta).
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,
UNRESOLVED_ARGBfor a referenced color.
getString
Gets the color as a String in the form described below:0xaarrggbbfor a literal,inherit, or%<reference>for a referenced color - the persisted form, read back bycreateGColor(String).- 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
getCSSValue
Gets the shortest CSS color string for this color.A referenced color returns the CSS of its unresolved magenta,
#F0F: this class resolves nothing. Thevar(--izc-...)a referenced color becomes on the client is the delivery phase's (color.js), and a build-time consumer wants a resolved literal fromColorResolver.- Returns:
- E.g. #123456 for opaque colors, rgba(r,g,b,a) for (semi-)transparency colors, or "inherit" if inherited.