public final class GenericColor extends AbstractDatatype
Datatype
for a Color
based on factors
. Color
for simple and efficient representation and transport of color information. However, if
precision is required or for transformation between different color models
use this
class instead. Modifier and Type | Field and Description |
---|---|
private Alpha |
alpha |
private Blue |
blue |
private Brightness |
brightness |
private Chroma |
chroma |
private Green |
green |
private Hue |
hue |
private Lightness |
lightness |
private static String |
PATTERN
The
Pattern for a valid string representation. |
private Red |
red |
private Saturation |
saturationHsb |
private Saturation |
saturationHsl |
private static long |
serialVersionUID
UID for serialization.
|
Modifier | Constructor and Description |
---|---|
protected |
GenericColor()
The constructor.
|
Modifier and Type | Method and Description |
---|---|
private static double |
calculateHue(double red,
double green,
double blue,
double max,
double chroma)
Calculate the
Hue . |
private static void |
calculateRgb(GenericColor genericColor,
Hue hue,
double min,
double chroma)
Calculates and the RGB values and sets them in the given
GenericColor . |
private static double |
calculateSaturationHsl(double chroma,
double lightness)
Calculate the
Saturation for ColorModel.HSL . |
GenericColor |
darken(ColorFactor factor)
Darkens this color by the given
factor . |
boolean |
equals(Object obj) |
Alpha |
getAlpha() |
Blue |
getBlue() |
Brightness |
getBrightness() |
Chroma |
getChroma() |
Green |
getGreen() |
Hue |
getHue() |
Lightness |
getLightness() |
Red |
getRed() |
Saturation |
getSaturationHsb() |
Saturation |
getSaturationHsl() |
AbstractDoubleSegment<?> |
getSegment(ColorSegmentType type) |
int |
hashCode() |
GenericColor |
invert(ColorModel model) |
GenericColor |
lighten(ColorFactor factor)
Lightens this color by the given
factor . |
Color |
toColor() |
String |
toString()
|
String |
toString(ColorModel colorModel) |
static GenericColor |
valueOf(Color color)
Converts the given
Color to a GenericColor . |
static GenericColor |
valueOf(Hue hue,
Saturation saturation,
Brightness brightness,
Alpha alpha)
|
static GenericColor |
valueOf(Hue hue,
Saturation saturation,
Lightness lightness,
Alpha alpha)
|
static GenericColor |
valueOf(Red red,
Green green,
Blue blue,
Alpha alpha)
|
static GenericColor |
valueOf(String colorString)
Parses the
GenericColor given as String representation. |
private static final long serialVersionUID
private static final String PATTERN
Pattern
for a valid string representation.valueOf(String)
,
toString(ColorModel)
,
Constant Field Valuesprivate Alpha alpha
getAlpha()
private Saturation saturationHsb
getSaturationHsb()
private Saturation saturationHsl
getSaturationHsl()
private Brightness brightness
getBrightness()
private Lightness lightness
getLightness()
private Chroma chroma
getChroma()
private Green green
getGreen()
protected GenericColor()
valueOf
methods to instantiate.public static GenericColor valueOf(String colorString) throws NlsParseException
GenericColor
given as String
representation.colorString
- is the color as String
.GenericColor
.NlsParseException
- if the syntax is invalid.public static GenericColor valueOf(Color color)
Color
to a GenericColor
.color
- is the discrete RGBA Color
.GenericColor
.public static GenericColor valueOf(Red red, Green green, Blue blue, Alpha alpha)
red
- is the Red
part.green
- is the Green
part.blue
- is the Blue
part.alpha
- is the Alpha
value.GenericColor
.private static double calculateSaturationHsl(double chroma, double lightness)
Saturation
for ColorModel.HSL
.chroma
- is the Chroma
value.lightness
- is the Lightness
value.Saturation
.private static double calculateHue(double red, double green, double blue, double max, double chroma)
Hue
.red
- is the Red
value.green
- is the Green
value.blue
- is the Blue
value.max
- is the maximum of RGB.chroma
- is the Chroma
value.Saturation
.public static GenericColor valueOf(Hue hue, Saturation saturation, Brightness brightness, Alpha alpha)
hue
- is the Hue
part.saturation
- is the Saturation
part.brightness
- is the Brightness
part.alpha
- is the Alpha
value.GenericColor
.public static GenericColor valueOf(Hue hue, Saturation saturation, Lightness lightness, Alpha alpha)
hue
- is the Hue
part.saturation
- is the Saturation
part.lightness
- is the Lightness
part.alpha
- is the Alpha
value.GenericColor
.private static void calculateRgb(GenericColor genericColor, Hue hue, double min, double chroma)
GenericColor
.genericColor
- is the GenericColor
to complete.hue
- is the Hue
value.min
- is the minimum Factor
of R/G/B.chroma
- is the Chroma
value.public Alpha getAlpha()
alpha value as factor
.public Saturation getSaturationHsb()
Saturation
in ColorModel.HSB
/ColorModel.HSV
color model (hexcone).ColorSegmentType.SATURATION_HSB
public Saturation getSaturationHsl()
Saturation
in ColorModel.HSL
color model
(bi-hexcone).ColorSegmentType.SATURATION_HSL
public Brightness getBrightness()
public Lightness getLightness()
public Chroma getChroma()
public Red getRed()
public Blue getBlue()
public Green getGreen()
public AbstractDoubleSegment<?> getSegment(ColorSegmentType type)
type
- is the ColorSegmentType
identifying the requested Segment
.Segment
of the given type
.public Color toColor()
Color
corresponding to this GenericColor
.public GenericColor invert(ColorModel model)
model
- the ColorModel
indicating the Segment
s to
invert
. Typically ColorModel.RGB
to build the
complement of the color.public GenericColor lighten(ColorFactor factor)
factor
.factor
- is the factor to increase by. E.g. 0.0
will cause no change, while
1.0
will return white
.factor
.public GenericColor darken(ColorFactor factor)
factor
.factor
- is the factor to decrease by. E.g. 0.0
will cause no change, while
1.0
will return black
.factor
.public String toString()
String
representation of this Datatype
. While the general contract
of Object.toString()
is very weak and mainly used for debugging, the contract here is very
strong. The returned String
has to be suitable for end-users and official output to any kind of
sink. NlsMessage
for this purpose and implement
NlsObject
if you want to support I18N/L10N.public String toString(ColorModel colorModel)
colorModel
- is the ColorModel
.String
in notation of the given ColorModel
(e.g.
"rgba(255, 128, 64, 1.0)" for ColorModel.RGB
).Copyright © 2001–2014 mmm-Team. All rights reserved.