KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > layout > Page


1 /*
2  * $Id: Page.java,v 1.17.2.4 2003/02/25 14:07:04 jeremias Exp $
3  * ============================================================================
4  * The Apache Software License, Version 1.1
5  * ============================================================================
6  *
7  * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without modifica-
10  * tion, are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * 3. The end-user documentation included with the redistribution, if any, must
20  * include the following acknowledgment: "This product includes software
21  * developed by the Apache Software Foundation (http://www.apache.org/)."
22  * Alternately, this acknowledgment may appear in the software itself, if
23  * and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. The names "FOP" and "Apache Software Foundation" must not be used to
26  * endorse or promote products derived from this software without prior
27  * written permission. For written permission, please contact
28  * apache@apache.org.
29  *
30  * 5. Products derived from this software may not be called "Apache", nor may
31  * "Apache" appear in their name, without prior written permission of the
32  * Apache Software Foundation.
33  *
34  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
35  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
36  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
37  * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
38  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
39  * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
40  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
41  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
42  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
43  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44  * ============================================================================
45  *
46  * This software consists of voluntary contributions made by many individuals
47  * on behalf of the Apache Software Foundation and was originally created by
48  * James Tauber <jtauber@jtauber.com>. For more information on the Apache
49  * Software Foundation, please see <http://www.apache.org/>.
50  */

51 package org.apache.fop.layout;
52
53 // FOP
54
import org.apache.fop.render.Renderer;
55 import org.apache.fop.fo.flow.*;
56 import org.apache.fop.datatypes.IDReferences;
57 import org.apache.fop.fo.pagination.PageSequence;
58
59 // Java
60
import java.util.ArrayList JavaDoc;
61
62 /*Modified by Mark Lillywhite mark-fop@inomial.com. Added getIDReferences.
63   This is just a convenience method for renderers who no longer have access
64   to the AreaTree when rendering.
65   */

66
67 public class Page {
68
69     private int height;
70     private int width;
71
72     private BodyAreaContainer body;
73     private AreaContainer before;
74     private AreaContainer after;
75     private AreaContainer start;
76     private AreaContainer end;
77
78     private AreaTree areaTree;
79
80     private ArrayList JavaDoc rootExtensions;
81
82     private PageSequence pageSequence;
83
84     protected int pageNumber = 0;
85     protected String JavaDoc formattedPageNumber;
86
87     protected ArrayList JavaDoc linkSets = new ArrayList JavaDoc();
88
89     private ArrayList JavaDoc idList = new ArrayList JavaDoc();
90
91     private ArrayList JavaDoc footnotes = null;
92
93     private ArrayList JavaDoc markers = null;
94
95     Page(AreaTree areaTree, int height, int width) {
96         this.areaTree = areaTree;
97         this.height = height;
98         this.width = width;
99         markers = new ArrayList JavaDoc();
100     }
101
102     public IDReferences getIDReferences() {
103         return areaTree.getIDReferences();
104     }
105
106     public void setPageSequence(PageSequence pageSequence) {
107         this.pageSequence = pageSequence;
108     }
109
110     public PageSequence getPageSequence() {
111         return pageSequence;
112     }
113
114     public AreaTree getAreaTree() {
115         return areaTree;
116     }
117
118     public void setNumber(int number) {
119         this.pageNumber = number;
120     }
121
122     public int getNumber() {
123         return this.pageNumber;
124     }
125
126     public void setFormattedNumber(String JavaDoc number) {
127         this.formattedPageNumber = number;
128     }
129
130     public String JavaDoc getFormattedNumber() {
131         return this.formattedPageNumber;
132     }
133
134     void addAfter(AreaContainer area) {
135         this.after = area;
136         area.setPage(this);
137     }
138
139     void addBefore(AreaContainer area) {
140         this.before = area;
141         area.setPage(this);
142     }
143
144     /**
145      * Ensure that page is set not only on B.A.C. but also on the
146      * three top-level reference areas.
147      * @param area The region-body area container (special)
148      */

149     public void addBody(BodyAreaContainer area) {
150         this.body = area;
151         area.setPage(this);
152         ((BodyAreaContainer)area).getMainReferenceArea().setPage(this);
153         ((BodyAreaContainer)area).getBeforeFloatReferenceArea().setPage(this);
154         ((BodyAreaContainer)area).getFootnoteReferenceArea().setPage(this);
155     }
156
157     void addEnd(AreaContainer area) {
158         this.end = area;
159         area.setPage(this);
160     }
161
162     void addStart(AreaContainer area) {
163         this.start = area;
164         area.setPage(this);
165     }
166
167     public void render(Renderer renderer) {
168         renderer.renderPage(this);
169     }
170
171     public AreaContainer getAfter() {
172         return this.after;
173     }
174
175     public AreaContainer getBefore() {
176         return this.before;
177     }
178
179     public AreaContainer getStart() {
180         return this.start;
181     }
182
183     public AreaContainer getEnd() {
184         return this.end;
185     }
186
187     public BodyAreaContainer getBody() {
188         return this.body;
189     }
190
191     public int getHeight() {
192         return this.height;
193     }
194
195     public int getWidth() {
196         return this.width;
197     }
198
199     public FontInfo getFontInfo() {
200         return this.areaTree.getFontInfo();
201     }
202
203     public void addLinkSet(LinkSet linkSet) {
204         this.linkSets.add(linkSet);
205     }
206
207     public ArrayList JavaDoc getLinkSets() {
208         return this.linkSets;
209     }
210
211     public boolean hasLinks() {
212         return (!this.linkSets.isEmpty());
213     }
214
215     public void addToIDList(String JavaDoc id) {
216         idList.add(id);
217     }
218
219     public ArrayList JavaDoc getIDList() {
220         return idList;
221     }
222
223     public ArrayList JavaDoc getPendingFootnotes() {
224         return footnotes;
225     }
226
227     public ArrayList JavaDoc getExtensions() {
228         return rootExtensions;
229     }
230
231     public void setExtensions(ArrayList JavaDoc extensions) {
232         this.rootExtensions = extensions;
233     }
234
235     public void setPendingFootnotes(ArrayList JavaDoc v) {
236         footnotes = v;
237         if (footnotes != null) {
238           for (int i = 0; i < footnotes.size(); i++ ) {
239                 FootnoteBody fb = (FootnoteBody)footnotes.get(i);
240                 if (!Footnote.layoutFootnote(this, fb, null)) {
241                     // footnotes are too large to fit on empty page
242
}
243
244             }
245             footnotes = null;
246         }
247     }
248
249     public void addPendingFootnote(FootnoteBody fb) {
250         if (footnotes == null) {
251             footnotes = new ArrayList JavaDoc();
252         }
253         footnotes.add(fb);
254     }
255
256     public void registerMarker(Marker marker) {
257         markers.add(marker);
258     }
259
260     public void unregisterMarker(Marker marker) {
261         markers.remove(marker);
262     }
263
264     public ArrayList JavaDoc getMarkers() {
265         return this.markers;
266     }
267
268 }
269
Popular Tags