KickJava   Java API By Example, From Geeks To Geeks.

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


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: RtfSection.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 /** Models a section in an RTF document
33  * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
34  */

35
36 public class RtfSection
37 extends RtfContainer
38 implements
39     IRtfParagraphContainer,
40     IRtfTableContainer,
41     IRtfListContainer,
42     IRtfExternalGraphicContainer,
43     IRtfBeforeContainer,
44     IRtfParagraphKeepTogetherContainer,
45     IRtfAfterContainer,
46     IRtfJforCmdContainer,
47     IRtfTextrunContainer {
48     private RtfParagraph paragraph;
49     private RtfTable table;
50     private RtfList list;
51     private RtfExternalGraphic externalGraphic;
52     private RtfBefore before;
53     private RtfAfter after;
54     private RtfJforCmd jforCmd;
55
56     /** Create an RTF container as a child of given container */
57     RtfSection(RtfDocumentArea parent, Writer JavaDoc w) throws IOException JavaDoc {
58         super(parent, w);
59     }
60
61     /**
62      * Start a new external graphic after closing current paragraph, list and table
63      * @return new RtfExternalGraphic object
64      * @throws IOException for I/O problems
65      */

66     public RtfExternalGraphic newImage() throws IOException JavaDoc {
67         closeAll();
68         externalGraphic = new RtfExternalGraphic(this, writer);
69         return externalGraphic;
70     }
71
72     /**
73      * Start a new paragraph after closing current paragraph, list and table
74      * @param attrs attributes for new RtfParagraph
75      * @return new RtfParagraph object
76      * @throws IOException for I/O problems
77      */

78     public RtfParagraph newParagraph(RtfAttributes attrs) throws IOException JavaDoc {
79         closeAll();
80         paragraph = new RtfParagraph(this, writer, attrs);
81         return paragraph;
82     }
83
84     /**
85      * Close current paragraph if any and start a new one with default attributes
86      * @return new RtfParagraph
87      * @throws IOException for I/O problems
88      */

89     public RtfParagraph newParagraph() throws IOException JavaDoc {
90         return newParagraph(null);
91     }
92
93     /**
94      * Close current paragraph if any and start a new one
95      * @return new RtfParagraphKeepTogether
96      * @throws IOException for I/O problems
97      */

98     public RtfParagraphKeepTogether newParagraphKeepTogether() throws IOException JavaDoc {
99         return new RtfParagraphKeepTogether(this, writer);
100     }
101
102     /**
103      * Start a new table after closing current paragraph, list and table
104      * @param tc Table context used for number-columns-spanned attribute (added by
105      * Boris Poudérous on july 2002)
106      * @return new RtfTable object
107      * @throws IOException for I/O problems
108      */

109     public RtfTable newTable(ITableColumnsInfo tc) throws IOException JavaDoc {
110         closeAll();
111         table = new RtfTable(this, writer, tc);
112         return table;
113     }
114
115     /**
116      * Start a new table after closing current paragraph, list and table
117      * @param attrs attributes of new RtfTable
118      * @param tc Table context used for number-columns-spanned attribute (added by
119      * Boris Poudérous on july 2002)
120      * @return new RtfTable object
121      * @throws IOException for I/O problems
122      */

123     public RtfTable newTable(RtfAttributes attrs, ITableColumnsInfo tc) throws IOException JavaDoc {
124         closeAll();
125         table = new RtfTable(this, writer, attrs, tc);
126         return table;
127     }
128
129     /**
130      * Start a new list after closing current paragraph, list and table
131      * @param attrs attributes of new RftList object
132      * @return new RtfList
133      * @throws IOException for I/O problems
134      */

135     public RtfList newList(RtfAttributes attrs) throws IOException JavaDoc {
136         closeAll();
137         list = new RtfList(this, writer, attrs);
138         return list;
139     }
140
141     /**
142      * IRtfBeforeContainer
143      * @param attrs attributes of new RtfBefore object
144      * @return new RtfBefore object
145      * @throws IOException for I/O problems
146      */

147     public RtfBefore newBefore(RtfAttributes attrs) throws IOException JavaDoc {
148         closeAll();
149         before = new RtfBefore(this, writer, attrs);
150         return before;
151     }
152
153     /**
154      * IRtfAfterContainer
155      * @param attrs attributes of new RtfAfter object
156      * @return new RtfAfter object
157      * @throws IOException for I/O problems
158      */

159     public RtfAfter newAfter(RtfAttributes attrs) throws IOException JavaDoc {
160         closeAll();
161         after = new RtfAfter(this, writer, attrs);
162         return after;
163     }
164
165     /**
166      *
167      * @param attrs attributes of new RtfJforCmd
168      * @return the new RtfJforCmd
169      * @throws IOException for I/O problems
170      */

171     public RtfJforCmd newJforCmd(RtfAttributes attrs) throws IOException JavaDoc {
172         jforCmd = new RtfJforCmd(this, writer, attrs);
173         return jforCmd;
174     }
175
176
177
178     /**
179      * Can be overridden to write RTF prefix code, what comes before our children
180      * @throws IOException for I/O problems
181      */

182     protected void writeRtfPrefix() throws IOException JavaDoc {
183         writeAttributes(attrib, RtfPage.PAGE_ATTR);
184         newLine();
185         writeControlWord("sectd");
186     }
187
188     /**
189      * Can be overridden to write RTF suffix code, what comes after our children
190      * @throws IOException for I/O problems
191      */

192     protected void writeRtfSuffix() throws IOException JavaDoc {
193         writeControlWord("sect");
194     }
195
196     private void closeCurrentTable() throws IOException JavaDoc {
197         if (table != null) {
198             table.close();
199         }
200     }
201
202     private void closeCurrentParagraph() throws IOException JavaDoc {
203         if (paragraph != null) {
204             paragraph.close();
205         }
206     }
207
208     private void closeCurrentList() throws IOException JavaDoc {
209         if (list != null) {
210             list.close();
211         }
212     }
213
214     private void closeCurrentExternalGraphic() throws IOException JavaDoc {
215         if (externalGraphic != null) {
216             externalGraphic.close();
217         }
218     }
219
220     private void closeCurrentBefore() throws IOException JavaDoc {
221         if (before != null) {
222             before.close();
223         }
224     }
225
226     private void closeAll()
227     throws IOException JavaDoc {
228         closeCurrentTable();
229         closeCurrentParagraph();
230         closeCurrentList();
231         closeCurrentExternalGraphic();
232         closeCurrentBefore();
233     }
234     
235     /**
236      * Returns the current RtfTextrun.
237      * @return Current RtfTextrun
238      * @throws IOException Thrown when an IO-problem occurs.
239      */

240     public RtfTextrun getTextrun()
241     throws IOException JavaDoc {
242         return RtfTextrun.getTextrun(this, writer, null);
243     }
244 }
245
Popular Tags