KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > render > rtf > rtflib > rtfdoc > RtfTable


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: RtfTable.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.render.rtf.rtflib.rtfdoc;
21
22 /*
23  * This file is part of the RTF library of the FOP project, which was originally
24  * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
25  * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
26  * the FOP project.
27  */

28
29 import java.io.Writer JavaDoc;
30 import java.io.IOException JavaDoc;
31
32 /** Container for RtfRow elements
33  * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
34  */

35
36 public class RtfTable extends RtfContainer {
37     private RtfTableRow row;
38     private int highestRow = 0;
39     private Boolean JavaDoc isNestedTable = null;
40     private RtfAttributes borderAttributes = null;
41
42     /** Added by Boris Poudérous on 07/22/2002 in order to process
43      * number-columns-spanned attribute */

44     private ITableColumnsInfo tableContext;
45
46     /** Create an RTF element as a child of given container */
47     RtfTable(IRtfTableContainer parent, Writer JavaDoc w, ITableColumnsInfo tc)
48             throws IOException JavaDoc {
49         super((RtfContainer)parent, w);
50         // Line added by Boris Poudérous on 07/22/2002
51
tableContext = tc;
52     }
53
54     /** Create an RTF element as a child of given container
55    * Modified by Boris Poudérous in order to process 'number-columns-spanned' attribute
56    */

57   RtfTable(IRtfTableContainer parent, Writer JavaDoc w, RtfAttributes attrs,
58            ITableColumnsInfo tc) throws IOException JavaDoc {
59         super((RtfContainer)parent, w, attrs);
60     // Line added by Boris Poudérous on 07/22/2002
61
tableContext = tc;
62     }
63
64     /**
65      * Close current row if any and start a new one
66      * @return new RtfTableRow
67      * @throws IOException for I/O problems
68      */

69     public RtfTableRow newTableRow() throws IOException JavaDoc {
70         if (row != null) {
71             row.close();
72         }
73
74         highestRow++;
75         row = new RtfTableRow(this, writer, attrib, highestRow);
76         return row;
77     }
78
79     /**
80      * Close current row if any and start a new one
81      * @param attrs attributs of new RtfTableRow
82      * @return new RtfTableRow
83      * @throws IOException for I/O problems
84      */

85     public RtfTableRow newTableRow(RtfAttributes attrs) throws IOException JavaDoc {
86         RtfAttributes attr = null;
87         if (attrib != null) {
88             attr = (RtfAttributes) attrib.clone ();
89             attr.set (attrs);
90         } else {
91             attr = attrs;
92         }
93         if (row != null) {
94             row.close();
95         }
96         highestRow++;
97
98         row = new RtfTableRow(this, writer, attr, highestRow);
99         return row;
100     }
101
102
103
104     /**
105      * Overridden to write RTF prefix code, what comes before our children
106      * @throws IOException for I/O problems
107      */

108     protected void writeRtfPrefix() throws IOException JavaDoc {
109         if (isNestedTable()) {
110             writeControlWordNS("pard");
111         }
112
113         writeGroupMark(true);
114     }
115     
116     /**
117      * Overridden to write RTF suffix code, what comes after our children
118      * @throws IOException for I/O problems
119      */

120     protected void writeRtfSuffix() throws IOException JavaDoc {
121         writeGroupMark(false);
122         
123         if (isNestedTable()) {
124             getRow().writeRowAndCellsDefintions();
125         }
126     }
127
128     /**
129      *
130      * @param id row to check (??)
131      * @return true if id is the highestRow
132      */

133     public boolean isHighestRow(int id) {
134         return (highestRow == id) ? true : false;
135     }
136
137     /**
138      * Added by Boris Poudérous on 07/22/2002
139      * @return ITableColumnsInfo for this table
140      */

141     public ITableColumnsInfo getITableColumnsInfo() {
142       return this.tableContext;
143     }
144
145     private RtfAttributes headerAttribs = null;
146
147     /**
148      * Added by Normand Masse
149      * Support for table-header attributes (used instead of table attributes)
150      * @param attrs attributes to be set
151      */

152     public void setHeaderAttribs(RtfAttributes attrs) {
153         headerAttribs = attrs;
154     }
155
156     /**
157      *
158      * @return RtfAttributes of Header
159      */

160     public RtfAttributes getHeaderAttribs() {
161         return headerAttribs;
162     }
163
164     /**
165      * Added by Normand Masse
166      * @return the table-header attributes if they are present, otherwise the
167      * parent's attributes are returned normally.
168      */

169     public RtfAttributes getRtfAttributes() {
170         if (headerAttribs != null) {
171             return headerAttribs;
172         }
173
174         return super.getRtfAttributes();
175     }
176     
177     /** @return true if the the table is a nested table */
178     public boolean isNestedTable() {
179         if (isNestedTable == null) {
180             RtfElement e = this;
181             while (e.parent != null) {
182                 if (e.parent instanceof RtfTableCell) {
183                     isNestedTable = Boolean.TRUE;
184                     return true;
185                 }
186
187                 e = e.parent;
188             }
189
190             isNestedTable = Boolean.FALSE;
191         } else {
192             return isNestedTable.booleanValue();
193         }
194
195         return false;
196     }
197     
198     /**
199      *
200      * @return Parent row table (for nested tables only)
201      */

202     public RtfTableRow getRow() {
203         RtfElement e = this;
204         while (e.parent != null) {
205             if (e.parent instanceof RtfTableRow) {
206                 return (RtfTableRow) e.parent;
207             }
208
209             e = e.parent;
210         }
211
212         return null;
213     }
214
215     /**
216      * Sets the RtfAttributes for the borders of the table.
217      * @param attributes Border attributes of the table.
218      */

219     public void setBorderAttributes(RtfAttributes attributes) {
220         borderAttributes = attributes;
221     }
222     
223     /**
224      * Returns the RtfAttributes for the borders of the table.
225      * @return Border attributes of the table.
226      */

227     public RtfAttributes getBorderAttributes() {
228         return borderAttributes;
229     }
230 }
231
Popular Tags