1 package org.catacomb.icon;
2
3
4
5 import java.net.URL;
6 import java.util.HashMap;
7
8 import org.catacomb.icon.images.IconRoot;
9 import org.catacomb.report.E;
10
11
12 public class IconLoader {
13
14
15
16 static HashMap<String, DImageIcon> icons;
17
18 static {
19 icons = new HashMap<String, DImageIcon>();
20 }
21
22
23 public static DImageIcon getImageIcon(String s) {
24 DImageIcon ret = null;
25 if (icons.containsKey(s)) {
26 ret = icons.get(s);
27 } else {
28 ret = createImageIcon(s);
29 icons.put(s, ret);
30 }
31 return ret;
32 }
33
34
35 public static DImageIcon createImageIcon(String namein) {
36 String name = namein;
37 if (name.endsWith(".gif") || name.endsWith(".png")) {
38
39 } else {
40 name = name + ".gif";
41 }
42
43 URL imgURL = IconRoot.class.getResource(name);
44
45 if (imgURL != null) {
46 return new DImageIcon(imgURL);
47
48 } else {
49 E.error("Couldn't find file: " + name);
50 return null;
51 }
52 }
53
54
55 }