01: /*
02: * The contents of this file are subject to the Mozilla Public License
03: * Version 1.1 (the "License"); you may not use this file except in
04: * compliance with the License. You may obtain a copy of the License at
05: * http://www.mozilla.org/MPL/
06: *
07: * Software distributed under the License is distributed on an "AS IS"
08: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
09: * License for the specific language governing rights and limitations
10: * under the License.
11: *
12: * The Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
13: *
14: * The Initial Developer of the Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
15: * Portions created by Mark A. Kobold are Copyright (C) 2000-2007. All Rights Reserved.
16: *
17: * Contributor(s):
18: * Mark A. Kobold [mkobold <at> isqlviewer <dot> com].
19: *
20: * If you didn't download this code from the following link, you should check
21: * if you aren't using an obsolete version: http://www.isqlviewer.com
22: */
23: package org.isqlviewer.ui.laf;
24:
25: import java.awt.Color;
26: import java.awt.Component;
27:
28: import javax.swing.JCheckBox;
29: import javax.swing.JTable;
30: import javax.swing.SwingConstants;
31: import javax.swing.UIManager;
32: import javax.swing.border.Border;
33: import javax.swing.border.EmptyBorder;
34: import javax.swing.plaf.UIResource;
35: import javax.swing.table.TableCellRenderer;
36:
37: /**
38: * Standard boolean value renderer in the form of a JCheckbox.
39: * <p>
40: *
41: * @author Mark A. Kobold <mkobold at isqlviewer dot com>
42: * @version 1.0
43: */
44: public class EnhancedBooleanCellRenderer extends JCheckBox implements
45: TableCellRenderer, UIResource {
46:
47: private static final long serialVersionUID = 8090643672945427653L;
48: private static final Border noFocusBorder = new EmptyBorder(1, 1,
49: 1, 1);
50:
51: public EnhancedBooleanCellRenderer() {
52:
53: super ();
54: setHorizontalAlignment(SwingConstants.CENTER);
55: setBorderPainted(true);
56: }
57:
58: public Component getTableCellRendererComponent(JTable table,
59: Object value, boolean isSelected, boolean hasFocus,
60: int row, int column) {
61:
62: if (isSelected) {
63: if (table.hasFocus()) {
64: setBackground(EnhancedTableCellRenderer.selectedFocusedColor);
65: setForeground(Color.WHITE);
66: } else {
67: setBackground(EnhancedTableCellRenderer.selectedNotFocusedColor);
68: setForeground(Color.BLACK);
69: }
70: } else {
71: Color color = row % 2 == 0 ? EnhancedTableCellRenderer.evenRowColor
72: : EnhancedTableCellRenderer.oddRowColor;
73: setBackground(color);
74: setForeground(Color.BLACK);
75: }
76:
77: setSelected((value != null && ((Boolean) value).booleanValue()));
78: if (hasFocus) {
79: setBorder(UIManager
80: .getBorder("Table.focusCellHighlightBorder"));
81: } else {
82: setBorder(noFocusBorder);
83: }
84: return this;
85: }
86: }
|