01: package vicazh.hyperpool.stream.net.http;
02:
03: import javax.swing.*;
04: import javax.swing.tree.*;
05: import java.awt.*;
06:
07: /**
08: * The monitor tree renderer
09: *
10: * @author Victor Zhigunov
11: * @version 0.4.0
12: */
13: public class IMonitorRenderer extends DefaultTreeCellRenderer {
14: private Icon iconRoot;
15:
16: private Icon iconClient;
17:
18: private Icon iconServer;
19:
20: private Icon iconFile;
21:
22: private Icon iconConnect;
23:
24: IMonitorRenderer() {
25: iconRoot = UIManager.getIcon("activeIcon");
26: iconClient = UIManager.getIcon("clientIcon");
27: iconServer = UIManager.getIcon("serverIcon");
28: iconFile = UIManager.getIcon("fileIcon");
29: iconConnect = UIManager.getIcon("connectIcon");
30: }
31:
32: public Component getTreeCellRendererComponent(JTree tree,
33: Object value, boolean sel, boolean expanded, boolean leaf,
34: int row, boolean hasFocus) {
35: super .getTreeCellRendererComponent(tree, value, sel, expanded,
36: leaf, row, hasFocus);
37: Icon editingIcon = null;
38: switch (((DefaultMutableTreeNode) value).getLevel()) {
39: case 0:
40: editingIcon = iconRoot;
41: setFont(getFont().deriveFont(Font.BOLD));
42: break;
43: case 1:
44: editingIcon = iconClient;
45: setFont(getFont().deriveFont(Font.BOLD + Font.ITALIC));
46: break;
47: default:
48: if (((DefaultMutableTreeNode) value).getUserObject() instanceof MonitorItem) {
49: if (((MonitorItem) ((DefaultMutableTreeNode) value)
50: .getUserObject()).name == null)
51: editingIcon = iconConnect;
52: else
53: editingIcon = iconFile;
54: setFont(getFont().deriveFont(Font.PLAIN));
55: } else {
56: editingIcon = iconServer;
57: setFont(getFont().deriveFont(Font.ITALIC));
58: }
59: }
60: if (editingIcon != null)
61: setIcon(editingIcon);
62: return this;
63: }
64: }
|