Class Color
- All Implemented Interfaces:
HasHandlers
Colors.getColor(). Contains RGB, HSL, and oklch properties pre-computed, a hex string, and convenience methods for manipulation that delegate to Colors classMethods. Properties are organized by color space: RGB (r, g, b ), HSL (h, s, l), and oklch (ok_L, ok_C, ok_h). The ok_ prefix distinguishes oklch from HSL (both have a hue component). Oklch is the perceptually uniform color space that all adjust() operations work in - equal numeric changes produce equal perceived visual differences.
For raw numeric components without the full Color object, use Colors.getValues() which returns a plain unstructured object ({r, g, b, alpha}, {h, s, l, alpha}, or {L, C, h, alpha}) for a single requested format.
getColor() always returns a Color object. If the input was unparseable, isValid() returns false and properties default to black. Color objects are immutable - manipulation methods return new instances.
Instance methods return new Color objects, enabling chaining:
-
Field Summary
Fields inherited from class com.smartgwt.client.core.DataClass
factoryCreated, factoryProperties -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns a new Color with the specified oklch deltas applied.Returns a new Color with hue rotated 180 degrees (oklch h + 180).Returns the approximate perceptual contrast ratio between this color and another (oklch-based).Returns the approximate perceptual contrast ratio between this color and another (oklch-based).darken(int amount) Returns a new Color darkened by the given amount (oklch L decreased).desaturate(int amount) Returns a new Color with chroma decreased (oklch C decreased).booleanReturns true if this color is visually identical to another (same RGB + alpha).booleanReturns true if this color is visually identical to another (same RGB + alpha).getAlpha()Opacity, 0 (fully transparent) to 1 (fully opaque).intgetB()Blue component, 0-255.The format detected from the source string used to create this Color (e.g.intgetG()Green component, 0-255.intgetH()HSL hue angle, 0-360 degrees.getHex()Pre-computed hex string representation of this color (e.g.intgetL()HSL lightness, 0 (black) to 100 (white), as a percentage.getOk_C()Oklch chroma (color intensity), typically 0 (gray) to ~0.4 (vivid).getOk_h()Oklch hue angle, 0-360 degrees.getOk_L()Oklch perceptual lightness, 0 (black) to 1 (white).static ColorgetOrCreateRef(JavaScriptObject jsObj) intgetR()Red component, 0-255.intgetS()HSL saturation, 0 (gray) to 100 (fully saturated), as a percentage.Returns a CSS color string in the specified format, defaulting to the source format detected when this Color was created.getString(ColorFormat format) Returns a CSS color string in the specified format, defaulting to the source format detected when this Color was created.booleanisDark()Returns true if this color is perceptually dark (oklch L < 0.6).booleanisValid()Returns true if this Color was successfully parsed from valid input.lighten(int amount) Returns a new Color lightened by the given amount (oklch L increased).saturate(int amount) Returns a new Color with chroma increased (oklch C increased).Methods inherited from class com.smartgwt.client.core.DataClass
applyFactoryProperties, doAddHandler, fireEvent, getAttribute, getAttributeAsBoolean, getAttributeAsBoolean, getAttributeAsDate, getAttributeAsDouble, getAttributeAsDoubleArray, getAttributeAsElement, getAttributeAsFloat, getAttributeAsInt, getAttributeAsIntArray, getAttributeAsJavaScriptObject, getAttributeAsLong, getAttributeAsMap, getAttributeAsObject, getAttributeAsRecord, getAttributeAsString, getAttributeAsStringArray, getAttributes, getHandlerCount, isFactoryCreated, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttributeAsJavaObject, setFactoryCreated
-
Constructor Details
-
Color
public Color() -
Color
-
-
Method Details
-
getOrCreateRef
-
getAlpha
Opacity, 0 (fully transparent) to 1 (fully opaque).- Returns:
- Current alpha value. Default value is IR
-
getB
public int getB()Blue component, 0-255.- Returns:
- Current b value. Default value is IR
-
getFormat
The format detected from the source string used to create this Color (e.g. "hex", "rgb", "hsl", "oklch"). Used as the default output format bygetString().- Returns:
- Current format value. Default value is IR
-
getG
public int getG()Green component, 0-255.- Returns:
- Current g value. Default value is IR
-
getH
public int getH()HSL hue angle, 0-360 degrees. Standard CSS hue wheel: red 0/360, yellow 60, green 120, cyan 180, blue 240, magenta 300.- Returns:
- Current h value. Default value is IR
-
getHex
Pre-computed hex string representation of this color (e.g. "#3366cc"). Includes an alpha component ("#3366ccbf") only when semi-transparent. This is the most commonly needed output format and avoids repeatedgetString("hex")calls.- Returns:
- Current hex value. Default value is IR
-
getL
public int getL()HSL lightness, 0 (black) to 100 (white), as a percentage.- Returns:
- Current l value. Default value is IR
-
getOk_C
Oklch chroma (color intensity), typically 0 (gray) to ~0.4 (vivid). This is the value thatsaturate()/desaturate()and thesaturationkey inadjust()operate on.- Returns:
- Current ok_C value. Default value is IR
-
getOk_h
Oklch hue angle, 0-360 degrees. This is the value that thehuekey inadjust()andcomplement()operate on. The oklch hue wheel: red ~30, yellow ~90, green ~145, cyan ~195, blue ~265, purple ~310.This differs from the HSL
hbecause oklch redistributes hue angles for perceptual uniformity - equal angular steps produce equal perceived color changes.- Returns:
- Current ok_h value. Default value is IR
-
getOk_L
Oklch perceptual lightness, 0 (black) to 1 (white). This is the value thatlighten()/darken()and thelightnesskey inadjust()operate on. Oklch lightness is perceptually uniform - equal numeric steps produce equal perceived brightness changes, unlike HSLl.- Returns:
- Current ok_L value. Default value is IR
-
getR
public int getR()Red component, 0-255.- Returns:
- Current r value. Default value is IR
-
getS
public int getS()HSL saturation, 0 (gray) to 100 (fully saturated), as a percentage.- Returns:
- Current s value. Default value is IR
-
adjust
Returns a new Color with the specified oklch deltas applied. Supports both friendly keys (lightness,saturation,hue,alpha) and raw oklch keys (L,C,h).- Parameters:
deltas- adjustments to apply - seeColors.adjust()- Returns:
- new Color object
- See Also:
-
complement
Returns a new Color with hue rotated 180 degrees (oklch h + 180).- Returns:
- new Color object
- See Also:
-
contrast
Returns the approximate perceptual contrast ratio between this color and another (oklch-based).- Parameters:
other- color to compare against- Returns:
- approximate contrast ratio (>= 1.0), or null if other is invalid
- See Also:
-
contrast
Returns the approximate perceptual contrast ratio between this color and another (oklch-based).- Parameters:
other- color to compare against- Returns:
- approximate contrast ratio (>= 1.0), or null if other is invalid
- See Also:
-
darken
Returns a new Color darkened by the given amount (oklch L decreased).- Parameters:
amount- percentage to darken, 0-100- Returns:
- new Color object
- See Also:
-
desaturate
Returns a new Color with chroma decreased (oklch C decreased).- Parameters:
amount- percentage to desaturate, 0-100- Returns:
- new Color object
- See Also:
-
equals
Returns true if this color is visually identical to another (same RGB + alpha).- Parameters:
other- color to compare- Returns:
- See Also:
-
equals
Returns true if this color is visually identical to another (same RGB + alpha).- Parameters:
other- color to compare- Returns:
- See Also:
-
getString
Returns a CSS color string in the specified format, defaulting to the source format detected when this Color was created.- Returns:
- CSS color string
-
getString
Returns a CSS color string in the specified format, defaulting to the source format detected when this Color was created.- Parameters:
format- output format - defaults toformat- Returns:
- CSS color string
-
isDark
public boolean isDark()Returns true if this color is perceptually dark (oklch L < 0.6).- Returns:
- See Also:
-
isValid
public boolean isValid()Returns true if this Color was successfully parsed from valid input. Invalid Colors (created from unparseable input) have all properties defaulting to black (#000000). Use this to check user-supplied color strings without needing null checks.- Returns:
- true if the color was parsed successfully
-
lighten
Returns a new Color lightened by the given amount (oklch L increased).- Parameters:
amount- percentage to lighten, 0-100- Returns:
- new Color object
- See Also:
-
saturate
Returns a new Color with chroma increased (oklch C increased).- Parameters:
amount- percentage to saturate, 0-100- Returns:
- new Color object
- See Also:
-