1 29 30 package com.caucho.xtpdoc; 31 32 import javax.xml.stream.XMLStreamException; 33 import javax.xml.stream.XMLStreamWriter; 34 import java.io.IOException ; 35 import java.io.PrintWriter ; 36 import java.util.ArrayList ; 37 38 public class Table extends Node implements ContentItem { 39 private static int _count = 0; 40 41 private int _myCount = _count++; 42 private Document _document; 43 protected String _title; 44 protected int _columns = 0; 45 protected ArrayList <TableRow> _rows = new ArrayList <TableRow>(); 46 47 public Table(Document document) 48 { 49 _document = document; 50 } 51 52 public void setTitle(String title) 53 { 54 _title = title; 55 } 56 57 public TableRow createTr() 58 { 59 TableRow row = new TableRow(_document); 60 _rows.add(row); 61 return row; 62 } 63 64 public void writeHtml(XMLStreamWriter out) 65 throws XMLStreamException 66 { 67 out.writeStartElement("table"); 68 69 for (TableRow row : _rows) 70 row.writeHtml(out); 71 72 out.writeEndElement(); 73 } 74 75 protected void writeRows(PrintWriter out) 76 throws IOException 77 { 78 for (TableRow row : _rows) 79 row.writeLaTeX(out); 80 } 81 82 public void writeLaTeX(PrintWriter out) 83 throws IOException 84 { 85 for (TableRow row : _rows) 86 _columns = Math.max(_columns, row.getNumberOfColumns()); 87 88 out.println("\\begin{filecontents}{ltx" + _myCount + ".tex}"); 89 out.print("\\begin{longtable}"); 90 91 out.print("{"); 92 93 for (int i = 0; i < _columns; i++) 94 out.print("X"); 95 96 out.println("}"); 97 98 writeRows(out); 99 100 out.println("\\end{longtable}"); 101 out.println("\\end{filecontents}"); 102 103 104 out.println("\\begin{center}"); 105 106 out.println("\\LTXtable{\\linewidth}{ltx" + _myCount + "}"); 107 108 if (_title != null) 109 out.println("\\textbf{" + LaTeXUtil.escapeForLaTeX(_title) + "}"); 110 111 out.println("\\end{center}"); 112 } 113 114 public void writeLaTeXEnclosed(PrintWriter out) 115 throws IOException 116 { 117 writeLaTeX(out); 118 } 119 120 public void writeLaTeXTop(PrintWriter out) 121 throws IOException 122 { 123 writeLaTeX(out); 124 } 125 } 126 | Popular Tags |