java::awt::Color Class Reference

Inheritance diagram for java::awt::Color:

Inheritance graph
java::lang::Objectjava::lang::Interfacejava::awt::Transparency
[legend]
Collaboration diagram for java::awt::Color:

Collaboration graph
java::lang::Objectjava::lang::Interfacejava::lang::ObjectRefjava::awt::Transparencyjava::lang::Comparable
[legend]

List of all members.


Detailed Description

The Color class is used encapsulate colors in the default sRGB color space or colors in arbitrary color spaces identified by a ColorSpace.

Every color has an implicit alpha value of 1.0 or an explicit one provided in the constructor. The alpha value defines the transparency of a color and can be represented by a float value in the range 0.0 - 1.0 or 0 - 255. An alpha value of 1.0 or 255 means that the color is completely opaque and an alpha value of 0 or 0.0 means that the color is completely transparent. When constructing a Color with an explicit alpha or getting the color/alpha components of a Color, the color components are never premultiplied by the alpha component.

The default color space for the Java 2D(tm) API is sRGB, a proposed standard RGB color space. For further information on sRGB, see http://www.w3.org/pub/WWW/Graphics/Color/sRGB.html .

Version:
10 Feb 1997
Author:
Sami Shaio

Arthur van Hoff

See also:
ColorSpace

AlphaComposite


Public Member Functions

 Color (jint rgb=0)
 Creates an opaque sRGB color with the specified combined RGB value consisting of the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7.
 Color (jint rgba, jboolean hasalpha)
 Creates an sRGB color with the specified combined RGBA value consisting of the alpha component in bits 24-31, the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7.
 Color (jint r, jint g, jint b, jint a=255)
 Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0 - 255).
 Color (jfloat r, jfloat g, jfloat b, jfloat a=1.0f)
 Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0.0 - 1.0).
virtual jint getRed () const
 Returns the red component in the range 0-255 in the default sRGB space.
virtual jint getGreen () const
 Returns the green component in the range 0-255 in the default sRGB space.
virtual jint getBlue () const
 Returns the blue component in the range 0-255 in the default sRGB space.
virtual jint getAlpha () const
 Returns the alpha component in the range 0-255.
virtual jint getRGB () const
 Returns the RGB value representing the color in the default sRGB ColorModel.
virtual Ref< Colorbrighter () const
 Creates a new Color that is a brighter version of this Color.
virtual Ref< Colordarker () const
 Creates a new Color that is a darker version of this Color.
virtual jint hashCode () const
 Computes the hash code for this Color.
virtual jboolean equals (const Object &obj) const
 Determines whether another object is equal to this Color.
virtual String toString () const
 Returns a string representation of this Color.
Array< jfloatgetRGBComponents () const
 Returns a float array containing the color and alpha components of the Color, as represented in the default sRGB color space.
Array< jfloatgetRGBColorComponents () const
 Returns a float array containing only the color components of the Color, in the default sRGB color space.
Array< jfloatgetComponents () const
 Returns a float array containing the color and alpha components of the Color, in the ColorSpace of the Color.
Array< jfloatgetColorComponents () const
 Returns a float array containing only the color components of the Color, in the ColorSpace of the Color.
virtual jint getTransparency () const
 Returns the transparency mode for this Color.

Static Public Member Functions

static Ref< Colordecode (const String &nm)
 Converts a String to an integer and returns the specified opaque Color.
static Ref< ColorgetColor (const String &nm, const Ref< Color > &v=0)
 Finds a color in the system properties.
static jint HSBtoRGB (jfloat hue, jfloat saturation, jfloat brightness)
 Converts the components of a color, as specified by the HSB model, to an equivalent set of values for the default RGB model.
static Array< jfloatRGBtoHSB (jint r, jint g, jint b)
 Converts the components of a color, as specified by the default RGB model, to an equivalent set of values for hue, saturation, and brightness that are the three components of the HSB model.
static Ref< ColorgetHSBColor (jfloat h, jfloat s, jfloat b)
 Creates a Color object based on the specified values for the HSB color model.

Static Public Attributes

static const Color WHITE
static const Color LIGHT_GRAY
static const Color GRAY
static const Color DARK_GRAY
static const Color BLACK
static const Color RED
static const Color PINK
static const Color ORANGE
static const Color YELLOW
static const Color GREEN
static const Color MAGENTA
static const Color CYAN
static const Color BLUE

Constructor & Destructor Documentation

java::awt::Color::Color ( jint  rgb = 0  ) 

Creates an opaque sRGB color with the specified combined RGB value consisting of the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7.

The actual color used in rendering depends on finding the best match given the color space available for a particular output device. Alpha is defaulted to 255.

Parameters:
rgb the combined RGB components
See also:
java.awt.image.ColorModel::getRGBdefault

getRed

getGreen

getBlue

getRGB

java::awt::Color::Color ( jint  rgba,
jboolean  hasalpha 
)

