1 11 package org.eclipse.debug.internal.ui.views.launch; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 import org.eclipse.debug.internal.ui.DelegatingModelPresentation; 17 import org.eclipse.debug.ui.IDebugModelPresentation; 18 import org.eclipse.jface.resource.ImageDescriptor; 19 import org.eclipse.jface.viewers.IColorProvider; 20 import org.eclipse.jface.viewers.IFontProvider; 21 import org.eclipse.swt.graphics.Color; 22 import org.eclipse.swt.graphics.Font; 23 import org.eclipse.swt.graphics.FontData; 24 import org.eclipse.swt.graphics.Image; 25 import org.eclipse.swt.graphics.RGB; 26 27 33 public class DebugElementHelper { 34 35 private static DelegatingModelPresentation fgPresenetation; 37 38 private static Map fgImages = new HashMap (); 40 41 44 public static void dispose() { 45 fgImages.clear(); 46 if (fgPresenetation != null) { 47 fgPresenetation.dispose(); 48 fgPresenetation = null; 49 } 50 } 51 52 53 public static boolean isInitialized(Object object) { 54 DelegatingModelPresentation presentation = getPresentation(); 55 return presentation.isInitialized(object); 56 } 57 58 63 public static ImageDescriptor getImageDescriptor(Object object) { 64 Image image = getPresentation().getImage(object); 65 return getImageDescriptor(image); 66 } 67 68 75 public static ImageDescriptor getImageDescriptor(Object object, IDebugModelPresentation presentation) { 76 Image image = presentation.getImage(object); 77 return getImageDescriptor(image); 78 } 79 80 public static ImageDescriptor getImageDescriptor(Image image) 81 { 82 if (image != null) { 83 ImageDescriptor descriptor = (ImageDescriptor) fgImages.get(image); 84 if (descriptor == null) { 85 descriptor = new ImageImageDescriptor(image); 86 fgImages.put(image, descriptor); 87 } 88 return descriptor; 89 } 90 return null; 91 } 92 93 98 public static String getLabel(Object o) { 99 return getPresentation().getText(o); 100 } 101 102 107 public static DelegatingModelPresentation getPresentation() { 108 if (fgPresenetation == null) { 109 fgPresenetation = new DelegatingModelPresentation(); 110 } 111 return fgPresenetation; 112 } 113 114 122 public static RGB getForeground(Object element) { 123 Color color = getPresentation().getForeground(element); 124 if (color != null) { 125 return color.getRGB(); 126 } 127 return null; 128 } 129 130 140 public static RGB getForeground(Object element, IDebugModelPresentation presentation) { 141 Color color = null; 142 if (presentation instanceof IColorProvider) { 143 IColorProvider colorProvider = (IColorProvider) presentation; 144 color = colorProvider.getForeground(element); 145 } else { 146 color = getPresentation().getForeground(element); 147 } 148 if (color != null) { 149 return color.getRGB(); 150 } 151 return null; 152 } 153 154 162 public static RGB getBackground(Object element) { 163 Color color = getPresentation().getBackground(element); 164 if (color != null) { 165 return color.getRGB(); 166 } 167 return null; 168 } 169 170 180 public static RGB getBackground(Object element, IDebugModelPresentation presentation) { 181 Color color = null; 182 if (presentation instanceof IColorProvider) { 183 IColorProvider colorProvider = (IColorProvider) presentation; 184 color = colorProvider.getBackground(element); 185 } else { 186 color = getPresentation().getBackground(element); 187 } 188 if (color != null) { 189 return color.getRGB(); 190 } 191 return null; 192 } 193 194 202 public static FontData getFont(Object element) { 203 Font font = getPresentation().getFont(element); 204 if (font != null) { 205 return font.getFontData()[0]; 206 } 207 return null; 208 } 209 210 220 public static FontData getFont(Object element, IDebugModelPresentation presentation) { 221 Font font = null; 222 if (presentation instanceof IFontProvider) { 223 IFontProvider provider = (IFontProvider) presentation; 224 font = provider.getFont(element); 225 } else { 226 font = getPresentation().getFont(element); 227 } 228 if (font != null) { 229 return font.getFontData()[0]; 230 } 231 return null; 232 } 233 } 234 | Popular Tags |