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;
17 import org.eclipse.jface.util.Assert;
18 import org.eclipse.swt.graphics.ImageData;
19 import org.eclipse.swt.graphics.Point;
22 * A JavaImageDescriptor consists of a base image and several adornments. The
23 * adornments are computed according to the flags either passed during creation
24 * or set via the method <code>setAdornments</code>.
27 * This class may be instantiated; it is not intended to be subclassed.
32 public class JavaElementImageDescriptor extends CompositeImageDescriptor {
34 /** Flag to render the abstract adornment */
35 public final static int ABSTRACT = 0x001;
37 /** Flag to render the final adornment */
38 public final static int FINAL = 0x002;
40 /** Flag to render the synchronized adornment */
41 public final static int SYNCHRONIZED = 0x004;
43 /** Flag to render the static adornment */
44 public final static int STATIC = 0x008;
46 /** Flag to render the runnable adornment */
47 public final static int RUNNABLE = 0x010;
49 /** Flag to render the waring adornment */
50 public final static int WARNING = 0x020;
52 /** Flag to render the error adornment */
53 public final static int ERROR = 0x040;
55 /** Flag to render the 'override' adornment */
56 public final static int OVERRIDES = 0x080;
58 /** Flag to render the 'implements' adornment */
59 public final static int IMPLEMENTS = 0x100;
61 /** Flag to render the 'constructor' adornment */
62 public final static int CONSTRUCTOR = 0x200;
64 private ImageDescriptor fBaseImage;
71 * Creates a new JavaElementImageDescriptor.
74 * an image descriptor used as the base image
76 * flags indicating which adornments are to be rendered. See
77 * <code>setAdornments</code> for valid values.
79 * the size of the resulting image
80 * @see #setAdornments(int)
82 public JavaElementImageDescriptor(ImageDescriptor baseImage, int flags,
84 fBaseImage = baseImage;
85 Assert.isNotNull(fBaseImage);
87 Assert.isTrue(fFlags >= 0);
89 Assert.isNotNull(fSize);
93 * Sets the descriptors adornments. Valid values are: <code>ABSTRACT</code>,
94 * <code>FINAL</code>, <code>SYNCHRONIZED</code>, </code>STATIC<code>,
95 * </code>RUNNABLE<code>, </code>WARNING<code>, </code>ERROR<code>,
96 * </code>OVERRIDDES<code>, <code>IMPLEMENTS</code>,
97 * <code>CONSTRUCTOR</code>, or any combination of those.
100 * the image descritpors adornments
102 public void setAdornments(int adornments) {
103 Assert.isTrue(adornments >= 0);
108 * Returns the current adornments.
110 * @return the current adornments
112 public int getAdronments() {
117 * Sets the size of the image created by calling <code>createImage()</code>.
120 * the size of the image returned from calling
121 * <code>createImage()</code>
122 * @see ImageDescriptor#createImage()
124 public void setImageSize(Point size) {
125 Assert.isNotNull(size);
126 Assert.isTrue(size.x >= 0 && size.y >= 0);
131 * Returns the size of the image created by calling
132 * <code>createImage()</code>.
134 * @return the size of the image created by calling
135 * <code>createImage()</code>
136 * @see ImageDescriptor#createImage()
138 public Point getImageSize() {
139 return new Point(fSize.x, fSize.y);
143 * (non-Javadoc) Method declared in CompositeImageDescriptor
145 protected Point getSize() {
150 * (non-Javadoc) Method declared on Object.
152 public boolean equals(Object object) {
154 || !JavaElementImageDescriptor.class.equals(object.getClass()))
157 JavaElementImageDescriptor other = (JavaElementImageDescriptor) object;
158 return (fBaseImage.equals(other.fBaseImage) && fFlags == other.fFlags && fSize
159 .equals(other.fSize));
163 * (non-Javadoc) Method declared on Object.
165 public int hashCode() {
166 return fBaseImage.hashCode() | fFlags | fSize.hashCode();
170 * (non-Javadoc) Method declared in CompositeImageDescriptor
172 protected void drawCompositeImage(int width, int height) {
174 if ((bg = fBaseImage.getImageData()) == null)
175 bg = DEFAULT_IMAGE_DATA;
183 private void drawTopRight() {
185 ImageData data = null;
186 if ((fFlags & ABSTRACT) != 0) {
187 data = PHPUiImages.DESC_OVR_ABSTRACT.getImageData();
189 drawImage(data, x, 0);
191 if ((fFlags & CONSTRUCTOR) != 0) {
192 data = PHPUiImages.DESC_OVR_CONSTRUCTOR.getImageData();
194 drawImage(data, x, 0);
196 if ((fFlags & FINAL) != 0) {
197 data = PHPUiImages.DESC_OVR_FINAL.getImageData();
199 drawImage(data, x, 0);
201 if ((fFlags & STATIC) != 0) {
202 data = PHPUiImages.DESC_OVR_STATIC.getImageData();
204 drawImage(data, x, 0);
208 private void drawBottomRight() {
209 Point size = getSize();
211 ImageData data = null;
212 if ((fFlags & OVERRIDES) != 0) {
213 data = PHPUiImages.DESC_OVR_OVERRIDES.getImageData();
215 drawImage(data, x, size.y - data.height);
217 if ((fFlags & IMPLEMENTS) != 0) {
218 data = PHPUiImages.DESC_OVR_IMPLEMENTS.getImageData();
220 drawImage(data, x, size.y - data.height);
222 if ((fFlags & SYNCHRONIZED) != 0) {
223 data = PHPUiImages.DESC_OVR_SYNCH.getImageData();
225 drawImage(data, x, size.y - data.height);
227 if ((fFlags & RUNNABLE) != 0) {
228 data = PHPUiImages.DESC_OVR_RUN.getImageData();
230 drawImage(data, x, size.y - data.height);
234 private void drawBottomLeft() {
235 Point size = getSize();
237 ImageData data = null;
238 if ((fFlags & ERROR) != 0) {
239 data = PHPUiImages.DESC_OVR_ERROR.getImageData();
240 drawImage(data, x, size.y - data.height);
243 if ((fFlags & WARNING) != 0) {
244 data = PHPUiImages.DESC_OVR_WARNING.getImageData();
245 drawImage(data, x, size.y - data.height);