/*
 * Smart GWT (GWT for SmartClient)
 * Copyright 2008 and beyond, Isomorphic Software, Inc.
 *
 * Smart GWT is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3
 * as published by the Free Software Foundation.  Smart GWT is also
 * available under typical commercial license terms - see
 * http://smartclient.com/license
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 */
/* sgwtgen */
 
package com.smartgwt.client.util;


import com.smartgwt.client.event.*;
import com.smartgwt.client.core.*;
import com.smartgwt.client.types.*;
import com.smartgwt.client.data.*;
import com.smartgwt.client.data.Record;
import com.smartgwt.client.data.events.*;
import com.smartgwt.client.browser.window.*;
import com.smartgwt.client.rpc.*;
import com.smartgwt.client.ai.*;
import com.smartgwt.client.callbacks.*;
import com.smartgwt.client.tools.*;
import com.smartgwt.client.bean.*;
import com.smartgwt.client.widgets.*;
import com.smartgwt.client.widgets.ai.*;
import com.smartgwt.client.widgets.events.*;
import com.smartgwt.client.widgets.form.*;
import com.smartgwt.client.widgets.form.validator.*;
import com.smartgwt.client.widgets.form.fields.*;
import com.smartgwt.client.widgets.tile.*;
import com.smartgwt.client.widgets.tile.events.*;
import com.smartgwt.client.widgets.grid.*;
import com.smartgwt.client.widgets.grid.events.*;
import com.smartgwt.client.widgets.chart.*;
import com.smartgwt.client.widgets.layout.*;
import com.smartgwt.client.widgets.layout.events.*;
import com.smartgwt.client.widgets.menu.*;
import com.smartgwt.client.widgets.tour.*;
import com.smartgwt.client.widgets.notify.*;
import com.smartgwt.client.widgets.rte.*;
import com.smartgwt.client.widgets.rte.events.*;
import com.smartgwt.client.widgets.ace.*;
import com.smartgwt.client.widgets.ace.events.*;
import com.smartgwt.client.widgets.tab.*;
import com.smartgwt.client.widgets.toolbar.*;
import com.smartgwt.client.widgets.tree.*;
import com.smartgwt.client.widgets.tree.events.*;
import com.smartgwt.client.widgets.tableview.*;
import com.smartgwt.client.widgets.viewer.*;
import com.smartgwt.client.widgets.calendar.*;
import com.smartgwt.client.widgets.calendar.events.*;
import com.smartgwt.client.widgets.cube.*;
import com.smartgwt.client.widgets.notify.*;
import com.smartgwt.client.widgets.drawing.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.google.gwt.event.shared.*;
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.core.client.JavaScriptObject;

import com.smartgwt.client.util.*;
import com.smartgwt.client.util.events.*;
import com.smartgwt.client.util.workflow.*;
import com.smartgwt.client.util.workflow.Process; // required to override java.lang.Process
import com.smartgwt.client.util.tour.*;


/**
 * A structured color object returned by {@link com.smartgwt.client.util.Colors#getColor Colors.getColor()}. Contains RGB,
 * HSL, and oklch properties pre-computed, a {@link com.smartgwt.client.util.Color#getHex hex} string, and convenience
 * methods for manipulation that delegate to {@link com.smartgwt.client.util.Colors} classMethods. <P> Properties are
 * organized by color space: RGB (<code>r</code>, <code>g</code>, <code>b</code> ), HSL (<code>h</code>, <code>s</code>,
 * <code>l</code>), and oklch (<code>ok_L</code>, <code>ok_C</code>, <code>ok_h</code>). The <code>ok_</code> prefix
 * distinguishes oklch from HSL (both have a hue component). Oklch is the perceptually uniform color space that all {@link
 * com.smartgwt.client.util.Colors#adjust adjust()} operations work in - equal numeric changes produce equal perceived
 * visual differences. <P> For raw numeric components without the full Color object, use {@link
 * com.smartgwt.client.util.Colors#getValues Colors.getValues()} which returns a plain unstructured object (<code>{r, g, b,
 * alpha}</code>, <code>{h, s, l, alpha}</code>, or <code>{L, C, h, alpha}</code>) for a single requested format. <P>
 * {@link com.smartgwt.client.util.Colors#getColor getColor()} always returns a Color object. If the input was unparseable,
 * {@link com.smartgwt.client.util.Color#isValid isValid()} returns false and properties default to black. Color objects
 * are immutable - manipulation methods return new instances. <P> Instance methods return new Color objects, enabling
 * chaining:
 */
@BeanFactory.FrameworkClass
public class Color extends DataClass {

    public static Color getOrCreateRef(JavaScriptObject jsObj) {
        if(jsObj == null) return null;
        return new Color(jsObj);
    }
        


    public Color(){
        
    }

