1 18 19 package org.objectweb.jac.aspects.gui; 20 21 import java.io.InputStream ; 22 import java.net.URL ; 23 import java.util.Hashtable ; 24 import javax.swing.ImageIcon ; 25 import org.apache.log4j.Logger; 26 27 33 34 public class ResourceManager { 35 static Logger logger = Logger.getLogger("gui.resources"); 36 37 38 public static final String RESOURCES_PATH = "org/objectweb/jac/aspects/gui/resources/"; 39 40 static Hashtable icons = new Hashtable (); 41 42 47 48 public static ImageIcon createIcon(String path) { 49 logger.debug("resolving URL for "+path); 50 URL url = ResourceManager.class.getClassLoader().getResource(path); 51 if (url==null) { 52 logger.warn("Could not find resource "+path); 53 return null; 54 } else { 55 logger.debug("URL="+url); 56 return new ImageIcon (url); 57 } 58 } 59 60 static Hashtable resources = new Hashtable (); 61 62 69 public static void defineResource(String name, String path) { 70 resources.put(name,path); 71 } 72 73 public static String getResource(String name) { 74 return (String )resources.get(name); 75 } 76 77 public static InputStream getResourceAsStream(String name) { 78 return ResourceManager.class.getClassLoader().getResourceAsStream( 79 getResource(name)); 80 } 81 82 89 90 public static ImageIcon getIcon(String resource) { 91 if (resource==null) 92 return null; 93 ImageIcon result = (ImageIcon )icons.get(resource); 94 if (result==null) { 95 result = createIcon(resource); 96 if (result!=null) 97 icons.put(resource,result); 98 } 99 return result; 100 } 101 102 110 public static ImageIcon getIconResource(String name) { 111 return getIcon(getResource(name)); 112 } 113 } 114 | Popular Tags |