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 Footer Renderer.
14: *
15: * @author Robin Sharp
16: */
17:
18: public class HTMLPagedTableFooterRenderer extends SLabel implements
19: STableCellRenderer {
20: /**
21: * Create a HTMLSortedTableHeaderRenderer.
22: */
23: public HTMLPagedTableFooterRenderer() {
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:
35: // column is really the command
36: public SComponent getTableCellRendererComponent(STable table,
37: Object value, int row, int column) {
38: if (value == null)
39: return null;
40:
41: if (value instanceof SComponent) {
42: ((SComponent) value).setName("" + column);
43: return (SComponent) value;
44: }
45:
46: setName("" + column);
47: setText(value.toString());
48: String command = table.getTableFooter().getCommand(column);
49: if (command != null) {
50: setLink(getLink(table, column));
51: } else {
52: setLink(null);
53: }
54: return this ;
55: }
56:
57: /**
58: * Get the link or this header. This caches the link string.
59: */
60: protected SLink getLink(STable table, int column) {
61: //Gauge the length of the buffer
62: if (column == 0) {
63: //If the table or container have changed reload the buffer
64: if (linkBuffer == null) {
65: linkBuffer = new StringBuffer(table.getComponentUrl());
66:
67: linkBuffer.append("&_TYPE=F");
68:
69: linkBuffer.append("&");
70: linkBuffer.append(STableFooter.COMMAND);
71: linkBuffer.append("=");
72:
73: linkLength = linkBuffer.length();
74: }
75: }
76:
77: //Remove the old column from the end of the buffer
78: linkBuffer.setLength(linkLength);
79:
80: //Now append the new column
81: linkBuffer.append(table.getTableFooter().getCommand(column));
82:
83: link.setUrl(linkBuffer.toString());
84:
85: return link;
86: }
87:
88: // PRIVATE ////////////////////////////////////////////////////
89:
90: private SLink link = new SLink();
91:
92: //This is for cached links
93: private StringBuffer linkBuffer;
94: private int linkLength;
95:
96: }
|