Creates an sRGB color with the specified combined RGBA value consisting of the alpha component in bits 24-31, the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7.

If the hasalpha argument is false, alpha is defaulted to 255.

Parameters:
rgba the combined RGBA components
hasalpha true if the alpha bits are valid; false otherwise
See also:
java.awt.image.ColorModel::getRGBdefault

getRed

getGreen

getBlue

getAlpha

getRGB

java::awt::Color::Color ( jint  r,
jint  g,
jint  b,
jint  a = 255 
)

Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0 - 255).

Parameters:
r the red component
g the green component
b the blue component
a the alpha component
See also:
getRed

getGreen

getBlue

getAlpha

getRGB

java::awt::Color::Color ( jfloat  r,
jfloat  g,
jfloat  b,
jfloat  a = 1.0f 
)

Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0.0 - 1.0).

The actual color used in rendering depends on finding the best match given the color space available for a particular output device.

Parameters:
r the red component
g the green component
b the blue component
a the alpha component
See also:
getRed

getGreen

getBlue

getAlpha

getRGB


Member Function Documentation

virtual jint java::awt::Color::getRed (  )  const [virtual]

Returns the red component in the range 0-255 in the default sRGB space.

Returns:
the red component.
See also:
getRGB

virtual jint java::awt::Color::getGreen (  )  const [virtual]

Returns the green component in the range 0-255 in the default sRGB space.

Returns:
the green component.
See also:
getRGB

virtual jint java::awt::Color::getBlue (  )  const [virtual]

Returns the blue component in the range 0-255 in the default sRGB space.

Returns:
the blue component.
See also:
getRGB

virtual jint java::awt::Color::getAlpha (  )  const [virtual]

Returns the alpha component in the range 0-255.

Returns:
the alpha component.
See also:
getRGB

virtual jint java::awt::Color::getRGB (  )  const [virtual]

Returns the RGB value representing the color in the default sRGB ColorModel.

(Bits 24-31 are alpha, 16-23 are red, 8-15 are green, 0-7 are blue).

Returns:
the RGB value of the color in the default sRGB ColorModel.
See also:
java.awt.image.ColorModel::getRGBdefault

getRed

getGreen

getBlue

Since:
JDK1.0

virtual Ref<Color> java::awt::Color::brighter (  )  const [virtual]

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. 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.

Returns:
a new Color object that is a brighter version of this Color.
See also:
java.awt.Color::darker
Since:
JDK1.0

virtual Ref<Color> java::awt::Color::darker (  )  const [virtual]

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. 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.

Returns:
a new Color object that is a darker version of this Color.
See also:
java.awt.Color::brighter
Since:
JDK1.0

virtual jint java::awt::Color::hashCode (  )  const [virtual]

Computes the hash code for this Color.

Returns:
a hash code value for this object.
Since:
JDK1.0

Reimplemented from java::lang::Object.

virtual jboolean java::awt::Color::equals ( const Object obj  )  const [virtual]

Determines whether another object is equal to this Color.

The result is true if and only if the argument is not null and is a Color object that has the same red, green, blue, and alpha values as this object.

Parameters:
obj the object to test for equality with this Color
Returns:
true if the objects are the same; false otherwise.
Since:
JDK1.0

Reimplemented from java::lang::Object.

virtual String java::awt::Color::toString (  )  const [virtual]

Returns a string representation of this Color.

This method is intended to be used only for debugging purposes. The content and format of the returned string might vary between implementations. The returned string might be empty but cannot be null.

Returns:
a string representation of this Color.

Reimplemented from java::lang::Object.

static Ref<Color> java::awt::Color::decode ( const String nm  )  [static]

Converts a String to an integer and returns the specified opaque Color.

This method handles string formats that are used to represent octal and hexidecimal numbers.

Parameters:
nm a String that represents an opaque color as a 24-bit integer
Returns:
the new Color object.
See also:
java.lang.Integer::decode
Exceptions:
NumberFormatException if the specified string cannot be interpreted as a decimal, octal, or hexidecimal integer.
Since:
JDK1.1

static Ref<Color> java::awt::Color::getColor ( const String nm,
const Ref< Color > &  v = 0 
) [static]

Finds a 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 cannot be parsed as an integer then the Color specified by the second argument is returned instead.

Parameters:
nm the name of the color property
v the default Color
Returns:
the Color converted from the system property, or the specified Color.
See also:
java.lang.System::getProperty(java.lang.String)

java.lang.Integer::getInteger(java.lang.String)

java.awt.Color::Color(int)

Since:
JDK1.0

static jint java::awt::Color::HSBtoRGB ( jfloat  hue,
jfloat  saturation,
jfloat  brightness 
) [static]

Converts the components of a color, as specified by the HSB model, to an equivalent set of values for the default RGB model.

