@Immutable public final class CSSColorHelper extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
HSL_MAX
HSL maximum value (for Hue only)
|
static int |
HSL_MIN
HSL minimum value (for Hue only)
|
static int |
HSL_RANGE
HSL range (max-min+1) (for Hue only)
|
static float |
OPACITY_MAX
Maximum opacity value
|
static float |
OPACITY_MIN
Minimum opacity value
|
static int |
PERCENTAGE_MAX
Percentage maximum value (for HSL)
|
static int |
PERCENTAGE_MIN
Percentage minimum value (for HSL)
|
static int |
RGB_MAX
RGB maximum value
|
static int |
RGB_MIN
RGB minimum value
|
static int |
RGB_RANGE
RGB range (max-min+1)
|
| Modifier and Type | Method and Description |
|---|---|
static String |
getHexColorValue(int nRed,
int nGreen,
int nBlue) |
static String |
getHSLAColorValue(float fHue,
float fSaturation,
float fLightness,
float fOpacity)
Get the passed values as CSS HSLA color value
|
static String |
getHSLAColorValue(int nHue,
int nSaturation,
int nLightness,
float fOpacity)
Get the passed values as CSS HSLA color value
|
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)
|
static String |
getHSLColorValue(float fHue,
float fSaturation,
float fLightness)
Get the passed values as CSS HSL color value
|
static String |
getHSLColorValue(int nHue,
int nSaturation,
int nLightness)
Get the passed values as CSS HSL color value
|
static float |
getHSLHueValue(float fHSLPart)
|
static int |
getHSLHueValue(int nHSLPart)
|
static float |
getHSLPercentageValue(float nHSLPart)
Get the passed value as a valid HSL Saturation or Lightness value in the
range of
PERCENTAGE_MIN-PERCENTAGE_MAX (percentage). |
static int |
getHSLPercentageValue(int nHSLPart)
|
static float |
getOpacityToUse(float fOpacity)
Ensure that the passed opacity value is in the range
OPACITY_MIN
and OPACITY_MAX. |
static CSSHSLA |
getParsedHSLAColorValue(String sValue) |
static CSSHSL |
getParsedHSLColorValue(String sValue) |
static CSSRGBA |
getParsedRGBAColorValue(String sValue) |
static CSSRGB |
getParsedRGBColorValue(String sValue)
Extract the CSS RGB color value from the passed String.
|
static String |
getRGBAColorValue(int nRed,
int nGreen,
int nBlue,
float fOpacity)
Get the passed values as CSS RGBA color value
|
static 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 String |
getRGBColorValue(int nRed,
int nGreen,
int nBlue)
Get the passed values as CSS RGB color value
|
static int |
getRGBValue(int nRGBPart)
Convert the passed value to a valid RGB value in the range 0-255.
|
static boolean |
isColorValue(String sValue)
Check if the passed string is any color value.
|
static boolean |
isHexColorValue(String sValue)
Check if the passed String is valid CSS hex color value.
|
static boolean |
isHSLAColorValue(String sValue)
Check if the passed String is valid CSS HSLA color value.
|
static boolean |
isHSLColorValue(String sValue)
Check if the passed String is valid CSS HSL color value.
|
static boolean |
isRGBAColorValue(String sValue)
Check if the passed String is valid CSS RGBA color value.
|
static boolean |
isRGBColorValue(String sValue)
Check if the passed String is valid CSS RGB color value.
|
public static final int RGB_MIN
public static final int RGB_MAX
public static final int RGB_RANGE
public static final int HSL_MIN
public static final int HSL_MAX
public static final int HSL_RANGE
public static final int PERCENTAGE_MIN
public static final int PERCENTAGE_MAX
public static final float OPACITY_MIN
public static final float OPACITY_MAX
public static boolean isColorValue(@Nullable String sValue)
sValue - The value to check. May be null.true if the passed value is not null, not
empty and a valid CSS color value.isRGBColorValue(String),
isRGBAColorValue(String),
isHSLColorValue(String),
isHSLAColorValue(String),
isHexColorValue(String),
ECSSColor.isDefaultColorName(String),
ECSSColorName.isDefaultColorName(String),
CCSSValue.CURRENTCOLORpublic static boolean isRGBColorValue(@Nullable String sValue)
rgb(255,0,0)sValue - The value to check. May be null.true if it is a CSS RGB color value,
false if not@Nullable public static CSSRGB getParsedRGBColorValue(@Nullable String sValue)
rgb(255,0,0)sValue - The value to extract the value from. May be null.null if the passed value is not a valid CSS RGB color
value.public static boolean isRGBAColorValue(@Nullable String sValue)
rgba(255,0,0, 0.1)sValue - The value to check. May be null.true if it is a CSS RGBA color value,
false if not@Nullable public static CSSRGBA getParsedRGBAColorValue(@Nullable String sValue)
public static boolean isHSLColorValue(@Nullable String sValue)
hsl(255,0%,0%)sValue - The value to check. May be null.true if it is a CSS HSL color value,
false if not@Nullable public static CSSHSL getParsedHSLColorValue(@Nullable String sValue)
public static boolean isHSLAColorValue(@Nullable String sValue)
hsla(255,0%,0%, 0.1)sValue - The value to check. May be null.true if it is a CSS HSLA color value,
false if not@Nullable public static CSSHSLA getParsedHSLAColorValue(@Nullable String sValue)
public static boolean isHexColorValue(@Nullable String sValue)
#ff0000sValue - The value to check. May be null.true if it is a CSS hex color value,
false if not@Nonnegative public static int getRGBValue(int nRGBPart)
nRGBPart - The original value@Nonnegative public static float getOpacityToUse(float fOpacity)
OPACITY_MIN
and OPACITY_MAX.fOpacity - The original opacity@Nonnull @Nonempty public static String getRGBColorValue(int nRed, int nGreen, int nBlue)
nRed - Red - is scaled to 0-255nGreen - Green - is scaled to 0-255nBlue - Blue - is scaled to 0-255@Nonnull @Nonempty public static String getRGBAColorValue(int nRed, int nGreen, int nBlue, float fOpacity)
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.@Nonnegative public static int getHSLHueValue(int nHSLPart)
@Nonnegative public static float getHSLHueValue(float fHSLPart)
@Nonnegative public static int getHSLPercentageValue(int nHSLPart)
@Nonnegative public static float getHSLPercentageValue(float nHSLPart)
PERCENTAGE_MIN-PERCENTAGE_MAX (percentage).@Nonnull @Nonempty public static String getHSLColorValue(int nHue, int nSaturation, int nLightness)
nHue - Hue - is scaled to 0-359nSaturation - Saturation - is scaled to 0-100nLightness - Lightness - is scaled to 0-100@Nonnull @Nonempty public static String getHSLColorValue(float fHue, float fSaturation, float fLightness)
fHue - Hue - is scaled to 0-359fSaturation - Saturation - is scaled to 0-100fLightness - Lightness - is scaled to 0-100@Nonnull @Nonempty public static String getHSLAColorValue(int nHue, int nSaturation, int nLightness, float fOpacity)
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@Nonnull @Nonempty public static String getHSLAColorValue(float fHue, float fSaturation, float fLightness, float fOpacity)
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@Nonnull @Nonempty public static String getHexColorValue(int nRed, int nGreen, int nBlue)
@Nonnull @Nonempty public static float[] getRGBAsHSLValue(int nRed, int nGreen, int nBlue)
nRed - red valuenGreen - green valuenBlue - blue value@Nonnull @Nonempty public static int[] getHSLAsRGBValue(float fHue, float fSaturation, float fLightness)
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-100Copyright © 2014–2018 Philip Helger. All rights reserved.