com.guiseframework.style
Class AbstractModeledColor<C extends java.lang.Enum<C> & ModeledColor.Component>

java.lang.Object
  extended by com.guiseframework.style.AbstractModeledColor<C>
Type Parameters:
C - The type of color component for this color space.
All Implemented Interfaces:
Color, ModeledColor<C>
Direct Known Subclasses:
HSLColor, RGBColor

public abstract class AbstractModeledColor<C extends java.lang.Enum<C> & ModeledColor.Component>
extends java.lang.Object
implements ModeledColor<C>

Abstract representation of a color value in a color space.

Author:
Garret Wilson
See Also:
Color Space FAQ, International Color Consortium

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.guiseframework.style.ModeledColor
ModeledColor.Component
 
Constructor Summary
AbstractModeledColor(double... values)
          Constructs a color with the given components.
 
Method Summary
protected static double checkComponentValue(double value)
          Checks the range of a given color component.
 boolean equals(java.lang.Object object)
          Indicates whether some other object is "equal to" this one.
 long getAbsoluteComponent(C component, int bitDepth)
          Determines the absolute value of the given color component with the given bit depth.
 double getComponent(C component)
          Determines the value of the given color component.
 double[] getValues()
           
 int hashCode()
           
static Color valueOf(java.lang.CharSequence charSequence)
          Creates a color from a string representation.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.guiseframework.style.Color
asHSL, asRGB
 

Constructor Detail

AbstractModeledColor

public AbstractModeledColor(double... values)
Constructs a color with the given components.

Parameters:
values - The values of components of the color in the correct color space, each within the range (0.0-1.0), in the order of the component ordinals.
Throws:
java.lang.NullPointerException - if the components is null. TODO fix @exception IllegalArgumentException if the number of component values do not equal the number of components.
Method Detail

getValues

public double[] getValues()
Returns:
The color component values, each within the range (0.0-1.0).

checkComponentValue

protected static double checkComponentValue(double value)
Checks the range of a given color component.

Parameters:
value - The value to check.
Returns:
The checked value.
Throws:
java.lang.IllegalArgumentException - if the given component is outside the range (0.0-1.0).

getComponent

public double getComponent(C component)
Determines the value of the given color component.

Specified by:
getComponent in interface ModeledColor<C extends java.lang.Enum<C> & ModeledColor.Component>
Parameters:
component - The color component for which a value should be retrieved.
Returns:
The value of the requested color component.

getAbsoluteComponent

public long getAbsoluteComponent(C component,
                                 int bitDepth)
Determines the absolute value of the given color component with the given bit depth. For example, retrieving a component with value 0.5 and a bit depth of 16 would produce 128 or 0x80.

Specified by:
getAbsoluteComponent in interface ModeledColor<C extends java.lang.Enum<C> & ModeledColor.Component>
Parameters:
component - The color component for which a value should be retrieved.
bitDepth - The number of bits to use for the given color component.
Returns:
The absolute value of the requested color component at the given bit depth.
See Also:
getComponent(Enum)

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
Returns:
A hash code value for the object.

equals

public boolean equals(java.lang.Object object)
Indicates whether some other object is "equal to" this one. This implementation returns whether the objects are of the same class with identical color component values.

Overrides:
equals in class java.lang.Object
Parameters:
object - The reference object with which to compare.
Returns:
true if this object is equivalent to the given object.

valueOf

public static Color valueOf(java.lang.CharSequence charSequence)
Creates a color from a string representation. This representation can be in one of the following forms: This method also recognizes the transparent color name as equivalent to rgba(0, 0, 0, 0), or black with zero alpha.

Parameters:
charSequence - The character sequence representation of a color.
Returns:
A color object representing the color represented by the given string.
Throws:
java.lang.NullPointerException - if the given string is null.
java.lang.IllegalArgumentException - if a color cannot be determined from the given string.
See Also:
HSLColor.valueOf(CharSequence), RGBColor.valueOf(CharSequence)


Copyright © 2005-2010 GlobalMentor, Inc. All Rights Reserved.