Class GColor

java.lang.Object
com.iizix.prop.GColor
All Implemented Interfaces:
Cloneable

public class GColor extends Object implements Cloneable
This is a data holder class for color, typically an RGB(A) color for a component.
Author:
Christopher Mindus
  • Field Summary Link icon

    Fields
    Modifier and Type
    Field
    Description
    static final GColor
    The inherited color, used for CSS.
    static final HashMap<Integer,String>
    The map of colors to name where only the first entry is taken.
    static final GColor
    The no-color, i.e.
  • Constructor Summary Link icon

    Constructors
    Constructor
    Description
    GColor(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 Link icon

    Modifier and Type
    Method
    Description
    void
    Appends the color to a transaction.
    static GColor
    Creates a GColor from a String.
    boolean
    equals(GColor color)
    Checks if two color objects are equal.
    boolean
    Checks if two color objects are equal.
    static GColor
    Creates a color from a transaction.
    int
    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.
    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
    Hash code.
    boolean
    Returns whether the color is inherited or not.
    boolean
    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
    Parses an HTML color String, such as "#nnn", "#123456", "rgb(r,g,b)", "rgba(r,g,b,a)" or a named color.
    Returns a string representation of this class instance and its values.

    Methods inherited from class java.lang.Object Link icon

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details Link icon

    • NONE Link icon

      public static final GColor NONE
      The no-color, i.e. full transparent.
    • INHERIT Link icon

      public static final GColor INHERIT
      The inherited color, used for CSS.
    • namesForColors Link icon

      public static final HashMap<Integer,String> namesForColors
      The map of colors to name where only the first entry is taken.
  • Constructor Details Link icon

    • GColor Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      public GColor(int rgb)
      Creates an opaque RGB color object.
      Parameters:
      rgb - The integer red, green and blue colors.
      Throws:
      IllegalArgumentException - if rgb < 0 or rgb > 0xFFFFFF.
    • GColor Link icon

      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 Link icon

    • getColorNames Link icon

      public static String[] getColorNames()
      Returns a list of all the color names sorted in alphabetical order.
      Returns:
      The color names array.
    • getRGBColorFromCSS3Name Link icon

      public static int getRGBColorFromCSS3Name(String name)
      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 Link icon

      public static GColor createGColor(String string)
      Creates a GColor from a String. If the string is null or empty, GColor.NONE is returned, otherwise a new GColor as if new 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 Link icon

      public static GColor parseGColor(String string) throws ParseException
      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 Link icon

      public static GColor from(ReadTransaction trans)
      Creates a color from a transaction.
      Parameters:
      trans - The transaction.
      Returns:
      The color.
    • getName Link icon

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

      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 Link icon

      public void appendColor(SendTransaction trans)
      Appends the color to a transaction.
      Parameters:
      trans - The transaction.
    • equals Link icon

      public boolean equals(Object o)
      Checks if two color objects are equal.
      Overrides:
      equals in class Object
    • equals Link icon

      public boolean equals(GColor color)
      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 Link icon

      public int hashCode()
      Hash code.
      Overrides:
      hashCode in class Object
      Returns:
      Returns the hash code.
    • isInherited Link icon

      public boolean isInherited()
      Returns whether the color is inherited or not.
      Returns:
      true for CSS "inherit" color, false otherwise.
    • isTransparent Link icon

      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 Link icon

      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 Link icon

      public int getColor()
      Gets the color value as ARGB.
      Returns:
      The color value, -1 if inherited.
    • getString Link icon

      public String getString()
      Gets the color as a String in the form described below.
      Returns:
      the String as described below.
    • paramString Link icon

      protected String 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 Link icon

      public String toString()
      Returns a string representation of this class instance and its values.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this class instance.
    • getCSSValue Link icon

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