KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > render > rtf > rtflib > testdocs > MergedTableCells


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: MergedTableCells.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20
21 /*
22  * This file is part of the RTF library of the FOP project, which was originally
23  * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
24  * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
25  * the FOP project.
26  */

27
28 package org.apache.fop.render.rtf.rtflib.testdocs;
29
30 import java.io.IOException JavaDoc;
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.RtfTableRow;
36 import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTableCell;
37
38 /** Generates an RTF test document containing merged table cells
39  * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
40  */

41
42 class MergedTableCells extends TestDocument {
43     static final int MM_TO_TWIPS = (int)(1440f / 25.4f);
44
45     /** generate the body of the test document */
46     protected void generateDocument(RtfDocumentArea rda, RtfSection sect)
47     throws IOException JavaDoc {
48         sect.newParagraph().newText("This document contains a table with some merged cells.");
49
50         final RtfTable tbl = sect.newTable(new DummyTableColumnsInfo());
51
52         // first row, test horizontal merging
53
{
54             RtfTableRow r = tbl.newTableRow();
55             RtfTableCell c = r.newTableCell(80 * MM_TO_TWIPS);
56             c.setHMerge(RtfTableCell.MERGE_START);
57             c.newParagraph().newText("cell 0,0, width 80mm, merge start, "
58                     + "followed by two merged cells totalling 80mm width.");
59
60             c = r.newTableCell(40 * MM_TO_TWIPS);
61             c.setHMerge(RtfTableCell.MERGE_WITH_PREVIOUS);
62             c.newParagraph().newText("THIS IS IN AN HMERGED CELL, MUST NOT APPEAR IN RTF DOCUMENT");
63
64             c = r.newTableCell(40 * MM_TO_TWIPS);
65             c.setHMerge(RtfTableCell.MERGE_WITH_PREVIOUS);
66             c.newParagraph().newText("THIS IS IN AN HMERGED CELL, MUST NOT APPEAR IN RTF DOCUMENT");
67         }
68
69         // second row, start vertical merging in column 1
70
{
71             RtfTableRow r = tbl.newTableRow();
72             RtfTableCell c = r.newTableCell(40 * MM_TO_TWIPS);
73             c.setVMerge(RtfTableCell.MERGE_START);
74             c.newParagraph().newText("cell 1,0, vertical merge start, 40mm, spans three rows.");
75
76             r.newTableCell(80 * MM_TO_TWIPS).newParagraph().newText("cell 1,1, no merge, 80mm");
77
78             c = r.newTableCell(40 * MM_TO_TWIPS);
79             c.setVMerge(RtfTableCell.MERGE_START);
80             c.newParagraph().newText("cell 1,2, vertical merge start, 40mm, spans two rows.");
81         }
82
83         // third row, column 1 merged with previous row
84
{
85             RtfTableRow r = tbl.newTableRow();
86             RtfTableCell c = r.newTableCell(40 * MM_TO_TWIPS);
87             c.setVMerge(RtfTableCell.MERGE_WITH_PREVIOUS);
88             c.newParagraph().newText("cell 2,0, VMERGED CELL, MUST NOT APPEAR IN RTF DOCUMENT");
89
90             r.newTableCell(40 * MM_TO_TWIPS).newParagraph().newText("cell 2,1, no merge, 40mm");
91             r.newTableCell(40 * MM_TO_TWIPS).newParagraph().newText("cell 2,2, no merge, 40mm");
92
93             c = r.newTableCell(40 * MM_TO_TWIPS);
94             c.setVMerge(RtfTableCell.MERGE_WITH_PREVIOUS);
95             c.newParagraph().newText("cell 2,3, VMERGED CELL, MUST NOT APPEAR IN RTF DOCUMENT");
96         }
97
98         // fourth row, column 1 merged with previous row
99
{
100             RtfTableRow r = tbl.newTableRow();
101             RtfTableCell c = r.newTableCell(40 * MM_TO_TWIPS);
102             c.setVMerge(RtfTableCell.MERGE_WITH_PREVIOUS);
103             c.newParagraph().newText("cell 3,0, VMERGED CELL, MUST NOT APPEAR IN RTF DOCUMENT");
104
105             r.newTableCell(10 * MM_TO_TWIPS).newParagraph().newText("cell 3,1, no merge, 10mm");
106             r.newTableCell(30 * MM_TO_TWIPS).newParagraph().newText("cell 3,2, no merge, 30mm");
107             r.newTableCell(40 * MM_TO_TWIPS).newParagraph().newText("cell 3,3, no merge, 40mm");
108             r.newTableCell(40 * MM_TO_TWIPS).newParagraph().newText("cell 3,4, no merge, 40mm");
109         }
110
111         // fifth row, just one cell
112
{
113             RtfTableRow r = tbl.newTableRow();
114             r.newTableCell(160 * MM_TO_TWIPS).newParagraph().newText
115                     ("cell 4,0, width 160mm, only cell in this row");
116         }
117     }
118 }
119
Popular Tags