1 package org.catacomb.druid.swing;
2
3
4 import java.awt.BorderLayout;
5 import java.awt.Color;
6 import java.awt.Component;
7 import java.awt.Dimension;
8 import java.awt.Font;
9 import java.awt.GridLayout;
10
11 import javax.swing.BorderFactory;
12 import javax.swing.JCheckBox;
13 import javax.swing.JLabel;
14 import javax.swing.JList;
15 import javax.swing.JPanel;
16 import javax.swing.ListCellRenderer;
17
18 import org.catacomb.interlish.structure.Colored;
19 import org.catacomb.interlish.structure.Named;
20
21
22 public class CheckListCellRenderer extends JPanel implements ListCellRenderer {
23 private static final long serialVersionUID = 1L;
24
25
26 private JCheckBox checkBox;
27
28 private JLabel label;
29 Color csel = new Color(0xd6, 0xd6, 0Xcc);
30 JPanel colorPanel;
31
32
33
34 public CheckListCellRenderer(ListCellRenderer renderer) {
35
36 setLayout(new BorderLayout(2, 2));
37 setOpaque(true);
38 checkBox = new JCheckBox();
39 checkBox.setOpaque(false);
40 setLayout(new BorderLayout());
41 label = new JLabel("");
42
43
44 label.setFont(new Font("sansserif", Font.PLAIN, 12));
45
46 add("West", checkBox);
47 add("Center", label);
48
49
50 colorPanel = new JPanel();
51 colorPanel.setPreferredSize(new Dimension(12, 12));
52 colorPanel.setMinimumSize(new Dimension(12, 12));
53 colorPanel.setMaximumSize(new Dimension(12, 12));
54 Color borderC = new Color(0xa0a0a0);
55
56
57 colorPanel.setBorder(BorderFactory.createLineBorder(borderC));
58
59 JPanel jp = new JPanel();
60 jp.setLayout(new GridLayout(1, 1, 4, 4));
61 jp.add(colorPanel);
62 jp.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
63
64 add("East", jp);
65 }
66
67 public Component getListCellRendererComponent(JList list, Object value,
68 int index, boolean isSelected, boolean cellHasFocus) {
69
70 ToggleItem ti = (ToggleItem)value;
71 checkBox.setSelected(ti.isOn());
72
73 Object refobj = ti.getRef();
74 if (refobj instanceof Named) {
75 label.setText(((Named)refobj).getName());
76 } else {
77 label.setText(ti.getRef().toString());
78 }
79
80 Color cbg = (isSelected ? csel : list.getBackground());
81
82
83 setBackground(cbg);
84
85
86 if (value instanceof Colored) {
87 Color c = ((Colored)value).getColor();
88 if (c != null) {
89 colorPanel.setBackground(c);
90 }
91 } else {
92
93 }
94
95
96 return this;
97 }
98 }