001: /*
002: * Copyright 2004 Paulo Soares
003: *
004: * The contents of this file are subject to the Mozilla Public License Version 1.1
005: * (the "License"); you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
007: *
008: * Software distributed under the License is distributed on an "AS IS" basis,
009: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
010: * for the specific language governing rights and limitations under the License.
011: *
012: * The Original Code is 'iText, a free JAVA-PDF library'.
013: *
014: * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
015: * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
016: * All Rights Reserved.
017: * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
018: * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
019: *
020: * Contributor(s): all the names of the contributors are added in the source code
021: * where applicable.
022: *
023: * Alternatively, the contents of this file may be used under the terms of the
024: * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
025: * provisions of LGPL are applicable instead of those above. If you wish to
026: * allow use of your version of this file only under the terms of the LGPL
027: * License and not to allow others to use your version of this file under
028: * the MPL, indicate your decision by deleting the provisions above and
029: * replace them with the notice and other provisions required by the LGPL.
030: * If you do not delete the provisions above, a recipient may use your version
031: * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
032: *
033: * This library is free software; you can redistribute it and/or modify it
034: * under the terms of the MPL as stated above or under the terms of the GNU
035: * Library General Public License as published by the Free Software Foundation;
036: * either version 2 of the License, or any later version.
037: *
038: * This library is distributed in the hope that it will be useful, but WITHOUT
039: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
040: * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
041: * details.
042: *
043: * If you didn't download this code from the following link, you should check if
044: * you aren't using an obsolete version:
045: * http://www.lowagie.com/iText/
046: */
047:
048: package com.lowagie.text.html.simpleparser;
049:
050: import java.util.ArrayList;
051: import java.util.Collections;
052: import java.util.HashMap;
053:
054: import com.lowagie.text.pdf.PdfPCell;
055: import com.lowagie.text.pdf.PdfPTable;
056:
057: /**
058: *
059: * @author psoares
060: */
061: public class IncTable {
062: private HashMap props = new HashMap();
063: private ArrayList rows = new ArrayList();
064: private ArrayList cols;
065:
066: /** Creates a new instance of IncTable */
067: public IncTable(HashMap props) {
068: this .props.putAll(props);
069: }
070:
071: public void addCol(PdfPCell cell) {
072: if (cols == null)
073: cols = new ArrayList();
074: cols.add(cell);
075: }
076:
077: public void addCols(ArrayList ncols) {
078: if (cols == null)
079: cols = new ArrayList(ncols);
080: else
081: cols.addAll(ncols);
082: }
083:
084: public void endRow() {
085: if (cols != null) {
086: Collections.reverse(cols);
087: rows.add(cols);
088: cols = null;
089: }
090: }
091:
092: public ArrayList getRows() {
093: return rows;
094: }
095:
096: public PdfPTable buildTable() {
097: if (rows.isEmpty())
098: return new PdfPTable(1);
099: int ncol = 0;
100: ArrayList c0 = (ArrayList) rows.get(0);
101: for (int k = 0; k < c0.size(); ++k) {
102: ncol += ((PdfPCell) c0.get(k)).getColspan();
103: }
104: PdfPTable table = new PdfPTable(ncol);
105: String width = (String) props.get("width");
106: if (width == null)
107: table.setWidthPercentage(100);
108: else {
109: if (width.endsWith("%"))
110: table.setWidthPercentage(Float.parseFloat(width
111: .substring(0, width.length() - 1)));
112: else {
113: table.setTotalWidth(Float.parseFloat(width));
114: table.setLockedWidth(true);
115: }
116: }
117: for (int row = 0; row < rows.size(); ++row) {
118: ArrayList col = (ArrayList) rows.get(row);
119: for (int k = 0; k < col.size(); ++k) {
120: table.addCell((PdfPCell) col.get(k));
121: }
122: }
123: return table;
124: }
125: }
|