1 /*
2 * Copyright (c) 2003-2008 by Cosylab d. d.
3 *
4 * This file is part of CosyBeans-Common.
5 *
6 * CosyBeans-Common is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * CosyBeans-Common is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with CosyBeans-Common. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 package com.cosylab.gui.components.table.renderers;
21
22 import java.awt.Component;
23
24 import javax.swing.JCheckBox;
25 import javax.swing.JTable;
26 import javax.swing.table.TableCellRenderer;
27
28 import com.cosylab.gui.components.table.cells.BooleanCell;
29
30 /**
31 * This is the default renderer for the ObjectTable cells implementing
32 * BooleanCell. Is is rendered as a checkbox that can be in two states.
33 * Since it is a renderer, the event handling for changing the states must
34 * be provided at ObjectTable level.
35 *
36 * @author <a href="mailto:ales.pucelj@cosylab.com">Ales Pucelj</a>
37 * @version $id$
38 */
39 public class BooleanCellRenderer
40 extends JCheckBox
41 implements TableCellRenderer {
42
43 private static final long serialVersionUID = 1L;
44
45 /**
46 * Default constructor for BooleanTableCellRenderer.
47 */
48 public BooleanCellRenderer() {
49 super();
50 setOpaque(true);
51 }
52
53 /*
54 * (non-Javadoc)
55 * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
56 */
57 public Component getTableCellRendererComponent(
58 JTable table,
59 Object booleanTableCell,
60 boolean isSelected,
61 boolean hasFocus,
62 int row,
63 int column) {
64
65 BooleanCell cellProperty = (BooleanCell) booleanTableCell;
66 setForeground(table.getForeground());
67 setBackground(table.getBackground());
68
69 setSelected(cellProperty.getBooleanValue());
70 return this;
71 }
72 }