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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.ui;
13 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
15 import org.eclipse.jface.resource.CompositeImageDescriptor;
16 import org.eclipse.jface.resource.ImageDescriptor;
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;
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>.
29 * This class may be instantiated; it is not intended to be subclassed.
34 public class JavaElementImageDescriptor extends CompositeImageDescriptor {
36 /** Flag to render the abstract adornment */
37 public final static int ABSTRACT = 0x001;
39 /** Flag to render the final adornment */
40 public final static int FINAL = 0x002;
42 /** Flag to render the synchronized adornment */
43 public final static int SYNCHRONIZED = 0x004;
45 /** Flag to render the static adornment */
46 public final static int STATIC = 0x008;
48 /** Flag to render the runnable adornment */
49 public final static int RUNNABLE = 0x010;
51 /** Flag to render the waring adornment */
52 public final static int WARNING = 0x020;
54 /** Flag to render the error adornment */
55 public final static int ERROR = 0x040;
57 /** Flag to render the 'override' adornment */
58 public final static int OVERRIDES = 0x080;
60 /** Flag to render the 'implements' adornment */
61 public final static int IMPLEMENTS = 0x100;
63 /** Flag to render the 'constructor' adornment */
64 public final static int CONSTRUCTOR = 0x200;
66 private ImageDescriptor fBaseImage;
73 * Creates a new JavaElementImageDescriptor.
76 * an image descriptor used as the base image
78 * flags indicating which adornments are to be rendered. See
79 * <code>setAdornments</code> for valid values.
81 * the size of the resulting image
82 * @see #setAdornments(int)
84 public JavaElementImageDescriptor(ImageDescriptor baseImage, int flags,
86 fBaseImage = baseImage;
87 Assert.isNotNull(fBaseImage);
89 Assert.isTrue(fFlags >= 0);
91 Assert.isNotNull(fSize);
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.
102 * the image descritpors adornments
104 public void setAdornments(int adornments) {
105 Assert.isTrue(adornments >= 0);
110 * Returns the current adornments.
112 * @return the current adornments
114 // public int getAdronments() {
119 * Sets the size of the image created by calling <code>createImage()</code>.
122 * the size of the image returned from calling
123 * <code>createImage()</code>
124 * @see ImageDescriptor#createImage()
126 // public void setImageSize(Point size) {
127 // Assert.isNotNull(size);
128 // Assert.isTrue(size.x >= 0 && size.y >= 0);
133 * Returns the size of the image created by calling
134 * <code>createImage()</code>.
136 * @return the size of the image created by calling
137 * <code>createImage()</code>
138 * @see ImageDescriptor#createImage()
140 public Point getImageSize() {
141 return new Point(fSize.x, fSize.y);
145 * (non-Javadoc) Method declared in CompositeImageDescriptor
147 protected Point getSize() {
152 * (non-Javadoc) Method declared on Object.
154 public boolean equals(Object object) {
156 || !JavaElementImageDescriptor.class.equals(object.getClass()))
159 JavaElementImageDescriptor other = (JavaElementImageDescriptor) object;
160 return (fBaseImage.equals(other.fBaseImage) && fFlags == other.fFlags && fSize
161 .equals(other.fSize));
165 * (non-Javadoc) Method declared on Object.
167 public int hashCode() {
168 return fBaseImage.hashCode() | fFlags | fSize.hashCode();
172 * (non-Javadoc) Method declared in CompositeImageDescriptor
174 protected void drawCompositeImage(int width, int height) {
176 if ((bg = fBaseImage.getImageData()) == null)
177 bg = DEFAULT_IMAGE_DATA;
185 private void drawTopRight() {
187 ImageData data = null;
188 if ((fFlags & ABSTRACT) != 0) {
189 data = PHPUiImages.DESC_OVR_ABSTRACT.getImageData();
191 drawImage(data, x, 0);
193 if ((fFlags & CONSTRUCTOR) != 0) {
194 data = PHPUiImages.DESC_OVR_CONSTRUCTOR.getImageData();
196 drawImage(data, x, 0);
198 if ((fFlags & FINAL) != 0) {
199 data = PHPUiImages.DESC_OVR_FINAL.getImageData();
201 drawImage(data, x, 0);
203 if ((fFlags & STATIC) != 0) {
204 data = PHPUiImages.DESC_OVR_STATIC.getImageData();
206 drawImage(data, x, 0);
210 private void drawBottomRight() {
211 Point size = getSize();
213 ImageData data = null;
214 if ((fFlags & OVERRIDES) != 0) {
215 data = PHPUiImages.DESC_OVR_OVERRIDES.getImageData();
217 drawImage(data, x, size.y - data.height);
219 if ((fFlags & IMPLEMENTS) != 0) {
220 data = PHPUiImages.DESC_OVR_IMPLEMENTS.getImageData();
222 drawImage(data, x, size.y - data.height);
224 if ((fFlags & SYNCHRONIZED) != 0) {
225 data = PHPUiImages.DESC_OVR_SYNCH.getImageData();
227 drawImage(data, x, size.y - data.height);
229 if ((fFlags & RUNNABLE) != 0) {
230 data = PHPUiImages.DESC_OVR_RUN.getImageData();
232 drawImage(data, x, size.y - data.height);
236 private void drawBottomLeft() {
237 Point size = getSize();
239 ImageData data = null;
240 if ((fFlags & ERROR) != 0) {
241 data = PHPUiImages.DESC_OVR_ERROR.getImageData();
242 drawImage(data, x, size.y - data.height);
245 if ((fFlags & WARNING) != 0) {
246 data = PHPUiImages.DESC_OVR_WARNING.getImageData();
247 drawImage(data, x, size.y - data.height);