    public Color(JavaScriptObject jsObj){
        
        setJavaScriptObject(jsObj);
    }



    // ********************* Properties / Attributes ***********************

    /**
     * Opacity, 0 (fully transparent) to 1 (fully opaque).
     *
     * @return Current alpha value. Default value is IR
     */
    public Double getAlpha()  {
        return getAttributeAsDouble("alpha");
    }
    

    /**
     * Blue component, 0-255.
     *
     * @return Current b value. Default value is IR
     */
    public int getB()  {
        return getAttributeAsInt("b");
    }
    

    /**
     * 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 {@link com.smartgwt.client.util.Color#getString getString()}.
     *
     * @return Current format value. Default value is IR
     */
    public ColorFormat getFormat()  {
        return EnumUtil.getEnum(ColorFormat.values(), getAttribute("format"));
    }
    

    /**
     * Green component, 0-255.
     *
     * @return Current g value. Default value is IR
     */
    public int getG()  {
        return getAttributeAsInt("g");
    }
    

    /**
     * HSL hue angle, 0-360 degrees. Standard CSS hue wheel: red 0/360, yellow 60, green 120, cyan 180, blue 240, magenta 300.
     *
     * @return Current h value. Default value is IR
     */
    public int getH()  {
        return getAttributeAsInt("h");
    }
    

    /**
     * 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 {@link
     * com.smartgwt.client.util.Color#getString getString("hex")} calls.
     *
     * @return Current hex value. Default value is IR
     */
    public String getHex()  {
        return getAttributeAsString("hex");
    }
    

    /**
     * HSL lightness, 0 (black) to 100 (white), as a percentage.
     *
     * @return Current l value. Default value is IR
     */
    public int getL()  {
        return getAttributeAsInt("l");
    }
    

    /**
     * Oklch chroma (color intensity), typically 0 (gray) to ~0.4 (vivid). This is the value that {@link
     * com.smartgwt.client.util.Colors#saturate saturate()}/{@link com.smartgwt.client.util.Colors#desaturate desaturate()} and
     * the <code> saturation</code> key in {@link com.smartgwt.client.util.Colors#adjust adjust()} operate on.
     *
     * @return Current ok_C value. Default value is IR
     */
    public Double getOk_C()  {
        return getAttributeAsDouble("ok_C");
    }
    

    /**
     * Oklch hue angle, 0-360 degrees. This is the value that the <code>hue</code> key in {@link
     * com.smartgwt.client.util.Colors#adjust adjust()} and {@link com.smartgwt.client.util.Colors#complement complement()}
     * operate on. The oklch hue wheel: red ~30, yellow ~90, green ~145, cyan ~195, blue ~265, purple ~310. <P> This differs
     * from the HSL {@link com.smartgwt.client.util.Color#getH h} because oklch redistributes hue angles for perceptual
     * uniformity - equal angular steps produce equal perceived color changes.
     *
     * @return Current ok_h value. Default value is IR
     */
    public Double getOk_h()  {
        return getAttributeAsDouble("ok_h");
    }
    

    /**
     * Oklch perceptual lightness, 0 (black) to 1 (white). This is the value that {@link
     * com.smartgwt.client.util.Colors#lighten lighten()}/{@link com.smartgwt.client.util.Colors#darken darken()} and the
     * <code>lightness </code> key in {@link com.smartgwt.client.util.Colors#adjust adjust()} operate on. Oklch lightness is
     * perceptually uniform - equal numeric steps produce equal perceived brightness changes, unlike HSL {@link
     * com.smartgwt.client.util.Color#getL l}.
     *
     * @return Current ok_L value. Default value is IR
     */
    public Double getOk_L()  {
        return getAttributeAsDouble("ok_L");
    }
    

    /**
     * Red component, 0-255.
     *
     * @return Current r value. Default value is IR
     */
    public int getR()  {
        return getAttributeAsInt("r");
    }
    

    /**
     * HSL saturation, 0 (gray) to 100 (fully saturated), as a percentage.
     *
     * @return Current s value. Default value is IR
     */
    public int getS()  {
        return getAttributeAsInt("s");
    }
    

    // ********************* Methods ***********************
	/**
     * Returns a new Color with the specified oklch deltas applied. Supports both friendly keys (<code>lightness</code>,
     * <code>saturation</code>, <code>hue</code>, <code>alpha</code>) and raw oklch keys (<code>L</code>, <code>C</code>,
     * <code>h</code>).
     * @param deltas adjustments to apply - see {@link com.smartgwt.client.util.Colors#adjust Colors.adjust()}
     *
     * @return new Color object
     * @see com.smartgwt.client.util.Colors#adjust
     */
    public native Color adjust(Map deltas) /*-{
        var self = this.@com.smartgwt.client.core.DataClass::getJsObj()();
        var ret = self.adjust(deltas == null ? null : @com.smartgwt.client.util.JSOHelper::convertMapToJavascriptObject(Ljava/util/Map;)(deltas));
        if(ret == null) return null;
        return @com.smartgwt.client.util.Color::getOrCreateRef(Lcom/google/gwt/core/client/JavaScriptObject;)(ret);
    }-*/;

