Refactory: remove unused classes, imports, fields and methods.
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpdt / ui / JavaElementImageDescriptor.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.ui;
12
13 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
14
15 import org.eclipse.jface.resource.CompositeImageDescriptor;
16 import org.eclipse.jface.resource.ImageDescriptor;
17 //incastrix
18 //import org.eclipse.jface.text.Assert;
19 import org.eclipse.core.runtime.Assert;
20 import org.eclipse.swt.graphics.ImageData;
21 import org.eclipse.swt.graphics.Point;
22
23 /**
24  * A JavaImageDescriptor consists of a base image and several adornments. The
25  * adornments are computed according to the flags either passed during creation
26  * or set via the method <code>setAdornments</code>.
27  * 
28  * <p>
29  * This class may be instantiated; it is not intended to be subclassed.
30  * </p>
31  * 
32  * @since 2.0
33  */
34 public class JavaElementImageDescriptor extends CompositeImageDescriptor {
35
36         /** Flag to render the abstract adornment */
37         public final static int ABSTRACT = 0x001;
38
39         /** Flag to render the final adornment */
40         public final static int FINAL = 0x002;
41
42         /** Flag to render the synchronized adornment */
43         public final static int SYNCHRONIZED = 0x004;
44
45         /** Flag to render the static adornment */
46         public final static int STATIC = 0x008;
47
48         /** Flag to render the runnable adornment */
49         public final static int RUNNABLE = 0x010;
50
51         /** Flag to render the waring adornment */
52         public final static int WARNING = 0x020;
53
54         /** Flag to render the error adornment */
55         public final static int ERROR = 0x040;
56
57         /** Flag to render the 'override' adornment */
58         public final static int OVERRIDES = 0x080;
59
60         /** Flag to render the 'implements' adornment */
61         public final static int IMPLEMENTS = 0x100;
62
63         /** Flag to render the 'constructor' adornment */
64         public final static int CONSTRUCTOR = 0x200;
65
66         private ImageDescriptor fBaseImage;
67
68         private int fFlags;
69
70         private Point fSize;
71
72         /**
73          * Creates a new JavaElementImageDescriptor.
74          * 
75          * @param baseImage
76          *            an image descriptor used as the base image
77          * @param flags
78          *            flags indicating which adornments are to be rendered. See
79          *            <code>setAdornments</code> for valid values.
80          * @param size
81          *            the size of the resulting image
82          * @see #setAdornments(int)
83          */
84         public JavaElementImageDescriptor(ImageDescriptor baseImage, int flags,
85                         Point size) {
86                 fBaseImage = baseImage;
87                 Assert.isNotNull(fBaseImage);
88                 fFlags = flags;
89                 Assert.isTrue(fFlags >= 0);
90                 fSize = size;
91                 Assert.isNotNull(fSize);
92         }
93
94         /**
95          * Sets the descriptors adornments. Valid values are: <code>ABSTRACT</code>,
96          * <code>FINAL</code>, <code>SYNCHRONIZED</code>, </code>STATIC<code>,
97          * </code>RUNNABLE<code>, </code>WARNING<code>, </code>ERROR<code>,
98          * </code>OVERRIDDES<code>, <code>IMPLEMENTS</code>,
99          * <code>CONSTRUCTOR</code>, or any combination of those.
100          * 
101          * @param adornments
102          *            the image descritpors adornments
103          */
104         public void setAdornments(int adornments) {
105                 Assert.isTrue(adornments >= 0);
106                 fFlags = adornments;
107         }
108
109         /**
110          * Returns the current adornments.
111          * 
112          * @return the current adornments
113          */
114 //      public int getAdronments() {
115 //              return fFlags;
116 //      }
117
118         /**
119          * Sets the size of the image created by calling <code>createImage()</code>.
120          * 
121          * @param size
122          *            the size of the image returned from calling
123          *            <code>createImage()</code>
124          * @see ImageDescriptor#createImage()
125          */
126 //      public void setImageSize(Point size) {
127 //              Assert.isNotNull(size);
128 //              Assert.isTrue(size.x >= 0 && size.y >= 0);
129 //              fSize = size;
130 //      }
131
132         /**
133          * Returns the size of the image created by calling
134          * <code>createImage()</code>.
135          * 
136          * @return the size of the image created by calling
137          *         <code>createImage()</code>
138          * @see ImageDescriptor#createImage()
139          */
140         public Point getImageSize() {
141                 return new Point(fSize.x, fSize.y);
142         }
143
144         /*
145          * (non-Javadoc) Method declared in CompositeImageDescriptor
146          */
147         protected Point getSize() {
148                 return fSize;
149         }
150
151         /*
152          * (non-Javadoc) Method declared on Object.
153          */
154         public boolean equals(Object object) {
155                 if (object == null
156                                 || !JavaElementImageDescriptor.class.equals(object.getClass()))
157                         return false;
158
159                 JavaElementImageDescriptor other = (JavaElementImageDescriptor) object;
160                 return (fBaseImage.equals(other.fBaseImage) && fFlags == other.fFlags && fSize
161                                 .equals(other.fSize));
162         }
163
164         /*
165          * (non-Javadoc) Method declared on Object.
166          */
167         public int hashCode() {
168                 return fBaseImage.hashCode() | fFlags | fSize.hashCode();
169         }
170
171         /*
172          * (non-Javadoc) Method declared in CompositeImageDescriptor
173          */
174         protected void drawCompositeImage(int width, int height) {
175                 ImageData bg;
176                 if ((bg = fBaseImage.getImageData()) == null)
177                         bg = DEFAULT_IMAGE_DATA;
178
179                 drawImage(bg, 0, 0);
180                 drawTopRight();
181                 drawBottomRight();
182                 drawBottomLeft();
183         }
184
185         private void drawTopRight() {
186                 int x = getSize().x;
187                 ImageData data = null;
188                 if ((fFlags & ABSTRACT) != 0) {
189                         data = PHPUiImages.DESC_OVR_ABSTRACT.getImageData();
190                         x -= data.width;
191                         drawImage(data, x, 0);
192                 }
193                 if ((fFlags & CONSTRUCTOR) != 0) {
194                         data = PHPUiImages.DESC_OVR_CONSTRUCTOR.getImageData();
195                         x -= data.width;
196                         drawImage(data, x, 0);
197                 }
198                 if ((fFlags & FINAL) != 0) {
199                         data = PHPUiImages.DESC_OVR_FINAL.getImageData();
200                         x -= data.width;
201                         drawImage(data, x, 0);
202                 }
203                 if ((fFlags & STATIC) != 0) {
204                         data = PHPUiImages.DESC_OVR_STATIC.getImageData();
205                         x -= data.width;
206                         drawImage(data, x, 0);
207                 }
208         }
209
210         private void drawBottomRight() {
211                 Point size = getSize();
212                 int x = size.x;
213                 ImageData data = null;
214                 if ((fFlags & OVERRIDES) != 0) {
215                         data = PHPUiImages.DESC_OVR_OVERRIDES.getImageData();
216                         x -= data.width;
217                         drawImage(data, x, size.y - data.height);
218                 }
219                 if ((fFlags & IMPLEMENTS) != 0) {
220                         data = PHPUiImages.DESC_OVR_IMPLEMENTS.getImageData();
221                         x -= data.width;
222                         drawImage(data, x, size.y - data.height);
223                 }
224                 if ((fFlags & SYNCHRONIZED) != 0) {
225                         data = PHPUiImages.DESC_OVR_SYNCH.getImageData();
226                         x -= data.width;
227                         drawImage(data, x, size.y - data.height);
228                 }
229                 if ((fFlags & RUNNABLE) != 0) {
230                         data = PHPUiImages.DESC_OVR_RUN.getImageData();
231                         x -= data.width;
232                         drawImage(data, x, size.y - data.height);
233                 }
234         }
235
236         private void drawBottomLeft() {
237                 Point size = getSize();
238                 int x = 0;
239                 ImageData data = null;
240                 if ((fFlags & ERROR) != 0) {
241                         data = PHPUiImages.DESC_OVR_ERROR.getImageData();
242                         drawImage(data, x, size.y - data.height);
243                         x += data.width;
244                 }
245                 if ((fFlags & WARNING) != 0) {
246                         data = PHPUiImages.DESC_OVR_WARNING.getImageData();
247                         drawImage(data, x, size.y - data.height);
248                         x += data.width;
249                 }
250         }
251 }