edu.neu.ccs
Class XColor

java.lang.Object
  extended byedu.neu.ccs.XObject
      extended byedu.neu.ccs.XColor
All Implemented Interfaces:
Cloneable, Serializable, Stringable

public final class XColor
extends XObject

Object wrapper for the Color class that also provides Stringable capabilities. The default value for this class is the Color representation of black, Color.black.

Since:
1.0
Version:
2.4.0
See Also:
Serialized Form

Field Summary
private  Color color
          The wrapped color for this object.
 
Fields inherited from class edu.neu.ccs.XObject
changeAdapter, VALUE
 
Constructor Summary
XColor()
          Constructs a wrapper for the default Color value.
XColor(Color c)
          Constructs a wrapper for the given Color value.
XColor(float r, float g, float b)
          Constructs a wrapper for the Color constructed from the specified red, green, and blue values in the range [0.0, 1.0].
XColor(float r, float g, float b, float a)
          Constructs a wrapper for the Color constructed from the specified red, green, blue, and alpha values in the range [0.0, 1.0].
XColor(int r, int g, int b)
          Constructs a wrapper for the Color constructed from the specified red, green, and blue values in the range [0, 255].
XColor(int r, int g, int b, int a)
          Constructs a wrapper for the Color constructed from the specified red, green, blue, and alpha values in the range [0, 255].
XColor(String s)
          Constructs a wrapper for the Color value whose state information is encapsulated in the given String data.
 
Method Summary
static String colorToString(Color color)
          Returns a String encapsulation of the Color parameter that contains the int values of red, green, blue, (and possibly alpha) each in the range [0, 255].
 boolean equals(Object other)
          Returns true if other is of class XColor and if the wrapped color of this object and the wrapped color of other are equal.
 void fromStringData(String data)
          Sets the state of the XColor object using information contained in the given String.
static Color getColor(String data)
          Gets a Color value from a data String if the data is valid or returns null.
private  Color getColorFromDecimal(String data)
          Returns the Color expressed in decimal data or throws a ParseException.
private  Color getColorFromHexidecimal(String data)
          Returns the Color expressed in hexidecimal data or throws a ParseException.
 Color getValue()
          Returns the value wrapped by this object.
 int hashCode()
          Returns an int hash code appropriate for the wrapped color.
static Color parseColor(String data)
          Gets a Color value from a data String if the data is valid or throws a ParseException.
 void setValue(Color c)
          Sets the value wrapped by this object to the given Color value.
 void setValue(float r, float g, float b)
          Sets the wrapped value to the Color constructed from the specified red, green, and blue values in the range [0.0, 1.0].
 void setValue(float r, float g, float b, float a)
          Sets the wrapped value to the Color constructed from the specified red, green, blue, and alpha values in the range [0.0, 1.0].
 void setValue(int r, int g, int b)
          Sets the wrapped value to the Color constructed from the specified red, green, and blue values in the range [0, 255].
 void setValue(int r, int g, int b, int a)
          Sets the wrapped value to the Color constructed from the specified red, green, blue, and alpha values in the range [0, 255].
static Color[] toPrimitiveArray(XColor[] x)
          Returns an array of Color objects copied from the given array of XColor objects.
 String toString()
          Returns a String representation of the wrapped value.
 String toStringData()
          Returns a String encapsulation of the XColor object that contains the int values of red, green, blue, (and possibly alpha) each in the range [0, 255].
static XColor[] toXArray(Color[] a)
          Returns an array of XColor objects initialized from the given array of Color objects.
 
Methods inherited from class edu.neu.ccs.XObject
addPropertyChangeListener, addPropertyChangeListener, formatErrorMessage, removePropertyChangeListener, removePropertyChangeListener, toStringArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

color

private Color color
The wrapped color for this object.

Constructor Detail

XColor

public XColor()
Constructs a wrapper for the default Color value.

See Also:
XColor(Color), XColor(int, int, int), XColor(int, int, int, int), XColor(float, float, float), XColor(float, float, float, float), XColor(String)

XColor

public XColor(Color c)
Constructs a wrapper for the given Color value.

