Mercurial > projects > dwt-addons
annotate dwtx/jface/viewers/DecorationOverlayIcon.d @ 192:c3583c6ec027
Added missing default cases for switch statements
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 03 Nov 2008 22:52:26 +0100 |
parents | 46a6e0e6ccd4 |
children |
rev | line source |
---|---|
10 | 1 /******************************************************************************* |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
2 * Copyright (c) 2006, 2008 IBM Corporation and others. |
10 | 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.viewers.DecorationOverlayIcon; | |
14 | |
15 import dwtx.jface.viewers.IDecoration; | |
16 import dwtx.jface.util.Util; | |
17 | |
18 // import tango.util.Arrays; | |
19 | |
20 import dwt.graphics.Image; | |
21 import dwt.graphics.ImageData; | |
22 import dwt.graphics.Point; | |
23 import dwtx.jface.resource.CompositeImageDescriptor; | |
24 import dwtx.jface.resource.ImageDescriptor; | |
25 | |
26 import dwt.dwthelper.utils; | |
27 | |
28 /** | |
29 * A <code>DecorationOverlayIcon</code> is an image descriptor that can be used | |
30 * to overlay decoration images on to the 4 corner quadrants of a base image. | |
31 * The four quadrants are {@link IDecoration#TOP_LEFT}, {@link IDecoration#TOP_RIGHT}, | |
32 * {@link IDecoration#BOTTOM_LEFT} and {@link IDecoration#BOTTOM_RIGHT}. Additionally, | |
33 * the overlay can be used to provide an underlay corresponding to {@link IDecoration#UNDERLAY}. | |
34 * | |
35 * @since 3.3 | |
36 * @see IDecoration | |
37 */ | |
38 public class DecorationOverlayIcon : CompositeImageDescriptor { | |
39 | |
40 // the base image | |
41 private Image base; | |
42 | |
43 // the overlay images | |
44 private ImageDescriptor[] overlays; | |
45 | |
46 // the size | |
47 private Point size; | |
48 | |
49 /** | |
50 * Create the decoration overlay for the base image using the array of | |
51 * provided overlays. The indices of the array correspond to the values | |
52 * of the 5 overlay constants defined on {@link IDecoration} | |
53 * ({@link IDecoration#TOP_LEFT}, {@link IDecoration#TOP_RIGHT}, | |
54 * {@link IDecoration#BOTTOM_LEFT}, {@link IDecoration#BOTTOM_RIGHT} | |
55 * and{@link IDecoration#UNDERLAY}). | |
56 * | |
57 * @param baseImage the base image | |
58 * @param overlaysArray the overlay images | |
59 * @param sizeValue the size of the resulting image | |
60 */ | |
61 public this(Image baseImage, | |
62 ImageDescriptor[] overlaysArray, Point sizeValue) { | |
63 this.base = baseImage; | |
64 this.overlays = overlaysArray; | |
65 this.size = sizeValue; | |
66 } | |
67 | |
68 /** | |
69 * Create the decoration overlay for the base image using the array of | |
70 * provided overlays. The indices of the array correspond to the values | |
71 * of the 5 overlay constants defined on {@link IDecoration} | |
72 * ({@link IDecoration#TOP_LEFT}, {@link IDecoration#TOP_RIGHT}, | |
73 * {@link IDecoration#BOTTOM_LEFT}, {@link IDecoration#BOTTOM_RIGHT} | |
74 * and {@link IDecoration#UNDERLAY}). | |
75 * | |
76 * @param baseImage the base image | |
77 * @param overlaysArray the overlay images | |
78 */ | |
79 public this(Image baseImage, ImageDescriptor[] overlaysArray) { | |
80 this(baseImage, overlaysArray, new Point(baseImage.getBounds().width, baseImage.getBounds().height)); | |
81 } | |
82 | |
83 /** | |
84 * Create a decoration overlay icon that will place the given overlay icon in | |
85 * the given quadrant of the base image. | |
86 * @param baseImage the base image | |
87 * @param overlayImage the overlay image | |
88 * @param quadrant the quadrant (one of {@link IDecoration} | |
89 * ({@link IDecoration#TOP_LEFT}, {@link IDecoration#TOP_RIGHT}, | |
90 * {@link IDecoration#BOTTOM_LEFT}, {@link IDecoration#BOTTOM_RIGHT} | |
91 * or {@link IDecoration#UNDERLAY}) | |
92 */ | |
93 public this(Image baseImage, ImageDescriptor overlayImage, int quadrant) { | |
94 this(baseImage, createArrayFrom(overlayImage, quadrant)); | |
95 } | |
96 | |
97 /** | |
98 * Convert the given image and quadrant into the proper input array. | |
99 * @param overlayImage the overlay image | |
100 * @param quadrant the quadrant | |
101 * @return an array with the given image in the proper quadrant | |
102 */ | |
103 private static ImageDescriptor[] createArrayFrom( | |
104 ImageDescriptor overlayImage, int quadrant) { | |
105 ImageDescriptor[] descs = [ cast(ImageDescriptor) null, null, null, null, null ]; | |
106 descs[quadrant] = overlayImage; | |
107 return descs; | |
108 } | |
109 | |
110 /** | |
111 * Draw the overlays for the receiver. | |
112 * @param overlaysArray | |
113 */ | |
114 private void drawOverlays(ImageDescriptor[] overlaysArray) { | |
115 | |
116 for (int i = 0; i < overlays.length; i++) { | |
117 ImageDescriptor overlay = overlaysArray[i]; | |
118 if (overlay is null) { | |
119 continue; | |
120 } | |
121 ImageData overlayData = overlay.getImageData(); | |
122 //Use the missing descriptor if it is not there. | |
123 if (overlayData is null) { | |
124 overlayData = ImageDescriptor.getMissingImageDescriptor() | |
125 .getImageData(); | |
126 } | |
127 switch (i) { | |
128 case IDecoration.TOP_LEFT: | |
129 drawImage(overlayData, 0, 0); | |
130 break; | |
131 case IDecoration.TOP_RIGHT: | |
132 drawImage(overlayData, size.x - overlayData.width, 0); | |
133 break; | |
134 case IDecoration.BOTTOM_LEFT: | |
135 drawImage(overlayData, 0, size.y - overlayData.height); | |
136 break; | |
137 case IDecoration.BOTTOM_RIGHT: | |
138 drawImage(overlayData, size.x - overlayData.width, size.y | |
139 - overlayData.height); | |
140 break; | |
192
c3583c6ec027
Added missing default cases for switch statements
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
141 default: |
10 | 142 } |
143 } | |
144 } | |
145 | |
146 /* (non-Javadoc) | |
147 * @see java.lang.Object#equals(java.lang.Object) | |
148 */ | |
149 public override int opEquals(Object o) { | |
150 if (!( cast(DecorationOverlayIcon)o )) { | |
151 return false; | |
152 } | |
153 DecorationOverlayIcon other = cast(DecorationOverlayIcon) o; | |
154 return base.opEquals(other.base) | |
155 && Util.opEquals(overlays, other.overlays); | |
156 } | |
157 | |
158 /* (non-Javadoc) | |
159 * @see java.lang.Object#hashCode() | |
160 */ | |
161 public override hash_t toHash() { | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
162 int code = System.identityHashCode(base); |
10 | 163 for (int i = 0; i < overlays.length; i++) { |
164 if (overlays[i] !is null) { | |
165 code ^= overlays[i].toHash(); | |
166 } | |
167 } | |
168 return code; | |
169 } | |
170 | |
171 /* (non-Javadoc) | |
172 * @see dwtx.jface.resource.CompositeImageDescriptor#drawCompositeImage(int, int) | |
173 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
174 protected override void drawCompositeImage(int width, int height) { |
10 | 175 if (overlays.length > IDecoration.UNDERLAY) { |
176 ImageDescriptor underlay = overlays[IDecoration.UNDERLAY]; | |
177 if (underlay !is null) { | |
178 drawImage(underlay.getImageData(), 0, 0); | |
179 } | |
180 } | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
181 if (overlays.length > IDecoration.REPLACE && overlays[IDecoration.REPLACE] !is null) { |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
182 drawImage(overlays[IDecoration.REPLACE].getImageData(), 0, 0); |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
183 } else { |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
184 drawImage(base.getImageData(), 0, 0); |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
185 } |
10 | 186 drawOverlays(overlays); |
187 } | |
188 | |
189 /* (non-Javadoc) | |
190 * @see dwtx.jface.resource.CompositeImageDescriptor#getSize() | |
191 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
192 protected override Point getSize() { |
10 | 193 return size; |
194 } | |
195 | |
196 /* (non-Javadoc) | |
197 * @see dwtx.jface.resource.CompositeImageDescriptor#getTransparentPixel() | |
198 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
199 protected override int getTransparentPixel() { |
10 | 200 return base.getImageData().transparentPixel; |
201 } | |
202 | |
203 } |