01: package org.swingml.tablebrowser.ext;
02:
03: import java.awt.*;
04:
05: import javax.swing.*;
06: import javax.swing.table.*;
07:
08: import org.swingml.component.*;
09: import org.swingml.model.*;
10:
11: /**
12: * @author Crosslogic
13: */
14: public class TableBrowserCellIconRenderer extends JPanel implements
15: TableCellRenderer {
16:
17: private TableCellRenderer originalRenderer;
18:
19: public TableBrowserCellIconRenderer(
20: TableCellRenderer originalRenderer) {
21: super ();
22: this .originalRenderer = originalRenderer;
23: }
24:
25: public Component getTableCellRendererComponent(JTable table,
26: Object value, boolean isSelected, boolean hasFocus,
27: int row, int column) {
28: Component originalComponent;
29: if (originalRenderer instanceof JCheckBox) {
30: originalComponent = originalRenderer
31: .getTableCellRendererComponent(table,
32: ((CellDataValue) value).toBoolean(),
33: isSelected, hasFocus, row, column);
34: } else {
35: originalComponent = originalRenderer
36: .getTableCellRendererComponent(table, value,
37: isSelected, hasFocus, row, column);
38: }
39: Component component;
40: TableBrowserComponent tbc = (TableBrowserComponent) table;
41: JTableModel model = (JTableModel) table.getModel();
42: TableDataModel cellModel = model.getDataModel(tbc
43: .convertRowIndexToModel(row), tbc
44: .convertColumnIndexToModel(column));
45: if (cellModel.hasIcons()) {
46:
47: this .setLayout(new GridLayout(1, 1 + cellModel.getIcons()
48: .size()));
49: this .removeAll();
50: for (int i = 0; i < cellModel.getIcons().size(); i++) {
51: IconModel iconModel = (IconModel) cellModel.getIcons()
52: .get(i);
53: this .add(new JIconComponent(iconModel));
54: }
55:
56: this .add(originalComponent);
57: if (isSelected) {
58: this .setBackground(table.getSelectionBackground());
59: this .setForeground(table.getSelectionForeground());
60: } else {
61: this .setBackground(cellModel.getBackground());
62: this .setForeground(cellModel.getForeground());
63: }
64: if (isFocusOwner()
65: && !this .getBackground().equals(
66: table.getBackground())) {
67: this .setBackground(new Color(this .getBackground()
68: .getRed(), this .getBackground().getGreen(),
69: this .getBackground().getBlue(), 125));
70: }
71: component = this;
72: } else {
73: component = originalComponent;
74: }
75:
76: return component;
77: }
78: }
|