1 11 package org.eclipse.jdt.internal.debug.ui.jres; 12 13 import com.ibm.icu.text.MessageFormat; 14 15 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 16 import org.eclipse.jdt.launching.IVMInstall; 17 import org.eclipse.jdt.launching.environments.IExecutionEnvironment; 18 import org.eclipse.jface.resource.JFaceResources; 19 import org.eclipse.jface.viewers.IFontProvider; 20 import org.eclipse.swt.SWT; 21 import org.eclipse.swt.graphics.Font; 22 import org.eclipse.swt.graphics.FontData; 23 import org.eclipse.swt.widgets.Display; 24 25 31 public class JREsEnvironmentLabelProvider extends JREsLabelProvider implements IFontProvider { 32 33 private IExecutionEnvironmentProvider fProvider; 34 private Font fFont = null; 35 36 41 public interface IExecutionEnvironmentProvider { 42 public IExecutionEnvironment getEnvironment(); 43 } 44 45 public JREsEnvironmentLabelProvider(IExecutionEnvironmentProvider provider) { 46 fProvider = provider; 47 } 48 49 50 51 54 public void dispose() { 55 if (fFont != null) { 56 fFont.dispose(); 57 } 58 super.dispose(); 59 } 60 61 62 63 66 public String getText(Object element) { 67 String label = super.getText(element); 68 if (isStrictlyCompatible(element)) { 69 label = MessageFormat.format(JREMessages.JREsEnvironmentLabelProvider_0, new String []{label, JREMessages.JREsEnvironmentLabelProvider_1}); 70 } 71 return label; 72 } 73 74 private boolean isStrictlyCompatible(Object element) { 75 IExecutionEnvironment environment = fProvider.getEnvironment(); 76 if (environment != null && element instanceof IVMInstall) { 77 return environment.isStrictlyCompatible((IVMInstall)element); 78 } 79 return false; 80 } 81 82 83 86 public Font getFont(Object element) { 87 if (isStrictlyCompatible(element)) { 88 if (fFont == null) { 89 Font dialogFont = JFaceResources.getDialogFont(); 90 FontData[] fontData = dialogFont.getFontData(); 91 for (int i = 0; i < fontData.length; i++) { 92 FontData data = fontData[i]; 93 data.setStyle(SWT.BOLD); 94 } 95 Display display = JDIDebugUIPlugin.getActiveWorkbenchShell().getDisplay(); 96 fFont = new Font(display, fontData); 97 } 98 return fFont; 99 } else { 100 return null; 101 } 102 } 103 104 } 105 | Popular Tags |