01: /*******************************************************************************
02: * Copyright (c) 2004, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jface.resource;
11:
12: import org.eclipse.swt.graphics.Device;
13: import org.eclipse.swt.graphics.Image;
14:
15: /**
16: * Manages SWT resources for a particular device.
17: *
18: * <p>
19: * IMPORTANT: in most cases clients should use a <code>LocalResourceManager</code> instead of a
20: * <code>DeviceResourceManager</code>. To create a resource manager on a particular display,
21: * use <code>new LocalResourceManager(JFaceResources.getResources(myDisplay))</code>.
22: * <code>DeviceResourceManager</code> should only be used directly when managing
23: * resources for a device other than a Display (such as a printer).
24: * </p>
25: *
26: * @see LocalResourceManager
27: *
28: * @since 3.1
29: */
30: public final class DeviceResourceManager extends
31: AbstractResourceManager {
32:
33: private Device device;
34: private Image missingImage;
35:
36: /* (non-Javadoc)
37: * @see org.eclipse.jface.resource.ResourceManager#getDevice()
38: */
39: public Device getDevice() {
40: return device;
41: }
42:
43: /**
44: * Creates a new registry for the given device.
45: *
46: * @param device device to manage
47: */
48: public DeviceResourceManager(Device device) {
49: this .device = device;
50: }
51:
52: /* (non-Javadoc)
53: * @see org.eclipse.jface.resource.AbstractResourceManager#allocate(org.eclipse.jface.resource.DeviceResourceDescriptor)
54: */
55: protected Object allocate(DeviceResourceDescriptor descriptor)
56: throws DeviceResourceException {
57: return descriptor.createResource(device);
58: }
59:
60: /* (non-Javadoc)
61: * @see org.eclipse.jface.resource.AbstractResourceManager#deallocate(java.lang.Object, org.eclipse.jface.resource.DeviceResourceDescriptor)
62: */
63: protected void deallocate(Object resource,
64: DeviceResourceDescriptor descriptor) {
65: descriptor.destroyResource(resource);
66: }
67:
68: /* (non-Javadoc)
69: * @see org.eclipse.jface.resource.ResourceManager#getDefaultImage()
70: */
71: protected Image getDefaultImage() {
72: if (missingImage == null) {
73: missingImage = ImageDescriptor.getMissingImageDescriptor()
74: .createImage();
75: }
76: return missingImage;
77: }
78:
79: /* (non-Javadoc)
80: * @see org.eclipse.jface.resource.AbstractResourceManager#dispose()
81: */
82: public void dispose() {
83: super.dispose();
84: if (missingImage != null) {
85: missingImage.dispose();
86: missingImage = null;
87: }
88: }
89: }
|