1 11 package org.eclipse.ui.internal.intro.impl.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.ui.internal.intro.impl.IIntroConstants; 23 import org.eclipse.ui.internal.intro.impl.IntroPlugin; 24 import org.osgi.framework.Bundle; 25 26 29 public final class ImageUtil { 30 31 34 public static final String DEFAULT_ROOT_LINK = "rootLink"; public static final String DEFAULT_SMALL_ROOT_LINK = "rootLinkSmall"; public static final String DEFAULT_FORM_BG = "formBg"; public static final String DEFAULT_LINK = "link"; 40 public static final String BACK = "back"; public static final String HELP_TOPIC = "helpTopic"; 44 public static final String RESTORE_WELCOME = "restoreWelcome"; 47 public static final String INTRO_MODEL_LEAF = "leaf"; public static final String INTRO_MODEL_CONTAINER = "container"; public static final String OPEN_ITNRO_VIEW = "introView"; 52 public static final String CONFIG_EXTENSION = "configExtension"; 54 public static final String ICONS_PATH = "$nl$/icons/"; 57 63 public static ImageDescriptor createImageDescriptor(String imageName) { 64 return createImageDescriptor(Platform 65 .getBundle(IIntroConstants.PLUGIN_ID), ICONS_PATH + imageName); 66 } 67 68 72 public static ImageDescriptor createImageDescriptor(Bundle bundle, 73 String imageName) { 74 try { 75 URL imageUrl = FileLocator.find(bundle, new Path(imageName), null); 76 if (imageUrl != null) { 77 ImageDescriptor desc = ImageDescriptor.createFromURL(imageUrl); 78 return desc; 79 } 80 } catch (Exception e) { 81 Log.error("could not create Image Descriptor", e); } 84 Log.warning("could not create Image Descriptor for: " + imageName + " in bundle: " + bundle.getSymbolicName()); return ImageDescriptor.getMissingImageDescriptor(); 87 } 88 89 93 public static ImageDescriptor createImageDescriptor(IPath base, 94 String imageName) { 95 try { 96 URL imageUrl = new URL (base.append(imageName).toOSString()); 97 if (imageUrl != null) { 98 ImageDescriptor desc = ImageDescriptor.createFromURL(imageUrl); 99 return desc; 100 } 101 } catch (Exception e) { 102 Log.error("could not create Image Descriptor", e); } 105 Log.warning("could not create Image Descriptor for: " + imageName); return ImageDescriptor.getMissingImageDescriptor(); 107 } 108 109 115 public static Image createImage(String imageName) { 116 try { 117 ImageDescriptor imageDsc = createImageDescriptor(imageName); 118 return imageDsc.createImage(); 119 } catch (Exception e) { 120 Log.error("could not create Image", e); return ImageDescriptor.getMissingImageDescriptor().createImage(); 123 } 124 } 125 126 132 public static Image getImage(String key) { 133 return IntroPlugin.getDefault().getVolatileImageRegistry().get(key); 138 } 139 140 public static boolean hasImage(String key) { 141 ImageRegistry registry = IntroPlugin.getDefault().getVolatileImageRegistry(); 142 return (registry.getDescriptor(key) != null); 143 } 144 145 152 public static void registerImage(String key, String imageName) { 153 ImageRegistry registry = IntroPlugin.getDefault().getVolatileImageRegistry(); 154 if (registry.getDescriptor(key) != null) 155 return; 157 registry.put(key, createImageDescriptor(imageName)); 158 } 159 160 public static void registerImage(String key, Bundle bundle, String imageName) { 161 162 ImageRegistry registry = IntroPlugin.getDefault().getVolatileImageRegistry(); 163 if (registry.getDescriptor(key) != null) 164 return; 166 registry.put(key, createImageDescriptor(bundle, imageName)); 167 } 168 169 public static void registerImage(String key, IPath base, String imageName) { 170 ImageRegistry registry = IntroPlugin.getDefault().getVolatileImageRegistry(); 171 if (registry.getDescriptor(key) != null) 172 return; 174 registry.put(key, createImageDescriptor(base, imageName)); 175 } 176 } 177 | Popular Tags |