01: package com.xoetrope.export.pdf;
02:
03: import com.xoetrope.export.Block;
04: import com.xoetrope.export.RowBlock;
05: import com.xoetrope.export.TableBlock;
06: import com.xoetrope.export.TableModelBlock;
07: import javax.swing.JLabel;
08: import javax.swing.JTable;
09: import javax.swing.table.TableModel;
10:
11: /**
12: *
13: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
14: * the GNU Public License (GPL), please see license.txt for more details. If
15: * you make commercial use of this software you must purchase a commercial
16: * license from Xoetrope.</p>
17: * <p> $Revision: 1.2 $</p>
18: */
19: public class PdfTableModelBlock extends TableModelBlock {
20: PdfExporter PdfExporter;
21:
22: // WritableSheet sheet;
23:
24: public PdfTableModelBlock(PdfExporter exporter) {
25: PdfExporter = exporter;
26: }
27:
28: // public void setWorksheet( WritableSheet worksheet )
29: // {
30: // sheet = worksheet;
31: // }
32:
33: protected String exportModel(JTable table, TableModel tableModel,
34: boolean includeHeader) {
35: TableModel oldModel = null;
36: if (tableModel == null) {
37: tableModel = table.getModel();
38: } else {
39: oldModel = table.getModel();
40: table.setModel(tableModel);
41: }
42: TableBlock tableExport = PdfExporter.getTableBlock();
43: if (includeHeader) {
44: RowBlock rowBlock = tableExport.addRow();
45: for (int col = 0; col < tableModel.getColumnCount(); col++) {
46: String value = tableModel.getColumnName(col);
47: String style = getHeaderStyle();
48: Block cellBlockItem = rowBlock.addCell(value, style, 1,
49: 1);
50: }
51: blocks.add(rowBlock);
52: }
53: for (int row = 0; row < tableModel.getRowCount(); row++) {
54: RowBlock rowBlock = tableExport.addRow();
55: for (int col = 0; col < tableModel.getColumnCount(); col++) {
56: String value = (String) tableModel.getValueAt(row, col);
57: Object comp = table.getCellRenderer(row, col)
58: .getTableCellRendererComponent(table, value,
59: false, false, row, col);
60: if (comp instanceof JLabel) {
61: value = ((JLabel) comp).getText();
62: }
63: String style = getHeaderStyle();
64: Block cellBlockItem = rowBlock.addCell(value, style, 1,
65: 1);
66: }
67: blocks.add(rowBlock);
68: }
69:
70: if (oldModel != null)
71: table.setModel(oldModel);
72:
73: return content.toString();
74: }
75: }
|