01: /*
02: * EachRowRenderer.java
03: *
04: * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU General Public License
08: * as published by the Free Software Foundation; either version 2
09: * of the License, or any later version.
10: *
11: * This program 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 this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19: *
20: */
21:
22: package org.underworldlabs.swing.table;
23:
24: import java.awt.Component;
25: import java.util.Hashtable;
26: import javax.swing.JTable;
27: import javax.swing.table.DefaultTableCellRenderer;
28: import javax.swing.table.TableCellRenderer;
29:
30: /* ----------------------------------------------------------
31: * CVS NOTE: Changes to the CVS repository prior to the
32: * release of version 3.0.0beta1 has meant a
33: * resetting of CVS revision numbers.
34: * ----------------------------------------------------------
35: */
36:
37: /**
38: *
39: * @author Takis Diakoumis
40: * @version $Revision: 1.5 $
41: * @date $Date: 2006/09/26 13:17:42 $
42: */
43: public class EachRowRenderer implements TableCellRenderer {
44:
45: protected Hashtable renderers;
46: protected TableCellRenderer renderer;
47: protected TableCellRenderer defaultRenderer;
48:
49: public EachRowRenderer() {
50: renderers = new Hashtable();
51: defaultRenderer = new DefaultTableCellRenderer();
52: }
53:
54: public void add(int row, TableCellRenderer renderer) {
55: renderers.put(new Integer(row), renderer);
56: }
57:
58: public Component getTableCellRendererComponent(JTable table,
59: Object value, boolean isSelected, boolean hasFocus,
60: int row, int column) {
61:
62: renderer = (TableCellRenderer) renderers.get(new Integer(row));
63:
64: if (renderer == null) {
65: renderer = defaultRenderer;
66: }
67:
68: if (value != null
69: && renderer instanceof DefaultTableCellRenderer) {
70: ((DefaultTableCellRenderer) renderer).setToolTipText(value
71: .toString());
72: }
73:
74: return renderer.getTableCellRendererComponent(table, value,
75: isSelected, hasFocus, row, column);
76:
77: }
78: }
|