1 11 package org.eclipse.ltk.internal.ui.refactoring; 12 13 import java.util.HashMap ; 14 import java.util.Iterator ; 15 import java.util.Map ; 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 fDescriptorImageMap= new HashMap (); 28 29 public ChangeElementLabelProvider() { 30 } 31 32 public Image getImage(Object object) { 33 return manageImageDescriptor(((PreviewNode)object).getImageDescriptor()); 34 } 35 36 public String getText(Object object) { 37 String 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 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 element) { 54 PreviewNode node= (PreviewNode)element; 55 return node.hasDerived(); 56 } 57 58 public void dispose() { 59 for (Iterator 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 |