Package mil.nga.color
Class Color
- java.lang.Object
-
- mil.nga.color.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 blackColor(float[] hsl)Create the color with HSL (hue, saturation, lightness) or HSL (alpha) valuesColor(float[] hsl, float alpha)Create the color with HSLA (hue, saturation, lightness, alpha) valuesColor(float red, float green, float blue)Create the color with arithmetic RGB valuesColor(float red, float green, float blue, float opacity)Create the color with arithmetic RGB valuesColor(int color)Create the color as a single integerColor(int red, int green, int blue)Create the color with RGB valuesColor(int red, int green, int blue, float opacity)Create the color with RGBA valuesColor(int red, int green, int blue, int alpha)Create the color with RGBA valuesColor(String color)Create the color in hexColor(String color, float opacity)Create the color in hex with an opacityColor(String color, int alpha)Create the color in hex with an alphaColor(String red, String green, String blue)Create the color with individual hex colorsColor(String red, String green, String blue, float opacity)Create the color with individual hex colors and opacityColor(String red, String green, String blue, String alpha)Create the color with individual hex colors and alphaColor(Color color)Copy constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Colorblack()Create a black colorstatic Colorblue()Create a blue colorstatic Colorbrown()Create a brown colorstatic Colorcolor(float[] hsl)Create the color with HSL (hue, saturation, lightness) or HSL (alpha) valuesstatic Colorcolor(float[] hsl, float alpha)Create the color with HSLA (hue, saturation, lightness, alpha) valuesstatic Colorcolor(float red, float green, float blue)Create the color with arithmetic RGB valuesstatic Colorcolor(float red, float green, float blue, float opacity)Create the color with arithmetic RGB valuesstatic Colorcolor(int color)Create the color as a single integerstatic Colorcolor(int red, int green, int blue)Create the color with RGB valuesstatic Colorcolor(int red, int green, int blue, float opacity)Create the color with RGBA valuesstatic Colorcolor(int red, int green, int blue, int alpha)Create the color with RGBA valuesstatic Colorcolor(String color)Create the color in hexstatic Colorcolor(String color, float opacity)Create the color in hex with an opacitystatic Colorcolor(String color, int alpha)Create the color in hex with an alphastatic Colorcolor(String red, String green, String blue)Create the color with individual hex colorsstatic Colorcolor(String red, String green, String blue, float opacity)Create the color with individual hex colors and opacitystatic Colorcolor(String red, String green, String blue, String alpha)Create the color with individual hex colors and alphaColorcopy()Copy the colorstatic Colorcyan()Create a cyan colorstatic ColordarkGray()Create a dark gray colorintgetAlpha()Get the alpha color as an integerfloatgetAlphaArithmetic()Get the alpha color as an arithmetic floatStringgetAlphaHex()Get the alpha color in hexStringgetAlphaHexShorthand()Get the alpha color in hex, shorthand when possibleintgetBlue()Get the blue color as an integerfloatgetBlueArithmetic()Get the blue color as an arithmetic floatStringgetBlueHex()Get the blue color in hexStringgetBlueHexShorthand()Get the blue color in hex, shorthand when possibleintgetColor()Get the color as an integerStringgetColorHex()Get the color as a hex stringStringgetColorHexShorthand()Get the color as a hex string, shorthanded when possibleStringgetColorHexShorthandWithAlpha()Get the color as a hex string with alpha, shorthanded when possibleStringgetColorHexWithAlpha()Get the color as a hex string with alphaintgetColorWithAlpha()Get the color as an integer including the alphaintgetGreen()Get the green color as an integerfloatgetGreenArithmetic()Get the green color as an arithmetic floatStringgetGreenHex()Get the green color in hexStringgetGreenHexShorthand()Get the green color in hex, shorthand when possiblefloat[]getHSL()Get the HSL (hue, saturation, lightness) valuesfloatgetHue()Get the HSL hue valuefloatgetLightness()Get the HSL lightness valuefloatgetOpacity()Get the opacity as an arithmetic floatintgetRed()Get the red color as an integerfloatgetRedArithmetic()Get the red color as an arithmetic floatStringgetRedHex()Get the red color in hexStringgetRedHexShorthand()Get the red color in hex, shorthand when possiblefloatgetSaturation()Get the HSL saturation valuestatic Colorgray()Create a gray colorstatic Colorgreen()Create a green colorbooleanisOpaque()Check if the color is opaque (opacity or alpha of 1.0, 255, or x00)static ColorlightGray()Create a light gray colorstatic Colormagenta()Create a magenta colorstatic Colororange()Create an orange colorstatic Colorpink()Create a pink colorstatic Colorpurple()Create a purple colorstatic Colorred()Create a red colorvoidsetAlpha(float alpha)Set the alpha color as an arithmetic floatvoidsetAlpha(int alpha)Set the alpha color as an integervoidsetAlpha(String alpha)Set the alpha color in hexvoidsetBlue(float blue)Set the blue color as an arithmetic floatvoidsetBlue(int blue)Set the blue color as an integervoidsetBlue(String blue)Set the blue color in hexvoidsetColor(float red, float green, float blue)Set the color with arithmetic RGB valuesvoidsetColor(float red, float green, float blue, float opacity)Set the color with arithmetic RGB valuesvoidsetColor(int color)Set the color as a single integervoidsetColor(int red, int green, int blue)Set the color with RGB valuesvoidsetColor(int red, int green, int blue, float opacity)Set the color with RGBA valuesvoidsetColor(int red, int green, int blue, int alpha)Set the color with RGBA valuesvoidsetColor(String color)Set the color in hexvoidsetColor(String color, float opacity)Set the color in hex with an opacityvoidsetColor(String color, int alpha)Set the color in hex with an alphavoidsetColor(String red, String green, String blue)Set the color with individual hex colorsvoidsetColor(String red, String green, String blue, float opacity)Set the color with individual hex colors and opacityvoidsetColor(String red, String green, String blue, String alpha)Set the color with individual hex colors and alphavoidsetColorByHSL(float hue, float saturation, float lightness)Set the color with HSL (hue, saturation, lightness) valuesvoidsetColorByHSL(float hue, float saturation, float lightness, float alpha)Set the color with HSLA (hue, saturation, lightness, alpha) valuesvoidsetGreen(float green)Set the green color as an arithmetic floatvoidsetGreen(int green)Set the green color as an integervoidsetGreen(String green)Set the green color in hexvoidsetOpacity(float opacity)Set the opacity as an arithmetic floatvoidsetRed(float red)Set the red color as an arithmetic floatvoidsetRed(int red)Set the red color as an integervoidsetRed(String red)Set the red color in hexstatic Colorviolet()Create a violet colorstatic Colorwhite()Create a white colorstatic Coloryellow()Create a yellow color
-
-
-
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 ARGBopacity- 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 ARGBalpha- 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 RRgreen- green hex color in format GGblue- 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 RRgreen- green hex color in format GGblue- blue hex color in format BBalpha- 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 RRgreen- green hex color in format GGblue- blue hex color in format BBopacity- 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 255green- green integer color inclusively between 0 and 255blue- 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 255green- green integer color inclusively between 0 and 255blue- blue integer color inclusively between 0 and 255alpha- 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 255green- green integer color inclusively between 0 and 255blue- blue integer color inclusively between 0 and 255opacity- 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.0green- green float color inclusively between 0.0 and 1.0blue- 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.0green- green float color inclusively between 0.0 and 1.0blue- blue float color inclusively between 0.0 and 1.0opacity- 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 = lightnessalpha- 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 ARGBopacity- 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 ARGBalpha- 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 RRgreen- green hex color in format GGblue- 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 RRgreen- green hex color in format GGblue- blue hex color in format BBalpha- 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 RRgreen- green hex color in format GGblue- blue hex color in format BBopacity- 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 255green- green integer color inclusively between 0 and 255blue- 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 255green- green integer color inclusively between 0 and 255blue- blue integer color inclusively between 0 and 255alpha- 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 255green- green integer color inclusively between 0 and 255blue- blue integer color inclusively between 0 and 255opacity- 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.0green- green float color inclusively between 0.0 and 1.0blue- 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.0green- green float color inclusively between 0.0 and 1.0blue- blue float color inclusively between 0.0 and 1.0opacity- 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 = lightnessalpha- 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 ARGBopacity- 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 ARGBalpha- 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 RRgreen- green hex color in format GGblue- 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 RRgreen- green hex color in format GGblue- blue hex color in format BBalpha- 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 RRgreen- green hex color in format GGblue- blue hex color in format BBopacity- 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 255green- green integer color inclusively between 0 and 255blue- 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 255green- green integer color inclusively between 0 and 255blue- blue integer color inclusively between 0 and 255alpha- 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 255green- green integer color inclusively between 0 and 255blue- blue integer color inclusively between 0 and 255opacity- 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.0green- green float color inclusively between 0.0 and 1.0blue- 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.0green- green float color inclusively between 0.0 and 1.0blue- blue float color inclusively between 0.0 and 1.0opacity- 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.0saturation- saturation inclusively between 0.0 and 1.0lightness- 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.0saturation- saturation inclusively between 0.0 and 1.0lightness- lightness inclusively between 0.0 and 1.0alpha- 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
-
-