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;
14 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
16 import org.eclipse.jface.resource.CompositeImageDescriptor;
17 import org.eclipse.jface.resource.ImageDescriptor;
18 import org.eclipse.jface.util.Assert;
19 import org.eclipse.swt.graphics.ImageData;
20 import org.eclipse.swt.graphics.Point;
23 * A JavaImageDescriptor consists of a base image and several adornments. The adornments
24 * are computed according to the flags either passed during creation or set via the method
25 * <code>setAdornments</code>.
28 * This class may be instantiated; it is not intended to be subclassed.
33 public class JavaElementImageDescriptor extends CompositeImageDescriptor {
35 /** Flag to render the abstract adornment */
36 public final static int ABSTRACT= 0x001;
38 /** Flag to render the final adornment */
39 public final static int FINAL= 0x002;
41 /** Flag to render the synchronized adornment */
42 public final static int SYNCHRONIZED= 0x004;
44 /** Flag to render the static adornment */
45 public final static int STATIC= 0x008;
47 /** Flag to render the runnable adornment */
48 public final static int RUNNABLE= 0x010;
50 /** Flag to render the waring adornment */
51 public final static int WARNING= 0x020;
53 /** Flag to render the error adornment */
54 public final static int ERROR= 0x040;
56 /** Flag to render the 'override' adornment */
57 public final static int OVERRIDES= 0x080;
59 /** Flag to render the 'implements' adornment */
60 public final static int IMPLEMENTS= 0x100;
62 /** Flag to render the 'constructor' adornment */
63 public final static int CONSTRUCTOR= 0x200;
65 private ImageDescriptor fBaseImage;
70 * Creates a new JavaElementImageDescriptor.
72 * @param baseImage an image descriptor used as the base image
73 * @param flags flags indicating which adornments are to be rendered. See <code>setAdornments</code>
75 * @param size the size of the resulting image
76 * @see #setAdornments(int)
78 public JavaElementImageDescriptor(ImageDescriptor baseImage, int flags, Point size) {
79 fBaseImage= baseImage;
80 Assert.isNotNull(fBaseImage);
82 Assert.isTrue(fFlags >= 0);
84 Assert.isNotNull(fSize);
88 * Sets the descriptors adornments. Valid values are: <code>ABSTRACT</code>, <code>FINAL</code>,
89 * <code>SYNCHRONIZED</code>, </code>STATIC<code>, </code>RUNNABLE<code>, </code>WARNING<code>,
90 * </code>ERROR<code>, </code>OVERRIDDES<code>, <code>IMPLEMENTS</code>, <code>CONSTRUCTOR</code>,
91 * or any combination of those.
93 * @param adornments the image descritpors adornments
95 public void setAdornments(int adornments) {
96 Assert.isTrue(adornments >= 0);
101 * Returns the current adornments.
103 * @return the current adornments
105 public int getAdronments() {
110 * Sets the size of the image created by calling <code>createImage()</code>.
112 * @param size the size of the image returned from calling <code>createImage()</code>
113 * @see ImageDescriptor#createImage()
115 public void setImageSize(Point size) {
116 Assert.isNotNull(size);
117 Assert.isTrue(size.x >= 0 && size.y >= 0);
122 * Returns the size of the image created by calling <code>createImage()</code>.
124 * @return the size of the image created by calling <code>createImage()</code>
125 * @see ImageDescriptor#createImage()
127 public Point getImageSize() {
128 return new Point(fSize.x, fSize.y);
132 * Method declared in CompositeImageDescriptor
134 protected Point getSize() {
139 * Method declared on Object.
141 public boolean equals(Object object) {
142 if (object == null || !JavaElementImageDescriptor.class.equals(object.getClass()))
145 JavaElementImageDescriptor other= (JavaElementImageDescriptor)object;
146 return (fBaseImage.equals(other.fBaseImage) && fFlags == other.fFlags && fSize.equals(other.fSize));
150 * Method declared on Object.
152 public int hashCode() {
153 return fBaseImage.hashCode() | fFlags | fSize.hashCode();
157 * Method declared in CompositeImageDescriptor
159 protected void drawCompositeImage(int width, int height) {
161 if ((bg= fBaseImage.getImageData()) == null)
162 bg= DEFAULT_IMAGE_DATA;
170 private void drawTopRight() {
172 ImageData data= null;
173 if ((fFlags & ABSTRACT) != 0) {
174 data= PHPUiImages.DESC_OVR_ABSTRACT.getImageData();
176 drawImage(data, x, 0);
178 if ((fFlags & CONSTRUCTOR) != 0) {
179 data= PHPUiImages.DESC_OVR_CONSTRUCTOR.getImageData();
181 drawImage(data, x, 0);
183 if ((fFlags & FINAL) != 0) {
184 data= PHPUiImages.DESC_OVR_FINAL.getImageData();
186 drawImage(data, x, 0);
188 if ((fFlags & STATIC) != 0) {
189 data= PHPUiImages.DESC_OVR_STATIC.getImageData();
191 drawImage(data, x, 0);
195 private void drawBottomRight() {
196 Point size= getSize();
198 ImageData data= null;
199 if ((fFlags & OVERRIDES) != 0) {
200 data= PHPUiImages.DESC_OVR_OVERRIDES.getImageData();
202 drawImage(data, x, size.y - data.height);
204 if ((fFlags & IMPLEMENTS) != 0) {
205 data= PHPUiImages.DESC_OVR_IMPLEMENTS.getImageData();
207 drawImage(data, x, size.y - data.height);
209 if ((fFlags & SYNCHRONIZED) != 0) {
210 data= PHPUiImages.DESC_OVR_SYNCH.getImageData();
212 drawImage(data, x, size.y - data.height);
214 if ((fFlags & RUNNABLE) != 0) {
215 data= PHPUiImages.DESC_OVR_RUN.getImageData();
217 drawImage(data, x, size.y - data.height);
221 private void drawBottomLeft() {
222 Point size= getSize();
224 ImageData data= null;
225 if ((fFlags & ERROR) != 0) {
226 data= PHPUiImages.DESC_OVR_ERROR.getImageData();
227 drawImage(data, x, size.y - data.height);
230 if ((fFlags & WARNING) != 0) {
231 data= PHPUiImages.DESC_OVR_WARNING.getImageData();
232 drawImage(data, x, size.y - data.height);