01: package org.swingml.component;
02:
03: import java.awt.*;
04:
05: import javax.swing.*;
06: import javax.swing.table.*;
07:
08: import org.swingml.*;
09: import org.swingml.model.*;
10:
11: /**
12: * @author Crosslogic
13: */
14: public class TableCellLabelRenderer implements TableCellRenderer {
15:
16: TableCellRenderer originalRenderer;
17:
18: public TableCellLabelRenderer(TableCellRenderer theOriginalRenderer) {
19: if (theOriginalRenderer == null) {
20: this .originalRenderer = new DefaultTableCellRenderer();
21: } else {
22: this .originalRenderer = theOriginalRenderer;
23: }
24: }
25:
26: public Component getTableCellRendererComponent(JTable table,
27: Object value, boolean isSelected, boolean hasFocus,
28: int row, int column) {
29: JLabel component = (JLabel) originalRenderer
30: .getTableCellRendererComponent(table, value,
31: isSelected, hasFocus, row, column);
32: JTableModel model = (JTableModel) table.getModel();
33: TableDataModel cellModel = model.getDataModel(row, table
34: .convertColumnIndexToModel(column));
35: LabelDecorator.decorateLabel(component, cellModel, table
36: .getFont());
37: if (isSelected && !cellModel.isEditable()) {
38: component.setBackground(table.getSelectionBackground());
39: component.setForeground(table.getSelectionForeground());
40: }
41:
42: // Set alignment
43: int alignment = JLabel.LEFT;
44: if (cellModel.getAlignment().equalsIgnoreCase(Constants.RIGHT)) {
45: alignment = JLabel.RIGHT;
46: } else if (cellModel.getAlignment().equalsIgnoreCase(
47: Constants.CENTER)) {
48: alignment = JLabel.CENTER;
49: }
50: component.setHorizontalAlignment(alignment);
51:
52: return component;
53: }
54: }
|