1 package org.columba.chat.resourceloader; 19 20 import java.net.URL ; 21 import java.util.Locale ; 22 import java.util.MissingResourceException ; 23 import java.util.ResourceBundle ; 24 25 import javax.swing.ImageIcon ; 26 27 import org.columba.core.io.DiskIO; 28 import org.columba.core.resourceloader.GlobalResourceLoader; 29 30 public class ResourceLoader { 31 32 private static final String ICON_PATH = "/org/columba/chat/icons"; 33 34 private static String i18nPath = "org.columba.chat.i18n"; 35 36 public static ImageIcon getMiscIcon(String resourceName) { 37 if (resourceName == null) 38 throw new IllegalArgumentException ("resourceName == null"); 39 40 URL url = ResourceLoader.class.getResource(ResourceLoader.ICON_PATH + "/MISC/" 41 + resourceName); 42 43 if (url == null) 44 url = getFallback(true); 45 46 ImageIcon icon = new ImageIcon (url); 47 48 return icon; 49 } 50 51 public static ImageIcon getIcon(String name) { 52 return getIcon(ResourceLoader.ICON_PATH, name, false); 53 } 54 55 public static ImageIcon getSmallIcon(String name) { 56 return getIcon(ResourceLoader.ICON_PATH, name, true); 57 } 58 59 public static ImageIcon getIcon(String path, String name, boolean small) { 60 URL url; 61 62 if (small) 63 url = ResourceLoader.class.getResource(path + "/16x16/" + name); 64 else 65 url = ResourceLoader.class.getResource(path + "/22x22/" + name); 66 67 if (url == null) 68 url = getFallback(small); 69 70 ImageIcon icon = new ImageIcon (url); 71 72 return icon; 73 } 74 75 79 private static URL getFallback(boolean small) { 80 String path; 81 String name; 82 URL url; 83 path = "/org/columba/core/icons"; 84 name = "image-missing.png"; 85 if (small) 86 url = ResourceLoader.class.getResource(path + "/16x16/" + name); 87 else 88 url = ResourceLoader.class.getResource(path + "/22x22/" + name); 89 return url; 90 } 91 92 public static final String getString(String resourceBundleName, 93 String resourceName) { 94 ResourceBundle bundle = null; 95 96 String bundlePath = i18nPath + "." + resourceBundleName; 97 98 try { 99 bundle = ResourceBundle.getBundle(bundlePath, Locale.getDefault()); 100 101 return bundle.getString(resourceName); 102 } catch (MissingResourceException e) { 103 104 return GlobalResourceLoader.getString(null, resourceBundleName, 106 resourceName); 107 } 108 } 109 } 110 | Popular Tags |