Package org.eclipse.swt.graphics
Class Color
- java.lang.Object
-
- org.eclipse.swt.graphics.Resource
-
- org.eclipse.swt.graphics.Color
-
public class Color extends Resource
Instances of this class manage resources that implement SWT's RGB color model.- Since:
- 1.0
- See Also:
RGB
,Device.getSystemColor(int)
-
-
Constructor Summary
Constructors Constructor Description Color(Device device, int red, int green, int blue)
Constructs a new instance of this class given a device and the desired red, green and blue values expressed as ints in the range 0 to 255 (where 0 is black and 255 is full brightness).Color(Device device, int red, int green, int blue, int alpha)
Constructs a new instance of this class given a device and the desired red, green, blue & alpha values expressed as ints in the range 0 to 255 (where 0 is black and 255 is full brightness).Color(Device device, RGB rgb)
Constructs a new instance of this class given a device and anRGB
describing the desired red, green and blue values.Color(Device device, RGBA rgba)
Constructs a new instance of this class given a device and anRGBA
describing the desired red, green, blue & alpha values.Color(Device device, RGB rgb, int alpha)
Constructs a new instance of this class given a device, anRGB
describing the desired red, green and blue values, alpha specifying the level of transparency.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object object)
Compares the argument to the receiver, and returns true if they represent the same object using a class specific comparison.int
getAlpha()
Returns the amount of alpha in the color, from 0 (transparent) to 255 (opaque).int
getBlue()
Returns the amount of blue in the color, from 0 to 255.int
getGreen()
Returns the amount of green in the color, from 0 to 255.int
getRed()
Returns the amount of red in the color, from 0 to 255.RGB
getRGB()
Returns anRGB
representing the receiver.RGBA
getRGBA()
Returns anRGBA
representing the receiver.int
hashCode()
Returns an integer hash code for the receiver.java.lang.String
toString()
Returns a string containing a concise, human-readable description of the receiver.-
Methods inherited from class org.eclipse.swt.graphics.Resource
dispose, getDevice, isDisposed
-
-
-
-
Constructor Detail
-
Color
public Color(Device device, RGB rgb)
Constructs a new instance of this class given a device and anRGB
describing the desired red, green and blue values. On limited color devices, the color instance created by this call may not have the same RGB values as the ones specified by the argument. The RGB values on the returned instance will be the color values of the operating system color.You must dispose the color when it is no longer required.
- Parameters:
device
- the device on which to allocate the colorrgb
- the RGB values of the desired color- Throws:
java.lang.IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if device is null and there is no current device
- ERROR_NULL_ARGUMENT - if the rgb argument is null
- ERROR_INVALID_ARGUMENT - if the red, green or blue components of the argument are not between 0 and 255
- Since:
- 1.3
- See Also:
Resource.dispose()
-
Color
public Color(Device device, RGB rgb, int alpha)
Constructs a new instance of this class given a device, anRGB
describing the desired red, green and blue values, alpha specifying the level of transparency. On limited color devices, the color instance created by this call may not have the same RGB values as the ones specified by the argument. The RGB values on the returned instance will be the color values of the operating system color.You must dispose the color when it is no longer required.
- Parameters:
device
- the device on which to allocate the colorrgb
- the RGB values of the desired coloralpha
- the alpha value of the desired color. Currently, SWT only honors extreme values for alpha i.e. 0 (transparent) or 255 (opaque).- Throws:
java.lang.IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if device is null and there is no current device
- ERROR_NULL_ARGUMENT - if the rgb argument is null
- ERROR_INVALID_ARGUMENT - if the red, green, blue or alpha components of the argument are not between 0 and 255
- Since:
- 3.1
- See Also:
Resource.dispose()
-
Color
public Color(Device device, RGBA rgba)
Constructs a new instance of this class given a device and anRGBA
describing the desired red, green, blue & alpha values. On limited color devices, the color instance created by this call may not have the same RGBA values as the ones specified by the argument. The RGBA values on the returned instance will be the color values of the operating system color + alpha.You must dispose the color when it is no longer required.
- Parameters:
device
- the device on which to allocate the colorrgba
- the RGBA values of the desired color. Currently, SWT only honors extreme values for alpha i.e. 0 (transparent) or 255 (opaque).- Throws:
java.lang.IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if device is null and there is no current device
- ERROR_NULL_ARGUMENT - if the rgba argument is null
- ERROR_INVALID_ARGUMENT - if the red, green, blue or alpha components of the argument are not between 0 and 255
- Since:
- 3.1
- See Also:
Resource.dispose()
-
Color
public Color(Device device, int red, int green, int blue)
Constructs a new instance of this class given a device and the desired red, green and blue values expressed as ints in the range 0 to 255 (where 0 is black and 255 is full brightness). On limited color devices, the color instance created by this call may not have the same RGB values as the ones specified by the arguments. The RGB values on the returned instance will be the color values of the operating system color.You must dispose the color when it is no longer required.
- Parameters:
device
- the device on which to allocate the colorred
- the amount of red in the colorgreen
- the amount of green in the colorblue
- the amount of blue in the color- Throws:
java.lang.IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if device is null and there is no current device
- ERROR_INVALID_ARGUMENT - if the red, green or blue argument is not between 0 and 255
- Since:
- 1.3
- See Also:
Resource.dispose()
-
Color
public Color(Device device, int red, int green, int blue, int alpha)
Constructs a new instance of this class given a device and the desired red, green, blue & alpha values expressed as ints in the range 0 to 255 (where 0 is black and 255 is full brightness). On limited color devices, the color instance created by this call may not have the same RGB values as the ones specified by the arguments. The RGB values on the returned instance will be the color values of the operating system color.You must dispose the color when it is no longer required.
- Parameters:
device
- the device on which to allocate the colorred
- the amount of red in the colorgreen
- the amount of green in the colorblue
- the amount of blue in the coloralpha
- the amount of alpha in the color. Currently, SWT only honors extreme values for alpha i.e. 0 (transparent) or 255 (opaque).- Throws:
java.lang.IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if device is null and there is no current device
- ERROR_INVALID_ARGUMENT - if the red, green, blue or alpha argument is not between 0 and 255
- Since:
- 3.1
- See Also:
Resource.dispose()
-
-
Method Detail
-
getBlue
public int getBlue()
Returns the amount of blue in the color, from 0 to 255.- Returns:
- the blue component of the color
- Throws:
SWTException
-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
-
getGreen
public int getGreen()
Returns the amount of green in the color, from 0 to 255.- Returns:
- the green component of the color
- Throws:
SWTException
-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
-
getRed
public int getRed()
Returns the amount of red in the color, from 0 to 255.- Returns:
- the red component of the color
- Throws:
SWTException
-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
-
getAlpha
public int getAlpha()
Returns the amount of alpha in the color, from 0 (transparent) to 255 (opaque).- Returns:
- the alpha component of the color
- Throws:
SWTException
-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- Since:
- 3.1
-
getRGB
public RGB getRGB()
Returns anRGB
representing the receiver.- Returns:
- the RGB for the color
- Throws:
SWTException
-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
-
getRGBA
public RGBA getRGBA()
Returns anRGBA
representing the receiver.- Returns:
- the RGBA for the color
- Throws:
SWTException
-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- Since:
- 3.1
-
equals
public boolean equals(java.lang.Object object)
Compares the argument to the receiver, and returns true if they represent the same object using a class specific comparison.- Overrides:
equals
in classjava.lang.Object
- Parameters:
object
- the object to compare with this object- Returns:
true
if the object is the same as this object andfalse
otherwise- See Also:
hashCode()
-
hashCode
public int hashCode()
Returns an integer hash code for the receiver. Any two objects that returntrue
when passed toequals
must return the same value for this method.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- the receiver's hash
- See Also:
equals(java.lang.Object)
-
toString
public java.lang.String toString()
Returns a string containing a concise, human-readable description of the receiver.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string representation of the receiver
-
-