public class Color extends AbstractSimpleDatatype<Integer>
Datatype
for a Color
. It is based on values for
red
, green
, getBlue()
, and alpha
.
Internally these values are encoded in a single ARGB value
. This class is similar to
AWT Color
but GWT compatible (AWT color is linked with AWT, see e.g.
createContext
) and especially compatible to CSS. ColorModel
s use GenericColor
. alpha
value has NOT been designed as a transparency value (inverse
logic so 0
means no transparency or in other words a regular color). Then if encoding in
A/R/G/B the hexadecimal RGB notation would be compatible with transparency because #2F4F8F would be the
same as #002F4F8F. Unfortunately pain is on our side and we have to keep with existing standards. Therefore
#2F4F8F is actually the same as #FF2F4F8F. To avoid confusion and to be compatible with CSS,
toString()
will print the hexadecimal RGB form (e.g. #2F4F8F) in case alpha
has its maximum value (255/FF). Otherwise the CSS RGBA notation is used (e.g. rgba(47,79,143,0.5) instead
of #7F2F4F8F).Modifier and Type | Field and Description |
---|---|
static Color |
BLACK
The
Color black. |
static Color |
BLUE
The
Color blue. |
static Color |
BLUE_VIOLET
The
Color BlueViolet. |
static Color |
BROWN
The
Color Brown. |
static Color |
CSS_GREEN
The
Color CSS green (a darker green while real green is called lime in CSS). |
static Color |
CYAN
The
Color cyan. |
static Color |
GREEN
The
Color green (lime). |
static Color |
GREY
The
Color grey. |
static String |
HEX_PREFIX
The prefix for the
title . |
private static int |
LENGTH_HEX_RGB
The length of an RGB value in hexadecimal notation (#RRGGBB).
|
private static int |
LENGTH_HEX_RGBA
The length of an RGBA value in hexadecimal notation (#AARRGGBB).
|
static Color |
MAGENTA
The
Color magenta. |
static Color |
MAROON
The
Color maroon. |
(package private) static int |
MASK
Bit-mask for a single R/G/B/A value such as
blue . |
private static int |
MASK_ALPHA
Bit-mask for a the
alpha value in combined value . |
private static Integer |
MAX_SEGMENT |
private static Integer |
MIN_VALUE |
private static Map<String,Color> |
NAME_TO_COLOR_MAP
Maps CSS names to
Color s. |
static Color |
NAVY
The
Color navy. |
static Color |
OLIVE
The
Color olive. |
static Color |
ORANGE
The
Color orange. |
private static String |
PATTERN
|
static Color |
PURPLE
The
Color purple. |
private static int |
RADIX_HEX
The
radix for hexadecimal notation. |
static Color |
RED
The
Color red. |
private static String |
RGBA_PREFIX
The prefix for the rgba(r,g,b,a) syntax.
|
private static String |
RGBA_SUFFIX
The suffix for the rgba(r,g,b) syntax.
|
private static char |
SEPARATOR
The separator for the the segments (e.g.
|
private static long |
serialVersionUID
UID for serialization.
|
private static int |
SHIFT_ALPHA
Number of bits to shift for
alpha value. |
private static int |
SHIFT_BLUE
Number of bits to shift for
blue value. |
private static int |
SHIFT_GREEN
Number of bits to shift for
green value. |
private static int |
SHIFT_RED
Number of bits to shift for
red value. |
static Color |
SILVER
The
Color silver. |
static Color |
TEAL
The
Color teal. |
static Color |
TRANSPARENT
The
Color transparent (actually not really a color). |
static Color |
WHITE
The
Color white. |
static Color |
YELLOW
The
Color yellow. |
Modifier | Constructor and Description |
---|---|
protected |
Color()
The constructor for de-serialization in GWT.
|
|
Color(int value)
The constructor.
|
|
Color(Integer value)
The constructor.
|
|
Color(int red,
int green,
int blue)
The constructor.
|
|
Color(int red,
int green,
int blue,
int alpha)
The constructor.
|
Modifier and Type | Method and Description |
---|---|
private static int |
createAndVerifyRgba(int red,
int green,
int blue,
int alpha) |
private static int |
createRgba(int red,
int green,
int blue,
int alpha) |
static Color |
fromName(String name) |
int |
getAlpha() |
int |
getBlue() |
int |
getGreen() |
int |
getRed() |
(package private) static Color |
parseHexString(String hexColor) |
private static Color |
parseRgb(String uppercaseColor) |
String |
toString()
|
static Color |
valueOf(String color)
|
private static void |
verifySegment(int segment,
ColorSegmentType type)
Verifies that the given segment is in the valid range from
MIN_VALUE to MAX_SEGMENT . |
getValue
equals, hashCode
private static final long serialVersionUID
private static final int RADIX_HEX
radix
for hexadecimal notation.private static final int SHIFT_BLUE
blue
value.private static final int SHIFT_GREEN
green
value.private static final int SHIFT_RED
red
value.private static final int SHIFT_ALPHA
alpha
value.public static final String HEX_PREFIX
title
.private static final String RGBA_PREFIX
private static final String RGBA_SUFFIX
private static final char SEPARATOR
private static final Integer MIN_VALUE
Color(Integer)
private static final int LENGTH_HEX_RGB
private static final int LENGTH_HEX_RGBA
static final int MASK
blue
.private static final int MASK_ALPHA
alpha
value in combined value
.private static final Integer MAX_SEGMENT
Color(int, int, int)
private static final String PATTERN
public static final Color TRANSPARENT
Color
transparent (actually not really a color).public static final Color CSS_GREEN
Color
CSS green (a darker green while real green is called lime in CSS).protected Color()
public Color(int red, int green, int blue)
public Color(int red, int green, int blue, int alpha)
public Color(int value)
value
- is the actual color value.public Color(Integer value)
value
- is the actual color value
.public static Color valueOf(String color) throws NlsParseException
color
- is the Color
given as String
representation.Color
.NlsParseException
- if the syntax is invalid.private static Color parseRgb(String uppercaseColor)
uppercaseColor
- is the Color
in rgb(a) notation in
upper case
.Color
or null
if NOT valid.private static int createAndVerifyRgba(int red, int green, int blue, int alpha)
red
- - see getRed()
.green
- - see getGreen()
.blue
- - see getBlue()
.alpha
- - see getAlpha()
.private static int createRgba(int red, int green, int blue, int alpha)
red
- - see getRed()
.green
- - see getGreen()
.blue
- - see getBlue()
.alpha
- - see getAlpha()
.private static void verifySegment(int segment, ColorSegmentType type)
MIN_VALUE
to MAX_SEGMENT
.segment
- is the segment to check.type
- is the type
of the segment
.public int getAlpha()
Alpha
part of the color value
as byte value
.public int getRed()
Red
part of the color value
as byte
value
.public int getGreen()
Green
part of the color value
as byte value
.public int getBlue()
Blue
part of the color value
as byte value
.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.Copyright © 2001–2014 mmm-Team. All rights reserved.