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.calendar.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.resourceloader.GlobalResourceLoader;
028:
029: /**
030: * ResourceLoader class
031: * @author unknown
032: *
033: */
034: public class ResourceLoader {
035: private static String ICON_PATH = "/org/columba/calendar/icons";
036: private static String i18nPath = "org.columba.calendar.i18n";
037:
038: /**
039: * getMiscIcon method
040: * @param resourceName
041: * @return icon
042: */
043: public static ImageIcon getMiscIcon(String resourceName) {
044: if (resourceName == null)
045: throw new IllegalArgumentException("resourceName == null");
046:
047: URL url = ResourceLoader.class
048: .getResource(ResourceLoader.ICON_PATH + "/MISC/"
049: + resourceName);
050:
051: if (url == null)
052: url = getFallback(true);
053:
054: ImageIcon icon = new ImageIcon(url);
055: return icon;
056: }
057:
058: /**
059: * getIcon method
060: * @param name
061: * @return standard icon
062: */
063: public static ImageIcon getIcon(String name) {
064: return getIcon(ResourceLoader.ICON_PATH, name, false);
065: }
066:
067: /**
068: * getSmallIcon method
069: * @param name
070: * @return small icon
071: */
072: public static ImageIcon getSmallIcon(String name) {
073: return getIcon(ResourceLoader.ICON_PATH, name, true);
074: }
075:
076: /**
077: * getIcon method
078: * @param path
079: * @param name
080: * @param small
081: * @return icon
082: */
083: public static ImageIcon getIcon(String path, String name,
084: boolean small) {
085: URL url;
086:
087: if (small)
088: url = ResourceLoader.class.getResource(path + "/16x16/"
089: + name);
090: else
091: url = ResourceLoader.class.getResource(path + "/22x22/"
092: + name);
093:
094: if (url == null)
095: url = getFallback(small);
096:
097: ImageIcon icon = new ImageIcon(url);
098:
099: return icon;
100: }
101:
102: /**
103: * GetFallback method - returns correct size image-missing icon if other icon does not exist
104: * @param small
105: * @return icon
106: */
107: private static URL getFallback(boolean small) {
108: String path;
109: String name;
110: URL url;
111: path = "org/columba/core/icons";
112: name = "image-missing.png";
113: if (small)
114:
115: url = ResourceLoader.class.getResource(path + "/16x16/"
116: + name);
117: else
118: url = ResourceLoader.class.getResource(path + "/22x22/"
119: + name);
120: return url;
121: }
122:
123: /**
124: * getString method - gets i18n bundle name
125: * @param resourceBundleName
126: * @param resourceName
127: * @return resource bundle
128: */
129: public static final String getString(String resourceBundleName,
130: String resourceName) {
131: ResourceBundle bundle = null;
132: String bundlePath = i18nPath + "." + resourceBundleName;
133:
134: try {
135: bundle = ResourceBundle.getBundle(bundlePath, Locale
136: .getDefault());
137:
138: return bundle.getString(resourceName);
139: } catch (MissingResourceException e) {
140:
141: // fall-back to global resource loader
142: return GlobalResourceLoader.getString(null,
143: resourceBundleName, resourceName);
144: }
145: }
146: }
|