001: package com.xoetrope.export.pdf;
002:
003: import com.xoetrope.export.ArrayArrayBlock;
004: import com.xoetrope.export.Block;
005: import com.xoetrope.export.RowBlock;
006: import com.xoetrope.export.TableBlock;
007: import java.util.ArrayList;
008: import net.xoetrope.xui.helper.XTranslator;
009:
010: /**
011: *
012: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
013: * the GNU Public License (GPL), please see license.txt for more details. If
014: * you make commercial use of this software you must purchase a commercial
015: * license from Xoetrope.</p>
016: * <p> $Revision: 1.2 $</p>
017: */
018: public class PdfArrayArrayBlock extends ArrayArrayBlock {
019: PdfExporter PdfExporter;
020: // WritableSheet sheet;
021: protected XTranslator translator;
022:
023: public PdfArrayArrayBlock(PdfExporter exporter) {
024: PdfExporter = exporter;
025: translator = exporter.getCurrentProject().getTranslator();
026: }
027:
028: // public void setWorksheet( WritableSheet worksheet )
029: // {
030: // sheet = worksheet;
031: // }
032:
033: protected String exportModel(ArrayList table, boolean includeHeader) {
034: // TableModel oldModel = null;
035: // if ( tableModel == null ) {
036: // tableModel = table.getModel();
037: // }
038: // else {
039: // oldModel = table.getModel();
040: // table.setModel( tableModel );
041: // }
042: // TableBlock tableExport = PdfExporter.getTableBlock();
043: // if ( includeHeader ) {
044: // RowBlock rowBlock = tableExport.addRow();
045: // for ( int col = 0; col < tableModel.getColumnCount(); col++ ) {
046: // String value = tableModel.getColumnName( col );
047: // String style = getHeaderStyle();
048: // Block cellBlockItem = rowBlock.addCell( value, style, 1, 1 );
049: // }
050: // blocks.add( rowBlock );
051: // }
052: // for ( int row = 0; row < tableModel.getRowCount(); row++ ) {
053: // RowBlock rowBlock = tableExport.addRow();
054: // for ( int col = 0; col < tableModel.getColumnCount(); col++ ) {
055: // String value = ( String )tableModel.getValueAt( row, col );
056: // Object comp = table.getCellRenderer( row, col ).getTableCellRendererComponent( table, value, false, false, row, col );
057: // if ( comp instanceof JLabel ) {
058: // value = ( ( JLabel ) comp ).getText();
059: // }
060: // String style = getHeaderStyle();
061: // Block cellBlockItem = rowBlock.addCell( value, style, 1, 1 );
062: // }
063: // blocks.add( rowBlock );
064: // }
065: //
066: // if ( oldModel != null )
067: // table.setModel( oldModel );
068: //
069: // return content.toString();
070: int startRow = 0;
071: int numRows = table.size();
072:
073: ArrayList row0 = (ArrayList) table.get(0);
074: int numCols = row0.size();
075:
076: TableBlock tableExport = PdfExporter.getTableBlock();
077:
078: // TableBlock tableExport = xlExporter.getTableBlock();
079: // if ( includeHeader ) {
080: // RowBlock rowBlock = tableExport.addRow();
081: // for ( int col = 0; col < tableModel.getColumnCount(); col++ ) {
082: // //String value = tableModel.getColumnName( col );
083: // String value = table.getTableHeader().getColumnModel().getColumn( col ).getHeaderValue().toString();
084: // if ( translator != null )
085: // value = translator.translate( value );
086: // String style = getHeaderStyle();
087: // Block cellBlockItem = rowBlock.addCell( value, style, 1, 1 );
088: // }
089: // blocks.add( rowBlock );
090: // }
091:
092: for (int i = startRow; i < numRows; i++) {
093: RowBlock rowBlock = tableExport.addRow();
094: ArrayList row = (ArrayList) table.get(i);
095: for (int j = 0; j < numCols; j++) {
096: String value = (String) row.get(j);
097: if (translator != null)
098: value = translator.translate(value);
099:
100: String style = getHeaderStyle();
101: Block cellBlockItem = rowBlock.addCell(value, style, 1,
102: 1);
103: }
104: blocks.add(rowBlock);
105: }
106:
107: return content.toString();
108: }
109: }
|