The saturation and brightness components should be floating-point values between zero and one (numbers in the range 0.0-1.0). The hue component can be any floating-point number. The floor of this number is subtracted from it to create a fraction between 0 and 1. This fractional number is then multiplied by 360 to produce the hue angle in the HSB color model.

The integer that is returned by HSBtoRGB encodes the value of a color in bits 0-23 of an integer value that is the same format used by the method getRGB. This integer can be supplied as an argument to the Color constructor that takes a single integer argument.

Parameters:
hue the hue component of the color
saturation the saturation of the color
brightness the brightness of the color
Returns:
the RGB value of the color with the indicated hue, saturation, and brightness.
See also:
java.awt.Color::getRGB()

java.awt.Color::Color(int)

java.awt.image.ColorModel::getRGBdefault()

Since:
JDK1.0

static Array<jfloat> java::awt::Color::RGBtoHSB ( jint  r,
jint  g,
jint  b 
) [static]

Converts the components of a color, as specified by the default RGB model, to an equivalent set of values for hue, saturation, and brightness that are the three components of the HSB model.

If the hsbvals argument is null, then a new array is allocated to return the result. Otherwise, the method returns the array hsbvals, with the values put into that array.

Parameters:
r the red component of the color
g the green component of the color
b the blue component of the color
hsbvals the array used to return the three HSB values, or null
Returns:
an array of three elements containing the hue, saturation, and brightness (in that order), of the color with the indicated red, green, and blue components.
See also:
java.awt.Color::getRGB()

java.awt.Color::Color(int)

java.awt.image.ColorModel::getRGBdefault()

Since:
JDK1.0

static Ref<Color> java::awt::Color::getHSBColor ( jfloat  h,
jfloat  s,
jfloat  b 
) [static]

Creates a Color object based on the specified values for the HSB color model.

The s and b components should be floating-point values between zero and one (numbers in the range 0.0-1.0). The h component can be any floating-point number. The floor of this number is subtracted from it to create a fraction between 0 and 1. This fractional number is then multiplied by 360 to produce the hue angle in the HSB color model.

Parameters:
h the hue component
s the saturation of the color
b the brightness of the color
Returns:
a Color object with the specified hue, saturation, and brightness.
Since:
JDK1.0

Array<jfloat> java::awt::Color::getRGBComponents (  )  const

Returns a float array containing the color and alpha components of the Color, as represented in the default sRGB color space.

If compArray is null, an array of length 4 is created for the return value. Otherwise, compArray must have length 4 or greater, and it is filled in with the components and returned.

Parameters:
compArray an array that this method fills with color and alpha components and returns
Returns:
the RGBA components in a float array.

Array<jfloat> java::awt::Color::getRGBColorComponents (  )  const

Returns a float array containing only the color components of the Color, in the default sRGB color space.

If compArray is null, an array of length 3 is created for the return value. Otherwise, compArray must have length 3 or greater, and it is filled in with the components and returned.

Parameters:
compArray an array that this method fills with color components and returns
Returns:
the RGB components in a float array.

Array<jfloat> java::awt::Color::getComponents (  )  const

Returns a float array containing the color and alpha components of the Color, in the ColorSpace of the Color.

If compArray is null, an array with length equal to the number of components in the associated ColorSpace plus one is created for the return value. Otherwise, compArray must have at least this length and it is filled in with the components and returned.

Parameters:
compArray an array that this method fills with the color and alpha components of this Color in its ColorSpace and returns
Returns:
the color and alpha components in a float array.

Array<jfloat> java::awt::Color::getColorComponents (  )  const

Returns a float array containing only the color components of the Color, in the ColorSpace of the Color.

If compArray is null, an array with length equal to the number of components in the associated ColorSpace is created for the return value. Otherwise, compArray must have at least this length and it is filled in with the components and returned.

Parameters:
compArray an array that this method fills with the color components of this Color in its ColorSpace and returns
Returns:
the color components in a float array.

virtual jint java::awt::Color::getTransparency (  )  const [virtual]

Returns the transparency mode for this Color.

This is required to implement the Paint interface.

Returns:
this Color object's transparency mode.
See also:
Paint

Transparency

createContext

Implements java::awt::Transparency.


Member Data Documentation

const Color java::awt::Color::WHITE [static]

const Color java::awt::Color::LIGHT_GRAY [static]

const Color java::awt::Color::GRAY [static]

const Color java::awt::Color::DARK_GRAY [static]

const Color java::awt::Color::BLACK [static]

const Color java::awt::Color::RED [static]

const Color java::awt::Color::PINK [static]

const Color java::awt::Color::ORANGE [static]

const Color java::awt::Color::YELLOW [static]

const Color java::awt::Color::GREEN [static]

const Color java::awt::Color::MAGENTA [static]

const Color java::awt::Color::CYAN [static]

const Color java::awt::Color::BLUE [static]


The documentation for this class was generated from the following file:
Generated on Fri May 16 11:55:55 2008 for CrossPlatformJavaLikeC++API by  doxygen 1.5.3