01: package org.cougaar.core.qos.frame.visualizer.icons;
02:
03: import javax.swing.*;
04: import java.util.HashMap;
05: import java.net.URL;
06:
07: /**
08: * Created by IntelliJ IDEA.
09: * User: mwalczak
10: * Date: Apr 28, 2005
11: * Time: 1:08:36 PM
12: * To change this template use File | Settings | File Templates.
13: */
14: public class IconFactory {
15: private static IconFactory instance = null;
16:
17: public static IconFactory getInstance() {
18: if (instance == null)
19: instance = new IconFactory();
20: return instance;
21: }
22:
23: public static Icon getIcon(String iconName) {
24: return (Icon) getInstance().iconMap.get(iconName);
25: }
26:
27: public final static String FRAME_ICON = "frame";
28: public final static String FRAME_PROTOYPE_ICON = "frameProto";
29: public final static String RELATION_ICON = "relationIcon";
30: public final static String CONTAINER_ICON = "container";
31: public final static String COMPONENT_ICON = "component";
32: public final static String CONTAINER_PROTOTYPE_ICON = "containerPrototype";
33: public final static String COMPONENT_PROTOTYPE_ICON = "componentPrototype";
34:
35: private HashMap iconMap;
36:
37: private IconFactory() {
38: iconMap = new HashMap();
39: loadIcons();
40: }
41:
42: private void load(ClassLoader cl, String key, String filename) {
43: URL icnURL = cl.getResource(filename);
44: ImageIcon icon = new ImageIcon(icnURL);
45: iconMap.put(key, icon);
46: }
47:
48: private void loadIcons() {
49: ClassLoader cl = IconFactory.class.getClassLoader();
50: String prefix = "org/cougaar/core/qos/frame/visualizer/icons/";
51: load(cl, FRAME_ICON, prefix + "frame.gif");
52: load(cl, FRAME_PROTOYPE_ICON, prefix + "frameProto.gif");
53: load(cl, RELATION_ICON, prefix + "relation.gif");
54: load(cl, CONTAINER_ICON, prefix + "container.gif");
55: load(cl, COMPONENT_ICON, prefix + "comp.gif");
56: load(cl, CONTAINER_PROTOTYPE_ICON, prefix + "proto.gif");
57: load(cl, COMPONENT_PROTOTYPE_ICON, prefix + "proto.gif");
58: }
59: }
|