Package com.smartgwt.client.util

# Class Color

java.lang.Object
com.smartgwt.client.core.JsObject
com.smartgwt.client.core.DataClass
com.smartgwt.client.util.Color

All Implemented Interfaces:
  `HasHandlers`

public class Color extends DataClass
A structured color object returned by `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`

  ### Fields inherited from class com.smartgwt.client.core.JsObject

  `jsObj`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Color()`
  `Color(JavaScriptObject jsObj)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Color`
  `adjust(Map deltas)`
  Returns a new Color with the specified oklch deltas applied.
  `Color`
  `brighten(double amount)`
  Returns a brighter, more vivid Color by boosting both lightness and chroma together.
  `Color`
  `complement()`
  Returns a new Color with hue rotated 180 degrees (oklch h + 180).
  `Double`
  `contrast(Color other)`
  Returns the approximate perceptual contrast ratio between this color and another (oklch-based).
  `Double`
  `contrast(String other)`
  Returns the approximate perceptual contrast ratio between this color and another (oklch-based).
  `Color`
  `darken(int amount)`
  Returns a new Color darkened by the given amount (oklch L decreased).
  `Color`
  `desaturate(int amount)`
  Returns a new Color with chroma decreased (oklch C decreased).
  `Color`
  `dim(double amount)`
  Returns a dimmer, more muted Color by reducing both lightness and chroma together.
  `Double`
  `distance(Color other)`
  Returns the perceptual distance between this color and another in oklab space.
  `Double`
  `distance(String other)`
  Returns the perceptual distance between this color and another in oklab space.
  `boolean`
  `equals(Color other)`
  Returns true if this color is visually identical to another (same RGB + alpha).
  `boolean`
  `equals(String other)`
  Returns true if this color is visually identical to another (same RGB + alpha).
  `Double`
  `getAlpha()`
  Opacity, 0 (fully transparent) to 1 (fully opaque).
  `int`
  `getB()`
  Blue component, 0-255.
  `ColorFormat`
  `getFormat()`
  The format detected from the source string used to create this Color (e.g.
  `int`
  `getG()`
  Green component, 0-255.
  `int`
  `getH()`
  HSL hue angle, 0-360 degrees.
  `String`
  `getHex()`
  Pre-computed hex string representation of this color (e.g.
  `int`
  `getL()`
  HSL lightness, 0 (black) to 100 (white), as a percentage.
  `Double`
  `getOk_C()`
  Oklch chroma (color intensity), typically 0 (gray) to ~0.4 (vivid).
  `Double`
  `getOk_h()`
  Oklch hue angle, 0-360 degrees.
  `Double`
  `getOk_L()`
  Oklch perceptual lightness, 0 (black) to 1 (white).
  `static Color`
  `getOrCreateRef(JavaScriptObject jsObj)`
  `int`
  `getR()`
  Red component, 0-255.
  `int`
  `getS()`
  HSL saturation, 0 (gray) to 100 (fully saturated), as a percentage.
  `String`
  `getString()`
  Returns a CSS color string in the specified format, defaulting to the source format detected when this Color was created.
  `String`
  `getString(ColorFormat format)`
  Returns a CSS color string in the specified format, defaulting to the source format detected when this Color was created.
  `boolean`
  `isDark()`
  Returns true if this color is perceptually dark (oklch L < 0.6).
  `boolean`
  `isValid()`
  Returns true if this Color was successfully parsed from valid input.
  `Color`
  `lighten(int amount)`
  Returns a new Color lightened by the given amount (oklch L increased).
  `Color`
  `saturate(int amount)`
  Returns a new Color with chroma increased (oklch C increased).
  `Color`
  `spin(double degrees)`
  Returns a new Color with hue rotated by the given number of degrees (oklch h).

  ### 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`

  ### Methods inherited from class com.smartgwt.client.core.JsObject

  `equals, getJsObj, hashCode, isCreated, setJavaScriptObject, setJsObj`

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### Color

    public Color()

  - ### Color

    public Color(JavaScriptObject jsObj)

