KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > internal > ui > refactoring > ChangeElementLabelProvider


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  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ltk.internal.ui.refactoring;
12
13 import java.util.HashMap JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.swt.graphics.Font;
18 import org.eclipse.swt.graphics.Image;
19
20 import org.eclipse.jface.resource.ImageDescriptor;
21 import org.eclipse.jface.resource.JFaceResources;
22 import org.eclipse.jface.viewers.IFontProvider;
23 import org.eclipse.jface.viewers.LabelProvider;
24
25 class ChangeElementLabelProvider extends LabelProvider implements IFontProvider {
26
27     private Map JavaDoc fDescriptorImageMap= new HashMap JavaDoc();
28
29     public ChangeElementLabelProvider() {
30     }
31         
32     public Image getImage(Object JavaDoc object) {
33         return manageImageDescriptor(((PreviewNode)object).getImageDescriptor());
34     }
35     
36     public String JavaDoc getText(Object JavaDoc object) {
37         String JavaDoc text= ((PreviewNode)object).getText();
38         if (isDerived(object)) {
39             return Messages.format(RefactoringUIMessages.ChangeElementLabelProvider_derived, text);
40         } else {
41             return text;
42         }
43     }
44     
45     public Font getFont(Object JavaDoc element) {
46         if (isDerived(element)) {
47             return JFaceResources.getFontRegistry().getItalic(JFaceResources.DIALOG_FONT);
48         } else {
49             return null;
50         }
51     }
52
53     private boolean isDerived(Object JavaDoc element) {
54         PreviewNode node= (PreviewNode)element;
55         return node.hasDerived();
56     }
57     
58     public void dispose() {
59         for (Iterator JavaDoc iter= fDescriptorImageMap.values().iterator(); iter.hasNext(); ) {
60             Image image= (Image)iter.next();
61             image.dispose();
62         }
63         super.dispose();
64     }
65     
66     private Image manageImageDescriptor(ImageDescriptor descriptor) {
67         Image image= (Image)fDescriptorImageMap.get(descriptor);
68         if (image == null) {
69             image= descriptor.createImage();
70             fDescriptorImageMap.put(descriptor, image);
71         }
72         return image;
73     }
74 }
75
Popular Tags