]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-before/ui/org/eclipse/jdt/ui/JavaElementImageDescriptor.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-before / ui / org / eclipse / jdt / ui / JavaElementImageDescriptor.java
CommitLineData
1b2798f6
EK
1/*******************************************************************************
2 * Copyright (c) 2000, 2012 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 *******************************************************************************/
11package org.eclipse.jdt.ui;
12
13
14import org.eclipse.swt.graphics.ImageData;
15import org.eclipse.swt.graphics.Point;
16
17import org.eclipse.core.runtime.Assert;
18
19import org.eclipse.jface.resource.CompositeImageDescriptor;
20import org.eclipse.jface.resource.ImageDescriptor;
21
22import org.eclipse.jdt.internal.ui.JavaPlugin;
23import org.eclipse.jdt.internal.ui.JavaPluginImages;
24
25/**
26 * A {@link JavaElementImageDescriptor} consists of a base image and several adornments. The adornments
27 * are computed according to the flags either passed during creation or set via the method
28 *{@link #setAdornments(int)}.
29 *
30 * <p>
31 * This class may be instantiated; it is not intended to be subclassed.
32 * </p>
33 *
34 * @since 2.0
35 *
36 * @noextend This class is not intended to be subclassed by clients.
37 */
38public class JavaElementImageDescriptor extends CompositeImageDescriptor {
39
40 /** Flag to render the abstract adornment. */
41 public final static int ABSTRACT= 0x001;
42
43 /** Flag to render the final adornment. */
44 public final static int FINAL= 0x002;
45
46 /** Flag to render the synchronized adornment. */
47 public final static int SYNCHRONIZED= 0x004;
48
49 /** Flag to render the static adornment. */
50 public final static int STATIC= 0x008;
51
52 /** Flag to render the runnable adornment. */
53 public final static int RUNNABLE= 0x010;
54
55 /** Flag to render the warning adornment. */
56 public final static int WARNING= 0x020;
57
58 /** Flag to render the error adornment. */
59 public final static int ERROR= 0x040;
60
61 /** Flag to render the 'override' adornment. */
62 public final static int OVERRIDES= 0x080;
63
64 /** Flag to render the 'implements' adornment. */
65 public final static int IMPLEMENTS= 0x100;
66
67 /** Flag to render the 'constructor' adornment. */
68 public final static int CONSTRUCTOR= 0x200;
69
70 /**
71 * Flag to render the 'deprecated' adornment.
72 * @since 3.0
73 */
74 public final static int DEPRECATED= 0x400;
75
76 /**
77 * Flag to render the 'volatile' adornment.
78 * @since 3.3
79 */
80 public final static int VOLATILE= 0x800;
81
82 /**
83 * Flag to render the 'transient' adornment.
84 * @since 3.3
85 */
86 public final static int TRANSIENT= 0x1000;
87
88 /**
89 * Flag to render the build path error adornment.
90 * @since 3.7
91 */
92 public final static int BUILDPATH_ERROR= 0x2000;
93
94 /**
95 * Flag to render the 'native' adornment.
96 * @since 3.7
97 */
98 public final static int NATIVE= 0x4000;
99
100 /**
101 * Flag to render the 'ignore optional compile problems' adornment.
102 * @since 3.8
103 */
104 public final static int IGNORE_OPTIONAL_PROBLEMS= 0x8000;
105
106 private ImageDescriptor fBaseImage;
107 private int fFlags;
108 private Point fSize;
109
110 /**
111 * Creates a new JavaElementImageDescriptor.
112 *
113 * @param baseImage an image descriptor used as the base image
114 * @param flags flags indicating which adornments are to be rendered. See {@link #setAdornments(int)}
115 * for valid values.
116 * @param size the size of the resulting image
117 */
118 public JavaElementImageDescriptor(ImageDescriptor baseImage, int flags, Point size) {
119 fBaseImage= baseImage;
120 Assert.isNotNull(fBaseImage);
121 fFlags= flags;
122 Assert.isTrue(fFlags >= 0);
123 fSize= size;
124 Assert.isNotNull(fSize);
125 }
126
127 /**
128 * Sets the descriptors adornments. Valid values are: {@link #ABSTRACT}, {@link #FINAL},
129 * {@link #SYNCHRONIZED}, {@link #STATIC}, {@link #RUNNABLE}, {@link #WARNING},
130 * {@link #ERROR}, {@link #OVERRIDES}, {@link #IMPLEMENTS}, {@link #CONSTRUCTOR},
131 * {@link #DEPRECATED}, {@link #VOLATILE}, {@link #TRANSIENT}, {@link #BUILDPATH_ERROR},
132 * {@link #NATIVE}, or any combination of those.
133 *
134 * @param adornments the image descriptors adornments
135 */
136 public void setAdornments(int adornments) {
137 Assert.isTrue(adornments >= 0);
138 fFlags= adornments;
139 }
140
141 /**
142 * Returns the current adornments.
143 *
144 * @return the current adornments
145 */
146 public int getAdronments() {
147 return fFlags;
148 }
149
150 /**
151 * Sets the size of the image created by calling {@link #createImage()}.
152 *
153 * @param size the size of the image returned from calling {@link #createImage()}
154 */
155 public void setImageSize(Point size) {
156 Assert.isNotNull(size);
157 Assert.isTrue(size.x >= 0 && size.y >= 0);
158 fSize= size;
159 }
160
161 /**
162 * Returns the size of the image created by calling {@link #createImage()}.
163 *
164 * @return the size of the image created by calling {@link #createImage()}
165 */
166 public Point getImageSize() {
167 return new Point(fSize.x, fSize.y);
168 }
169
170 /* (non-Javadoc)
171 * Method declared in CompositeImageDescriptor
172 */
173 @Override
174 protected Point getSize() {
175 return fSize;
176 }
177
178 /* (non-Javadoc)
179 * Method declared on Object.
180 */
181 @Override
182 public boolean equals(Object object) {
183 if (object == null || !JavaElementImageDescriptor.class.equals(object.getClass()))
184 return false;
185
186 JavaElementImageDescriptor other= (JavaElementImageDescriptor)object;
187 return (fBaseImage.equals(other.fBaseImage) && fFlags == other.fFlags && fSize.equals(other.fSize));
188 }
189
190 /* (non-Javadoc)
191 * Method declared on Object.
192 */
193 @Override
194 public int hashCode() {
195 return fBaseImage.hashCode() | fFlags | fSize.hashCode();
196 }
197
198 /* (non-Javadoc)
199 * Method declared in CompositeImageDescriptor
200 */
201 @Override
202 protected void drawCompositeImage(int width, int height) {
203 ImageData bg= getImageData(fBaseImage);
204
205 if ((fFlags & DEPRECATED) != 0) { // draw *behind* the full image
206 Point size= getSize();
207 ImageData data= getImageData(JavaPluginImages.DESC_OVR_DEPRECATED);
208 drawImage(data, 0, size.y - data.height);
209 }
210 drawImage(bg, 0, 0);
211
212 drawTopRight();
213 drawBottomRight();
214 drawBottomLeft();
215
216
217 }
218
219 private ImageData getImageData(ImageDescriptor descriptor) {
220 ImageData data= descriptor.getImageData(); // see bug 51965: getImageData can return null
221 if (data == null) {
222 data= DEFAULT_IMAGE_DATA;
223 JavaPlugin.logErrorMessage("Image data not available: " + descriptor.toString()); //$NON-NLS-1$
224 }
225 return data;
226 }
227
228 private void addTopRightImage(ImageDescriptor desc, Point pos) {
229 ImageData data= getImageData(desc);
230 int x= pos.x - data.width;
231 if (x >= 0) {
232 drawImage(data, x, pos.y);
233 pos.x= x;
234 }
235 }
236
237 private void addBottomRightImage(ImageDescriptor desc, Point pos) {
238 ImageData data= getImageData(desc);
239 int x= pos.x - data.width;
240 int y= pos.y - data.height;
241 if (x >= 0 && y >= 0) {
242 drawImage(data, x, y);
243 pos.x= x;
244 }
245 }
246
247 private void addBottomLeftImage(ImageDescriptor desc, Point pos) {
248 ImageData data= getImageData(desc);
249 int x= pos.x;
250 int y= pos.y - data.height;
251 if (x + data.width < getSize().x && y >= 0) {
252 drawImage(data, x, y);
253 pos.x= x + data.width;
254 }
255 }
256
257
258 private void drawTopRight() {
259 Point pos= new Point(getSize().x, 0);
260 if ((fFlags & ABSTRACT) != 0) {
261 addTopRightImage(JavaPluginImages.DESC_OVR_ABSTRACT, pos);
262 }
263 if ((fFlags & CONSTRUCTOR) != 0) {
264 addTopRightImage(JavaPluginImages.DESC_OVR_CONSTRUCTOR, pos);
265 }
266 if ((fFlags & FINAL) != 0) {
267 addTopRightImage(JavaPluginImages.DESC_OVR_FINAL, pos);
268 }
269 if ((fFlags & VOLATILE) != 0) {
270 addTopRightImage(JavaPluginImages.DESC_OVR_VOLATILE, pos);
271 }
272 if ((fFlags & STATIC) != 0) {
273 addTopRightImage(JavaPluginImages.DESC_OVR_STATIC, pos);
274 }
275 if ((fFlags & NATIVE) != 0) {
276 addTopRightImage(JavaPluginImages.DESC_OVR_NATIVE, pos);
277 }
278 }
279
280 private void drawBottomRight() {
281 Point size= getSize();
282 Point pos= new Point(size.x, size.y);
283
284 int flags= fFlags;
285
286 int syncAndOver= SYNCHRONIZED | OVERRIDES;
287 int syncAndImpl= SYNCHRONIZED | IMPLEMENTS;
288
289 // methods:
290 if ((flags & syncAndOver) == syncAndOver) { // both flags set: merged overlay image
291 addBottomRightImage(JavaPluginImages.DESC_OVR_SYNCH_AND_OVERRIDES, pos);
292 flags &= ~syncAndOver; // clear to not render again
293 } else if ((flags & syncAndImpl) == syncAndImpl) { // both flags set: merged overlay image
294 addBottomRightImage(JavaPluginImages.DESC_OVR_SYNCH_AND_IMPLEMENTS, pos);
295 flags &= ~syncAndImpl; // clear to not render again
296 }
297 if ((flags & OVERRIDES) != 0) {
298 addBottomRightImage(JavaPluginImages.DESC_OVR_OVERRIDES, pos);
299 }
300 if ((flags & IMPLEMENTS) != 0) {
301 addBottomRightImage(JavaPluginImages.DESC_OVR_IMPLEMENTS, pos);
302 }
303 if ((flags & SYNCHRONIZED) != 0) {
304 addBottomRightImage(JavaPluginImages.DESC_OVR_SYNCH, pos);
305 }
306
307 // types:
308 if ((flags & RUNNABLE) != 0) {
309 addBottomRightImage(JavaPluginImages.DESC_OVR_RUN, pos);
310 }
311
312 // fields:
313 if ((flags & TRANSIENT) != 0) {
314 addBottomRightImage(JavaPluginImages.DESC_OVR_TRANSIENT, pos);
315 }
316 }
317
318 private void drawBottomLeft() {
319 Point pos= new Point(0, getSize().y);
320 if ((fFlags & ERROR) != 0) {
321 addBottomLeftImage(JavaPluginImages.DESC_OVR_ERROR, pos);
322 }
323 if ((fFlags & BUILDPATH_ERROR) != 0) {
324 addBottomLeftImage(JavaPluginImages.DESC_OVR_BUILDPATH_ERROR, pos);
325 }
326 if ((fFlags & WARNING) != 0) {
327 addBottomLeftImage(JavaPluginImages.DESC_OVR_WARNING, pos);
328 }
329 if ((fFlags & IGNORE_OPTIONAL_PROBLEMS) != 0) {
330 addBottomLeftImage(JavaPluginImages.DESC_OVR_IGNORE_OPTIONAL_PROBLEMS, pos);
331 }
332
333 }
334}