01: package vicazh.hyperpool;
02:
03: import javax.swing.*;
04: import javax.swing.tree.*;
05: import java.awt.*;
06:
07: /**
08: * The tree renderer
09: *
10: * @author Victor Zhigunov
11: * @version 0.4.0
12: */
13: public class ITreeRenderer extends DefaultTreeCellRenderer {
14: private Icon iconProject;
15:
16: private Icon iconService;
17:
18: private Icon iconGroup;
19:
20: private Icon iconLine;
21:
22: private Icon iconSelector;
23:
24: ITreeRenderer() {
25: iconProject = UIManager.getIcon("projectIcon");
26: iconService = UIManager.getIcon("serviceIcon");
27: iconGroup = UIManager.getIcon("groupIcon");
28: iconLine = UIManager.getIcon("lineIcon");
29: iconSelector = UIManager.getIcon("selectorIcon");
30: setTextNonSelectionColor(UIManager
31: .getColor("Tree.selectionForeground"));
32: setTextSelectionColor(UIManager.getColor("Tree.textForeground"));
33: setBackgroundNonSelectionColor(UIManager
34: .getColor("Tree.selectionBackground"));
35: setBackgroundSelectionColor(UIManager
36: .getColor("Tree.textBackground"));
37: }
38:
39: public Component getTreeCellRendererComponent(JTree tree,
40: Object value, boolean sel, boolean expanded, boolean leaf,
41: int row, boolean hasFocus) {
42: super .getTreeCellRendererComponent(tree, value, sel, expanded,
43: leaf, row, hasFocus);
44: Object o = ((DefaultMutableTreeNode) value).getUserObject();
45: Icon editingIcon = null;
46: if (o instanceof IProject) {
47: editingIcon = iconProject;
48: setFont(getFont().deriveFont(Font.BOLD));
49: } else if (o instanceof IGroup) {
50: editingIcon = iconGroup;
51: setFont(getFont().deriveFont(Font.BOLD + Font.ITALIC));
52: } else if (o instanceof ILine) {
53: editingIcon = iconLine;
54: setFont(getFont().deriveFont(Font.ITALIC));
55: } else if (o instanceof IService) {
56: editingIcon = iconService;
57: setFont(getFont().deriveFont(Font.PLAIN));
58: } else {
59: editingIcon = iconSelector;
60: setFont(getFont().deriveFont(Font.PLAIN));
61: }
62: if (editingIcon != null)
63: setIcon(editingIcon);
64: return this;
65: }
66: }
|