	/**
     * Returns a brighter, more vivid Color by boosting both lightness and chroma together.
     * @param amount percentage to brighten, 0-100
     *
     * @return new Color object
     * @see com.smartgwt.client.util.Colors#brighten
     */
    public native Color brighten(double amount) /*-{
        var self = this.@com.smartgwt.client.core.DataClass::getJsObj()();
        var ret = self.brighten(amount);
        if(ret == null) return null;
        return @com.smartgwt.client.util.Color::getOrCreateRef(Lcom/google/gwt/core/client/JavaScriptObject;)(ret);
    }-*/;

	/**
     * Returns a new Color with hue rotated 180 degrees (oklch h + 180).
     *
     * @return new Color object
     * @see com.smartgwt.client.util.Colors#complement
     */
    public native Color complement() /*-{
        var self = this.@com.smartgwt.client.core.DataClass::getJsObj()();
        var ret = self.complement();
        if(ret == null) return null;
        return @com.smartgwt.client.util.Color::getOrCreateRef(Lcom/google/gwt/core/client/JavaScriptObject;)(ret);
    }-*/;

	/**
     * Returns the approximate perceptual contrast ratio between this color and another (oklch-based).
     * @param other color to compare against
     *
     * @return approximate contrast ratio (>= 1.0), or null if other is invalid
     * @see com.smartgwt.client.util.Colors#contrast
     */
    public native Double contrast(String other) /*-{
        var self = this.@com.smartgwt.client.core.DataClass::getJsObj()();
        var ret = self.contrast(other);
        if(ret == null) return null;
        return @com.smartgwt.client.util.JSOHelper::toDouble(D)(ret);
    }-*/;

	/**
     * Returns the approximate perceptual contrast ratio between this color and another (oklch-based).
     * @param other color to compare against
     *
     * @return approximate contrast ratio (>= 1.0), or null if other is invalid
     * @see com.smartgwt.client.util.Colors#contrast
     */
    public native Double contrast(Color other) /*-{
        var self = this.@com.smartgwt.client.core.DataClass::getJsObj()();
        var ret = self.contrast(other.@com.smartgwt.client.core.DataClass::getJsObj()());
        if(ret == null) return null;
        return @com.smartgwt.client.util.JSOHelper::toDouble(D)(ret);
    }-*/;

	/**
     * Returns a new Color darkened by the given amount (oklch L decreased).
     * @param amount percentage to darken, 0-100
     *
     * @return new Color object
     * @see com.smartgwt.client.util.Colors#darken
     */
    public native Color darken(int amount) /*-{
        var self = this.@com.smartgwt.client.core.DataClass::getJsObj()();
        var ret = self.darken(amount);
        if(ret == null) return null;
        return @com.smartgwt.client.util.Color::getOrCreateRef(Lcom/google/gwt/core/client/JavaScriptObject;)(ret);
    }-*/;

	/**
     * Returns a new Color with chroma decreased (oklch C decreased).
     * @param amount percentage to desaturate, 0-100
     *
     * @return new Color object
     * @see com.smartgwt.client.util.Colors#desaturate
     */
    public native Color desaturate(int amount) /*-{
        var self = this.@com.smartgwt.client.core.DataClass::getJsObj()();
        var ret = self.desaturate(amount);
        if(ret == null) return null;
        return @com.smartgwt.client.util.Color::getOrCreateRef(Lcom/google/gwt/core/client/JavaScriptObject;)(ret);
    }-*/;

	/**
     * Returns a dimmer, more muted Color by reducing both lightness and chroma together.
     * @param amount percentage to dim, 0-100
     *
     * @return new Color object
     * @see com.smartgwt.client.util.Colors#dim
     */
    public native Color dim(double amount) /*-{
        var self = this.@com.smartgwt.client.core.DataClass::getJsObj()();
        var ret = self.dim(amount);
        if(ret == null) return null;
        return @com.smartgwt.client.util.Color::getOrCreateRef(Lcom/google/gwt/core/client/JavaScriptObject;)(ret);
    }-*/;

	/**
     * Returns the perceptual distance between this color and another in oklab space.
     * @param other color to compare against
     *
     * @return perceptual distance (>= 0), or null if other is invalid
     * @see com.smartgwt.client.util.Colors#distance
     */
    public native Double distance(String other) /*-{
        var self = this.@com.smartgwt.client.core.DataClass::getJsObj()();
        var ret = self.distance(other);
        if(ret == null) return null;
        return @com.smartgwt.client.util.JSOHelper::toDouble(D)(ret);
    }-*/;

