Eclipse Platform
Release 3.1

org.eclipse.jface.resource
Class ColorDescriptor

java.lang.Object
  extended byorg.eclipse.jface.resource.DeviceResourceDescriptor
      extended byorg.eclipse.jface.resource.ColorDescriptor

public abstract class ColorDescriptor
extends DeviceResourceDescriptor

Lightweight descriptor for an SWT color. Each ColorDescriptor will create a particular SWT Color on demand. This object will be compared so hashCode(...) and equals(...) must return meaningful values.

Since:
3.1

Constructor Summary
ColorDescriptor()
           
 
Method Summary
abstract  Color createColor(Device device)
          Returns the Color described by this descriptor.
static ColorDescriptor createFrom(Color toCreate)
          Creates a ColorDescriptor from an existing color.
static ColorDescriptor createFrom(Color toCreate, Device originalDevice)
          Creates a ColorDescriptor from an existing Color, given the Device associated with the original Color.
static ColorDescriptor createFrom(RGB toCreate)
          Returns a color descriptor for the given RGB values
 Object createResource(Device device)
          Creates the resource described by this descriptor
abstract  void destroyColor(Color toDestroy)
          Undoes whatever was done by createColor.
 void destroyResource(Object previouslyCreatedObject)
          Undoes everything that was done by a previous call to create(...), given the object that was returned by create(...).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ColorDescriptor

public ColorDescriptor()
Method Detail

createFrom

public static ColorDescriptor createFrom(Color toCreate,
                                         Device originalDevice)
Creates a ColorDescriptor from an existing Color, given the Device associated with the original Color. This is the usual way to convert a Color into a ColorDescriptor. Note that the returned ColorDescriptor depends on the original Color, and disposing the Color will invalidate the ColorDescriptor.

Parameters:
toCreate - Color to convert into a ColorDescriptor.
originalDevice - this must be the same Device that was passed into the original Color's constructor.
Returns:
a newly created ColorDescriptor that describes the given Color.
Since:
3.1

createFrom

public static ColorDescriptor createFrom(Color toCreate)
Creates a ColorDescriptor from an existing color.

This is less efficient than createFrom(Color, Device), so this version should only be used in situations where the device associated with the color is unknown.

The returned ColorDescriptor depends on the original Color. Disposing the original colour while the color descriptor is still in use may cause SWT to throw a graphic disposed exception.

Parameters:
toCreate - Color to generate a ColorDescriptor from
Returns:
a newly created ColorDescriptor
Since:
3.1

createFrom

public static ColorDescriptor createFrom(RGB toCreate)
Returns a color descriptor for the given RGB values

Parameters:
toCreate - RGB values to create
Returns:
a new ColorDescriptor
Since:
3.1

createColor

public abstract Color createColor(Device device)
                           throws DeviceResourceException
Returns the Color described by this descriptor.

Parameters:
device - SWT device on which to allocate the Color
Returns:
a newly allocated SWT Color object (never null)
Throws:
DeviceResourceException - if unable to allocate the Color

destroyColor

public abstract void destroyColor(Color toDestroy)
Undoes whatever was done by createColor.

Parameters:
toDestroy - a Color that was previously allocated by an equal ColorDescriptor
Since:
3.1

createResource

public final Object createResource(Device device)
                            throws DeviceResourceException
Description copied from class: DeviceResourceDescriptor
Creates the resource described by this descriptor

Specified by:
createResource in class DeviceResourceDescriptor
Parameters:
device - the Device on which to allocate the resource
Returns:
the newly allocated resource (not null)
Throws:
DeviceResourceException - if unable to allocate the resource

destroyResource

public final void destroyResource(Object previouslyCreatedObject)
Description copied from class: DeviceResourceDescriptor
Undoes everything that was done by a previous call to create(...), given the object that was returned by create(...).

Specified by:
destroyResource in class DeviceResourceDescriptor
Parameters:
previouslyCreatedObject - an object that was returned by an equal descriptor in a previous call to createResource(...).

Eclipse Platform
Release 3.1

Guidelines for using Eclipse APIs.

Copyright (c) IBM Corp. and others 2000, 2005. All rights reserved.