1 11 package org.eclipse.ui.internal.intro.universal.util; 12 13 import java.net.URL ; 14 15 import org.eclipse.core.runtime.FileLocator; 16 import org.eclipse.core.runtime.IPath; 17 import org.eclipse.core.runtime.Path; 18 import org.eclipse.core.runtime.Platform; 19 import org.eclipse.jface.resource.ImageDescriptor; 20 import org.eclipse.jface.resource.ImageRegistry; 21 import org.eclipse.swt.graphics.Image; 22 import org.eclipse.swt.widgets.Display; 23 import org.eclipse.ui.PlatformUI; 24 import org.eclipse.ui.internal.intro.universal.IUniversalIntroConstants; 25 import org.eclipse.ui.internal.intro.universal.UniversalIntroPlugin; 26 import org.osgi.framework.Bundle; 27 28 31 public final class ImageUtil { 32 33 36 public static final String DEFAULT_ROOT_LINK = "rootLink"; 39 public static final String DEFAULT_SMALL_ROOT_LINK = "rootLinkSmall"; 41 public static final String DEFAULT_FORM_BG = "formBg"; 43 public static final String DEFAULT_LINK = "link"; 45 public static final String BACK = "back"; 48 public static final String HELP_TOPIC = "helpTopic"; 50 public static final String RESTORE_WELCOME = "restoreWelcome"; 53 public static final String INTRO_MODEL_LEAF = "leaf"; 56 public static final String INTRO_MODEL_CONTAINER = "container"; 58 public static final String OPEN_ITNRO_VIEW = "introView"; 60 public static final String CONFIG_EXTENSION = "configExtension"; 62 public static final String ICONS_PATH = "$nl$/icons/"; 65 71 public static ImageDescriptor createImageDescriptor(String imageName) { 72 return createImageDescriptor(Platform 73 .getBundle(IUniversalIntroConstants.PLUGIN_ID), ICONS_PATH + imageName); 74 } 75 76 80 public static ImageDescriptor createImageDescriptor(Bundle bundle, 81 String imageName) { 82 try { 83 URL imageUrl = FileLocator.find(bundle, new Path(imageName), null); 84 if (imageUrl != null) { 85 ImageDescriptor desc = ImageDescriptor.createFromURL(imageUrl); 86 return desc; 87 } 88 } catch (Exception e) { 89 Log.error("could not create Image Descriptor", e); } 92 Log.warning("could not create Image Descriptor for: " + imageName + " in bundle: " + bundle.getSymbolicName()); return ImageDescriptor.getMissingImageDescriptor(); 95 } 96 97 101 public static ImageDescriptor createImageDescriptor(IPath base, 102 String imageName) { 103 try { 104 URL imageUrl = new URL (base.append(imageName).toOSString()); 105 if (imageUrl != null) { 106 ImageDescriptor desc = ImageDescriptor.createFromURL(imageUrl); 107 return desc; 108 } 109 } catch (Exception e) { 110 Log.error("could not create Image Descriptor", e); } 113 Log.warning("could not create Image Descriptor for: " + imageName); return ImageDescriptor.getMissingImageDescriptor(); 115 } 116 117 123 public static Image createImage(String imageName) { 124 try { 125 ImageDescriptor imageDsc = createImageDescriptor(imageName); 126 return imageDsc.createImage(); 127 } catch (Exception e) { 128 Log.error("could not create Image", e); return ImageDescriptor.getMissingImageDescriptor().createImage(); 131 } 132 } 133 134 140 public static Image getImage(String key) { 141 return UniversalIntroPlugin.getDefault().getVolatileImageRegistry() 146 .get(key); 147 } 148 149 public static boolean hasImage(String key) { 150 ImageRegistry registry = UniversalIntroPlugin.getDefault() 151 .getVolatileImageRegistry(); 152 return (registry.getDescriptor(key) != null); 153 } 154 155 162 public static void registerImage(String key, String imageName) { 163 ImageRegistry registry = UniversalIntroPlugin.getDefault() 164 .getVolatileImageRegistry(); 165 if (registry.getDescriptor(key) != null) 166 return; 168 registry.put(key, createImageDescriptor(imageName)); 169 } 170 171 public static void registerImage(String key, Bundle bundle, String imageName) { 172 173 ImageRegistry registry = UniversalIntroPlugin.getDefault() 174 .getVolatileImageRegistry(); 175 if (registry.getDescriptor(key) != null) 176 return; 178 registry.put(key, createImageDescriptor(bundle, imageName)); 179 } 180 181 public static void registerImage(String key, IPath base, String imageName) { 182 ImageRegistry registry = UniversalIntroPlugin.getDefault() 183 .getVolatileImageRegistry(); 184 if (registry.getDescriptor(key) != null) 185 return; 187 registry.put(key, createImageDescriptor(base, imageName)); 188 } 189 190 196 public static boolean isHighContrast() { 197 if (PlatformUI.isWorkbenchRunning()) { 198 Display display = PlatformUI.getWorkbench().getDisplay(); 199 if (Display.getCurrent() == display) { 200 return display.getHighContrast(); 201 } 202 } 203 return false; 204 } 205 } 206 | Popular Tags |