Parameters:
c - the value to be wrapped
See Also:
XColor(), XColor(int, int, int), XColor(int, int, int, int), XColor(float, float, float), XColor(float, float, float, float), XColor(String)

XColor

public XColor(int r,
              int g,
              int b)
Constructs a wrapper for the Color constructed from the specified red, green, and blue values in the range [0, 255].

Parameters:
r - the red value in the range [0, 255]
g - the green value in the range [0, 255]
b - the blue value in the range [0, 255]
See Also:
XColor(), XColor(Color), XColor(int, int, int, int), XColor(float, float, float), XColor(float, float, float, float), XColor(String)

XColor

public XColor(int r,
              int g,
              int b,
              int a)
Constructs a wrapper for the Color constructed from the specified red, green, blue, and alpha values in the range [0, 255].

Parameters:
r - the red value in the range [0, 255]
g - the green value in the range [0, 255]
b - the blue value in the range [0, 255]
a - the alpha value in the range [0, 255]
See Also:
XColor(), XColor(Color), XColor(int, int, int), XColor(float, float, float), XColor(float, float, float, float), XColor(String)

XColor

public XColor(float r,
              float g,
              float b)
Constructs a wrapper for the Color constructed from the specified red, green, and blue values in the range [0.0, 1.0].

Parameters:
r - the red value in the range [0.0, 1.0]
g - the green value in the range [0.0, 1.0]
b - the blue value in the range [0.0, 1.0]
See Also:
XColor(), XColor(Color), XColor(int, int, int), XColor(int, int, int, int), XColor(float, float, float, float), XColor(String)

XColor

public XColor(float r,
              float g,
              float b,
              float a)
Constructs a wrapper for the Color constructed from the specified red, green, blue, and alpha values in the range [0.0, 1.0].

Parameters:
r - the red value in the range [0.0, 1.0]
g - the green value in the range [0.0, 1.0]
b - the blue value in the range [0.0, 1.0]
a - the alpha value in the range [0.0, 1.0]
See Also:
XColor(), XColor(Color), XColor(int, int, int), XColor(int, int, int, int), XColor(float, float, float), XColor(String)

XColor

public XColor(String s)
       throws ParseException
Constructs a wrapper for the Color value whose state information is encapsulated in the given String data.

Parameters:
s - a String representation of the desired value
Throws:
ParseException - if the data is malformed
See Also:
XColor(), XColor(Color), XColor(int, int, int), XColor(int, int, int, int), XColor(float, float, float), XColor(float, float, float, float)
Method Detail

fromStringData

public void fromStringData(String data)
                    throws ParseException

Sets the state of the XColor object using information contained in the given String.

The following formats are supported for input of a color using a text string.

Data format 1: A comma and/or blank separated text string with 3 int components: red, green, blue or 4 int components: red, green, blue, alpha.

The int components should be in the range [0, 255].

If the alpha component is omitted then it is assumed to be 255.

Data format 2: A String of the form #rRgGbB or #rRgGbBaA where r, R, g, G, b, B, a, A are hex digits with red = rR, green = gG, blue = bB, alpha = aA.

Data format 3: A String of the form #rgb or #rgba that is interpreted as #rrggbb or #rrggbbaa respectively.

Data format 4: A color name that is contained in the internal static structure of the class Colors. An array with the currently valid installed color names can be obtained via the call:

Colors.getColorNamesAsArray()

Specified by:
fromStringData in interface Stringable
Specified by:
fromStringData in class XObject
Parameters:
data - the String containing color information
Throws:
ParseException - if the data is malformed
See Also:
toStringData()

getColorFromDecimal

private Color getColorFromDecimal(String data)
                           throws ParseException
Returns the Color expressed in decimal data or throws a ParseException.

Parameters:
data - the String that may contain decimal color information
Throws:
ParseException

getColorFromHexidecimal

private Color getColorFromHexidecimal(String data)
                               throws ParseException
Returns the Color expressed in hexidecimal data or throws a ParseException. Assumes the initial char is '#'.

Parameters:
data - the String that may contain hexidecimal color information
Throws:
ParseException

