Class GColor

  • All Implemented Interfaces:
    java.lang.Cloneable

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

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

      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

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void appendColor​(SendTransaction trans)
      Appends the color to a transaction.
      static GColor createGColor​(java.lang.String string)
      Creates a GColor from a String.
      boolean equals​(GColor color)
      Checks if two color objects are equal.
      boolean equals​(java.lang.Object o)
      Checks if two color objects are equal.
      static GColor from​(ReadTransaction trans)
      Creates a color from a transaction.
      int getColor()
      Gets the color value as ARGB.
      static java.lang.String[] getColorNames()
      Returns a list of all the color names sorted in alphabetical order.
      java.lang.String getCSSValue()
      Gets the shortest CSS color string for this color.
      java.lang.String getName()
      Returns the color name.
      static int getRGBColorFromCSS3Name​(java.lang.String name)
      Gets a color RGB value from a CSS3 color name.
      java.lang.String getString()
      Gets the color as a String in the form described below.
      int hashCode()
      Hash code.
      boolean isInherited()
      Returns whether the color is inherited or not.
      boolean isOpaque()
      Checks if this color is (100%) opaque and not a color by name or not a system color, i.e.
      boolean isThemeColor()
      Returns the theme color flag.
      boolean isTransparent()
      Checks if this color is transparent, or no color is set.
      protected java.lang.String paramString()
      Returns the parameter string representing the state of this event.
      static GColor parseGColor​(java.lang.String string)
      Parses an HTML color String, such as "#nnn", "#123456", "rgb(r,g,b)", "rgba(r,g,b,a)" or a named color.
      java.lang.String toString()
      Returns a string representation of this class instance and its values.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • NONE

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

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

        public static final java.util.HashMap<java.lang.Integer,​java.lang.String> namesForColors
        The map of colors to name where only the first entry is taken.
    • Constructor Detail

      • 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:
        java.lang.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:
        java.lang.IllegalArgumentException - if any r,g,b color 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:
        java.lang.IllegalArgumentException - if any r,g,b color is not 0-255.
      • GColor

        public GColor​(int rgb)
        Creates an opaque RGB color object.
        Parameters:
        rgb - The integer red, green and blue colors.
        Throws:
        java.lang.IllegalArgumentException - if rgb < 0 or rgb > 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:
        java.lang.IllegalArgumentException - if any r,g,b color is not 0-255.
    • Method Detail

      • getColorNames

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

        public static int getRGBColorFromCSS3Name​(java.lang.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

        public static GColor createGColor​(java.lang.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:
        java.lang.IllegalArgumentException - for errors in the string specification.
        java.lang.NumberFormatException - for invalid number formats.
      • parseGColor

        public static GColor parseGColor​(java.lang.String string)
                                  throws java.text.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:
        java.text.ParseException - If parsing failed.
      • from

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

        public java.lang.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

        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

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

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

        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

        public int hashCode()
        Hash code.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        Returns the hash code.
      • 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).
      • 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.
      • getString

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

        protected java.lang.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

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

        public java.lang.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.