2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation; either version 2 of the License, or
5
* (at your option) any later version.
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software
14
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
* ResultSetTableCellRenderer.java
19
* Copyright (C) 2005 University of Waikato, Hamilton, New Zealand
25
import java.awt.Color;
26
import java.awt.Component;
28
import javax.swing.JTable;
29
import javax.swing.SwingConstants;
30
import javax.swing.UIManager;
31
import javax.swing.table.DefaultTableCellRenderer;
34
* Handles the background colors for missing values differently than the
35
* DefaultTableCellRenderer.
37
* @author FracPete (fracpete at waikato dot ac dot nz)
38
* @version $Revision: 1.2 $
40
public class ResultSetTableCellRenderer
41
extends DefaultTableCellRenderer {
43
/** for serialization */
44
private static final long serialVersionUID = -8106963669703497351L;
46
// the color for missing values
47
private Color missingColor;
48
private Color missingColorSelected;
51
* initializes the Renderer with a standard color
53
public ResultSetTableCellRenderer() {
54
this( new Color(223, 223, 223),
55
new Color(192, 192, 192) );
59
* initializes the Renderer with the given colors
61
public ResultSetTableCellRenderer( Color missingColor,
62
Color missingColorSelected ) {
66
this.missingColor = missingColor;
67
this.missingColorSelected = missingColorSelected;
71
* Returns the default table cell renderer.
72
* stuff for the header is taken from <a href="http://www.chka.de/swing/table/faq.html">here</a>
74
public Component getTableCellRendererComponent(
75
JTable table, Object value, boolean isSelected,
76
boolean hasFocus, int row, int column ) {
78
ResultSetTableModel model;
82
result = super.getTableCellRendererComponent(
83
table, value, isSelected, hasFocus, row, column);
85
if (table.getModel() instanceof ResultSetTableModel) {
86
model = (ResultSetTableModel) table.getModel();
89
if (model.isNullAt(row, column)) {
90
setToolTipText("NULL");
92
result.setBackground(missingColorSelected);
94
result.setBackground(missingColor);
99
result.setBackground(table.getSelectionBackground());
101
result.setBackground(Color.WHITE);
105
if (model.isNumericAt(column))
106
setHorizontalAlignment(SwingConstants.RIGHT);
108
setHorizontalAlignment(SwingConstants.LEFT);
112
setBorder(UIManager.getBorder("TableHeader.cellBorder"));
113
setHorizontalAlignment(SwingConstants.CENTER);
114
if (table.getColumnModel().getSelectionModel().isSelectedIndex(column))
115
result.setBackground(UIManager.getColor("TableHeader.background").darker());
117
result.setBackground(UIManager.getColor("TableHeader.background"));