comparison org.eclipse.jface/src/org/eclipse/jface/resource/DeviceResourceManager.d @ 12:bc29606a740c

Added dwt-addons in original directory structure of eclipse.org
author Frank Benoit <benoit@tionex.de>
date Sat, 14 Mar 2009 18:23:29 +0100
parents
children
comparison
equal deleted inserted replaced
11:43904fec5dca 12:bc29606a740c
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 org.eclipse.jface.resource.DeviceResourceManager;
14
15 import org.eclipse.jface.resource.AbstractResourceManager;
16 import org.eclipse.jface.resource.DeviceResourceDescriptor;
17 import org.eclipse.jface.resource.ImageDescriptor;
18
19 import org.eclipse.swt.graphics.Device;
20 import org.eclipse.swt.graphics.Image;
21
22 import java.lang.all;
23
24 /**
25 * Manages SWT 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 org.eclipse.jface.resource.ResourceManager#getDevice()
46 */
47 public override 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 org.eclipse.jface.resource.AbstractResourceManager#allocate(org.eclipse.jface.resource.DeviceResourceDescriptor)
62 */
63 protected override Object allocate(DeviceResourceDescriptor descriptor){
64 return descriptor.createResource(device);
65 }
66
67 /* (non-Javadoc)
68 * @see org.eclipse.jface.resource.AbstractResourceManager#deallocate(java.lang.Object, org.eclipse.jface.resource.DeviceResourceDescriptor)
69 */
70 protected override void deallocate(Object resource, DeviceResourceDescriptor descriptor) {
71 descriptor.destroyResource(resource);
72 }
73
74 /* (non-Javadoc)
75 * @see org.eclipse.jface.resource.ResourceManager#getDefaultImage()
76 */
77 protected override Image getDefaultImage() {
78 if (missingImage is null) {
79 missingImage = ImageDescriptor.getMissingImageDescriptor().createImage();
80 }
81 return missingImage;
82 }
83
84 /* (non-Javadoc)
85 * @see org.eclipse.jface.resource.AbstractResourceManager#dispose()
86 */
87 public override void dispose() {
88 super.dispose();
89 if (missingImage !is null) {
90 missingImage.dispose();
91 missingImage = null;
92 }
93 }
94 }