Package org.eclipse.jface.resource
Class DeviceResourceDescriptor<R>
java.lang.Object
org.eclipse.jface.resource.DeviceResourceDescriptor<R>
- Type Parameters:
R
- The resource's type described by this descriptor
- Direct Known Subclasses:
ColorDescriptor
,FontDescriptor
,ImageDescriptor
Instances of this class can allocate and dispose SWT resources. Each instance describes a
particular resource (such as a Color, Font, or Image) and can create and destroy that resource on
demand. DeviceResourceDescriptors are managed by a ResourceRegistry.
Note: It is recommended that subclasses implement #equals
and
#hashCode
, so that clients, like decoration managers, can recognize when they have
two equal descriptors at hand, e.g. decorating an identical object.
- Since:
- 3.1
- See Also:
-
Constructor Summary
ModifierConstructorDescriptiondefault constructor with shouldBeCached=falseprotected
DeviceResourceDescriptor
(boolean shouldBeCached) -
Method Summary
Modifier and TypeMethodDescriptionabstract Object
createResource
(Device device) Creates the resource described by this descriptorabstract void
destroyResource
(Object previouslyCreatedObject) Undoes everything that was done by a previous call to create(...), given the object that was returned by create(...).
-
Constructor Details
-
DeviceResourceDescriptor
public DeviceResourceDescriptor()default constructor with shouldBeCached=false -
DeviceResourceDescriptor
protected DeviceResourceDescriptor(boolean shouldBeCached) - Parameters:
shouldBeCached
- Indicates if the resource instance described by the descriptor should to be kept byResourceManager
even if all references to the resource are lost (due toResourceManager.destroy(DeviceResourceDescriptor)
).
Should return true for resources that are costly to create (for example by involving I/O Operation). Has only an effect if caching is enabled (see org.eclipse.jface.resource.JFaceResources#cacheSize). Caching relies onObject.equals(Object)
andObject.hashCode()
. For equal DeviceResourceDescriptors the same Resource instance is returned by theResourceManager
instance return byJFaceResources.getResources(org.eclipse.swt.widgets.Display)
as long as the cache is big enough to cache all resources.
Instances which equal (in terms ofObject.equals(Object)
) must have the same shouldBeCached mode.- Since:
- 3.24
- See Also:
-
-
Method Details
-
createResource
Creates the resource described by this descriptor- 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- Since:
- 3.1
-
destroyResource
Undoes everything that was done by a previous call to create(...), given the object that was returned by create(...).- Parameters:
previouslyCreatedObject
- an object that was returned by an equal descriptor in a previous call to createResource(...).- Since:
- 3.1
-