A nested registry can be used to manage the resources for, say, a dialog box.
Constructor SummaryConstructorDescriptionCreates a local registry that delegates to the given global registry for all resource allocation and deallocation.Creates a local registry that wraps the given global registry.
Method SummaryModifier and TypeMethodDescription
protected ObjectCalled the first time a resource is requested.
final ObjectReturns the resource described by the given descriptor.
protected voidCalled the last time a resource is dereferenced.
final voidDeallocates a resource previously allocated by
dispose()Deallocates any resources allocated by this registry that have not yet been deallocated.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 resources
Methods inherited from class org.eclipse.jface.resource.ResourceManager
cancelDisposeExec, createColor, createColor, createFont, createImage, createImageWithDefault, destroyColor, destroyColor, destroyFont, destroyImage, disposeExec, get
(ResourceManager parentRegistry)Creates a local registry that delegates to the given global registry for all resource allocation and deallocation.
parentRegistry- global registry
LocalResourceManagerCreates a local registry that wraps the given global registry. Anything allocated by this registry will be automatically cleaned up with the given control is disposed. Note that registries created in this way should not be used to allocate any resource that must outlive the given control.
parentRegistry- global registry that handles resource allocation
owner- control whose disposal will trigger cleanup of everything in the registry.
getDevicepublic Device getDevice()Returns the Device for which this ResourceManager will create resources
allocateCalled the first time a resource is requested. Should allocate and return a resource of the correct type.
descriptor- identifier for the resource to allocate
- the newly allocated resource
DeviceResourceException- Thrown when allocation of an SWT device resource fails
deallocateCalled the last time a resource is dereferenced. Should release any resources reserved by allocate(...).
resource- resource being deallocated
descriptor- identifier for the resource
getDefaultImageprotected Image getDefaultImage()Returns the default image that will be returned in the event that the intended image is missing.
createReturns 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 to
If the resource is intended to live for entire lifetime of the resource manager, a subsequent call to
ResourceManager.destroy(DeviceResourceDescriptor)may be omitted and the resource will be cleaned up when the resource manager is disposed. This pattern is useful for short-lived
LocalResourceManagers, 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.
Callers may safely downcast the result to the resource type associated with the descriptor. For example, when given an ImageDescriptor, the return value of this method will always be an Image.
destroypublic final void destroy
(DeviceResourceDescriptor descriptor)Deallocates a resource previously allocated by
ResourceManager.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.
disposepublic void dispose()Deallocates any resources allocated by this registry that have not yet been deallocated.
findReturns a previously allocated resource associated with the given descriptor, or null if none exists yet.