1 47 48 package com.lowagie.text.html.simpleparser; 49 50 import java.util.ArrayList ; 51 import java.util.Collections ; 52 import java.util.HashMap ; 53 54 import com.lowagie.text.pdf.PdfPCell; 55 import com.lowagie.text.pdf.PdfPTable; 56 57 61 public class IncTable { 62 private HashMap props = new HashMap (); 63 private ArrayList rows = new ArrayList (); 64 private ArrayList cols; 65 66 public IncTable(HashMap props) { 67 this.props.putAll(props); 68 } 69 70 public void addCol(PdfPCell cell) { 71 if (cols == null) 72 cols = new ArrayList (); 73 cols.add(cell); 74 } 75 76 public void addCols(ArrayList ncols) { 77 if (cols == null) 78 cols = new ArrayList (ncols); 79 else 80 cols.addAll(ncols); 81 } 82 83 public void endRow() { 84 if (cols != null) { 85 Collections.reverse(cols); 86 rows.add(cols); 87 cols = null; 88 } 89 } 90 91 public ArrayList getRows() { 92 return rows; 93 } 94 95 public PdfPTable buildTable() { 96 if (rows.isEmpty()) 97 return new PdfPTable(1); 98 int ncol = 0; 99 ArrayList c0 = (ArrayList )rows.get(0); 100 for (int k = 0; k < c0.size(); ++k) { 101 ncol += ((PdfPCell)c0.get(k)).getColspan(); 102 } 103 PdfPTable table = new PdfPTable(ncol); 104 String width = (String )props.get("width"); 105 if (width == null) 106 table.setWidthPercentage(100); 107 else { 108 if (width.endsWith("%")) 109 table.setWidthPercentage(Float.parseFloat(width.substring(0, width.length() - 1))); 110 else { 111 table.setTotalWidth(Float.parseFloat(width)); 112 table.setLockedWidth(true); 113 } 114 } 115 for (int row = 0; row < rows.size(); ++row) { 116 ArrayList col = (ArrayList )rows.get(row); 117 for (int k = 0; k < col.size(); ++k) { 118 table.addCell((PdfPCell)col.get(k)); 119 } 120 } 121 return table; 122 } 123 } 124 | Popular Tags |