	/**
     * Returns the perceptual distance between this color and another in oklab space.
     * @param other color to compare against
     *
     * @return perceptual distance (>= 0), or null if other is invalid
     * @see com.smartgwt.client.util.Colors#distance
     */
    public native Double distance(Color other) /*-{
        var self = this.@com.smartgwt.client.core.DataClass::getJsObj()();
        var ret = self.distance(other.@com.smartgwt.client.core.DataClass::getJsObj()());
        if(ret == null) return null;
        return @com.smartgwt.client.util.JSOHelper::toDouble(D)(ret);
    }-*/;

	/**
     * Returns true if this color is visually identical to another (same RGB + alpha).
     * @param other color to compare
     *
     * @return 
     * @see com.smartgwt.client.util.Colors#equals
     */
    public native boolean equals(String other) /*-{
        var self = this.@com.smartgwt.client.core.DataClass::getJsObj()();
        var ret = self.equals(other);
        return ret == null ? false : ret;
    }-*/;

	/**
     * Returns true if this color is visually identical to another (same RGB + alpha).
     * @param other color to compare
     *
     * @return 
     * @see com.smartgwt.client.util.Colors#equals
     */
    public native boolean equals(Color other) /*-{
        var self = this.@com.smartgwt.client.core.DataClass::getJsObj()();
        var ret = self.equals(other.@com.smartgwt.client.core.DataClass::getJsObj()());
        return ret == null ? false : ret;
    }-*/;

	/**
     * Returns a CSS color string in the specified format, defaulting to the source format detected when this Color was
     * created.
     *
     * @return CSS color string
     */
    public native String getString() /*-{
        var self = this.@com.smartgwt.client.core.DataClass::getJsObj()();
        var ret = self.getString();
        return ret;
    }-*/;

	/**
     * Returns a CSS color string in the specified format, defaulting to the source format detected when this Color was
     * created.
     * @param format output format - defaults to {@link com.smartgwt.client.util.Color#getFormat format}
     *
     * @return CSS color string
     */
    public native String getString(ColorFormat format) /*-{
        var self = this.@com.smartgwt.client.core.DataClass::getJsObj()();
        var ret = self.getString(format == null ? null : format.@com.smartgwt.client.types.ColorFormat::getValue()());
        return ret;
    }-*/;
	
	/**
     * Returns true if this color is perceptually dark (oklch L &lt; 0.6).
     *
     * @return 
     * @see com.smartgwt.client.util.Colors#isDark
     */
    public native boolean isDark() /*-{
        var self = this.@com.smartgwt.client.core.DataClass::getJsObj()();
        var ret = self.isDark();
        return ret == null ? false : ret;
    }-*/;

	/**
     * 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.
     *
     * @return true if the color was parsed successfully
     */
    public native boolean isValid() /*-{
        var self = this.@com.smartgwt.client.core.DataClass::getJsObj()();
        var ret = self.isValid();
        return ret == null ? false : ret;
    }-*/;

	/**
     * Returns a new Color lightened by the given amount (oklch L increased).
     * @param amount percentage to lighten, 0-100
     *
     * @return new Color object
     * @see com.smartgwt.client.util.Colors#lighten
     */
    public native Color lighten(int amount) /*-{
        var self = this.@com.smartgwt.client.core.DataClass::getJsObj()();
        var ret = self.lighten(amount);
        if(ret == null) return null;
        return @com.smartgwt.client.util.Color::getOrCreateRef(Lcom/google/gwt/core/client/JavaScriptObject;)(ret);
    }-*/;

	/**
     * Returns a new Color with chroma increased (oklch C increased).
     * @param amount percentage to saturate, 0-100
     *
     * @return new Color object
     * @see com.smartgwt.client.util.Colors#saturate
     */
    public native Color saturate(int amount) /*-{
        var self = this.@com.smartgwt.client.core.DataClass::getJsObj()();
        var ret = self.saturate(amount);
        if(ret == null) return null;
        return @com.smartgwt.client.util.Color::getOrCreateRef(Lcom/google/gwt/core/client/JavaScriptObject;)(ret);
    }-*/;

	/**
     * Returns a new Color with hue rotated by the given number of degrees (oklch h).
     * @param degrees degrees to rotate, positive or negative
     *
     * @return new Color object
     * @see com.smartgwt.client.util.Colors#spin
     */
    public native Color spin(double degrees) /*-{
        var self = this.@com.smartgwt.client.core.DataClass::getJsObj()();
        var ret = self.spin(degrees);
        if(ret == null) return null;
        return @com.smartgwt.client.util.Color::getOrCreateRef(Lcom/google/gwt/core/client/JavaScriptObject;)(ret);
    }-*/;


    // ********************* Static Methods ***********************

    // ***********************************************************

}
