GNU Classpath (0.95) | |
Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
java.awt.Color
ColorSpace
, AlphaComposite
, Serialized FormField Summary | |
static Color |
|
static Color |
|
static Color |
|
static Color |
|
static Color |
|
static Color |
|
static Color |
|
static Color |
|
static Color |
|
static Color |
|
static Color |
|
static Color |
|
static Color |
|
static Color |
|
static Color |
|
static Color |
|
static Color |
|
static Color |
|
static Color |
|
static Color |
|
static Color |
|
static Color |
|
static Color |
|
static Color |
|
static Color |
|
static Color |
|
Fields inherited from interface java.awt.Transparency | |
BITMASK , OPAQUE , TRANSLUCENT |
Constructor Summary | |
| |
| |
| |
| |
| |
| |
|
Method Summary | |
static int |
|
static float[] |
|
Color |
|
PaintContext |
|
Color |
|
static Color | |
boolean | |
int |
|
int |
|
static Color | |
static Color | |
static Color | |
float[] |
|
float[] |
|
ColorSpace |
|
float[] |
|
float[] |
|
int |
|
static Color |
|
int |
|
float[] |
|
float[] |
|
int |
|
int |
|
int |
|
String |
|
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
public static final Color DARK_GRAY
Constant for the color dark gray: R=64, G=64, B=64.
- Since:
- 1.4
public static final Color LIGHT_GRAY
Constant for the color light gray: R=192, G=192, B=192.
- Since:
- 1.4
public static final Color MAGENTA
Constant for the color magenta: R=255, G=0, B=255.
- Since:
- 1.4
public Color(float red, float green, float blue)
Initializes a new instance ofColor
using the specified RGB values. These must be in the range of 0.0-1.0. Alpha is assigned the value of 1.0 (opaque). When drawing to screen, the actual color may be adjusted to the best match of hardware capabilities.
- Parameters:
red
- the red component of the RGB valuegreen
- the green component of the RGB valueblue
- the blue component of the RGB value
- Throws:
IllegalArgumentException
- tf the values are out of range 0.0f-1.0f
- See Also:
getRed()
,getGreen()
,getBlue()
,getRGB()
,Color(float,float,float,float)
public Color(float red, float green, float blue, float alpha)
Initializes a new instance ofColor
using the specified RGB and alpha values. These must be in the range of 0.0-1.0. When drawing to screen, the actual color may be adjusted to the best match of hardware capabilities.
- Parameters:
red
- the red component of the RGB valuegreen
- the green component of the RGB valueblue
- the blue component of the RGB valuealpha
- the alpha value of the color
- Throws:
IllegalArgumentException
- tf the values are out of range 0.0f-1.0f
- See Also:
getRed()
,getGreen()
,getBlue()
,getAlpha()
,getRGB()
public Color(int value)
Initializes a new instance ofColor
using the specified RGB value. The blue value is in bits 0-7, green in bits 8-15, and red in bits 16-23. The other bits are ignored. The alpha value is set to 255 (opaque). When drawing to screen, the actual color may be adjusted to the best match of hardware capabilities.
- Parameters:
value
- the RGB value
public Color(int value, boolean hasalpha)
Initializes a new instance ofColor
using the specified RGB value. The blue value is in bits 0-7, green in bits 8-15, and red in bits 16-23. The alpha value is in bits 24-31, unless hasalpha is false, in which case alpha is set to 255. When drawing to screen, the actual color may be adjusted to the best match of hardware capabilities.
- Parameters:
value
- the RGB valuehasalpha
- true if value includes the alpha
- See Also:
ColorModel.getRGBdefault()
,getRed()
,getGreen()
,getBlue()
,getAlpha()
,getRGB()
public Color(int red, int green, int blue)
Initializes a new instance ofColor
using the specified red, green, and blue values, which must be given as integers in the range of 0-255. Alpha will default to 255 (opaque). When drawing to screen, the actual color may be adjusted to the best match of hardware capabilities.
- Parameters:
red
- the red component of the RGB valuegreen
- the green component of the RGB valueblue
- the blue component of the RGB value
- Throws:
IllegalArgumentException
- if the values are out of range 0-255
- See Also:
getRed()
,getGreen()
,getBlue()
,getRGB()
,Color(int,int,int,int)
public Color(int red, int green, int blue, int alpha)
Initializes a new instance ofColor
using the specified red, green, blue, and alpha values, which must be given as integers in the range of 0-255. When drawing to screen, the actual color may be adjusted to the best match of hardware capabilities.
- Parameters:
red
- the red component of the RGB valuegreen
- the green component of the RGB valueblue
- the blue component of the RGB valuealpha
- the alpha value of the color
- Throws:
IllegalArgumentException
- if the values are out of range 0-255
- See Also:
getRed()
,getGreen()
,getBlue()
,getAlpha()
,getRGB()
public Color(ColorSpace space, float[] components, float alpha)
Creates a color in the given ColorSpace with the specified alpha. The array must be non-null and have enough elements for the color space (for example, RGB requires 3 elements, CMYK requires 4). When drawing to screen, the actual color may be adjusted to the best match of hardware capabilities.
- Parameters:
space
- the color space of componentscomponents
- the color components, except alphaalpha
- the alpha value of the color
- Throws:
NullPointerException
- if cpsace or components is nullArrayIndexOutOfBoundsException
- if components is too smallIllegalArgumentException
- if alpha or any component is out of range
public static int HSBtoRGB(float hue, float saturation, float brightness)
Converts from the HSB (hue, saturation, brightness) color model to the RGB (red, green, blue) color model. The hue may be any floating point; it's fractional portion is used to select the angle in the HSB model. The saturation and brightness must be between 0 and 1. The result is suitable for creating an RGB color with the one-argument constructor.
- Parameters:
hue
- the hue of the HSB valuesaturation
- the saturation of the HSB valuebrightness
- the brightness of the HSB value
- Returns:
- the RGB value
- See Also:
getRGB()
,Color(int)
,ColorModel.getRGBdefault()
public static float[] RGBtoHSB(int red, int green, int blue, array[] )
Converts from the RGB (red, green, blue) color model to the HSB (hue, saturation, brightness) color model. If the array is null, a new one is created, otherwise it is recycled. The results will be in the range 0.0-1.0 if the inputs are in the range 0-255.
- Parameters:
red
- the red part of the RGB valuegreen
- the green part of the RGB valueblue
- the blue part of the RGB value
- Returns:
- the array containing HSB value
- Throws:
ArrayIndexOutOfBoundsException
- of array is too small
- See Also:
getRGB()
,Color(int)
,ColorModel.getRGBdefault()
public Color brighter()
Returns a brighter version of this color. This is done by increasing the RGB values by an arbitrary scale factor. The new color is opaque (an alpha of 255). Note that this method and thedarker()
method are not necessarily inverses.
- Returns:
- a brighter version of this color
- See Also:
darker()
public PaintContext createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform xform, RenderingHints hints)
Returns a paint context, used for filling areas of a raster scan with this color. Since the color is constant across the entire rectangle, and since it is always in sRGB space, this implementation returns the same object, regardless of the parameters. Subclasses, however, may have a mutable result.
- Specified by:
- createContext in interface Paint
- Parameters:
cm
- the requested color modeldeviceBounds
- the bounding box in device coordinates, ignoreduserBounds
- the bounding box in user coordinates, ignoredxform
- the bounds transformation, ignoredhints
- any rendering hints, ignored
- Returns:
- a context for painting this solid color
public Color darker()
Returns a darker version of this color. This is done by decreasing the RGB values by an arbitrary scale factor. The new color is opaque (an alpha of 255). Note that this method and thebrighter()
method are not necessarily inverses.
- Returns:
- a darker version of this color
- See Also:
brighter()
public static Color decode(String str)
Converts the specified string to a number, using Integer.decode, and creates a new instance ofColor
from the value. The alpha value will be 255 (opaque).
- Parameters:
str
- the numeric color string
- Returns:
- a new instance of
Color
for the string
- Throws:
NumberFormatException
- if the string cannot be parsedNullPointerException
- if the string is null
- Since:
- 1.1
- See Also:
Integer.decode(String)
,Color(int)
public boolean equals(Object obj)
Tests this object for equality against the specified object. This will be true if and only if the specified object is an instance ofColor
and has the same 8-bit integer red, green, and blue values as this object. Note that two colors may be slightly different as float values, but round to the same integer values. Also note that this does not accurately compare SystemColors, since that class does not store its internal data in RGB format like regular colors.
- Parameters:
obj
- the object to compare to
- Returns:
- true if the specified object is semantically equal to this one
public int getAlpha()
Returns the alpha value for this color, as an integer in the range 0-255.
- Returns:
- the alpha value for this color
- See Also:
getRGB()
public int getBlue()
Returns the blue value for this color, as an integer in the range 0-255 in the sRGB color space.
- Returns:
- the blue value for this color
- See Also:
getRGB()
public static Color getColor(String prop)
Returns a new instance ofColor
from the value of the system property named by the specified string. If the property does not exist, or cannot be parsed, thennull
will be returned.
- Parameters:
prop
- the system property to retrieve
- Throws:
SecurityException
- if getting the property is denied
public static Color getColor(String prop, int defrgb)
Returns a new instance ofColor
from the value of the system property named by the specified string. If the property does not exist, or cannot be parsed, then the default RGB value will be used to create a return value.
- Parameters:
prop
- the system property to retrievedefrgb
- the default RGB value
- Throws:
SecurityException
- if getting the property is denied
public static Color getColor(String prop, Color defcolor)
Returns a new instance ofColor
from the value of the system property named by the specified string. If the property does not exist, or cannot be parsed, then the default color value will be returned.
- Parameters:
prop
- the system property to retrievedefcolor
- the default color
- Throws:
SecurityException
- if getting the property is denied
- See Also:
Integer.getInteger(String)
public float[] getColorComponents(float[] array)
Returns a float array containing the color components of this color in the ColorSpace it was created with (the constructors which do not take a ColorSpace parameter use a default sRGB ColorSpace). If the array is null, a new one is created, otherwise it is recycled, and must have at least as many positions as used in the color space.
- Parameters:
array
- the array to put results into, or null
- Returns:
- the original color space components
- Throws:
ArrayIndexOutOfBoundsException
- if array is too small
public float[] getColorComponents(ColorSpace space, float[] array)
Returns a float array containing the color components of this color in the given ColorSpace. If the array is null, a new one is created, otherwise it is recycled, and must have at least as many positions as used in the color space.
- Parameters:
space
- the color space to translate to
- Returns:
- the color space components
- Throws:
ArrayIndexOutOfBoundsException
- if array is too smallNullPointerException
- if space is null
public ColorSpace getColorSpace()
Returns the color space of this color. Except for the constructor which takes a ColorSpace argument, this will be an implementation of ColorSpace.CS_sRGB.
- Returns:
- the color space
public float[] getComponents(float[] array)
Returns a float array containing the color and alpha components of this color in the ColorSpace it was created with (the constructors which do not take a ColorSpace parameter use a default sRGB ColorSpace). If the array is null, a new one is created, otherwise it is recycled, and must have at least one more position than components used in the color space.
- Parameters:
array
- the array to put results into, or null
- Returns:
- the original color space components and alpha value
- Throws:
ArrayIndexOutOfBoundsException
- if array is too small
public float[] getComponents(ColorSpace space, float[] array)
Returns a float array containing the color and alpha components of this color in the given ColorSpace. If the array is null, a new one is created, otherwise it is recycled, and must have at least one more position than components used in the color space.
- Parameters:
space
- the color space to translate toarray
- the array to put results into, or null
- Returns:
- the color space components and alpha value
- Throws:
ArrayIndexOutOfBoundsException
- if array is too smallNullPointerException
- if space is null
public int getGreen()
Returns the green value for this color, as an integer in the range 0-255 in the sRGB color space.
- Returns:
- the green value for this color
- See Also:
getRGB()
public static Color getHSBColor(float hue, float saturation, float brightness)
Returns a new instance ofColor
based on the specified HSB values. The hue may be any floating point; it's fractional portion is used to select the angle in the HSB model. The saturation and brightness must be between 0 and 1.
- Parameters:
hue
- the hue of the HSB valuesaturation
- the saturation of the HSB valuebrightness
- the brightness of the HSB value
- Returns:
- the new
Color
object
public int getRGB()
Returns the RGB value for this color, in the sRGB color space. The blue value will be in bits 0-7, green in 8-15, red in 16-23, and alpha value in 24-31.
- Returns:
- the RGB value for this color
- See Also:
ColorModel.getRGBdefault()
,getRed()
,getGreen()
,getBlue()
,getAlpha()
public float[] getRGBColorComponents(float[] array)
Returns a float array with the red, green, and blue components, in the default sRGB space, with values in the range 0.0-1.0. If the array is null, a new one is created, otherwise it is recycled.
- Parameters:
array
- the array to put results into (at least 3 elements), or null
- Returns:
- the RGB components
- Throws:
ArrayIndexOutOfBoundsException
- if array is too small
public float[] getRGBComponents(float[] array)
Returns a float array with the red, green, and blue components, and the alpha value, in the default sRGB space, with values in the range 0.0-1.0. If the array is null, a new one is created, otherwise it is recycled.
- Parameters:
array
- the array to put results into (at least 4 elements), or null
- Returns:
- the RGB components and alpha value
- Throws:
ArrayIndexOutOfBoundsException
- if array is too small
public int getRed()
Returns the red value for this color, as an integer in the range 0-255 in the sRGB color space.
- Returns:
- the red value for this color
- See Also:
getRGB()
public int getTransparency()
Returns the transparency level of this color.
- Specified by:
- getTransparency in interface Transparency
- Returns:
- one of
Transparency.OPAQUE
,Transparency.BITMASK
, orTransparency.TRANSLUCENT
public int hashCode()
Returns a hash value for this color. This is simply the color in 8-bit precision, in the format 0xAARRGGBB (alpha, red, green, blue).
- Returns:
- a hash value for this color
public String toString()
Returns a string representation of this object. Subclasses may return any desired format, except for null, but this implementation returnsgetClass().getName() + "[r=" + getRed() + ",g=" + getGreen() + ",b=" + getBlue() + ']'
.
- Returns:
- a string representation of this object
GNU Classpath (0.95) |