public class ColorUtil
extends java.lang.Object
Color property format preference have the following choices:
Modifier and Type | Field and Description |
---|---|
static int |
CSS_ABSOLUTE_FORMAT
Color display preference for CSS absolute style: RGB(r,g,b).
|
static int |
CSS_RELATIVE_FORMAT
Color display preference for CSS relative style: RGB(r%,g%,b%).
|
static int |
DEFAULT_FORMAT
Default format for display preference:
CSS_ABSOLUTE_FORMAT . |
static int |
HTML_FORMAT
Color display preference for HTML style: #RRGGBB.
|
static int |
INT_FORMAT
Useful constant for Color display preference, display Color as integer.
|
static int |
JAVA_FORMAT
Color display preference for JAVA style: 0xRRGGBB.
|
Constructor and Description |
---|
ColorUtil() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
format(int rgbValue,
int rgbFormat)
Formats an integer RGB value according to the format preference provided.
|
static java.lang.String |
format(java.lang.String value,
int rgbFormat)
Formats an color value according to the format preference provided.
|
static int |
formRGB(int r,
int g,
int b)
Calculates the integer color value given its red, blue, green values.
|
static java.lang.String |
getPredefinedColor(int rgb)
Gets a css predefined color given its rgb value.
|
static int[] |
getRGBs(int rgbValue)
Returns the Red, Blue, Green value for a integer RGB color value.
|
static int[] |
getRGBs(java.lang.String colorValue)
Returns the Red, Blue, Green value for a color value.
|
static boolean |
isCssAbsolute(java.lang.String value)
Indicates whether the color value is of valid css absolute format:
"RGB(r,g,b)".
|
static boolean |
isCssRelative(java.lang.String value)
Indicates whether the color value is of a valid css relative format:
"RGB( r%, g%, b%)".
|
static int |
parseColor(java.lang.String value)
Parses the string color value as a color keyword or a numerical RGB
notation, return its corresponding rgb integer value.
|
static int |
parsePredefinedColor(java.lang.String color)
Gets the integer value of a predefined color.
|
public static final int HTML_FORMAT
public static final int INT_FORMAT
public static final int JAVA_FORMAT
public static final int CSS_ABSOLUTE_FORMAT
public static final int CSS_RELATIVE_FORMAT
public static final int DEFAULT_FORMAT
CSS_ABSOLUTE_FORMAT
.public static int parsePredefinedColor(java.lang.String color)
color
should be a predefined color name, otherwise -1
is returned.color
- a given color name, it is case insensitive.public static java.lang.String getPredefinedColor(int rgb)
rgb
- integer rgb value.rgb
, return null
otherwise.public static boolean isCssAbsolute(java.lang.String value)
value
- a string color valuetrue
if the color value is in a valid css absolute
color representation.public static boolean isCssRelative(java.lang.String value)
value
- a string color valuetrue
if the color value is in a valid css relative.
color representation.public static java.lang.String format(int rgbValue, int rgbFormat)
The integer value will first be converted into 6-digits hex format(filling "0" from left), so only the right most 6 digits will be used.
rgbValue
- integer RGB value for a colorrgbFormat
- Color display preference, one of Color display preference
constants. For example, CSS_ABSOLUTE_FORMAT that will convert
into style "RGB(255,0,0)". If the preference provided is not
in the predefined list, then
CSS_ABSOLUTE_FORMAT
will be applied.INT_FORMAT
,
HTML_FORMAT
,
JAVA_FORMAT
,
CSS_ABSOLUTE_FORMAT
,
CSS_RELATIVE_FORMAT
,
DEFAULT_FORMAT
public static java.lang.String format(java.lang.String value, int rgbFormat)
parseColor(String)
for the allowed color value representations.value
- a given string containing one of the allowed notation.rgbFormat
- Color display preference, one of Color display preference
constants. For example, CSS_ABSOLUTE_FORMAT that will convert
into style "RGB(255,0,0)". If the preference provided is not
in the predefined list, then
CSS_ABSOLUTE_FORMAT
will be applied.java.lang.NumberFormatException
- if the String
representing a numerical value
does not contain a parsable integer.INT_FORMAT
,
HTML_FORMAT
,
JAVA_FORMAT
,
CSS_ABSOLUTE_FORMAT
,
CSS_RELATIVE_FORMAT
,
DEFAULT_FORMAT
,
parseColor(String)
,
format(int, int)
public static int parseColor(java.lang.String value)
These examples given a allowed color value that can be parsed into an integer.
value
- a given string containing one of the allowed notation.-1
if the
value is not in one of the allowed format. If the value is in a
valid integer format, return value will be clipped to 0 ~
0xFFFFFFpublic static int[] getRGBs(int rgbValue)
null
.rgbValue
- a given integer RGB color value.null
if the value is not in (0~0xFFFFFF).public static int[] getRGBs(java.lang.String colorValue)
colorValue
- a given string color value in one of the allowed notations.null
if the given color value is not parsable.public static int formRGB(int r, int g, int b)
r
- red value.g
- green value.b
- blue value.Copyright © 2014 OpenText Corp. All rights reserved.