Package com.helger.css.utils
Class CSSColorHelper
java.lang.Object
com.helger.css.utils.CSSColorHelper
Provides color handling sanity methods.
- Author:
- Philip Helger
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intHSL maximum value (for Hue only)static final intHSL minimum value (for Hue only)static final intHSL range (max-min+1) (for Hue only)static final floatMaximum opacity valuestatic final floatMinimum opacity valuestatic final intPercentage maximum value (for HSL)static final intPercentage minimum value (for HSL)static final intRGB maximum valuestatic final intRGB minimum valuestatic final intRGB range (max-min+1) -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetHexColorValue(int nRed, int nGreen, int nBlue) static StringgetHSLAColorValue(float fHue, float fSaturation, float fLightness, float fOpacity) Get the passed values as CSS HSLA color valuestatic StringgetHSLAColorValue(int nHue, int nSaturation, int nLightness, float fOpacity) Get the passed values as CSS HSLA color valuestatic int[]getHSLAsRGBValue(float fHue, float fSaturation, float fLightness) Get the passed RGB values as HSL values compliant for CSS in the CSS range (0-359, 0-100, 0-100)static StringgetHSLColorValue(float fHue, float fSaturation, float fLightness) Get the passed values as CSS HSL color valuestatic StringgetHSLColorValue(int nHue, int nSaturation, int nLightness) Get the passed values as CSS HSL color valuestatic floatgetHSLHueValue(float fHSLPart) static intgetHSLHueValue(int nHSLPart) static floatgetHSLPercentageValue(float nHSLPart) Get the passed value as a valid HSL Saturation or Lightness value in the range ofPERCENTAGE_MIN-PERCENTAGE_MAX(percentage).static intgetHSLPercentageValue(int nHSLPart) static floatgetOpacityToUse(float fOpacity) Ensure that the passed opacity value is in the rangeOPACITY_MINandOPACITY_MAX.static CSSHSLAgetParsedHSLAColorValue(String sValue) static CSSHSLgetParsedHSLColorValue(String sValue) static CSSRGBAgetParsedRGBAColorValue(String sValue) static CSSRGBgetParsedRGBColorValue(String sValue) Extract the CSS RGB color value from the passed String.static StringgetRGBAColorValue(int nRed, int nGreen, int nBlue, float fOpacity) Get the passed values as CSS RGBA color valuestatic float[]getRGBAsHSLValue(int nRed, int nGreen, int nBlue) Get the passed RGB values as HSL values compliant for CSS in the CSS range (0-359, 0-100, 0-100)static StringgetRGBColorValue(int nRed, int nGreen, int nBlue) Get the passed values as CSS RGB color valuestatic intgetRGBValue(int nRGBPart) Convert the passed value to a valid RGB value in the range 0-255.static booleanisColorValue(String sValue) Check if the passed string is any color value.static booleanisHexColorValue(String sValue) Check if the passed String is valid CSS hex color value.static booleanisHSLAColorValue(String sValue) Check if the passed String is valid CSS HSLA color value.static booleanisHSLColorValue(String sValue) Check if the passed String is valid CSS HSL color value.static booleanisRGBAColorValue(String sValue) Check if the passed String is valid CSS RGBA color value.static booleanisRGBColorValue(String sValue) Check if the passed String is valid CSS RGB color value.
-
Field Details
-
RGB_MIN
public static final int RGB_MINRGB minimum value- See Also:
-
RGB_MAX
public static final int RGB_MAXRGB maximum value- See Also:
-
RGB_RANGE
public static final int RGB_RANGERGB range (max-min+1)- See Also:
-
HSL_MIN
public static final int HSL_MINHSL minimum value (for Hue only)- See Also:
-
HSL_MAX
public static final int HSL_MAXHSL maximum value (for Hue only)- See Also:
-
HSL_RANGE
public static final int HSL_RANGEHSL range (max-min+1) (for Hue only)- See Also:
-
PERCENTAGE_MIN
public static final int PERCENTAGE_MINPercentage minimum value (for HSL)- See Also:
-
PERCENTAGE_MAX
public static final int PERCENTAGE_MAXPercentage maximum value (for HSL)- See Also:
-
OPACITY_MIN
public static final float OPACITY_MINMinimum opacity value- See Also:
-
OPACITY_MAX
public static final float OPACITY_MAXMaximum opacity value- See Also:
-
-
Method Details
-
isColorValue
Check if the passed string is any color value.- Parameters:
sValue- The value to check. May benull.- Returns:
trueif the passed value is notnull, not empty and a valid CSS color value.- See Also:
-
isRGBColorValue
Check if the passed String is valid CSS RGB color value. Example value:rgb(255,0,0)- Parameters:
sValue- The value to check. May benull.- Returns:
trueif it is a CSS RGB color value,falseif not
-
getParsedRGBColorValue
Extract the CSS RGB color value from the passed String. Example value:rgb(255,0,0)- Parameters:
sValue- The value to extract the value from. May benull.- Returns:
nullif the passed value is not a valid CSS RGB color value.
-
isRGBAColorValue
Check if the passed String is valid CSS RGBA color value. Example value:rgba(255,0,0, 0.1)- Parameters:
sValue- The value to check. May benull.- Returns:
trueif it is a CSS RGBA color value,falseif not
-
getParsedRGBAColorValue
-
isHSLColorValue
Check if the passed String is valid CSS HSL color value. Example value:hsl(255,0%,0%)- Parameters:
sValue- The value to check. May benull.- Returns:
trueif it is a CSS HSL color value,falseif not
-
getParsedHSLColorValue
-
isHSLAColorValue
Check if the passed String is valid CSS HSLA color value. Example value:hsla(255,0%,0%, 0.1)- Parameters:
sValue- The value to check. May benull.- Returns:
trueif it is a CSS HSLA color value,falseif not
-
getParsedHSLAColorValue
-
isHexColorValue
Check if the passed String is valid CSS hex color value. Example value:#ff0000- Parameters:
sValue- The value to check. May benull.- Returns:
trueif it is a CSS hex color value,falseif not
-
getRGBValue
Convert the passed value to a valid RGB value in the range 0-255.- Parameters:
nRGBPart- The original value- Returns:
- The value between 0 and 255.
-
getOpacityToUse
Ensure that the passed opacity value is in the rangeOPACITY_MINandOPACITY_MAX.- Parameters:
fOpacity- The original opacity- Returns:
- The opacity in the correct range between 0 and 1.
-
getRGBColorValue
Get the passed values as CSS RGB color value- Parameters:
nRed- Red - is scaled to 0-255nGreen- Green - is scaled to 0-255nBlue- Blue - is scaled to 0-255- Returns:
- The CSS string to use
-
getRGBAColorValue
@Nonnull @Nonempty public static String getRGBAColorValue(int nRed, int nGreen, int nBlue, float fOpacity) Get the passed values as CSS RGBA color value- Parameters:
nRed- Red - is scaled to 0-255nGreen- Green - is scaled to 0-255nBlue- Blue - is scaled to 0-255fOpacity- Opacity to use - is scaled to 0-1.- Returns:
- The CSS string to use
-
getHSLHueValue
-
getHSLHueValue
-
getHSLPercentageValue
-
getHSLPercentageValue
Get the passed value as a valid HSL Saturation or Lightness value in the range ofPERCENTAGE_MIN-PERCENTAGE_MAX(percentage). -
getHSLColorValue
Get the passed values as CSS HSL color value- Parameters:
nHue- Hue - is scaled to 0-359nSaturation- Saturation - is scaled to 0-100nLightness- Lightness - is scaled to 0-100- Returns:
- The CSS string to use
-
getHSLColorValue
@Nonnull @Nonempty public static String getHSLColorValue(float fHue, float fSaturation, float fLightness) Get the passed values as CSS HSL color value- Parameters:
fHue- Hue - is scaled to 0-359fSaturation- Saturation - is scaled to 0-100fLightness- Lightness - is scaled to 0-100- Returns:
- The CSS string to use
-
getHSLAColorValue
@Nonnull @Nonempty public static String getHSLAColorValue(int nHue, int nSaturation, int nLightness, float fOpacity) Get the passed values as CSS HSLA color value- Parameters:
nHue- Hue - is scaled to 0-359nSaturation- Saturation - is scaled to 0-100nLightness- Lightness - is scaled to 0-100fOpacity- Opacity - is scaled to 0-1- Returns:
- The CSS string to use
-
getHSLAColorValue
@Nonnull @Nonempty public static String getHSLAColorValue(float fHue, float fSaturation, float fLightness, float fOpacity) Get the passed values as CSS HSLA color value- Parameters:
fHue- Hue - is scaled to 0-359fSaturation- Saturation - is scaled to 0-100fLightness- Lightness - is scaled to 0-100fOpacity- Opacity - is scaled to 0-1- Returns:
- The CSS string to use
-
getHexColorValue
-
getRGBAsHSLValue
Get the passed RGB values as HSL values compliant for CSS in the CSS range (0-359, 0-100, 0-100)- Parameters:
nRed- red valuenGreen- green valuenBlue- blue value- Returns:
- An array of 3 floats, containing hue, saturation and lightness (in this order). The first value is in the range 0-359, and the remaining two values are in the range 0-100 (percentage).
-
getHSLAsRGBValue
@Nonnull @Nonempty public static int[] getHSLAsRGBValue(float fHue, float fSaturation, float fLightness) Get the passed RGB values as HSL values compliant for CSS in the CSS range (0-359, 0-100, 0-100)- Parameters:
fHue- the hue component of the color - in the range 0-359fSaturation- the saturation of the color - in the range 0-100fLightness- the lightness of the color - in the range 0-100- Returns:
- An array of 3 ints, containing red, green and blue (in this order). All values are in the range 0-255.
-