Package mil.nga.color

Class Color


  • public class Color
    extends Object
    Color representation with support for hex, RBG, arithmetic RBG, HSL, and integer colors
    Author:
    osbornb
    • Constructor Summary

      Constructors 
      Constructor Description
      Color()
      Default color constructor, opaque black
      Color​(float[] hsl)
      Create the color with HSL (hue, saturation, lightness) or HSL (alpha) values
      Color​(float[] hsl, float alpha)
      Create the color with HSLA (hue, saturation, lightness, alpha) values
      Color​(float red, float green, float blue)
      Create the color with arithmetic RGB values
      Color​(float red, float green, float blue, float opacity)
      Create the color with arithmetic RGB values
      Color​(int color)
      Create the color as a single integer
      Color​(int red, int green, int blue)
      Create the color with RGB values
      Color​(int red, int green, int blue, float opacity)
      Create the color with RGBA values
      Color​(int red, int green, int blue, int alpha)
      Create the color with RGBA values
      Color​(String color)
      Create the color in hex
      Color​(String color, float opacity)
      Create the color in hex with an opacity
      Color​(String color, int alpha)
      Create the color in hex with an alpha
      Color​(String red, String green, String blue)
      Create the color with individual hex colors
      Color​(String red, String green, String blue, float opacity)
      Create the color with individual hex colors and opacity
      Color​(String red, String green, String blue, String alpha)
      Create the color with individual hex colors and alpha
      Color​(Color color)
      Copy constructor
    • Constructor Detail

      • Color

        public Color()
        Default color constructor, opaque black
      • Color

        public Color​(String color)
        Create the color in hex
        Parameters:
        color - hex color in format #RRGGBB, RRGGBB, #RGB, RGB, #AARRGGBB, AARRGGBB, #ARGB, or ARGB
      • Color

        public Color​(String color,
                     float opacity)
        Create the color in hex with an opacity
        Parameters:
        color - hex color in format #RRGGBB, RRGGBB, #RGB, RGB, #AARRGGBB, AARRGGBB, #ARGB, or ARGB
        opacity - opacity float inclusively between 0.0 and 1.0
      • Color

        public Color​(String color,
                     int alpha)
        Create the color in hex with an alpha
        Parameters:
        color - hex color in format #RRGGBB, RRGGBB, #RGB, RGB, #AARRGGBB, AARRGGBB, #ARGB, or ARGB
        alpha - alpha integer color inclusively between 0 and 255
      • Color

        public Color​(String red,
                     String green,
                     String blue)
        Create the color with individual hex colors
        Parameters:
        red - red hex color in format RR
        green - green hex color in format GG
        blue - blue hex color in format BB
      • Color

        public Color​(String red,
                     String green,
                     String blue,
                     String alpha)
        Create the color with individual hex colors and alpha
        Parameters:
        red - red hex color in format RR
        green - green hex color in format GG
        blue - blue hex color in format BB
        alpha - alpha hex color in format AA
      • Color

        public Color​(String red,
                     String green,
                     String blue,
                     float opacity)
        Create the color with individual hex colors and opacity
        Parameters:
        red - red hex color in format RR
        green - green hex color in format GG
        blue - blue hex color in format BB
        opacity - opacity float inclusively between 0.0 and 1.0
      • Color

        public Color​(int red,
                     int green,
                     int blue)
        Create the color with RGB values
        Parameters:
        red - red integer color inclusively between 0 and 255
        green - green integer color inclusively between 0 and 255
        blue - blue integer color inclusively between 0 and 255
      • Color

        public Color​(int red,
                     int green,
                     int blue,
                     int alpha)
        Create the color with RGBA values
        Parameters:
        red - red integer color inclusively between 0 and 255
        green - green integer color inclusively between 0 and 255
        blue - blue integer color inclusively between 0 and 255
        alpha - alpha integer color inclusively between 0 and 255
      • Color

        public Color​(int red,
                     int green,
                     int blue,
                     float opacity)
        Create the color with RGBA values
        Parameters:
        red - red integer color inclusively between 0 and 255
        green - green integer color inclusively between 0 and 255
        blue - blue integer color inclusively between 0 and 255
        opacity - opacity float inclusively between 0.0 and 1.0
      • Color

        public Color​(float red,
                     float green,
                     float blue)
        Create the color with arithmetic RGB values
        Parameters:
        red - red float color inclusively between 0.0 and 1.0
        green - green float color inclusively between 0.0 and 1.0
        blue - blue float color inclusively between 0.0 and 1.0
      • Color

        public Color​(float red,
                     float green,
                     float blue,
                     float opacity)
        Create the color with arithmetic RGB values
        Parameters:
        red - red float color inclusively between 0.0 and 1.0
        green - green float color inclusively between 0.0 and 1.0
        blue - blue float color inclusively between 0.0 and 1.0
        opacity - opacity float inclusively between 0.0 and 1.0
      • Color

        public Color​(float[] hsl)
        Create the color with HSL (hue, saturation, lightness) or HSL (alpha) values
        Parameters:
        hsl - HSL array where: 0 = hue, 1 = saturation, 2 = lightness, optional 3 = alpha
      • Color

        public Color​(float[] hsl,
                     float alpha)
        Create the color with HSLA (hue, saturation, lightness, alpha) values
        Parameters:
        hsl - HSL array where: 0 = hue, 1 = saturation, 2 = lightness
        alpha - alpha inclusively between 0.0 and 1.0
      • Color

        public Color​(int color)
        Create the color as a single integer
        Parameters:
        color - color integer
      • Color

        public Color​(Color color)
        Copy constructor
        Parameters:
        color - color to copy
    • Method Detail

      • black

        public static Color black()
        Create a black color
        Returns:
        color
      • blue

        public static Color blue()
        Create a blue color
        Returns:
        color
      • brown

        public static Color brown()
        Create a brown color
        Returns:
        color
      • cyan

        public static Color cyan()
        Create a cyan color
        Returns:
        color
      • darkGray

        public static Color darkGray()
        Create a dark gray color
        Returns:
        color
      • gray

        public static Color gray()
        Create a gray color
        Returns:
        color
      • green

        public static Color green()
        Create a green color
        Returns:
        color
      • lightGray

        public static Color lightGray()
        Create a light gray color
        Returns:
        color
      • magenta

        public static Color magenta()
        Create a magenta color
        Returns:
        color
      • orange

        public static Color orange()
        Create an orange color
        Returns:
        color
      • pink

        public static Color pink()
        Create a pink color
        Returns:
        color
      • purple

        public static Color purple()
        Create a purple color
        Returns:
        color
      • red

        public static Color red()
        Create a red color
        Returns:
        color
      • violet

        public static Color violet()
        Create a violet color
        Returns:
        color
      • white

        public static Color white()
        Create a white color
        Returns:
        color
      • yellow

        public static Color yellow()
        Create a yellow color
        Returns:
        color
      • color

        public static Color color​(String color)
        Create the color in hex
        Parameters:
        color - hex color in format #RRGGBB, RRGGBB, #RGB, RGB, #AARRGGBB, AARRGGBB, #ARGB, or ARGB
        Returns:
        color
      • color

        public static Color color​(String color,
                                  float opacity)
        Create the color in hex with an opacity
        Parameters:
        color - hex color in format #RRGGBB, RRGGBB, #RGB, RGB, #AARRGGBB, AARRGGBB, #ARGB, or ARGB
        opacity - opacity float inclusively between 0.0 and 1.0
        Returns:
        color
      • color

        public static Color color​(String color,
                                  int alpha)
        Create the color in hex with an alpha
        Parameters:
        color - hex color in format #RRGGBB, RRGGBB, #RGB, RGB, #AARRGGBB, AARRGGBB, #ARGB, or ARGB
        alpha - alpha integer color inclusively between 0 and 255
        Returns:
        color
      • color

        public static Color color​(String red,
                                  String green,
                                  String blue)
        Create the color with individual hex colors
        Parameters:
        red - red hex color in format RR
        green - green hex color in format GG
        blue - blue hex color in format BB
        Returns:
        color
      • color

        public static Color color​(String red,
                                  String green,
                                  String blue,
                                  String alpha)
        Create the color with individual hex colors and alpha
        Parameters:
        red - red hex color in format RR
        green - green hex color in format GG
        blue - blue hex color in format BB
        alpha - alpha hex color in format AA
        Returns:
        color
      • color

        public static Color color​(String red,
                                  String green,
                                  String blue,
                                  float opacity)
        Create the color with individual hex colors and opacity
        Parameters:
        red - red hex color in format RR
        green - green hex color in format GG
        blue - blue hex color in format BB
        opacity - opacity float inclusively between 0.0 and 1.0
        Returns:
        color
      • color

        public static Color color​(int red,
                                  int green,
                                  int blue)
        Create the color with RGB values
        Parameters:
        red - red integer color inclusively between 0 and 255
        green - green integer color inclusively between 0 and 255
        blue - blue integer color inclusively between 0 and 255
        Returns:
        color
      • color

        public static Color color​(int red,
                                  int green,
                                  int blue,
                                  int alpha)
        Create the color with RGBA values
        Parameters:
        red - red integer color inclusively between 0 and 255
        green - green integer color inclusively between 0 and 255
        blue - blue integer color inclusively between 0 and 255
        alpha - alpha integer color inclusively between 0 and 255
        Returns:
        color
      • color

        public static Color color​(int red,
                                  int green,
                                  int blue,
                                  float opacity)
        Create the color with RGBA values
        Parameters:
        red - red integer color inclusively between 0 and 255
        green - green integer color inclusively between 0 and 255
        blue - blue integer color inclusively between 0 and 255
        opacity - opacity float inclusively between 0.0 and 1.0
        Returns:
        color
      • color

        public static Color color​(float red,
                                  float green,
                                  float blue)
        Create the color with arithmetic RGB values
        Parameters:
        red - red float color inclusively between 0.0 and 1.0
        green - green float color inclusively between 0.0 and 1.0
        blue - blue float color inclusively between 0.0 and 1.0
        Returns:
        color
      • color

        public static Color color​(float red,
                                  float green,
                                  float blue,
                                  float opacity)
        Create the color with arithmetic RGB values
        Parameters:
        red - red float color inclusively between 0.0 and 1.0
        green - green float color inclusively between 0.0 and 1.0
        blue - blue float color inclusively between 0.0 and 1.0
        opacity - opacity float inclusively between 0.0 and 1.0
        Returns:
        color
      • color

        public static Color color​(float[] hsl)
        Create the color with HSL (hue, saturation, lightness) or HSL (alpha) values
        Parameters:
        hsl - HSL array where: 0 = hue, 1 = saturation, 2 = lightness, optional 3 = alpha
        Returns:
        color
      • color

        public static Color color​(float[] hsl,
                                  float alpha)
        Create the color with HSLA (hue, saturation, lightness, alpha) values
        Parameters:
        hsl - HSL array where: 0 = hue, 1 = saturation, 2 = lightness
        alpha - alpha inclusively between 0.0 and 1.0
        Returns:
        color
      • color

        public static Color color​(int color)
        Create the color as a single integer
        Parameters:
        color - color integer
        Returns:
        color
      • setColor

        public void setColor​(String color)
        Set the color in hex
        Parameters:
        color - hex color in format #RRGGBB, RRGGBB, #RGB, RGB, #AARRGGBB, AARRGGBB, #ARGB, or ARGB
      • setColor

        public void setColor​(String color,
                             float opacity)
        Set the color in hex with an opacity
        Parameters:
        color - hex color in format #RRGGBB, RRGGBB, #RGB, RGB, #AARRGGBB, AARRGGBB, #ARGB, or ARGB
        opacity - opacity float inclusively between 0.0 and 1.0
      • setColor

        public void setColor​(String color,
                             int alpha)
        Set the color in hex with an alpha
        Parameters:
        color - hex color in format #RRGGBB, RRGGBB, #RGB, RGB, #AARRGGBB, AARRGGBB, #ARGB, or ARGB
        alpha - alpha integer color inclusively between 0 and 255
      • setColor

        public void setColor​(String red,
                             String green,
                             String blue)
        Set the color with individual hex colors
        Parameters:
        red - red hex color in format RR
        green - green hex color in format GG
        blue - blue hex color in format BB
      • setColor

        public void setColor​(String red,
                             String green,
                             String blue,
                             String alpha)
        Set the color with individual hex colors and alpha
        Parameters:
        red - red hex color in format RR
        green - green hex color in format GG
        blue - blue hex color in format BB
        alpha - alpha hex color in format AA
      • setColor

        public void setColor​(String red,
                             String green,
                             String blue,
                             float opacity)
        Set the color with individual hex colors and opacity
        Parameters:
        red - red hex color in format RR
        green - green hex color in format GG
        blue - blue hex color in format BB
        opacity - opacity float inclusively between 0.0 and 1.0
      • setColor

        public void setColor​(int red,
                             int green,
                             int blue)
        Set the color with RGB values
        Parameters:
        red - red integer color inclusively between 0 and 255
        green - green integer color inclusively between 0 and 255
        blue - blue integer color inclusively between 0 and 255
      • setColor

        public void setColor​(int red,
                             int green,
                             int blue,
                             int alpha)
        Set the color with RGBA values
        Parameters:
        red - red integer color inclusively between 0 and 255
        green - green integer color inclusively between 0 and 255
        blue - blue integer color inclusively between 0 and 255
        alpha - alpha integer color inclusively between 0 and 255
      • setColor

        public void setColor​(int red,
                             int green,
                             int blue,
                             float opacity)
        Set the color with RGBA values
        Parameters:
        red - red integer color inclusively between 0 and 255
        green - green integer color inclusively between 0 and 255
        blue - blue integer color inclusively between 0 and 255
        opacity - opacity float inclusively between 0.0 and 1.0
      • setColor

        public void setColor​(float red,
                             float green,
                             float blue)
        Set the color with arithmetic RGB values
        Parameters:
        red - red float color inclusively between 0.0 and 1.0
        green - green float color inclusively between 0.0 and 1.0
        blue - blue float color inclusively between 0.0 and 1.0
      • setColor

        public void setColor​(float red,
                             float green,
                             float blue,
                             float opacity)
        Set the color with arithmetic RGB values
        Parameters:
        red - red float color inclusively between 0.0 and 1.0
        green - green float color inclusively between 0.0 and 1.0
        blue - blue float color inclusively between 0.0 and 1.0
        opacity - opacity float inclusively between 0.0 and 1.0
      • setColorByHSL

        public void setColorByHSL​(float hue,
                                  float saturation,
                                  float lightness)
        Set the color with HSL (hue, saturation, lightness) values
        Parameters:
        hue - hue value inclusively between 0.0 and 360.0
        saturation - saturation inclusively between 0.0 and 1.0
        lightness - lightness inclusively between 0.0 and 1.0
      • setColorByHSL

        public void setColorByHSL​(float hue,
                                  float saturation,
                                  float lightness,
                                  float alpha)
        Set the color with HSLA (hue, saturation, lightness, alpha) values
        Parameters:
        hue - hue value inclusively between 0.0 and 360.0
        saturation - saturation inclusively between 0.0 and 1.0
        lightness - lightness inclusively between 0.0 and 1.0
        alpha - alpha inclusively between 0.0 and 1.0
      • setColor

        public void setColor​(int color)
        Set the color as a single integer
        Parameters:
        color - color integer
      • setRed

        public void setRed​(String red)
        Set the red color in hex
        Parameters:
        red - red hex color in format RR or R
      • setGreen

        public void setGreen​(String green)
        Set the green color in hex
        Parameters:
        green - green hex color in format GG or G
      • setBlue

        public void setBlue​(String blue)
        Set the blue color in hex
        Parameters:
        blue - blue hex color in format BB or B
      • setAlpha

        public void setAlpha​(String alpha)
        Set the alpha color in hex
        Parameters:
        alpha - alpha hex color in format AA or A
      • setRed

        public void setRed​(int red)
        Set the red color as an integer
        Parameters:
        red - red integer color inclusively between 0 and 255
      • setGreen

        public void setGreen​(int green)
        Set the green color as an integer
        Parameters:
        green - green integer color inclusively between 0 and 255
      • setBlue

        public void setBlue​(int blue)
        Set the blue color as an integer
        Parameters:
        blue - blue integer color inclusively between 0 and 255
      • setAlpha

        public void setAlpha​(int alpha)
        Set the alpha color as an integer
        Parameters:
        alpha - alpha integer color inclusively between 0 and 255
      • setRed

        public void setRed​(float red)
        Set the red color as an arithmetic float
        Parameters:
        red - red float color inclusively between 0.0 and 1.0
      • setGreen

        public void setGreen​(float green)
        Set the green color as an arithmetic float
        Parameters:
        green - green float color inclusively between 0.0 and 1.0
      • setBlue

        public void setBlue​(float blue)
        Set the blue color as an arithmetic float
        Parameters:
        blue - blue float color inclusively between 0.0 and 1.0
      • setOpacity

        public void setOpacity​(float opacity)
        Set the opacity as an arithmetic float
        Parameters:
        opacity - opacity float color inclusively between 0.0 and 1.0
      • setAlpha

        public void setAlpha​(float alpha)
        Set the alpha color as an arithmetic float
        Parameters:
        alpha - alpha float color inclusively between 0.0 and 1.0
      • isOpaque

        public boolean isOpaque()
        Check if the color is opaque (opacity or alpha of 1.0, 255, or x00)
        Returns:
        true if opaque
      • getColorHex

        public String getColorHex()
        Get the color as a hex string
        Returns:
        hex color in the format #RRGGBB
      • getColorHexWithAlpha

        public String getColorHexWithAlpha()
        Get the color as a hex string with alpha
        Returns:
        hex color in the format #AARRGGBB
      • getColorHexShorthand

        public String getColorHexShorthand()
        Get the color as a hex string, shorthanded when possible
        Returns:
        hex color in the format #RGB or #RRGGBB
      • getColorHexShorthandWithAlpha

        public String getColorHexShorthandWithAlpha()
        Get the color as a hex string with alpha, shorthanded when possible
        Returns:
        hex color in the format #ARGB or #AARRGGBB
      • getColor

        public int getColor()
        Get the color as an integer
        Returns:
        integer color
      • getColorWithAlpha

        public int getColorWithAlpha()
        Get the color as an integer including the alpha
        Returns:
        integer color
      • getRedHex

        public String getRedHex()
        Get the red color in hex
        Returns:
        red hex color in format RR
      • getGreenHex

        public String getGreenHex()
        Get the green color in hex
        Returns:
        green hex color in format GG
      • getBlueHex

        public String getBlueHex()
        Get the blue color in hex
        Returns:
        blue hex color in format BB
      • getAlphaHex

        public String getAlphaHex()
        Get the alpha color in hex
        Returns:
        alpha hex color in format AA
      • getRedHexShorthand

        public String getRedHexShorthand()
        Get the red color in hex, shorthand when possible
        Returns:
        red hex color in format R or RR
      • getGreenHexShorthand

        public String getGreenHexShorthand()
        Get the green color in hex, shorthand when possible
        Returns:
        green hex color in format G or GG
      • getBlueHexShorthand

        public String getBlueHexShorthand()
        Get the blue color in hex, shorthand when possible
        Returns:
        blue hex color in format B or BB
      • getAlphaHexShorthand

        public String getAlphaHexShorthand()
        Get the alpha color in hex, shorthand when possible
        Returns:
        alpha hex color in format A or AA
      • getRed

        public int getRed()
        Get the red color as an integer
        Returns:
        red integer color inclusively between 0 and 255
      • getGreen

        public int getGreen()
        Get the green color as an integer
        Returns:
        green integer color inclusively between 0 and 255
      • getBlue

        public int getBlue()
        Get the blue color as an integer
        Returns:
        blue integer color inclusively between 0 and 255
      • getAlpha

        public int getAlpha()
        Get the alpha color as an integer
        Returns:
        alpha integer color inclusively between 0 and 255
      • getRedArithmetic

        public float getRedArithmetic()
        Get the red color as an arithmetic float
        Returns:
        red float color inclusively between 0.0 and 1.0
      • getGreenArithmetic

        public float getGreenArithmetic()
        Get the green color as an arithmetic float
        Returns:
        green float color inclusively between 0.0 and 1.0
      • getBlueArithmetic

        public float getBlueArithmetic()
        Get the blue color as an arithmetic float
        Returns:
        blue float color inclusively between 0.0 and 1.0
      • getOpacity

        public float getOpacity()
        Get the opacity as an arithmetic float
        Returns:
        opacity float inclusively between 0.0 and 1.0
      • getAlphaArithmetic

        public float getAlphaArithmetic()
        Get the alpha color as an arithmetic float
        Returns:
        alpha float color inclusively between 0.0 and 1.0
      • getHSL

        public float[] getHSL()
        Get the HSL (hue, saturation, lightness) values
        Returns:
        HSL array where: 0 = hue, 1 = saturation, 2 = lightness
      • getHue

        public float getHue()
        Get the HSL hue value
        Returns:
        hue value
      • getSaturation

        public float getSaturation()
        Get the HSL saturation value
        Returns:
        saturation value
      • getLightness

        public float getLightness()
        Get the HSL lightness value
        Returns:
        lightness value
      • copy

        public Color copy()
        Copy the color
        Returns:
        color copy