comparison org.eclipse.jface/src/org/eclipse/jface/resource/LocalResourceManager.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.LocalResourceManager;
14
15 import org.eclipse.jface.resource.AbstractResourceManager;
16 import org.eclipse.jface.resource.ResourceManager;
17 import org.eclipse.jface.resource.DeviceResourceDescriptor;
18
19 import org.eclipse.swt.events.DisposeEvent;
20 import org.eclipse.swt.events.DisposeListener;
21 import org.eclipse.swt.graphics.Device;
22 import org.eclipse.swt.graphics.Image;
23 import org.eclipse.swt.widgets.Control;
24
25 import java.lang.all;
26
27 /**
28 * A local registry that shares its resources with some global registry.
29 * LocalResourceManager is typically used to safeguard against leaks. Clients
30 * can use a nested registry to allocate and deallocate resources in the
31 * global registry. Calling dispose() on the nested registry will deallocate
32 * everything allocated for the nested registry without affecting the rest
33 * of the global registry.
34 * <p>
35 * A nested registry can be used to manage the resources for, say, a dialog
36 * box.
37 * </p>
38 * @since 3.1
39 */
40 public final class LocalResourceManager : AbstractResourceManager {
41
42 private ResourceManager parentRegistry;
43
44 /**
45 * Creates a local registry that delegates to the given global registry
46 * for all resource allocation and deallocation.
47 *
48 * @param parentRegistry global registry
49 */
50 public this(ResourceManager parentRegistry) {
51 this.parentRegistry = parentRegistry;
52 }
53
54 /**
55 * Creates a local registry that wraps the given global registry. Anything
56 * allocated by this registry will be automatically cleaned up with the given
57 * control is disposed. Note that registries created in this way should not
58 * be used to allocate any resource that must outlive the given control.
59 *
60 * @param parentRegistry global registry that handles resource allocation
61 * @param owner control whose disposal will trigger cleanup of everything
62 * in the registry.
63 */
64 public this(ResourceManager parentRegistry, Control owner) {
65 this(parentRegistry);
66
67 owner.addDisposeListener(new class DisposeListener {
68 /* (non-Javadoc)
69 * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
70 */
71 public void widgetDisposed(DisposeEvent e) {
72 this.outer.dispose();
73 }
74 });
75 }
76
77 /* (non-Javadoc)
78 * @see org.eclipse.jface.resource.ResourceManager#getDevice()
79 */
80 public override Device getDevice() {
81 return parentRegistry.getDevice();
82 }
83
84 /* (non-Javadoc)
85 * @see org.eclipse.jface.resource.AbstractResourceManager#allocate(org.eclipse.jface.resource.DeviceResourceDescriptor)
86 */
87 protected override Object allocate(DeviceResourceDescriptor descriptor) {
88 return parentRegistry.create(descriptor);
89 }
90
91 /* (non-Javadoc)
92 * @see org.eclipse.jface.resource.AbstractResourceManager#deallocate(java.lang.Object, org.eclipse.jface.resource.DeviceResourceDescriptor)
93 */
94 protected override void deallocate(Object resource,
95 DeviceResourceDescriptor descriptor) {
96
97 parentRegistry.destroy(descriptor);
98 }
99
100 /* (non-Javadoc)
101 * @see org.eclipse.jface.resource.ResourceManager#getDefaultImage()
102 */
103 protected override Image getDefaultImage() {
104 return parentRegistry.getDefaultImage_();
105 }
106 }