public class Color extends Object implements Serializable
A simple class representing a color in a platform-independent way.
In the most basic form, colors are defined using RGB components. In more
complex scenarios a color can be represented by a string - for instance, if
it is determined by a complex style sheet definition. The
isLogicColor()
method can be used to distinguish between these kinds
of objects. If it returns true, the color is defined based
on a string, and thus concrete RGB values are not available.
Color
objects are created using static factory methods. They are
immutable and thus can be shared between different threads.
Modifier and Type | Field and Description |
---|---|
static int |
COMPONENT_UNDEFINED
Constant for an undefined color component.
|
static Color |
UNDEFINED
Constant for an undefined color.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj)
Tests if a passed in object equals this object.
|
int |
getBlue()
Returns the blue component of this color.
|
String |
getColorDefinition()
Returns the logic color definition this
Color instance is based
on. |
int |
getGreen()
Returns the green component of this color.
|
int |
getRed()
Returns the red component of this color.
|
int |
hashCode()
Determines a hash code for this object.
|
boolean |
isLogicColor()
Returns a flag whether this
Color instance is based on a logic
color definition. |
static Color |
newInstance(int r,
int g,
int b)
Deprecated.
Use
newRGBInstance() instead. |
static Color |
newLogicInstance(String coldef)
Creates a new instance of
Color based on a logic, text-based
color definition. |
static Color |
newRGBInstance(int r,
int g,
int b)
Creates a new instance of
Color and initializes it with the given
components for the red, green, and blue part. |
String |
toString()
Returns a String representation of this object.
|
public static final int COMPONENT_UNDEFINED
getRed()
,
getGreen()
, or getBlue()
to indicate that this component
is undefined - which is the case for logic colors.public static final Color UNDEFINED
public boolean isLogicColor()
Color
instance is based on a logic
color definition. This means that it was constructed from a text-based
definition. In this case, the values of the RGB components are undefined.Color
instance is based on
a logic definition, false otherwisepublic int getBlue()
isLogicColor()
returns false.public int getGreen()
isLogicColor()
returns false.public int getRed()
isLogicColor()
returns false.public String getColorDefinition()
Color
instance is based
on. This value is only defined of isLogicColor()
returns
true.public String toString()
public boolean equals(Object obj)
Color
objects
are considered equal if and only if all color components are equal.public int hashCode()
@Deprecated public static Color newInstance(int r, int g, int b)
newRGBInstance()
instead.Color
and initializes the single
components. This method will check whether the passed in values are
valid; if one is out of range, an exception will be thrown.r
- the r componentg
- the g componentb
- the b componentColor
instanceIllegalArgumentException
- if a component is invalidpublic static Color newRGBInstance(int r, int g, int b)
Color
and initializes it with the given
components for the red, green, and blue part. This method checks whether
the passed in values are valid; if one argument is out of range, an
exception is thrown.r
- the r componentg
- the g componentb
- the b componentColor
instanceIllegalArgumentException
- if a component is invalidpublic static Color newLogicInstance(String coldef)
Color
based on a logic, text-based
color definition. The passed in string is just stored and not interpreted
in any form. It must not be null.coldef
- the logic color definitionColor
instanceIllegalArgumentException
- if the color definition is undefinedCopyright © 2016 The JGUIraffe Team. All rights reserved.