1 17 18 19 20 21 27 28 package org.apache.fop.render.rtf.rtflib.testdocs; 29 30 import java.io.IOException ; 31 32 import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfDocumentArea; 33 import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfSection; 34 import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTable; 35 import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfParagraph; 36 import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTableRow; 37 import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTableCell; 38 39 42 43 class NestedTable extends TestDocument { 44 private static final int MM_TO_TWIPS = (int)(1440f / 25.4f); 45 46 47 protected void generateDocument(RtfDocumentArea rda, RtfSection sect) 48 throws IOException { 49 sect.newParagraph().newText("This document demonstrates pseudo-nested " 50 + "tables created using merged table cells"); 51 52 firstTestTable(sect); 53 RtfParagraph p = sect.newParagraph(); 54 p.newText("Test continues on next page."); 55 p.newPageBreak(); 56 secondTestTable(sect); 57 58 p = sect.newParagraph(); 59 p.newText("Test continues on next page."); 60 p.newPageBreak(); 61 thirdTestTable(sect); 62 63 sect.newParagraph().newText("End of nested tables test document"); 64 } 65 66 private void firstTestTable(RtfSection sect) 67 throws IOException { 68 69 sect.newParagraph().newText("First test: table with one nested table in cell 1,1"); 70 final RtfTable tbl = sect.newTable(new DummyTableColumnsInfo()); 71 { 73 RtfTableRow r = tbl.newTableRow(); 74 RtfTableCell c = r.newTableCell(160 * MM_TO_TWIPS); 75 c.newParagraph().newText("cell 0,0, width 160mm, only cell in this row."); 76 } 77 78 { 80 RtfTableRow r = tbl.newTableRow(); 81 r.newTableCell(40 * MM_TO_TWIPS).newParagraph().newText 82 ("cell 1,0, width 40mm, to the left of nested table."); 83 84 final RtfTableCell c = r.newTableCell(80 * MM_TO_TWIPS); 85 c.newParagraph().newText("cell 1,1, width 80mm, this text is " 86 + "followed by a nested table in the same cell, followed " 87 + "by text that says 'AFTER NESTED TABLE'."); 88 fillNestedTable(c.newTable(new DummyTableColumnsInfo()), 1); 89 c.newParagraph().newText("AFTER NESTED TABLE"); 90 91 r.newTableCell(40 * MM_TO_TWIPS).newParagraph().newText 92 ("cell 1,2, width 40mm, to the right of nested table."); 93 } 94 95 { 97 RtfTableRow r = tbl.newTableRow(); 98 r.newTableCell(80 * MM_TO_TWIPS).newParagraph().newText 99 ("cell 2,0, width 80mm, this row has two cells."); 100 r.newTableCell(80 * MM_TO_TWIPS).newParagraph().newText 101 ("cell 2,1, width 80mm, last cell."); 102 } 103 104 } 105 106 private void secondTestTable(RtfSection sect) 107 throws IOException { 108 sect.newParagraph().newText("Second test: table with two nested tables in cell 1,1"); 109 final RtfTable tbl = sect.newTable(new DummyTableColumnsInfo()); 110 { 112 RtfTableRow r = tbl.newTableRow(); 113 RtfTableCell c = r.newTableCell(160 * MM_TO_TWIPS); 114 c.newParagraph().newText("second test table: cell 0,0, width 160mm, " 115 + "only cell in this row."); 116 } 117 118 { 120 RtfTableRow r = tbl.newTableRow(); 121 r.newTableCell(40 * MM_TO_TWIPS).newParagraph().newText 122 ("cell 1,0, width 40mm, to the left of nested tables."); 123 124 final RtfTableCell c = r.newTableCell(80 * MM_TO_TWIPS); 125 c.newParagraph().newText("cell 1,1, width 80mm, this text is " 126 + "followed by a nested table in the same cell, followed " 127 + "by text that says 'BETWEEN', then another table, then 'AFTER'."); 128 fillNestedTable(c.newTable(new DummyTableColumnsInfo()), 2); 129 c.newParagraph().newText("BETWEEN"); 130 fillNestedTable(c.newTable(new DummyTableColumnsInfo()), 3); 131 c.newParagraph().newText("AFTER"); 132 133 r.newTableCell(40 * MM_TO_TWIPS).newParagraph().newText 134 ("cell 1,2, width 40mm, to the right of nested table."); 135 } 136 137 { 139 RtfTableRow r = tbl.newTableRow(); 140 r.newTableCell(80 * MM_TO_TWIPS).newParagraph().newText 141 ("cell 2,0, width 80mm, this row has two cells."); 142 r.newTableCell(80 * MM_TO_TWIPS).newParagraph().newText 143 ("cell 2,1, width 80mm, last cell."); 144 } 145 } 146 147 private void thirdTestTable(RtfSection sect) 148 throws IOException { 149 sect.newParagraph().newText("Third test: table with two nested tables " 150 + "in cell 1,1 and one nested table in cell 0,1"); 151 final RtfTable tbl = sect.newTable(new DummyTableColumnsInfo()); 152 { 154 RtfTableRow r = tbl.newTableRow(); 155 RtfTableCell c = r.newTableCell(80 * MM_TO_TWIPS); 156 c.newParagraph().newText("third test table: cell 0,0, width 40mm, " 157 + "the cell to its right contains a nested table with no other text."); 158 c = r.newTableCell(80 * MM_TO_TWIPS); 159 fillNestedTable(c.newTable(new DummyTableColumnsInfo()), 4); 160 } 161 162 { 164 RtfTableRow r = tbl.newTableRow(); 165 r.newTableCell(40 * MM_TO_TWIPS).newParagraph().newText 166 ("cell 1,0, width 40mm, to the left of nested tables."); 167 168 final RtfTableCell c = r.newTableCell(80 * MM_TO_TWIPS); 169 c.newParagraph().newText("cell 1,1, width 80mm, this text is " 170 + "followed by a nested table in the same cell, followed " 171 + "by text that says 'BETWEEN', then another table, then 'AFTER'."); 172 fillNestedTable(c.newTable(new DummyTableColumnsInfo()), 5); 173 c.newParagraph().newText("BETWEEN"); 174 fillNestedTable(c.newTable(new DummyTableColumnsInfo()), 6); 175 c.newParagraph().newText("AFTER"); 176 177 r.newTableCell(40 * MM_TO_TWIPS).newParagraph().newText 178 ("cell 1,2, width 40mm, to the right of nested table."); 179 } 180 181 { 183 RtfTableRow r = tbl.newTableRow(); 184 r.newTableCell(80 * MM_TO_TWIPS).newParagraph().newText 185 ("cell 2,0, width 80mm, this row has two cells."); 186 r.newTableCell(80 * MM_TO_TWIPS).newParagraph().newText 187 ("cell 2,1, width 80mm, last cell."); 188 } 189 } 190 191 192 private void fillNestedTable(RtfTable tbl, int index) 193 throws IOException { 194 final String id = "TABLE " + index; 195 { 196 RtfTableRow r = tbl.newTableRow(); 197 r.newTableCell(80 * MM_TO_TWIPS).newParagraph().newText( 198 id + ":nested cell 0,0. Nested table contains 3 rows with 1,2 and 3 cells respectively" 199 ); 200 } 201 202 { 203 RtfTableRow r = tbl.newTableRow(); 204 r.newTableCell(40 * MM_TO_TWIPS).newParagraph().newText(id + ":nested cell 1,0, 40mm."); 205 r.newTableCell(40 * MM_TO_TWIPS).newParagraph().newText(id + ":nested cell 1,1, 40mm."); 206 } 207 208 { 209 RtfTableRow r = tbl.newTableRow(); 210 r.newTableCell(30 * MM_TO_TWIPS).newParagraph().newText(id + ":nested cell 2,0, 30mm."); 211 r.newTableCell(30 * MM_TO_TWIPS).newParagraph().newText(id + ":nested cell 2,1, 30mm."); 212 r.newTableCell(20 * MM_TO_TWIPS).newParagraph().newText(id + ":nested cell 2,2, 20mm."); 213 } 214 } 215 } | Popular Tags |