01: // The contents of this file are subject to the Mozilla Public License Version
02: // 1.1
03: //(the "License"); you may not use this file except in compliance with the
04: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
05: //
06: //Software distributed under the License is distributed on an "AS IS" basis,
07: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
08: //for the specific language governing rights and
09: //limitations under the License.
10: //
11: //The Original Code is "The Columba Project"
12: //
13: //The Initial Developers of the Original Code are Frederik Dietz and Timo
14: // Stich.
15: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16: //
17: //All Rights Reserved.
18: package org.columba.core.resourceloader;
19:
20: import java.net.URL;
21:
22: import javax.swing.ImageIcon;
23:
24: import org.columba.core.io.DiskIO;
25:
26: public class ImageLoader {
27:
28: private static final String ICON_PATH = "org/columba/core/icons";
29:
30: public static ImageIcon getMimetypeIcon(String name) {
31: URL url;
32:
33: url = DiskIO.getResourceURL(ICON_PATH + "/MIMETYPE/" + name);
34:
35: if (url == null)
36: url = getFallback(false);
37:
38: ImageIcon icon = new ImageIcon(url);
39:
40: return icon;
41: }
42:
43: public static ImageIcon getIcon(String name) {
44: return getIcon(ImageLoader.ICON_PATH, name, false);
45: }
46:
47: public static ImageIcon getSmallIcon(String name) {
48: return getIcon(ImageLoader.ICON_PATH, name, true);
49: }
50:
51: public static ImageIcon getIcon(String path, String name,
52: boolean small) {
53: URL url;
54:
55: if (small)
56: url = DiskIO.getResourceURL(path + "/16x16/" + name);
57: else
58: url = DiskIO.getResourceURL(path + "/22x22/" + name);
59:
60: if (url == null) {
61: url = getFallback(small);
62: }
63:
64: ImageIcon icon = new ImageIcon(url);
65:
66: return icon;
67: }
68:
69: public static ImageIcon getMiscIcon(String name) {
70: URL url;
71: String path = ImageLoader.ICON_PATH;
72:
73: url = DiskIO.getResourceURL(path + "/MISC/" + name);
74:
75: if (url == null) {
76: url = getFallback(true);
77: }
78:
79: ImageIcon icon = new ImageIcon(url);
80:
81: return icon;
82: }
83:
84: private static URL getFallback(boolean small) {
85: String path;
86: String name;
87: URL url;
88: path = ImageLoader.ICON_PATH;
89: name = "image-missing.png";
90: if (small)
91: url = DiskIO.getResourceURL(path + "/16x16/" + name);
92: else
93: url = DiskIO.getResourceURL(path + "/22x22/" + name);
94: return url;
95: }
96:
97: }
|