1 package sk.stuba.fiit.foo07.genex.gui;
2
3 import java.awt.Color;
4 import java.awt.Component;
5
6 import javax.swing.JCheckBox;
7 import javax.swing.JTree;
8 import javax.swing.tree.DefaultMutableTreeNode;
9 import javax.swing.tree.DefaultTreeCellRenderer;
10
11 public class CheckBoxTreeCellRenderer extends DefaultTreeCellRenderer {
12
13
14
15 private static final long serialVersionUID = 8107334924911925818L;
16
17 private Color b = new Color(255, 255, 240);
18 private Color s = new Color(255, 255, 190);
19
20 @Override
21 public Component getTreeCellRendererComponent(JTree tree, Object value,
22 boolean sel, boolean expanded, boolean leaf, int row,
23 boolean hasFocus) {
24
25 DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
26 Object obj = node.getUserObject();
27 JCheckBox ret = new JCheckBox(obj.toString());
28 ret.setBackground(b);
29 if (obj instanceof CheckBoxCategory) {
30 ret.setSelected(((CheckBoxCategory) obj).isSelected());
31 if (ret.isSelected())
32 ret.setBackground(s);
33 }
34
35 return ret;
36 }
37 }