- ## Method Details

  - ### getOrCreateRef

    public static Color getOrCreateRef(JavaScriptObject jsObj)

  - ### getAlpha

    public Double 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

    public ColorFormat 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 by `getString()`.
    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

    public String 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 repeated `getString("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

    public Double getOk_C()
    Oklch chroma (color intensity), typically 0 (gray) to ~0.4 (vivid). This is the value that `saturate()`/`desaturate()` and the `saturation` key in `adjust()` operate on.
    Returns:
      Current ok_C value. Default value is IR

  - ### getOk_h

    public Double getOk_h()
    Oklch hue angle, 0-360 degrees. This is the value that the `hue` key in `adjust()` and `complement()` operate on. The oklch hue wheel: red ~30, yellow ~90, green ~145, cyan ~195, blue ~265, purple ~310.

    This differs from the HSL `h` because 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

    public Double getOk_L()
    Oklch perceptual lightness, 0 (black) to 1 (white). This is the value that `lighten()`/`darken()` and the `lightness` key in `adjust()` operate on. Oklch lightness is perceptually uniform - equal numeric steps produce equal perceived brightness changes, unlike HSL `l`.
    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

    public Color adjust(Map deltas)
    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 - see `Colors.adjust()`
    Returns:
      new Color object
    See Also:
      - `Colors.adjust(java.lang.String, java.util.Map)`

  - ### brighten

    public Color brighten(double amount)
    Returns a brighter, more vivid Color by boosting both lightness and chroma together.
    Parameters:
      `amount` - percentage to brighten, 0-100
    Returns:
      new Color object
    See Also:
      - `Colors.brighten(java.lang.String, double)`

  - ### complement

    public Color complement()
    Returns a new Color with hue rotated 180 degrees (oklch h + 180).
    Returns:
      new Color object
    See Also:
      - `Colors.complement(java.lang.String)`

  - ### contrast

    public Double contrast(String other)
    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:
      - `Colors.contrast(java.lang.String, java.lang.String)`

  - ### contrast

    public Double contrast(Color other)
    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:
      - `Colors.contrast(java.lang.String, java.lang.String)`

  - ### darken

    public Color darken(int amount)
    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:
      - `Colors.darken(java.lang.String, double)`

  - ### desaturate

    public Color desaturate(int amount)
    Returns a new Color with chroma decreased (oklch C decreased).
    Parameters:
      `amount` - percentage to desaturate, 0-100
    Returns:
      new Color object
    See Also:
      - `Colors.desaturate(java.lang.String, double)`

  - ### dim

    public Color dim(double amount)
    Returns a dimmer, more muted Color by reducing both lightness and chroma together.
    Parameters:
      `amount` - percentage to dim, 0-100
    Returns:
      new Color object
    See Also:
      - `Colors.dim(java.lang.String, double)`

  - ### distance

    public Double distance(String other)
    Returns the perceptual distance between this color and another in oklab space.
    Parameters:
      `other` - color to compare against
    Returns:
      perceptual distance (>= 0), or null if other is invalid
    See Also:
      - `Colors.distance(java.lang.String, java.lang.String)`

  - ### distance

    public Double distance(Color other)
    Returns the perceptual distance between this color and another in oklab space.
    Parameters:
      `other` - color to compare against
    Returns:
      perceptual distance (>= 0), or null if other is invalid
    See Also:
      - `Colors.distance(java.lang.String, java.lang.String)`

  - ### equals

    public boolean equals(String other)
    Returns true if this color is visually identical to another (same RGB + alpha).
    Parameters:
      `other` - color to compare
    Returns:
    See Also:
      - `Colors.equals(java.lang.String, java.lang.String)`

  - ### equals

    public boolean equals(Color other)
    Returns true if this color is visually identical to another (same RGB + alpha).
    Parameters:
      `other` - color to compare
    Returns:
    See Also:
      - `Colors.equals(java.lang.String, java.lang.String)`

  - ### getString

    public String 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

    public String getString(ColorFormat format)
    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 to `format`
    Returns:
      CSS color string

  - ### isDark

    public boolean isDark()
    Returns true if this color is perceptually dark (oklch L < 0.6).
    Returns:
    See Also:
      - `Colors.isDark(java.lang.String)`

  - ### 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

    public Color lighten(int amount)
    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:
      - `Colors.lighten(java.lang.String, double)`

  - ### saturate

    public Color saturate(int amount)
    Returns a new Color with chroma increased (oklch C increased).
    Parameters:
      `amount` - percentage to saturate, 0-100
    Returns:
      new Color object
    See Also:
      - `Colors.saturate(java.lang.String, double)`

  - ### spin

    public Color spin(double degrees)
    Returns a new Color with hue rotated by the given number of degrees (oklch h).
    Parameters:
      `degrees` - degrees to rotate, positive or negative
    Returns:
      new Color object
    See Also:
      - `Colors.spin(java.lang.String, double)`