1 50 51 package com.lowagie.text.rtf; 52 53 import java.io.ByteArrayOutputStream ; 54 import java.io.IOException ; 55 import java.util.ArrayList ; 56 import java.util.Iterator ; 57 58 import com.lowagie.text.DocumentException; 59 import com.lowagie.text.Element; 60 import com.lowagie.text.Row; 61 import com.lowagie.text.Table; 62 63 75 public class RtfTable { 76 77 private ArrayList rowsList = new ArrayList (); 78 79 private RtfWriter writer = null; 80 81 private Table origTable = null; 82 83 84 85 90 public RtfTable(RtfWriter writer) { 91 super(); 92 this.writer = writer; 93 } 94 95 102 public boolean importTable(Table table, int pageWidth) { 103 origTable = table; 104 Iterator rows = table.iterator(); 106 Row row = null; 107 108 int tableWidth = (int) table.getWidth(); 109 int cellpadding = (int) (table.getPadding() * RtfWriter.TWIPSFACTOR); 110 int cellspacing = (int) (table.getSpacing() * RtfWriter.TWIPSFACTOR); 111 float[] propWidths = table.getProportionalWidths(); 112 113 int borders = table.getBorder(); 114 java.awt.Color borderColor = table.getBorderColor(); 115 float borderWidth = table.getBorderWidth(); 116 117 for (int i = 0; i < table.size(); i++) { 118 RtfRow rtfRow = new RtfRow(writer, this); 119 rtfRow.pregenerateRows(table.getColumns()); 120 rowsList.add(rtfRow); 121 } 122 int i = 0; 123 while (rows.hasNext()) { 124 row = (Row) rows.next(); 125 row.setHorizontalAlignment(table.getAlignment()); 126 RtfRow rtfRow = (RtfRow) rowsList.get(i); 127 rtfRow.importRow(row, propWidths, tableWidth, pageWidth, cellpadding, cellspacing, borders, borderColor, borderWidth, i); 128 i++; 129 } 130 return true; 131 } 132 133 141 public boolean writeTable(ByteArrayOutputStream os) throws DocumentException, IOException { 142 143 if(!this.writer.writingHeaderFooter()) { 144 os.write(RtfWriter.escape); 147 os.write(RtfWriter.paragraph); 148 } 149 150 int size = rowsList.size(); 151 for (int i = 0; i < size; i++) { 152 RtfRow row = (RtfRow) rowsList.get(i); 153 row.writeRow(os, i, origTable); 154 os.write((byte) '\n'); 155 } 156 if (!writer.writingHeaderFooter()) { 157 os.write(RtfWriter.escape); 158 os.write(RtfWriter.paragraphDefaults); 159 os.write(RtfWriter.escape); 160 os.write(RtfWriter.paragraph); 161 switch (origTable.getAlignment()) { 162 case Element.ALIGN_LEFT: 163 os.write(RtfWriter.escape); 164 os.write(RtfWriter.alignLeft); 165 break; 166 case Element.ALIGN_RIGHT: 167 os.write(RtfWriter.escape); 168 os.write(RtfWriter.alignRight); 169 break; 170 case Element.ALIGN_CENTER: 171 os.write(RtfWriter.escape); 172 os.write(RtfWriter.alignCenter); 173 break; 174 case Element.ALIGN_JUSTIFIED: 175 case Element.ALIGN_JUSTIFIED_ALL: 176 os.write(RtfWriter.escape); 177 os.write(RtfWriter.alignJustify); 178 break; 179 } 180 } 181 return true; 182 } 183 184 192 public void setMerge(int x, int y, int mergeType, RtfCell mergeCell) { 193 RtfRow row = (RtfRow) rowsList.get(y); 194 row.setMerge(x, mergeType, mergeCell); 195 } 196 197 202 protected Table getOriginalTable() { 203 return origTable; 204 } 205 } 206 | Popular Tags |