01: package com.xoetrope.swing.table;
02:
03: import java.awt.Color;
04: import java.awt.Component;
05: import java.util.Hashtable;
06: import javax.swing.JTable;
07: import javax.swing.table.DefaultTableCellRenderer;
08:
09: /**
10: * A table cell renderer that sets the background color to match a color
11: * value set in a hashtable
12: *
13: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
14: * the GNU Public License (GPL), please see license.txt for more details. If
15: * you make commercial use of this software you must purchase a commercial
16: * license from Xoetrope.</p>
17: * <p> $Revision: 1.2 $</p>
18: */
19: public class XColorTableCellRenderer extends DefaultTableCellRenderer {
20: private Hashtable colorTable;
21:
22: /**
23: * Creates a new instance of XColorTableCellRenderer
24: */
25: public XColorTableCellRenderer(Hashtable colors) {
26: super ();
27: colorTable = colors;
28: }
29:
30: /**
31: *
32: * Returns the default table cell renderer.
33: *
34: * @param table the <code>JTable</code>
35: * @param value the value to assign to the cell at
36: * <code>[row, column]</code>
37: * @param isSelected true if cell is selected
38: * @param hasFocus true if cell has focus
39: * @param row the row of the cell to render
40: * @param column the column of the cell to render
41: * @return the default table cell renderer
42: */
43: public Component getTableCellRendererComponent(JTable table,
44: Object value, boolean isSelected, boolean hasFocus,
45: int row, int column) {
46: super .getTableCellRendererComponent(table, value, isSelected,
47: hasFocus, row, column);
48: if (!isSelected)
49: super .setBackground((Color) colorTable
50: .get(value.toString()));
51: return this ;
52: }
53:
54: /**
55: * Sets the <code>String</code> object for the cell being rendered to
56: * <code>value</code>.
57: *
58: * @param value the string value for this cell; if value is
59: * <code>null</code> it sets the text value to an empty string
60: * @see JLabel#setText
61: *
62: */
63: public void setValue(Object value) {
64: setText("");
65: }
66: }
|