KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.swt.graphics.Image;
15 import org.eclipse.swt.graphics.Point;
16 import org.eclipse.swt.graphics.Rectangle;
17
18 import org.eclipse.jface.resource.ImageDescriptor;
19 import org.eclipse.jface.viewers.ILabelDecorator;
20 import org.eclipse.jface.viewers.ILabelProviderListener;
21
22 import org.eclipse.jdt.internal.ui.JavaPlugin;
23 import org.eclipse.jdt.internal.ui.viewsupport.ImageImageDescriptor;
24
25 import org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper;
26
27 /**
28  * LabelDecorator that decorates an method's image with recursion overlays.
29  * The viewer using this decorator is responsible for updating the images on element changes.
30  */

31 public class CallHierarchyLabelDecorator implements ILabelDecorator {
32
33     /**
34      * Creates a decorator. The decorator creates an own image registry to cache
35      * images.
36      */

37     public CallHierarchyLabelDecorator() {
38         // Do nothing
39
}
40
41     /* (non-Javadoc)
42      * @see ILabelDecorator#decorateText(String, Object)
43      */

44     public String JavaDoc decorateText(String JavaDoc text, Object JavaDoc element) {
45         return text;
46     }
47
48     /* (non-Javadoc)
49      * @see ILabelDecorator#decorateImage(Image, Object)
50      */

51     public Image decorateImage(Image image, Object JavaDoc element) {
52         int adornmentFlags= computeAdornmentFlags(element);
53         if (adornmentFlags != 0) {
54             ImageDescriptor baseImage= new ImageImageDescriptor(image);
55             Rectangle bounds= image.getBounds();
56             return JavaPlugin.getImageDescriptorRegistry().get(new CallHierarchyImageDescriptor(baseImage, adornmentFlags, new Point(bounds.width, bounds.height)));
57         }
58         return image;
59     }
60     
61     /**
62      * Note: This method is for internal use only. Clients should not call this method.
63      */

64     private int computeAdornmentFlags(Object JavaDoc element) {
65         int flags= 0;
66         if (element instanceof MethodWrapper) {
67             MethodWrapper methodWrapper= (MethodWrapper) element;
68             if (methodWrapper.isRecursive()) {
69                 flags= CallHierarchyImageDescriptor.RECURSIVE;
70             }
71             if (isMaxCallDepthExceeded(methodWrapper)) {
72                 flags|= CallHierarchyImageDescriptor.MAX_LEVEL;
73             }
74         }
75         return flags;
76     }
77
78     private boolean isMaxCallDepthExceeded(MethodWrapper methodWrapper) {
79         return methodWrapper.getLevel() > CallHierarchyUI.getDefault().getMaxCallDepth();
80     }
81     
82     /* (non-Javadoc)
83      * @see IBaseLabelProvider#addListener(ILabelProviderListener)
84      */

85     public void addListener(ILabelProviderListener listener) {
86         // Do nothing
87
}
88
89     /* (non-Javadoc)
90      * @see IBaseLabelProvider#dispose()
91      */

92     public void dispose() {
93         // Nothing to dispose
94
}
95
96     /* (non-Javadoc)
97      * @see IBaseLabelProvider#isLabelProperty(Object, String)
98      */

99     public boolean isLabelProperty(Object JavaDoc element, String JavaDoc property) {
100         return true;
101     }
102
103     /* (non-Javadoc)
104      * @see IBaseLabelProvider#removeListener(ILabelProviderListener)
105      */

106     public void removeListener(ILabelProviderListener listener) {
107         // Do nothing
108
}
109 }
110
Popular Tags