001: /*
002: * Copyright (c) 1998-2000 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Emil Ong
028: */
029:
030: package com.caucho.xtpdoc;
031:
032: import javax.xml.stream.XMLStreamException;
033: import javax.xml.stream.XMLStreamWriter;
034: import java.io.IOException;
035: import java.io.PrintWriter;
036: import java.util.ArrayList;
037:
038: public class Table extends Node implements ContentItem {
039: private static int _count = 0;
040:
041: private int _myCount = _count++;
042: private Document _document;
043: protected String _title;
044: protected int _columns = 0;
045: protected ArrayList<TableRow> _rows = new ArrayList<TableRow>();
046:
047: public Table(Document document) {
048: _document = document;
049: }
050:
051: public void setTitle(String title) {
052: _title = title;
053: }
054:
055: public TableRow createTr() {
056: TableRow row = new TableRow(_document);
057: _rows.add(row);
058: return row;
059: }
060:
061: public void writeHtml(XMLStreamWriter out)
062: throws XMLStreamException {
063: out.writeStartElement("table");
064:
065: int index = 0;
066: for (TableRow row : _rows)
067: row.writeHtml(out, index++);
068:
069: out.writeEndElement();
070: }
071:
072: protected void writeRows(PrintWriter out) throws IOException {
073: for (TableRow row : _rows)
074: row.writeLaTeX(out);
075: }
076:
077: public void writeLaTeX(PrintWriter out) throws IOException {
078: for (TableRow row : _rows)
079: _columns = Math.max(_columns, row.getNumberOfColumns());
080:
081: out.println("\\begin{filecontents}{ltx" + _myCount + ".tex}");
082: out.print("\\begin{longtable}");
083:
084: out.print("{");
085:
086: for (int i = 0; i < _columns; i++)
087: out.print("X");
088:
089: out.println("}");
090:
091: writeRows(out);
092:
093: out.println("\\end{longtable}");
094: out.println("\\end{filecontents}");
095:
096: out.println("\\begin{center}");
097:
098: out.println("\\LTXtable{\\linewidth}{ltx" + _myCount + "}");
099:
100: if (_title != null)
101: out.println("\\textbf{" + LaTeXUtil.escapeForLaTeX(_title)
102: + "}");
103:
104: out.println("\\end{center}");
105: }
106:
107: public void writeLaTeXEnclosed(PrintWriter out) throws IOException {
108: writeLaTeX(out);
109: }
110:
111: public void writeLaTeXTop(PrintWriter out) throws IOException {
112: writeLaTeX(out);
113: }
114: }
|