Class DeviceResourceManager
IMPORTANT: in most cases clients should use a LocalResourceManager instead of a
DeviceResourceManager. To create a resource manager on a particular display,
use new LocalResourceManager(JFaceResources.getResources(myDisplay)).
DeviceResourceManager should only be used directly when managing
resources for a device other than a Display (such as a printer).
- Since:
- 3.1
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDeviceResourceManager(Device device) Creates a new registry for the given device. -
Method Summary
Modifier and TypeMethodDescriptionprotected <R> Rallocate(DeviceResourceDescriptor<R> descriptor) Called the first time a resource is requested.final <R> Rcreate(DeviceResourceDescriptor<R> descriptor) Returns the resource described by the given descriptor.protected <R> voiddeallocate(Object resource, DeviceResourceDescriptor<R> descriptor) Called the last time a resource is dereferenced.final <R> voiddestroy(DeviceResourceDescriptor<R> descriptor) Deallocates a resource previously allocated byResourceManager.create(DeviceResourceDescriptor).voiddispose()Deallocates any resources allocated by this registry that have not yet been deallocated.<R> Rfind(DeviceResourceDescriptor<R> descriptor) Returns a previously allocated resource associated with the given descriptor, or null if none exists yet.protected ImageReturns the default image that will be returned in the event that the intended image is missing.Returns the Device for which this ResourceManager will create resourcesMethods inherited from class org.eclipse.jface.resource.ResourceManager
cancelDisposeExec, createColor, createColor, createFont, createImage, createImageWithDefault, destroyColor, destroyColor, destroyFont, destroyImage, disposeExec, get
-
Constructor Details
-
DeviceResourceManager
Creates a new registry for the given device.- Parameters:
device- device to manage
-
-
Method Details
-
getDevice
Description copied from class:ResourceManagerReturns the Device for which this ResourceManager will create resources- Specified by:
getDevicein classResourceManager- Returns:
- the Device associated with this ResourceManager
-
allocate
Called the first time a resource is requested. Should allocate and return a resource of the correct type.- Parameters:
descriptor- identifier for the resource to allocate- Returns:
- the newly allocated resource
- Throws:
DeviceResourceException- Thrown when allocation of an SWT device resource fails
-
deallocate
Called the last time a resource is dereferenced. Should release any resources reserved by allocate(...).- Parameters:
resource- resource being deallocateddescriptor- identifier for the resource
-
getDefaultImage
Description copied from class:ResourceManagerReturns the default image that will be returned in the event that the intended image is missing.- Specified by:
getDefaultImagein classResourceManager- Returns:
- a default image that will be returned in the event that the intended image is missing.
-
dispose
public void dispose()Deallocates any resources allocated by this registry that have not yet been deallocated. -
create
Description copied from class:ResourceManagerReturns the resource described by the given descriptor. If the resource already exists, the reference count is incremented and the exiting resource is returned. Otherwise, a new resource is allocated. Every call to this method should have a corresponding call toResourceManager.destroy(DeviceResourceDescriptor).If the resource is intended to live for entire lifetime of this resource-manager, a subsequent call to
ResourceManager.destroy(DeviceResourceDescriptor)may be omitted and the resource will be cleaned up when this resource-manager is disposed. This pattern is useful for short-livedLocalResourceManagers, but should never be used with the global resource-manager since doing so effectively leaks the resource.The resources returned from this method are reference counted and may be shared internally with other resource-managers. They should never be disposed outside of the ResourceManager framework, or it will cause exceptions in other code that shares them. For example, never call
Resource.dispose()on anything returned from this method.- Specified by:
createin classResourceManager- Parameters:
descriptor- descriptor for the resource to allocate- Returns:
- the newly allocated resource (not null)
- Throws:
DeviceResourceException- if unable to allocate the resource
-
destroy
Description copied from class:ResourceManagerDeallocates a resource previously allocated byResourceManager.create(DeviceResourceDescriptor). Descriptors are compared by equality, not identity. If the same resource was created multiple times, this may decrement a reference count rather than disposing the actual resource.- Specified by:
destroyin classResourceManager- Parameters:
descriptor- identifier for the resource
-
find
Description copied from class:ResourceManagerReturns a previously allocated resource associated with the given descriptor, or null if none exists yet.- Specified by:
findin classResourceManager- Parameters:
descriptor- descriptor to find- Returns:
- a previously allocated resource for the given descriptor or null if none.
-