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 org.eclipse.swt.graphics.ImageData;
15 import org.eclipse.swt.graphics.Point;
17 import org.eclipse.jface.resource.CompositeImageDescriptor;
18 import org.eclipse.jface.resource.ImageDescriptor;
19 import org.eclipse.jface.util.Assert;
21 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
24 * A JavaImageDescriptor consists of a base image and several adornments. The adornments
25 * are computed according to the flags either passed during creation or set via the method
26 * <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;
71 * Creates a new JavaElementImageDescriptor.
73 * @param baseImage an image descriptor used as the base image
74 * @param flags flags indicating which adornments are to be rendered. See <code>setAdornments</code>
76 * @param size the size of the resulting image
77 * @see #setAdornments(int)
79 public JavaElementImageDescriptor(ImageDescriptor baseImage, int flags, Point size) {
80 fBaseImage= baseImage;
81 Assert.isNotNull(fBaseImage);
83 Assert.isTrue(fFlags >= 0);
85 Assert.isNotNull(fSize);
89 * Sets the descriptors adornments. Valid values are: <code>ABSTRACT</code>, <code>FINAL</code>,
90 * <code>SYNCHRONIZED</code>, </code>STATIC<code>, </code>RUNNABLE<code>, </code>WARNING<code>,
91 * </code>ERROR<code>, </code>OVERRIDDES<code>, <code>IMPLEMENTS</code>, <code>CONSTRUCTOR</code>,
92 * or any combination of those.
94 * @param adornments the image descritpors adornments
96 public void setAdornments(int adornments) {
97 Assert.isTrue(adornments >= 0);
102 * Returns the current adornments.
104 * @return the current adornments
106 public int getAdronments() {
111 * Sets the size of the image created by calling <code>createImage()</code>.
113 * @param size the size of the image returned from calling <code>createImage()</code>
114 * @see ImageDescriptor#createImage()
116 public void setImageSize(Point size) {
117 Assert.isNotNull(size);
118 Assert.isTrue(size.x >= 0 && size.y >= 0);
123 * Returns the size of the image created by calling <code>createImage()</code>.
125 * @return the size of the image created by calling <code>createImage()</code>
126 * @see ImageDescriptor#createImage()
128 public Point getImageSize() {
129 return new Point(fSize.x, fSize.y);
133 * Method declared in CompositeImageDescriptor
135 protected Point getSize() {
140 * Method declared on Object.
142 public boolean equals(Object object) {
143 if (object == null || !JavaElementImageDescriptor.class.equals(object.getClass()))
146 JavaElementImageDescriptor other= (JavaElementImageDescriptor)object;
147 return (fBaseImage.equals(other.fBaseImage) && fFlags == other.fFlags && fSize.equals(other.fSize));
151 * Method declared on Object.
153 public int hashCode() {
154 return fBaseImage.hashCode() | fFlags | fSize.hashCode();
158 * Method declared in CompositeImageDescriptor
160 protected void drawCompositeImage(int width, int height) {
162 if ((bg= fBaseImage.getImageData()) == null)
163 bg= DEFAULT_IMAGE_DATA;
171 private void drawTopRight() {
173 ImageData data= null;
174 if ((fFlags & ABSTRACT) != 0) {
175 data= PHPUiImages.DESC_OVR_ABSTRACT.getImageData();
177 drawImage(data, x, 0);
179 if ((fFlags & CONSTRUCTOR) != 0) {
180 data= PHPUiImages.DESC_OVR_CONSTRUCTOR.getImageData();
182 drawImage(data, x, 0);
184 if ((fFlags & FINAL) != 0) {
185 data= PHPUiImages.DESC_OVR_FINAL.getImageData();
187 drawImage(data, x, 0);
189 if ((fFlags & STATIC) != 0) {
190 data= PHPUiImages.DESC_OVR_STATIC.getImageData();
192 drawImage(data, x, 0);
196 private void drawBottomRight() {
197 Point size= getSize();
199 ImageData data= null;
200 if ((fFlags & OVERRIDES) != 0) {
201 data= PHPUiImages.DESC_OVR_OVERRIDES.getImageData();
203 drawImage(data, x, size.y - data.height);
205 if ((fFlags & IMPLEMENTS) != 0) {
206 data= PHPUiImages.DESC_OVR_IMPLEMENTS.getImageData();
208 drawImage(data, x, size.y - data.height);
210 if ((fFlags & SYNCHRONIZED) != 0) {
211 data= PHPUiImages.DESC_OVR_SYNCH.getImageData();
213 drawImage(data, x, size.y - data.height);
215 if ((fFlags & RUNNABLE) != 0) {
216 data= PHPUiImages.DESC_OVR_RUN.getImageData();
218 drawImage(data, x, size.y - data.height);
222 private void drawBottomLeft() {
223 Point size= getSize();
225 ImageData data= null;
226 if ((fFlags & ERROR) != 0) {
227 data= PHPUiImages.DESC_OVR_ERROR.getImageData();
228 drawImage(data, x, size.y - data.height);
231 if ((fFlags & WARNING) != 0) {
232 data= PHPUiImages.DESC_OVR_WARNING.getImageData();
233 drawImage(data, x, size.y - data.height);