KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > resourceloader > ImageLoader


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//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 JavaDoc;
21
22 import javax.swing.ImageIcon JavaDoc;
23
24 import org.columba.core.io.DiskIO;
25
26 public class ImageLoader {
27
28     private static final String JavaDoc ICON_PATH = "org/columba/core/icons";
29     
30     public static ImageIcon JavaDoc getMimetypeIcon(String JavaDoc name) {
31         URL JavaDoc url;
32
33         url = DiskIO.getResourceURL(ICON_PATH + "/MIMETYPE/" + name);
34         
35         if (url == null)
36             url = getFallback(false);
37
38         ImageIcon JavaDoc icon = new ImageIcon JavaDoc(url);
39
40         return icon;
41     }
42
43     public static ImageIcon JavaDoc getIcon(String JavaDoc name) {
44         return getIcon(ImageLoader.ICON_PATH, name, false);
45     }
46
47     public static ImageIcon JavaDoc getSmallIcon(String JavaDoc name) {
48         return getIcon(ImageLoader.ICON_PATH, name, true);
49     }
50
51     public static ImageIcon JavaDoc getIcon(String JavaDoc path, String JavaDoc name, boolean small) {
52         URL JavaDoc url;
53
54         if (small)
55             url = DiskIO.getResourceURL(path + "/16x16/" + name);
56         else
57             url = DiskIO.getResourceURL(path + "/22x22/" + name);
58
59         if (url == null) {
60             url = getFallback(small);
61         }
62
63         ImageIcon JavaDoc icon = new ImageIcon JavaDoc(url);
64
65         return icon;
66     }
67
68     public static ImageIcon JavaDoc getMiscIcon(String JavaDoc name) {
69         URL JavaDoc url;
70         String JavaDoc path = ImageLoader.ICON_PATH;
71
72         url = DiskIO.getResourceURL(path + "/MISC/" + name);
73
74         if (url == null) {
75             url = getFallback(true);
76         }
77
78         ImageIcon JavaDoc icon = new ImageIcon JavaDoc(url);
79
80         return icon;
81     }
82
83     private static URL JavaDoc getFallback(boolean small) {
84         String JavaDoc path;
85         String JavaDoc name;
86         URL JavaDoc url;
87         path = ImageLoader.ICON_PATH;
88         name = "image-missing.png";
89         if (small)
90             url = DiskIO.getResourceURL(path + "/16x16/" + name);
91         else
92             url = DiskIO.getResourceURL(path + "/22x22/" + name);
93         return url;
94     }
95
96 }
Popular Tags