Class Color
- java.lang.Object
-
- net.sf.jguiraffe.gui.builder.components.Color
-
- All Implemented Interfaces:
Serializable
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.- Version:
- $Id: Color.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static int
COMPONENT_UNDEFINED
Constant for an undefined color component.static Color
UNDEFINED
Constant for an undefined color.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method 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 thisColor
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 thisColor
instance is based on a logic color definition.static Color
newInstance(int r, int g, int b)
Deprecated.UsenewRGBInstance()
instead.static Color
newLogicInstance(String coldef)
Creates a new instance ofColor
based on a logic, text-based color definition.static Color
newRGBInstance(int r, int g, int b)
Creates a new instance ofColor
and initializes it with the given components for the red, green, and blue part.String
toString()
Returns a String representation of this object.
-
-
-
Field Detail
-
COMPONENT_UNDEFINED
public static final int COMPONENT_UNDEFINED
Constant for an undefined color component. This value is returned by the access methods for the single color components (getRed()
,getGreen()
, orgetBlue()
to indicate that this component is undefined - which is the case for logic colors.- Since:
- 1.3
- See Also:
- Constant Field Values
-
UNDEFINED
public static final Color UNDEFINED
Constant for an undefined color. This constant defines a special instance which does not have RGB components nor a logic color definition. It can be used to represent an undefined color.- Since:
- 1.3
-
-
Method Detail
-
isLogicColor
public boolean isLogicColor()
Returns a flag whether thisColor
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.- Returns:
- true if this
Color
instance is based on a logic definition, false otherwise - Since:
- 1.3
-
getBlue
public int getBlue()
Returns the blue component of this color. This value is only defined ifisLogicColor()
returns false.- Returns:
- the blue component
-
getGreen
public int getGreen()
Returns the green component of this color. This value is only defined ifisLogicColor()
returns false.- Returns:
- the green component
-
getRed
public int getRed()
Returns the red component of this color. This value is only defined ifisLogicColor()
returns false.- Returns:
- the red component
-
getColorDefinition
public String getColorDefinition()
Returns the logic color definition thisColor
instance is based on. This value is only defined ofisLogicColor()
returns true.- Returns:
- the logic color definition
- Since:
- 1.3
-
toString
public String toString()
Returns a String representation of this object.
-
equals
public boolean equals(Object obj)
Tests if a passed in object equals this object. TwoColor
objects are considered equal if and only if all color components are equal.
-
hashCode
public int hashCode()
Determines a hash code for this object.
-
newInstance
@Deprecated public static Color newInstance(int r, int g, int b)
Deprecated.UsenewRGBInstance()
instead.Creates a new instance ofColor
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.- Parameters:
r
- the r componentg
- the g componentb
- the b component- Returns:
- the new
Color
instance - Throws:
IllegalArgumentException
- if a component is invalid
-
newRGBInstance
public static Color newRGBInstance(int r, int g, int b)
Creates a new instance ofColor
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.- Parameters:
r
- the r componentg
- the g componentb
- the b component- Returns:
- the new
Color
instance - Throws:
IllegalArgumentException
- if a component is invalid- Since:
- 1.3
-
newLogicInstance
public static Color newLogicInstance(String coldef)
Creates a new instance ofColor
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.- Parameters:
coldef
- the logic color definition- Returns:
- the new
Color
instance - Throws:
IllegalArgumentException
- if the color definition is undefined- Since:
- 1.3
-
-