001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * Jesper Kamstrup Linnet (eclipse@kamstrup-linnet.dk) - initial API and implementation
010: * (report 36180: Callers/Callees view)
011: *******************************************************************************/package org.eclipse.jdt.internal.ui.callhierarchy;
012:
013: import org.eclipse.core.runtime.Assert;
014:
015: import org.eclipse.swt.graphics.ImageData;
016: import org.eclipse.swt.graphics.Point;
017:
018: import org.eclipse.jface.resource.CompositeImageDescriptor;
019: import org.eclipse.jface.resource.ImageDescriptor;
020:
021: import org.eclipse.jdt.internal.ui.JavaPlugin;
022: import org.eclipse.jdt.internal.ui.JavaPluginImages;
023:
024: public class CallHierarchyImageDescriptor extends
025: CompositeImageDescriptor {
026:
027: /** Flag to render the recursive adornment */
028: public final static int RECURSIVE = 0x001;
029:
030: /** Flag to render the callee adornment */
031: public final static int MAX_LEVEL = 0x002;
032:
033: private ImageDescriptor fBaseImage;
034: private int fFlags;
035: private Point fSize;
036:
037: /**
038: * Creates a new CallHierarchyImageDescriptor.
039: *
040: * @param baseImage an image descriptor used as the base image
041: * @param flags flags indicating which adornments are to be rendered. See <code>setAdornments</code>
042: * for valid values.
043: * @param size the size of the resulting image
044: * @see #setAdornments(int)
045: */
046: public CallHierarchyImageDescriptor(ImageDescriptor baseImage,
047: int flags, Point size) {
048: fBaseImage = baseImage;
049: Assert.isNotNull(fBaseImage);
050: fFlags = flags;
051: Assert.isTrue(fFlags >= 0);
052: fSize = size;
053: Assert.isNotNull(fSize);
054: }
055:
056: /**
057: * Sets the descriptors adornments. Valid values are: <code>RECURSIVE</code>, <code>CALLER</code>,
058: * <code>CALLEE</code>, <code>MAX_LEVEL</code>, or any combination of those.
059: *
060: * @param adornments the image descritpors adornments
061: */
062: public void setAdornments(int adornments) {
063: Assert.isTrue(adornments >= 0);
064: fFlags = adornments;
065: }
066:
067: /**
068: * Returns the current adornments.
069: *
070: * @return the current adornments
071: */
072: public int getAdronments() {
073: return fFlags;
074: }
075:
076: /**
077: * Sets the size of the image created by calling <code>createImage()</code>.
078: *
079: * @param size the size of the image returned from calling <code>createImage()</code>
080: * @see ImageDescriptor#createImage()
081: */
082: public void setImageSize(Point size) {
083: Assert.isNotNull(size);
084: Assert.isTrue(size.x >= 0 && size.y >= 0);
085: fSize = size;
086: }
087:
088: /**
089: * Returns the size of the image created by calling <code>createImage()</code>.
090: *
091: * @return the size of the image created by calling <code>createImage()</code>
092: * @see ImageDescriptor#createImage()
093: */
094: public Point getImageSize() {
095: return new Point(fSize.x, fSize.y);
096: }
097:
098: /* (non-Javadoc)
099: * 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 object) {
109: if (object == null
110: || !CallHierarchyImageDescriptor.class.equals(object
111: .getClass()))
112: return false;
113:
114: CallHierarchyImageDescriptor other = (CallHierarchyImageDescriptor) object;
115: return (fBaseImage.equals(other.fBaseImage)
116: && fFlags == other.fFlags && fSize.equals(other.fSize));
117: }
118:
119: /* (non-Javadoc)
120: * Method declared on Object.
121: */
122: public int hashCode() {
123: return fBaseImage.hashCode() | fFlags | fSize.hashCode();
124: }
125:
126: /* (non-Javadoc)
127: * Method declared in CompositeImageDescriptor
128: */
129: protected void drawCompositeImage(int width, int height) {
130: ImageData bg = getImageData(fBaseImage);
131:
132: drawImage(bg, 0, 0);
133: drawBottomLeft();
134: }
135:
136: private ImageData getImageData(ImageDescriptor descriptor) {
137: ImageData data = descriptor.getImageData(); // see bug 51965: getImageData can return null
138: if (data == null) {
139: data = DEFAULT_IMAGE_DATA;
140: JavaPlugin
141: .logErrorMessage("Image data not available: " + descriptor.toString()); //$NON-NLS-1$
142: }
143: return data;
144: }
145:
146: private void drawBottomLeft() {
147: Point size = getSize();
148: int x = 0;
149: ImageData data = null;
150: if ((fFlags & RECURSIVE) != 0) {
151: data = getImageData(JavaPluginImages.DESC_OVR_RECURSIVE);
152: drawImage(data, x, size.y - data.height);
153: x += data.width;
154: }
155: if ((fFlags & MAX_LEVEL) != 0) {
156: data = getImageData(JavaPluginImages.DESC_OVR_MAX_LEVEL);
157: drawImage(data, x, size.y - data.height);
158: x += data.width;
159: }
160: }
161: }
|