001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.chat.resourceloader;
019:
020: import java.net.URL;
021: import java.util.Locale;
022: import java.util.MissingResourceException;
023: import java.util.ResourceBundle;
024:
025: import javax.swing.ImageIcon;
026:
027: import org.columba.core.io.DiskIO;
028: import org.columba.core.resourceloader.GlobalResourceLoader;
029:
030: public class ResourceLoader {
031:
032: private static final String ICON_PATH = "/org/columba/chat/icons";
033:
034: private static String i18nPath = "org.columba.chat.i18n";
035:
036: public static ImageIcon getMiscIcon(String resourceName) {
037: if (resourceName == null)
038: throw new IllegalArgumentException("resourceName == null");
039:
040: URL url = ResourceLoader.class
041: .getResource(ResourceLoader.ICON_PATH + "/MISC/"
042: + resourceName);
043:
044: if (url == null)
045: url = getFallback(true);
046:
047: ImageIcon icon = new ImageIcon(url);
048:
049: return icon;
050: }
051:
052: public static ImageIcon getIcon(String name) {
053: return getIcon(ResourceLoader.ICON_PATH, name, false);
054: }
055:
056: public static ImageIcon getSmallIcon(String name) {
057: return getIcon(ResourceLoader.ICON_PATH, name, true);
058: }
059:
060: public static ImageIcon getIcon(String path, String name,
061: boolean small) {
062: URL url;
063:
064: if (small)
065: url = ResourceLoader.class.getResource(path + "/16x16/"
066: + name);
067: else
068: url = ResourceLoader.class.getResource(path + "/22x22/"
069: + name);
070:
071: if (url == null)
072: url = getFallback(small);
073:
074: ImageIcon icon = new ImageIcon(url);
075:
076: return icon;
077: }
078:
079: /**
080: * @param small
081: * @return
082: */
083: private static URL getFallback(boolean small) {
084: String path;
085: String name;
086: URL url;
087: path = "/org/columba/core/icons";
088: name = "image-missing.png";
089: if (small)
090: url = ResourceLoader.class.getResource(path + "/16x16/"
091: + name);
092: else
093: url = ResourceLoader.class.getResource(path + "/22x22/"
094: + name);
095: return url;
096: }
097:
098: public static final String getString(String resourceBundleName,
099: String resourceName) {
100: ResourceBundle bundle = null;
101:
102: String bundlePath = i18nPath + "." + resourceBundleName;
103:
104: try {
105: bundle = ResourceBundle.getBundle(bundlePath, Locale
106: .getDefault());
107:
108: return bundle.getString(resourceName);
109: } catch (MissingResourceException e) {
110:
111: // fall-back to global resource loader
112: return GlobalResourceLoader.getString(null,
113: resourceBundleName, resourceName);
114: }
115: }
116: }
|