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.model.*;
09:
10: /**
11: * @author Crosslogic
12: */
13: public class TableCellIconRenderer extends JPanel implements
14: TableCellRenderer {
15:
16: TableCellRenderer originalRenderer;
17:
18: public TableCellIconRenderer(TableCellRenderer originalRenderer) {
19: super ();
20: this .originalRenderer = originalRenderer;
21: }
22:
23: public Component getTableCellRendererComponent(JTable table,
24: Object value, boolean isSelected, boolean hasFocus,
25: int row, int column) {
26: Component originalComponent = originalRenderer
27: .getTableCellRendererComponent(table, value,
28: isSelected, hasFocus, row, column);
29: Component component;
30: JTableModel model = (JTableModel) table.getModel();
31: TableDataModel cellModel = model.getDataModel(row, table
32: .convertColumnIndexToModel(column));
33:
34: if (cellModel.hasIcons()) {
35: this .setLayout(new GridLayout(1, 1 + cellModel.getIcons()
36: .size()));
37: this .removeAll();
38: for (int i = 0; i < cellModel.getIcons().size(); i++) {
39: IconModel iconModel = (IconModel) cellModel.getIcons()
40: .get(i);
41: this .add(new JIconComponent(iconModel));
42: }
43: this.add(originalComponent);
44: if (isSelected && !cellModel.isEditable()) {
45: this.setBackground(table.getSelectionBackground());
46: this.setForeground(table.getSelectionForeground());
47: } else {
48: this.setBackground(cellModel.getBackground());
49: this.setForeground(cellModel.getForeground());
50: }
51: component = this;
52: } else {
53: component = originalComponent;
54: }
55:
56: return component;
57: }
58: }
|