Package de.xima.fc.color
Class CssColor
java.lang.Object
de.xima.fc.color.CssColor
- All Implemented Interfaces:
Serializable
A CSS color value, with optional transparency. Has got some utility methods to create a color from a CSS color
string, and to convert the color to different CSS representation. An instance of this class is immutable.
CssColor.valueOf("#ff0000"); CssColor.valueOf("orange");
- Author:
- XIMA MEDIA GmbH
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCssColor
(double red, double green, double blue, double alpha) A new CSS color with the given red, green, blue, and alpha channel. -
Method Summary
Modifier and TypeMethodDescriptionboolean
double
getAlpha()
double
getBlue()
double
getGreen()
double
getRed()
boolean
hasAlpha()
int
hashCode()
boolean
double
static CssColor
ofHex
(long hexCode) static CssColor
static CssColor
ofRgb
(double red, double green, double blue) static CssColor
ofRgb
(int red, int green, int blue) static CssColor
ofRgb
(long red, long green, long blue) static CssColor
static CssColor
ofRgba
(int red, int green, int blue, double alpha) static CssColor
ofRgba
(int red, int green, int blue, int alpha) static CssColor
ofRgba
(long red, long green, long blue, double alpha) static CssColor
ofRgba
(long red, long green, long blue, long alpha) static CssColor
static CssColor
ofRgbOrRgba
(String hexCode, CssColor defaultColor) toHexString
(boolean withHashTag) toNameOrHexOrRgba
(double precision) toString()
static CssColor
static CssColor
static CssColor
valueOf
(String color, ENamedCssColor defaultColor) withAlpha
(double alpha)
-
Constructor Details
-
CssColor
public CssColor(double red, double green, double blue, double alpha) A new CSS color with the given red, green, blue, and alpha channel.- Parameters:
red
- Red channel, 0 to 1.green
- Green channel, 0 to 1.blue
- Blue channel, 0 to 1.alpha
- Alpha channel, 0 to 1.
-
-
Method Details
-
equals
-
getAlpha
public double getAlpha()- Returns:
- The alpha component of the color.
-
getBlue
public double getBlue()- Returns:
- The blue component of the color.
-
getGreen
public double getGreen()- Returns:
- The green component of the color.
-
getRed
public double getRed()- Returns:
- The red component of the color.
-
hasAlpha
public boolean hasAlpha() -
hashCode
public int hashCode() -
isTransparent
public boolean isTransparent()- Returns:
- Whether this color has any transparency.
-
norm1
- Parameters:
other
- Another color.- Returns:
- 1-norm between this and the other color.
-
toClosestColorName
- Returns:
- The CSS color name that is closest to this color.
-
toCssString
- Returns:
- This color as a CSS string that can be used in color properties.
-
toHexString
- Returns:
- A hex string of this color, such as
#ff00ff
.
-
toHexString
- Parameters:
withHashTag
- Iftrue
, prepends the#
hash tag.- Returns:
- A hex string of this color, such as
#ff00ff
.
-
toNameOrHexOrRgba
- Parameters:
precision
- How close a named or hex color must lie to be considered valid.- Returns:
- Converts this color to a CSS color name, if one is close to this color. Otherwise, converts to a
#ff00ff
hex string if one is close to this color. Otherwise, returns argba(0,2.5,4
} RGB(A) CSS color.
-
toRgbaOrHexString
- Returns:
- Converts this color to a
#ff00ff
hex string if one is close to this color. Otherwise, returns argba(0,2.5,4)
RGB(A) CSS color.
-
toRgbaString
- Returns:
- Converts this color to a
rgba(0,2.5,4)
RGB(A) CSS color.
-
toRgbTripel
-
toString
-
withAlpha
- Parameters:
alpha
- New alpha value.- Returns:
- This color, with the new alpha value.
-
ofHex
- Parameters:
hexCode
- Hex code to parse.- Returns:
- The parsed CSS color.
-
ofHex
- Parameters:
hexCode
- Hex code to parse.defaultColor
- Default color if hex code is invalid.- Returns:
- The parsed CSS color.
-
ofRgb
- Parameters:
red
- Red component, in the range [0,1].green
- Green component, in the range [0,1].blue
- Blue component, in the range [0,1].- Returns:
- An immutable CSS color for the given values.
-
ofRgb
- Parameters:
red
- Red component, in the range [0,255].green
- Green component, in the range [0,255].blue
- Blue component, in the range [0,255].- Returns:
- An immutable CSS color for the given values.
-
ofRgb
- Parameters:
red
- Red component, in the range [0,255].green
- Green component, in the range [0,255].blue
- Blue component, in the range [0,255].- Returns:
- An immutable CSS color for the given values.
-
ofRgb
-
ofRgba
- Parameters:
red
- Red component, in the range [0,255].green
- Green component, in the range [0,255].blue
- Blue component, in the range [0,255].alpha
- Alpha component, in the range [0,1]. 0 is fully transparent.- Returns:
- An immutable CSS color for the given values.
-
ofRgba
- Parameters:
red
- Red component, in the range [0,255].green
- Green component, in the range [0,255].blue
- Blue component, in the range [0,255].alpha
- Alpha component, in the range [0,1]. 0 is fully transparent.- Returns:
- An immutable CSS color for the given values.
-
ofRgba
- Parameters:
red
- Red component, in the range [0,255].green
- Green component, in the range [0,255].blue
- Blue component, in the range [0,255].alpha
- Alpha component, in the range [0,255]. 0 is fully transparent.- Returns:
- An immutable CSS color for the given values.
-
ofRgba
- Parameters:
red
- Red component, in the range [0,255].green
- Green component, in the range [0,255].blue
- Blue component, in the range [0,255].alpha
- Alpha component, in the range [0,255]. 0 is fully transparent.- Returns:
- An immutable CSS color for the given values.
-
ofRgba
-
ofRgbOrRgba
-
valueOf
- Throws:
IllegalArgumentException
-
valueOf
-
valueOf
-