Mercurial > projects > dwt-addons
comparison dwtx/jface/resource/DeviceResourceManager.d @ 9:6c14e54dfc11
completed /jface/resource/
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 29 Mar 2008 02:25:12 +0100 |
parents | |
children | ea8ff534f622 |
comparison
equal
deleted
inserted
replaced
8:a3ff22a98bef | 9:6c14e54dfc11 |
---|---|
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 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.jface.resource.DeviceResourceManager; | |
14 | |
15 import dwtx.jface.resource.AbstractResourceManager; | |
16 import dwtx.jface.resource.DeviceResourceDescriptor; | |
17 import dwtx.jface.resource.ImageDescriptor; | |
18 | |
19 import dwt.graphics.Device; | |
20 import dwt.graphics.Image; | |
21 | |
22 import dwt.dwthelper.utils; | |
23 | |
24 /** | |
25 * Manages DWT resources for a particular device. | |
26 * | |
27 * <p> | |
28 * IMPORTANT: in most cases clients should use a <code>LocalResourceManager</code> instead of a | |
29 * <code>DeviceResourceManager</code>. To create a resource manager on a particular display, | |
30 * use <code>new LocalResourceManager(JFaceResources.getResources(myDisplay))</code>. | |
31 * <code>DeviceResourceManager</code> should only be used directly when managing | |
32 * resources for a device other than a Display (such as a printer). | |
33 * </p> | |
34 * | |
35 * @see LocalResourceManager | |
36 * | |
37 * @since 3.1 | |
38 */ | |
39 public final class DeviceResourceManager : AbstractResourceManager { | |
40 | |
41 private Device device; | |
42 private Image missingImage; | |
43 | |
44 /* (non-Javadoc) | |
45 * @see dwtx.jface.resource.ResourceManager#getDevice() | |
46 */ | |
47 public Device getDevice() { | |
48 return device; | |
49 } | |
50 | |
51 /** | |
52 * Creates a new registry for the given device. | |
53 * | |
54 * @param device device to manage | |
55 */ | |
56 public this(Device device) { | |
57 this.device = device; | |
58 } | |
59 | |
60 /* (non-Javadoc) | |
61 * @see dwtx.jface.resource.AbstractResourceManager#allocate(dwtx.jface.resource.DeviceResourceDescriptor) | |
62 */ | |
63 protected Object allocate(DeviceResourceDescriptor descriptor){ | |
64 return descriptor.createResource(device); | |
65 } | |
66 | |
67 /* (non-Javadoc) | |
68 * @see dwtx.jface.resource.AbstractResourceManager#deallocate(java.lang.Object, dwtx.jface.resource.DeviceResourceDescriptor) | |
69 */ | |
70 protected void deallocate(Object resource, DeviceResourceDescriptor descriptor) { | |
71 descriptor.destroyResource(resource); | |
72 } | |
73 | |
74 /* (non-Javadoc) | |
75 * @see dwtx.jface.resource.ResourceManager#getDefaultImage() | |
76 */ | |
77 protected Image getDefaultImage() { | |
78 if (missingImage is null) { | |
79 missingImage = ImageDescriptor.getMissingImageDescriptor().createImage(); | |
80 } | |
81 return missingImage; | |
82 } | |
83 | |
84 /* (non-Javadoc) | |
85 * @see dwtx.jface.resource.AbstractResourceManager#dispose() | |
86 */ | |
87 public void dispose() { | |
88 super.dispose(); | |
89 if (missingImage !is null) { | |
90 missingImage.dispose(); | |
91 missingImage = null; | |
92 } | |
93 } | |
94 } |