1 50 51 package com.lowagie.text.rtf.table; 52 53 import java.io.ByteArrayOutputStream ; 54 import java.io.IOException ; 55 import java.io.OutputStream ; 56 import java.util.ArrayList ; 57 import java.util.Iterator ; 58 59 import com.lowagie.text.Element; 60 import com.lowagie.text.Row; 61 import com.lowagie.text.Table; 62 import com.lowagie.text.rtf.RtfElement; 63 import com.lowagie.text.rtf.document.RtfDocument; 64 import com.lowagie.text.rtf.text.RtfParagraph; 65 66 67 77 public class RtfTable extends RtfElement { 78 79 82 private ArrayList rows = null; 83 86 private float tableWidthPercent = 80; 87 90 private float[] proportionalWidths = null; 91 94 private float cellPadding = 0; 95 98 private float cellSpacing = 0; 99 102 private RtfBorderGroup borders = null; 103 106 private int alignment = Element.ALIGN_CENTER; 107 110 private boolean cellsFitToPage = false; 111 114 private boolean tableFitToPage = false; 115 118 private int headerRows = 0; 119 120 126 public RtfTable(RtfDocument doc, Table table) { 127 super(doc); 128 table.complete(); 129 importTable(table); 130 } 131 132 138 private void importTable(Table table) { 139 this.rows = new ArrayList (); 140 this.tableWidthPercent = table.getWidth(); 141 this.proportionalWidths = table.getProportionalWidths(); 142 this.cellPadding = (float) (table.getPadding() * TWIPS_FACTOR); 143 this.cellSpacing = (float) (table.getSpacing() * TWIPS_FACTOR); 144 this.borders = new RtfBorderGroup(this.document, RtfBorder.ROW_BORDER, table.getBorder(), table.getBorderWidth(), table.getBorderColor()); 145 this.alignment = table.getAlignment(); 146 147 int i = 0; 148 Iterator rowIterator = table.iterator(); 149 while(rowIterator.hasNext()) { 150 this.rows.add(new RtfRow(this.document, this, (Row) rowIterator.next(), i)); 151 i++; 152 } 153 for(i = 0; i < this.rows.size(); i++) { 154 ((RtfRow) this.rows.get(i)).handleCellSpanning(); 155 ((RtfRow) this.rows.get(i)).cleanRow(); 156 } 157 this.headerRows = table.getLastHeaderRow(); 158 this.cellsFitToPage = table.isCellsFitPage(); 159 this.tableFitToPage = table.isTableFitsPage(); 160 } 161 162 168 public byte[] write() 169 { 170 ByteArrayOutputStream result = new ByteArrayOutputStream (); 171 try { 172 writeContent(result); 173 } catch(IOException ioe) { 174 ioe.printStackTrace(); 175 } 176 return result.toByteArray(); 177 } 178 181 public void writeContent(final OutputStream result) throws IOException 182 { 183 if(!inHeader) { 184 result.write(RtfParagraph.PARAGRAPH); 185 } 186 187 for(int i = 0; i < this.rows.size(); i++) { 188 RtfElement re = (RtfElement)this.rows.get(i); 189 re.writeContent(result); 191 } 192 193 result.write(RtfParagraph.PARAGRAPH_DEFAULTS); 194 } 195 196 201 protected int getAlignment() { 202 return alignment; 203 } 204 205 210 protected RtfBorderGroup getBorders() { 211 return this.borders; 212 } 213 214 219 protected float getCellPadding() { 220 return cellPadding; 221 } 222 223 228 protected float getCellSpacing() { 229 return cellSpacing; 230 } 231 232 237 protected float[] getProportionalWidths() { 238 return (float[]) proportionalWidths.clone(); 239 } 240 241 246 protected float getTableWidthPercent() { 247 return tableWidthPercent; 248 } 249 250 255 protected ArrayList getRows() { 256 return this.rows; 257 } 258 259 264 protected boolean getCellsFitToPage() { 265 return this.cellsFitToPage; 266 } 267 268 273 protected boolean getTableFitToPage() { 274 return this.tableFitToPage; 275 } 276 277 282 protected int getHeaderRows() { 283 return this.headerRows; 284 } 285 } 286 | Popular Tags |