KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > resource > DeviceResourceManager


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jface.resource;
12
13 import org.eclipse.swt.graphics.Device;
14 import org.eclipse.swt.graphics.Image;
15
16 /**
17  * Manages SWT resources for a particular device.
18  *
19  * <p>
20  * IMPORTANT: in most cases clients should use a <code>LocalResourceManager</code> instead of a
21  * <code>DeviceResourceManager</code>. To create a resource manager on a particular display,
22  * use <code>new LocalResourceManager(JFaceResources.getResources(myDisplay))</code>.
23  * <code>DeviceResourceManager</code> should only be used directly when managing
24  * resources for a device other than a Display (such as a printer).
25  * </p>
26  *
27  * @see LocalResourceManager
28  *
29  * @since 3.1
30  */

31 public final class DeviceResourceManager extends 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 JavaDoc allocate(DeviceResourceDescriptor descriptor) throws DeviceResourceException {
56         return descriptor.createResource(device);
57     }
58
59     /* (non-Javadoc)
60      * @see org.eclipse.jface.resource.AbstractResourceManager#deallocate(java.lang.Object, org.eclipse.jface.resource.DeviceResourceDescriptor)
61      */

62     protected void deallocate(Object JavaDoc resource, DeviceResourceDescriptor descriptor) {
63         descriptor.destroyResource(resource);
64     }
65     
66     /* (non-Javadoc)
67      * @see org.eclipse.jface.resource.ResourceManager#getDefaultImage()
68      */

69     protected Image getDefaultImage() {
70         if (missingImage == null) {
71             missingImage = ImageDescriptor.getMissingImageDescriptor().createImage();
72         }
73         return missingImage;
74     }
75     
76     /* (non-Javadoc)
77      * @see org.eclipse.jface.resource.AbstractResourceManager#dispose()
78      */

79     public void dispose() {
80         super.dispose();
81         if (missingImage != null) {
82             missingImage.dispose();
83             missingImage = null;
84         }
85     }
86 }
87
Popular Tags