01: package abbot.editor;
02:
03: import java.awt.Component;
04: import javax.swing.*;
05: import java.util.*;
06: import java.net.URL;
07:
08: /** Provides JTree icons for different Components. */
09:
10: class ComponentTreeIcons {
11: private Map icons = new HashMap();
12:
13: public Icon getIcon(Class cls) {
14: String className = cls.getName();
15: int lastdot = className.lastIndexOf(".");
16: String simpleName = lastdot != -1 ? className.substring(
17: lastdot + 1).toLowerCase() : className;
18: Icon icon = (Icon) icons.get(className);
19: if (icon == null) {
20: URL url = getClass().getResource(
21: "icons/" + className + ".gif");
22: if (url == null) {
23: url = getClass().getResource(
24: "icons/" + simpleName + ".gif");
25: }
26: if (url == null) {
27: if (Component.class.equals(cls))
28: return null;
29: icon = getIcon(cls.getSuperclass());
30: } else {
31: icon = new ImageIcon(url);
32: }
33: if (icon != null) {
34: icons.put(className, icon);
35: }
36: }
37: return icon;
38: }
39: }
|