toStringData

public String toStringData()

Returns a String encapsulation of the XColor object that contains the int values of red, green, blue, (and possibly alpha) each in the range [0, 255].

The alpha component is omitted if it is equal to 255.

Specified by:
toStringData in interface Stringable
Specified by:
toStringData in class XObject
See Also:
fromStringData(String)

toString

public String toString()
Returns a String representation of the wrapped value.


equals

public boolean equals(Object other)
Returns true if other is of class XColor and if the wrapped color of this object and the wrapped color of other are equal.

Parameters:
other - the object to be compared with the wrapped object

hashCode

public int hashCode()
Returns an int hash code appropriate for the wrapped color.


setValue

public void setValue(Color c)
Sets the value wrapped by this object to the given Color value. If null, the value is set to Color.black.

Parameters:
c - the value to be wrapped
See Also:
setValue(int, int, int), setValue(int, int, int, int), setValue(float, float, float), setValue(float, float, float, float), getValue()

setValue

public void setValue(int r,
                     int g,
                     int b)
Sets the wrapped value to the Color constructed from the specified red, green, and blue values in the range [0, 255].

Parameters:
r - the red value in the range [0, 255]
g - the green value in the range [0, 255]
b - the blue value in the range [0, 255]
See Also:
setValue(Color), setValue(int, int, int, int), setValue(float, float, float), setValue(float, float, float, float), getValue()

setValue

public void setValue(int r,
                     int g,
                     int b,
                     int a)
Sets the wrapped value to the Color constructed from the specified red, green, blue, and alpha values in the range [0, 255].

Parameters:
r - the red value in the range [0, 255]
g - the green value in the range [0, 255]
b - the blue value in the range [0, 255]
a - the alpha value in the range [0, 255]
See Also:
setValue(Color), setValue(int, int, int), setValue(float, float, float), setValue(float, float, float, float), getValue()

setValue

public void setValue(float r,
                     float g,
                     float b)
Sets the wrapped value to the Color constructed from the specified red, green, and blue values in the range [0.0, 1.0].

Parameters:
r - the red value in the range [0.0, 1.0]
g - the green value in the range [0.0, 1.0]
b - the blue value in the range [0.0, 1.0]
See Also:
setValue(Color), setValue(int, int, int), setValue(int, int, int, int), setValue(float, float, float, float), getValue()

setValue

public void setValue(float r,
                     float g,
                     float b,
                     float a)
Sets the wrapped value to the Color constructed from the specified red, green, blue, and alpha values in the range [0.0, 1.0].

See Also:
setValue(Color), setValue(int, int, int), setValue(int, int, int, int), setValue(float, float, float), getValue()

getValue

public Color getValue()
Returns the value wrapped by this object.

See Also:
setValue(Color), setValue(int, int, int), setValue(int, int, int, int), setValue(float, float, float), setValue(float, float, float, float)

getColor

public static Color getColor(String data)

Gets a Color value from a data String if the data is valid or returns null.

Parameters:
data - the String to parse
Returns:
the extracted Color value

parseColor

public static Color parseColor(String data)
                        throws ParseException

Gets a Color value from a data String if the data is valid or throws a ParseException.

Parameters:
data - the String to parse
Returns:
the extracted Color value
Throws:
ParseException - if the data is invalid

colorToString

public static String colorToString(Color color)

Returns a String encapsulation of the Color parameter that contains the int values of red, green, blue, (and possibly alpha) each in the range [0, 255].

The alpha component is omitted if it is equal to 255.

Parameters:
color - the color to represent as a string

toPrimitiveArray

public static Color[] toPrimitiveArray(XColor[] x)
Returns an array of Color objects copied from the given array of XColor objects.

Parameters:
x - an array of XColors
Returns:
the resulting array of Color objects
See Also:
toXArray(Color[])

toXArray

public static XColor[] toXArray(Color[] a)
Returns an array of XColor objects initialized from the given array of Color objects.

Parameters:
a - an array of Colors
Returns:
the resulting array of XColor objects
See Also:
toPrimitiveArray(XColor[])