01: /*
02: * Copyright Javelin Software, All rights reserved.
03: */
04:
05: package com.javelin.swinglets.plaf.html;
06:
07: import java.awt.*;
08:
09: import com.javelin.swinglets.*;
10: import com.javelin.swinglets.table.*;
11:
12: /**
13: * This defines the the default HTML Table Header Renderer.
14: *
15: * @author Robin Sharp
16: */
17:
18: public class HTMLSortedTableHeaderRenderer extends SLabel implements
19: STableCellRenderer {
20: /**
21: * Create a HTMLSortedTableHeaderRenderer.
22: */
23: public HTMLSortedTableHeaderRenderer() {
24: }
25:
26: /**
27: * If the value is a SComponent it is returned.
28: * <p>
29: * Otherwise the value is converted this.setText( value.toString() )
30: * and a link back to the tabl header is made.
31: * <p>
32: * Currently the component.setName( "" + column ) MUST be called.
33: */
34: public SComponent getTableCellRendererComponent(STable table,
35: Object value, int row, int column) {
36: if (value == null)
37: return null;
38:
39: if (value instanceof SComponent) {
40: ((SComponent) value).setName("" + column);
41: return (SComponent) value;
42: }
43:
44: setName("" + column);
45: setText(value.toString());
46: setLink(getLink(table, column));
47:
48: return this ;
49: }
50:
51: /**
52: * Get the link or this header. This caches the link string.
53: */
54: protected SLink getLink(STable table, int column) {
55: //Gauge the length of the buffer
56: if (column == 0) {
57: SContainer container = table.getTopLevelAncestor();
58:
59: if (linkBuffer == null) {
60: linkBuffer = new StringBuffer(table.getComponentUrl());
61:
62: linkBuffer.append("&_TYPE=H");
63:
64: linkBuffer.append("&");
65: linkBuffer.append(STableHeader.SOURCE_COLUMN);
66: linkBuffer.append("=");
67:
68: linkLength = linkBuffer.length();
69: }
70: }
71:
72: //Remove the old column from the end of the buffer
73: linkBuffer.setLength(linkLength);
74:
75: //Now append the new column
76: linkBuffer.append(column);
77:
78: link.setUrl(linkBuffer.toString());
79:
80: return link;
81: }
82:
83: // PRIVATE ////////////////////////////////////////////////////
84:
85: private SLink link = new SLink();
86:
87: //This is for cached links
88: private StringBuffer linkBuffer;
89: private int linkLength;
90:
91: }
|