1 5 package org.hibernate.eclipse.console.utils; 6 7 import java.net.MalformedURLException ; 8 import java.net.URL ; 9 import java.util.HashMap ; 10 import java.util.Map ; 11 12 import org.eclipse.jface.resource.ImageDescriptor; 13 import org.eclipse.jface.resource.ImageRegistry; 14 import org.eclipse.swt.graphics.Image; 15 import org.hibernate.console.ImageMap; 16 import org.hibernate.eclipse.console.HibernateConsolePlugin; 17 18 22 public class EclipseImageMap extends ImageMap { 23 24 public EclipseImageMap() { 25 26 declareImages(); 27 } 28 29 30 protected static URL ICON_BASE_URL = null; 31 32 static { 33 String pathSuffix = "icons/"; 35 try { 36 ICON_BASE_URL = new URL (HibernateConsolePlugin.getDefault().getBundle().getEntry("/"), pathSuffix); } catch (MalformedURLException e) { 38 } 40 } 41 42 43 Map imageDescriptors = new HashMap (); 44 45 46 ImageRegistry imageRegistry = new ImageRegistry(); 47 48 protected void declareRegistryImage(String key, String path) { 49 ImageDescriptor desc = ImageDescriptor.getMissingImageDescriptor(); 50 try { 51 desc = ImageDescriptor.createFromURL(makeIconFileURL(path)); 52 } catch (MalformedURLException me) { 53 HibernateConsolePlugin.getDefault().log(me); 54 } 55 imageRegistry.put(key, desc); 56 imageDescriptors.put(key, desc); 57 } 58 59 protected static URL makeIconFileURL(String iconPath) 60 throws MalformedURLException { 61 if (ICON_BASE_URL == null) { 62 throw new MalformedURLException (); 63 } 64 65 return new URL (ICON_BASE_URL, iconPath); 66 } 67 68 public Image getImage(String key) { 69 return imageRegistry.get(key); 70 } 71 72 public ImageDescriptor getImageDescriptor(String key) { 73 74 return (ImageDescriptor) imageDescriptors.get(key); 75 } 76 77 } 78 | Popular Tags |