01: package vicazh.hyperpool;
02:
03: import javax.swing.*;
04: import javax.swing.tree.*;
05: import java.awt.*;
06:
07: /**
08: * The tree editor
09: *
10: * @author Victor Zhigunov
11: * @version 0.4.0
12: */
13: public class ITreeEditor extends DefaultTreeCellEditor {
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: private int i;
25:
26: ITreeEditor(int i) {
27: super (null, null);
28: this .i = i;
29: iconProject = UIManager.getIcon("projectIcon");
30: iconService = UIManager.getIcon("serviceIcon");
31: iconGroup = UIManager.getIcon("groupIcon");
32: iconLine = UIManager.getIcon("lineIcon");
33: iconSelector = UIManager.getIcon("selectorIcon");
34: }
35:
36: public Component getTreeCellEditorComponent(JTree tree,
37: Object value, boolean sel, boolean expanded, boolean leaf,
38: int row) {
39: Component c = super .getTreeCellEditorComponent(tree, value,
40: sel, expanded, leaf, row);
41: Object o = ((DefaultMutableTreeNode) value).getUserObject();
42: if (o instanceof IProject) {
43: editingIcon = iconProject;
44: c.setFont(c.getFont().deriveFont(Font.BOLD));
45: } else if (o instanceof IGroup) {
46: editingIcon = iconGroup;
47: c.setFont(c.getFont().deriveFont(Font.BOLD + Font.ITALIC));
48: } else if (o instanceof ILine) {
49: editingIcon = iconLine;
50: c.setFont(c.getFont().deriveFont(Font.ITALIC));
51: } else if (o instanceof IService) {
52: editingIcon = iconService;
53: c.setFont(c.getFont().deriveFont(Font.PLAIN));
54: } else {
55: editingIcon = iconSelector;
56: c.setFont(c.getFont().deriveFont(Font.PLAIN));
57: }
58: if (editingIcon != null)
59: offset = i + editingIcon.getIconWidth();
60: return c;
61: }
62: }
|