Mercurial > projects > dwt-addons
annotate dwtx/jface/resource/DerivedImageDescriptor.d @ 43:ea8ff534f622
Fix override and super aliases
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Fri, 11 Apr 2008 01:24:25 +0200 |
parents | c87617952847 |
children |
rev | line source |
---|---|
4 | 1 /******************************************************************************* |
2 * Copyright (c) 2005, 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.DerivedImageDescriptor; | |
14 | |
15 import dwtx.jface.resource.ImageDescriptor; | |
16 import dwtx.jface.resource.DeviceResourceException; | |
17 | |
18 import dwt.DWT; | |
19 import dwt.DWTException; | |
20 import dwt.graphics.Device; | |
21 import dwt.graphics.Image; | |
22 import dwt.graphics.ImageData; | |
23 import dwt.widgets.Display; | |
24 | |
25 import dwt.dwthelper.utils; | |
26 | |
27 /** | |
28 * An image descriptor which creates images based on another ImageDescriptor, but with | |
29 * additional DWT flags. Note that this is only intended for compatibility. | |
30 * | |
31 * @since 3.1 | |
32 */ | |
33 final class DerivedImageDescriptor : ImageDescriptor { | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
34 alias ImageDescriptor.createImage createImage; |
4 | 35 |
36 private ImageDescriptor original; | |
37 private int flags; | |
38 | |
39 /** | |
40 * Create a new image descriptor | |
41 * @param original the original one | |
42 * @param swtFlags flags to be used when image is created {@link Image#Image(Device, Image, int)} | |
43 * @see DWT#IMAGE_COPY | |
44 * @see DWT#IMAGE_DISABLE | |
45 * @see DWT#IMAGE_GRAY | |
46 */ | |
47 public this(ImageDescriptor original, int swtFlags) { | |
48 this.original = original; | |
49 flags = swtFlags; | |
50 } | |
51 | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
52 public override Object createResource(Device device) { |
4 | 53 try { |
54 return internalCreateImage(device); | |
55 } catch (DWTException e) { | |
56 throw new DeviceResourceException(this, e); | |
57 } | |
58 } | |
59 | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
60 public override Image createImage(Device device) { |
4 | 61 return internalCreateImage(device); |
62 } | |
63 | |
64 public override hash_t toHash() { | |
65 return original.toHash() + flags; | |
66 } | |
67 | |
68 public override int opEquals(Object arg0) { | |
69 if ( auto desc = cast(DerivedImageDescriptor)arg0 ) { | |
70 return desc.original is original && flags is desc.flags; | |
71 } | |
72 | |
73 return false; | |
74 } | |
75 | |
76 /** | |
77 * Creates a new Image on the given device. Note that we defined a new | |
78 * method rather than overloading createImage since this needs to be | |
79 * called by getImageData(), and we want to be absolutely certain not | |
80 * to cause infinite recursion if the base class gets refactored. | |
81 * | |
82 * @param device device to create the image on | |
83 * @return a newly allocated Image. Must be disposed by calling image.dispose(). | |
84 */ | |
85 private final Image internalCreateImage(Device device) { | |
86 Image originalImage = original.createImage(device); | |
87 Image result = new Image(device, originalImage, flags); | |
88 original.destroyResource(originalImage); | |
89 return result; | |
90 } | |
91 | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
92 public override ImageData getImageData() { |
4 | 93 Image image = internalCreateImage(Display.getCurrent()); |
94 ImageData result = image.getImageData(); | |
95 image.dispose(); | |
96 return result; | |
97 } | |
98 | |
99 } |