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.*;
09: import org.swingml.component.*;
10:
11: /**
12: * @author NumberSix
13: */
14: public class TreeTableBrowserCellLabelRenderer implements
15: TableCellRenderer {
16:
17: TableCellRenderer originalRenderer;
18:
19: public TreeTableBrowserCellLabelRenderer(TableCellRenderer aRenderer) {
20: this .originalRenderer = aRenderer;
21: }
22:
23: public Component getTableCellRendererComponent(JTable table,
24: Object value, boolean isSelected, boolean hasFocus,
25: int row, int column) {
26: JLabel component = (JLabel) originalRenderer
27: .getTableCellRendererComponent(table, value,
28: isSelected, hasFocus, row, column);
29: TreeTableBrowserModelAdapter model = (TreeTableBrowserModelAdapter) table
30: .getModel();
31: TreeTableBrowserDataModel cellModel = model.getDataModel(row,
32: table.convertColumnIndexToModel(column));
33: if (cellModel != null) {
34: LabelDecorator.decorateLabel(component, cellModel, table
35: .getFont());
36: if (isSelected) {
37: component.setBackground(table.getSelectionBackground());
38: component.setForeground(table.getSelectionForeground());
39: }
40: Color compBg = component.getBackground();
41: Color tableBg = table.getBackground();
42: if (hasFocus && compBg != null && tableBg != null
43: && !compBg.equals(tableBg)) {
44: component.setBackground(new Color(component
45: .getBackground().getRed(), component
46: .getBackground().getGreen(), component
47: .getBackground().getBlue(), 125));
48: }
49:
50: // Set alignment
51: int alignment = JLabel.LEFT;
52: if (cellModel.getAlignment().equalsIgnoreCase(
53: Constants.RIGHT)) {
54: alignment = JLabel.RIGHT;
55: } else if (cellModel.getAlignment().equalsIgnoreCase(
56: Constants.CENTER)) {
57: alignment = JLabel.CENTER;
58: }
59: component.setHorizontalAlignment(alignment);
60: }
61:
62: return component;
63: }
64: }
|