01: package org.swingml.treetablebrowser.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 TreeTableBrowserCellIconRenderer extends JPanel implements
15: TableCellRenderer {
16:
17: TableCellRenderer originalRenderer;
18:
19: public TreeTableBrowserCellIconRenderer(
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 = originalRenderer
29: .getTableCellRendererComponent(table, value,
30: isSelected, hasFocus, row, column);
31: Component component;
32: TreeTableBrowserModelAdapter model = (TreeTableBrowserModelAdapter) table
33: .getModel();
34: TreeTableBrowserDataModel cellModel = model.getDataModel(row,
35: table.convertColumnIndexToModel(column));
36: if (cellModel != null && cellModel.hasIcons()) {
37: this .setLayout(new GridLayout(1, 1 + cellModel.getIcons()
38: .size()));
39: this .removeAll();
40: for (int i = 0; i < cellModel.getIcons().size(); i++) {
41: IconModel iconModel = (IconModel) cellModel.getIcons()
42: .get(i);
43: this .add(new JIconComponent(iconModel));
44: }
45: this .add(originalComponent);
46: if (isSelected) {
47: this .setBackground(table.getSelectionBackground());
48: this .setForeground(table.getSelectionForeground());
49: } else {
50: this .setBackground(cellModel.getBackground());
51: this .setForeground(cellModel.getForeground());
52: }
53: if (isFocusOwner()
54: && !this .getBackground().equals(
55: table.getBackground())) {
56: this .setBackground(new Color(this .getBackground()
57: .getRed(), this .getBackground().getGreen(),
58: this .getBackground().getBlue(), 125));
59: }
60: component = this;
61: } else {
62: component = originalComponent;
63: }
64: return component;
65: }
66: }
|