KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > callhierarchy > CallHierarchyImageDescriptor


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * Jesper Kamstrup Linnet (eclipse@kamstrup-linnet.dk) - initial API and implementation
10  * (report 36180: Callers/Callees view)
11  *******************************************************************************/

12 package org.eclipse.jdt.internal.ui.callhierarchy;
13
14 import org.eclipse.core.runtime.Assert;
15
16 import org.eclipse.swt.graphics.ImageData;
17 import org.eclipse.swt.graphics.Point;
18
19 import org.eclipse.jface.resource.CompositeImageDescriptor;
20 import org.eclipse.jface.resource.ImageDescriptor;
21
22 import org.eclipse.jdt.internal.ui.JavaPlugin;
23 import org.eclipse.jdt.internal.ui.JavaPluginImages;
24
25
26 public class CallHierarchyImageDescriptor extends CompositeImageDescriptor {
27     
28     /** Flag to render the recursive adornment */
29     public final static int RECURSIVE= 0x001;
30     
31     /** Flag to render the callee adornment */
32     public final static int MAX_LEVEL= 0x002;
33
34     private ImageDescriptor fBaseImage;
35     private int fFlags;
36     private Point fSize;
37
38     /**
39      * Creates a new CallHierarchyImageDescriptor.
40      *
41      * @param baseImage an image descriptor used as the base image
42      * @param flags flags indicating which adornments are to be rendered. See <code>setAdornments</code>
43      * for valid values.
44      * @param size the size of the resulting image
45      * @see #setAdornments(int)
46      */

47     public CallHierarchyImageDescriptor(ImageDescriptor baseImage, int flags, Point size) {
48         fBaseImage= baseImage;
49         Assert.isNotNull(fBaseImage);
50         fFlags= flags;
51         Assert.isTrue(fFlags >= 0);
52         fSize= size;
53         Assert.isNotNull(fSize);
54     }
55     
56     /**
57      * Sets the descriptors adornments. Valid values are: <code>RECURSIVE</code>, <code>CALLER</code>,
58      * <code>CALLEE</code>, <code>MAX_LEVEL</code>, or any combination of those.
59      *
60      * @param adornments the image descritpors adornments
61      */

62     public void setAdornments(int adornments) {
63         Assert.isTrue(adornments >= 0);
64         fFlags= adornments;
65     }
66
67     /**
68      * Returns the current adornments.
69      *
70      * @return the current adornments
71      */

72     public int getAdronments() {
73         return fFlags;
74     }
75
76     /**
77      * Sets the size of the image created by calling <code>createImage()</code>.
78      *
79      * @param size the size of the image returned from calling <code>createImage()</code>
80      * @see ImageDescriptor#createImage()
81      */

82     public void setImageSize(Point size) {
83         Assert.isNotNull(size);
84         Assert.isTrue(size.x >= 0 && size.y >= 0);
85         fSize= size;
86     }
87     
88     /**
89      * Returns the size of the image created by calling <code>createImage()</code>.
90      *
91      * @return the size of the image created by calling <code>createImage()</code>
92      * @see ImageDescriptor#createImage()
93      */

94     public Point getImageSize() {
95         return new Point(fSize.x, fSize.y);
96     }
97     
98     /* (non-Javadoc)
99      * Method declared in CompositeImageDescriptor
100      */

101     protected Point getSize() {
102         return fSize;
103     }
104     
105     /* (non-Javadoc)
106      * Method declared on Object.
107      */

108     public boolean equals(Object JavaDoc object) {
109         if (object == null || !CallHierarchyImageDescriptor.class.equals(object.getClass()))
110             return false;
111             
112         CallHierarchyImageDescriptor other= (CallHierarchyImageDescriptor)object;
113         return (fBaseImage.equals(other.fBaseImage) && fFlags == other.fFlags && fSize.equals(other.fSize));
114     }
115     
116     /* (non-Javadoc)
117      * Method declared on Object.
118      */

119     public int hashCode() {
120         return fBaseImage.hashCode() | fFlags | fSize.hashCode();
121     }
122     
123     /* (non-Javadoc)
124      * Method declared in CompositeImageDescriptor
125      */

126     protected void drawCompositeImage(int width, int height) {
127         ImageData bg= getImageData(fBaseImage);
128             
129         drawImage(bg, 0, 0);
130         drawBottomLeft();
131     }
132     
133     private ImageData getImageData(ImageDescriptor descriptor) {
134         ImageData data= descriptor.getImageData(); // see bug 51965: getImageData can return null
135
if (data == null) {
136             data= DEFAULT_IMAGE_DATA;
137             JavaPlugin.logErrorMessage("Image data not available: " + descriptor.toString()); //$NON-NLS-1$
138
}
139         return data;
140     }
141     
142     private void drawBottomLeft() {
143         Point size= getSize();
144         int x= 0;
145         ImageData data= null;
146         if ((fFlags & RECURSIVE) != 0) {
147             data= getImageData(JavaPluginImages.DESC_OVR_RECURSIVE);
148             drawImage(data, x, size.y - data.height);
149             x+= data.width;
150         }
151         if ((fFlags & MAX_LEVEL) != 0) {
152             data= getImageData(JavaPluginImages.DESC_OVR_MAX_LEVEL);
153             drawImage(data, x, size.y - data.height);
154             x+= data.width;
155         }
156     }
157 }
158
Popular Tags