Eclipse Platform
Release 3.6

org.eclipse.swt.graphics
Class Color

java.lang.Object
  extended by org.eclipse.swt.graphics.Resource
      extended by org.eclipse.swt.graphics.Color

public final class Color
extends Resource

Instances of this class manage the operating system resources that implement SWT's RGB color model. To create a color you can either specify the individual color components as integers in the range 0 to 255 or provide an instance of an RGB.

Application code must explicitly invoke the Color.dispose() method to release the operating system resources managed by each instance when those instances are no longer required.

See Also:
RGB, Device.getSystemColor(int), Color and RGB snippets, SWT Example: PaintExample, Sample code and further information

Field Summary
 int handle
          the handle to the OS color resource (Warning: This field is platform dependent) IMPORTANT: This field is not part of the SWT public API.
 
Constructor Summary
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, RGB rgb)
          Constructs a new instance of this class given a device and an RGB describing the desired red, green and blue values.
 
Method Summary
 boolean equals(Object object)
          Compares the argument to the receiver, and returns true if they represent the same object using a class specific comparison.
 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 an RGB representing the receiver.
 int hashCode()
          Returns an integer hash code for the receiver.
 boolean isDisposed()
          Returns true if the color has been disposed, and false otherwise.
 String toString()
          Returns a string containing a concise, human-readable description of the receiver.
static Color win32_new(Device device, int handle)
          Invokes platform specific functionality to allocate a new color.
 
Methods inherited from class org.eclipse.swt.graphics.Resource
dispose, getDevice
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

handle

public int handle
the handle to the OS color resource (Warning: This field is platform dependent)

IMPORTANT: This field is not part of the SWT public API. It is marked public only so that it can be shared within the packages provided by SWT. It is not available on all platforms and should never be accessed from application code.

Restriction:
This field is not intended to be referenced by clients.
Constructor Detail

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 color
red - the amount of red in the color
green - the amount of green in the color
blue - the amount of blue in the color
Throws:
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
See Also:
Resource.dispose()

Color

public Color(Device device,
             RGB rgb)
Constructs a new instance of this class given a device and an RGB 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 color
rgb - the RGB values of the desired color
Throws:
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
See Also:
Resource.dispose()
Method Detail

equals

public boolean equals(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 class Object
Parameters:
object - the object to compare with this object
Returns:
true if the object is the same as this object and false otherwise
See Also:
hashCode()

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

getRGB

public RGB getRGB()
Returns an RGB representing the receiver.

Returns:
the RGB for the color
Throws:
SWTException -
  • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed

hashCode

public int hashCode()
Returns an integer hash code for the receiver. Any two objects that return true when passed to equals must return the same value for this method.

Overrides:
hashCode in class Object
Returns:
the receiver's hash
See Also:
equals(java.lang.Object)

isDisposed

public boolean isDisposed()
Returns true if the color has been disposed, and false otherwise.

This method gets the dispose state for the color. When a color has been disposed, it is an error to invoke any other method (except Resource.dispose()) using the color.

Specified by:
isDisposed in class Resource
Returns:
true when the color is disposed and false otherwise

toString

public String toString()
Returns a string containing a concise, human-readable description of the receiver.

Overrides:
toString in class Object
Returns:
a string representation of the receiver

win32_new

public static Color win32_new(Device device,
                              int handle)
Invokes platform specific functionality to allocate a new color.

IMPORTANT: This method is not part of the public API for Color. It is marked public only so that it can be shared within the packages provided by SWT. It is not available on all platforms, and should never be called from application code.

Parameters:
device - the device on which to allocate the color
handle - the handle for the color
Returns:
a new color object containing the specified device and handle
Restriction:
This method is not intended to be referenced by clients.

Eclipse Platform
Release 3.6

Guidelines for using Eclipse APIs.

Copyright (c) Eclipse contributors and others 2000, 2010. All rights reserved.