1 package com.explosion.datastream.exql.gui.table.editandrender;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import java.awt.Color;
24 import java.awt.Component;
25
26 import javax.swing.JTable;
27 import javax.swing.table.DefaultTableCellRenderer;
28 import javax.swing.table.TableCellRenderer;
29
30 import com.explosion.datastream.exql.EXQLConstants;
31 import com.explosion.datastream.exql.EXQLModuleManager;
32 import com.explosion.expfmodules.rdbmsconn.dbom.DBEntityColumn;
33
34
35 /***
36 * @author Steve.Cowx
37 * Used for rendering cells whose values have been updated
38 */
39 public class DisplayValueCellRenderer extends DefaultTableCellRenderer implements TableCellRenderer {
40
41 private JTable table;
42 private DBEntityColumn dbColumn;
43 protected Color fore;
44 protected Color back;
45
46 public DisplayValueCellRenderer(DBEntityColumn dbColumn, JTable table) {
47 super();
48 this.setFont(table.getFont());
49 this.table = table;
50 this.dbColumn = dbColumn;
51 fore = (Color) EXQLModuleManager.instance().getPreference(
52 EXQLConstants.TABLE_COLORS_FOREGROUND).getValue();
53 back = (Color) EXQLModuleManager.instance().getPreference(
54 EXQLConstants.TABLE_COLORS_BACKGROUND).getValue();
55
56 this.setBackground(back);
57 this.setForeground(fore);
58 }
59
60 /***
61 *
62 * Returns the default table cell renderer.
63 *
64 * @param table the <code>JTable</code>
65 * @param value the value to assign to the cell at
66 * <code>[row, column]</code>
67 * @param isSelected true if cell is selected
68 * @param hasFocus true if cell has focus
69 * @param row the row of the cell to render
70 * @param column the column of the cell to render
71 * @return the default table cell renderer
72 */
73 public Component getTableCellRendererComponent(JTable table, Object value,
74 boolean isSelected, boolean hasFocus, int row, int column) {
75 return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
76 }
77
78
79 /***
80 * Sets the value for this component. Actually, it interperets what is in the table into text
81 * @param data
82 * @return
83 */
84 public void setValue(Object data) {
85 String text = null;
86 if (data == null)
87 {
88 this.setBackground((Color) EXQLModuleManager.instance().getPreference(
89 EXQLConstants.TABLE_NULL_INDICATOR_BACKGROUND).getValue());
90 text = "";
91 }
92 else
93 {
94 if (dbColumn != null)
95 {
96 text = EditorAndRenderFactory.renderValueForColumn(data, dbColumn);
97 }
98 else
99 {
100 text = data.toString();
101 }
102 }
103
104 this.setText(text);
105 }
106
107
108
109 }