01: package org.wingx.treetable;
02:
03: import org.wings.*;
04: import org.wings.table.STableCellRenderer;
05:
06: import org.wingx.XTreeTable;
07:
08: public class TreeColumnRenderer extends SPanel implements
09: STableCellRenderer {
10: public static final SIcon ARROW_DOWN = new SResourceIcon(
11: "org/wings/icons/ArrowDown.gif");
12: public static final SIcon ARROW_RIGHT = new SResourceIcon(
13: "org/wings/icons/ArrowRight.gif");
14:
15: protected final SLabel indention = new SLabel();
16: protected final SLabel label = new SLabel();
17:
18: public TreeColumnRenderer() {
19: super (new SBorderLayout());
20: setHorizontalAlignment(SConstants.LEFT_ALIGN);
21: add(indention, SBorderLayout.WEST);
22: add(label, SBorderLayout.CENTER);
23: label.setHorizontalAlignment(SConstants.LEFT_ALIGN);
24: label.setWordWrap(true);
25: label.setIconTextGap(7);
26: }
27:
28: public SComponent getTableCellRendererComponent(STable table,
29: Object value, boolean selected, final int row, final int col) {
30: if (value instanceof SComponent)
31: return (SComponent) value;
32:
33: XTreeTable treeTable = (XTreeTable) table;
34: XTreeTableModel tableModel = treeTable.getTreeTableModel();
35:
36: if (col == 0 && row >= 0
37: && row < tableModel.getNodeModel().size()) {
38: XTreeTableNode node = (XTreeTableNode) tableModel
39: .getNodeModel().get(row);
40:
41: indention.setText(indention(node.getDepth()));
42: label.setIcon((!node.getAllowsChildren()) ? null : ((node
43: .isExpanded()) ? ARROW_DOWN : ARROW_RIGHT));
44: label.setText(value.toString());
45: return this ;
46: }
47:
48: label.setText(value != null ? value.toString() : null);
49: return label;
50: }
51:
52: private String indention(int depth) {
53: StringBuilder indent = new StringBuilder("<html>");
54: for (int i = 1; i < depth; i++) {
55: indent.append(" ");
56: }
57: return indent.toString();
58: }
59:
60: protected String nonBreakingSpaces(String value) {
61: return "<html>" + value.replaceAll(" ", " ");
62: }
63: }
|