Modifier and Type | Field and Description |
---|---|
static Color |
black |
static Color |
BLACK |
static Color |
blue |
static Color |
BLUE |
static Color |
cyan |
static Color |
CYAN |
static Color |
DARK_GRAY |
static Color |
darkGray |
static Color |
gray |
static Color |
GRAY |
static Color |
green |
static Color |
GREEN |
static Color |
LIGHT_GRAY |
static Color |
lightGray |
static Color |
magenta |
static Color |
MAGENTA |
static Color |
orange |
static Color |
ORANGE |
static Color |
pink |
static Color |
PINK |
static Color |
red |
static Color |
RED |
static Color |
white |
static Color |
WHITE |
static Color |
yellow |
static Color |
YELLOW |
Constructor and Description |
---|
Color(Color color)
Copy constructor.
|
Color(int value)
Creates an opaque RGB (no alpha component) color from the provided integer representation.
|
Color(int value,
boolean hasalpha)
Creates a RGB color from the provided integer representation.
|
Color(int r,
int g,
int b)
Creates an opaque RGB (no alpha component) color from the provided integer representation.
|
Color(int r,
int g,
int b,
int a)
Creates a RGBA color from the provided integer representation.
|
Modifier and Type | Method and Description |
---|---|
Color |
brighter()
|
Color |
darker()
|
static Color |
decode(String colorValue)
|
boolean |
equals(Object obj) |
int |
getAlpha()
Gets the alpha component.
|
int |
getBlue()
Gets the blue component in the default sRGB space.
|
static Color |
getColor(String name)
Finds a RGB color in the system properties.
|
static Color |
getColor(String name,
Color defaultValue)
Finds a RGB color in the system properties.
|
static Color |
getColor(String name,
int defaultValue)
Finds a RGB color in the system properties.
|
static Color |
getColorAt(Integer colorIndex)
Returns the
Color associated to the provided index. |
int |
getGreen()
Gets the green component in the default sRGB space.
|
static List<Color> |
getIndexedColors()
Returns the list of currently indexed
Color s. |
static Color |
getRandomColor()
Returns a randomly generated
Color object. |
static Color |
getRandomColor(Random random)
|
int |
getRed()
Gets the red component in the default sRGB space.
|
int |
getRGB()
Gets the RGB value representing the color.
|
int |
hashCode() |
static int |
indexOf(Color color)
Searches for the color index associated with the current
Color . |
public static final Color white
public static final Color WHITE
public static final Color lightGray
public static final Color LIGHT_GRAY
public static final Color gray
public static final Color GRAY
public static final Color darkGray
public static final Color DARK_GRAY
public static final Color black
public static final Color BLACK
public static final Color red
public static final Color RED
public static final Color pink
public static final Color PINK
public static final Color orange
public static final Color ORANGE
public static final Color yellow
public static final Color YELLOW
public static final Color green
public static final Color GREEN
public static final Color magenta
public static final Color MAGENTA
public static final Color cyan
public static final Color CYAN
public static final Color blue
public static final Color BLUE
public Color(int r, int g, int b, int a)
Creates a RGBA color from the provided integer representation.
r
- value of the red component, as a [0,255] integer.g
- value of the green component, as a [0,255] integer.b
- value of the blue component, as a [0,255] integer.a
- value of the alpha component, as a [0,255] integer.public Color(int r, int g, int b)
Creates an opaque RGB (no alpha component) color from the provided integer representation.
r
- value of the red component, as a [0,255] integer.g
- value of the green component, as a [0,255] integer.b
- value of the blue component, as a [0,255] integer.public Color(int value)
Creates an opaque RGB (no alpha component) color from the provided integer representation.
value
- the combined RGB component, as an integer.public Color(int value, boolean hasalpha)
Creates a RGB color from the provided integer representation.
value
- the combined RGBA component, as an integer.hasalpha
- true
if the alpha component should be taken into account.public int getRed()
Gets the red component in the default sRGB space.
public int getGreen()
Gets the green component in the default sRGB space.
public int getBlue()
Gets the blue component in the default sRGB space.
public int getAlpha()
Gets the alpha component.
public int getRGB()
Gets the RGB value representing the color.
public static List<Color> getIndexedColors()
Returns the list of currently indexed Color
s.
Color
s.indexOf(Color)
,
getColorAt(Integer)
public static Color decode(String colorValue) throws NumberFormatException
Converts a String
to an integer and returns the specified opaque Color
.
This method handles string formats that are used to represent octal and hexadecimal numbers.
colorValue
- a String
that represents an opaque color as a 24-bit integerColor
object.NumberFormatException
- if the specified string cannot be interpreted as a decimal, octal,
or hexadecimal integer.Integer.decode(java.lang.String)
public static Color getColor(String name)
Finds a RGB color in the system properties.
The argument is treated as the name of a system property to be obtained. The string value of this property is
then interpreted as an integer which is then converted to a Color
object.
If the specified property is not found or could not be parsed as an integer then null
is returned.
name
- the name of the color property.Color
converted from the system property.System.getProperty(java.lang.String)
,
Integer.getInteger(java.lang.String)
,
Color(int)
public static Color getColor(String name, Color defaultValue)
Finds a RGB color in the system properties.
The first argument is treated as the name of a system property to
be obtained. The string value of this property is then interpreted
as an integer which is then converted to a Color
object.
If the specified property is not found or could not be parsed as
an integer then the Color
defaultValue
is used instead.
name
- the name of the color property.defaultValue
- the default color value, a Color
object.Color
converted from the system property or the Color
converted from the
specified integer.System.getProperty(java.lang.String)
,
Integer.getInteger(java.lang.String)
,
Color(int)
public static Color getColor(String name, int defaultValue)
Finds a RGB color in the system properties.
The first argument is treated as the name of a system property to be obtained. The string value of this
property is then interpreted as an integer which is then converted to a Color
object.
If the specified property is not found or could not be parsed as an integer then the integer value
defaultValue
is used instead, and is converted to a Color
object.
name
- the name of the color propertydefaultValue
- the default color value, as an integerColor
converted from the system property or the Color
converted from the
specified integer.System.getProperty(java.lang.String)
,
Integer.getInteger(java.lang.String)
,
Color(int)
public Color brighter()
Creates a new Color
that is a brighter version of this Color
.
This method applies an arbitrary scale factor to each of the three RGB
components of this Color
to create a brighter version
of this Color
.
The alpha
value is preserved.
Although brighter()
and darker()
are inverse operations, the results of a series of
invocations of these two methods might be inconsistent because of rounding errors.
public Color darker()
Creates a new Color
that is a darker version of this Color
.
This method applies an arbitrary scale factor to each of the three RGB components of this Color
to
create a darker version of this Color
.
The alpha
value is preserved.
Although brighter()
and darker()
are inverse operations, the results of a series of
invocations of these two methods might be inconsistent because of rounding errors.
Color
object that is a darker version of this Color
with the same alpha
value.brighter()
public static Color getColorAt(Integer colorIndex)
Returns the Color
associated to the provided index.
The Color
returned for a specific index will remain the same across instances.
This method is typically used to associate a Color
to an identifier. Missing Color
s are thus
generated (from 0
to intColor
) on demand, and stored for later use.
colorIndex
- the index of the Color
.Color
associated to the provided index.indexOf(Color)
,
getIndexedColors()
public static int indexOf(Color color)
Searches for the color index associated with the current Color
.
Only already generated and indexed Color
s can be found.
color
- the Color
to be searched for.-1
if not found.getColorAt(Integer)
,
getIndexedColors()
public static Color getRandomColor(Random random)
Returns a Color
object generated using 3 calls to the provided Random
object.
If the provided random is null, the result of getRandomColor()
is returned.
random
- a Random
object to be used. Can be null.Color
object.getRandomColor()
public static Color getRandomColor()
Returns a randomly generated Color
object.
The Color
is created by using 3 calls to Math.random()
.
Color
object.getRandomColor(Random)