KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > fo > flow > AbstractFlow


1 /*
2  * $Id: AbstractFlow.java,v 1.1.2.6 2003/04/11 00:24:38 pietsch 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.fo.flow;
52
53 // FOP
54
import org.apache.fop.fo.*;
55 import org.apache.fop.fo.pagination.*;
56 import org.apache.fop.layout.Area;
57 import org.apache.fop.layout.BodyAreaContainer;
58 import org.apache.fop.apps.FOPException;
59
60 // Java
61
import java.util.ArrayList JavaDoc;
62
63 public abstract class AbstractFlow extends FObj {
64
65     /**
66      * PageSequence container
67      */

68     protected PageSequence pageSequence;
69
70     /**
71      * Area in which we lay out our kids
72      */

73     private Area area;
74
75     /**
76      * ArrayList to store snapshot
77      */

78     private ArrayList JavaDoc markerSnapshot;
79
80     /**
81      * flow-name attribute
82      */

83     protected String JavaDoc _flowName;
84
85     /**
86      * Content-width of current column area during layout
87      */

88     private int contentWidth;
89
90     private int _status = Status.AREA_FULL_NONE;
91
92
93     protected AbstractFlow(FObj parent, PropertyList propertyList,
94                            String JavaDoc systemId, int line, int column) throws FOPException {
95         super(parent, propertyList, systemId, line, column);
96
97         if (parent.getName().equals("fo:page-sequence")) {
98             this.pageSequence = (PageSequence)parent;
99         } else {
100             throw new FOPException("flow must be child of page-sequence, not "
101                                    + parent.getName(), systemId, line, column);
102         }
103     }
104
105     public String JavaDoc getFlowName() {
106         return _flowName;
107     }
108
109     public int layout(Area area) throws FOPException {
110         return layout(area, null);
111
112     }
113
114     public int layout(Area area, Region region) throws FOPException {
115         if (this.marker == START) {
116             this.marker = 0;
117         }
118
119         // flow is *always* laid out into a BodyAreaContainer
120
BodyAreaContainer bac = (BodyAreaContainer)area;
121
122         boolean prevChildMustKeepWithNext = false;
123         ArrayList JavaDoc pageMarker = this.getMarkerSnapshot(new ArrayList JavaDoc());
124
125         int numChildren = this.children.size();
126         if (numChildren == 0) {
127             throw new FOPException("fo:flow must contain block-level children",
128                                    systemId, line, column);
129         }
130         for (int i = this.marker; i < numChildren; i++) {
131             FObj fo = (FObj)children.get(i);
132
133             if (bac.isBalancingRequired(fo)) {
134                 // reset the the just-done span area in preparation
135
// for a backtrack for balancing
136
bac.resetSpanArea();
137
138                 this.rollback(markerSnapshot);
139                 // one less because of the "continue"
140
i = this.marker - 1;
141                 continue;
142             }
143             // current column area
144
Area currentArea = bac.getNextArea(fo);
145             // temporary hack for IDReferences
146
currentArea.setIDReferences(bac.getIDReferences());
147             if (bac.isNewSpanArea()) {
148                 this.marker = i;
149                 markerSnapshot = this.getMarkerSnapshot(new ArrayList JavaDoc());
150             }
151             // Set current content width for percent-based lengths in children
152
setContentWidth(currentArea.getContentWidth());
153
154             _status = fo.layout(currentArea);
155
156             /*
157              * if((_status.isPageBreak() || i == numChildren - 1) && bac.needsFootnoteAdjusting()) {
158              * bac.adjustFootnoteArea();
159              * this.rollback(pageMarker);
160              * i = this.marker - 1;
161              * Area mainReferenceArea = bac.getMainReferenceArea();
162              * // remove areas
163              * continue;
164              * }
165              */

166             if (Status.isIncomplete(_status)) {
167                 if ((prevChildMustKeepWithNext) && (Status.laidOutNone(_status))) {
168                     this.marker = i - 1;
169                     FObj prevChild = (FObj)children.get(this.marker);
170                     prevChild.removeAreas();
171                     prevChild.resetMarker();
172                     prevChild.removeID(area.getIDReferences());
173                     _status = Status.AREA_FULL_SOME;
174                     return _status;
175                     // should probably return AREA_FULL_NONE if first
176
// or perhaps an entirely new status code
177
}
178                 if (bac.isLastColumn())
179                     if (_status == Status.FORCE_COLUMN_BREAK) {
180                         this.marker = i;
181                         _status = Status.FORCE_PAGE_BREAK; // same thing
182
return _status;
183                     } else {
184                         this.marker = i;
185                         return _status;
186                     }
187                 else {
188                     // not the last column, but could be page breaks
189
if (Status.isPageBreak(_status)) {
190                         this.marker = i;
191                         return _status;
192                     }
193                     // I don't much like exposing this. (AHS 001217)
194
((org.apache.fop.layout.ColumnArea)currentArea).incrementSpanIndex();
195                     i--;
196                 }
197             }
198             if (_status == Status.KEEP_WITH_NEXT) {
199                 prevChildMustKeepWithNext = true;
200             } else {
201                 prevChildMustKeepWithNext = false;
202             }
203         }
204         return _status;
205     }
206
207     protected void setContentWidth(int contentWidth) {
208         this.contentWidth = contentWidth;
209     }
210     /**
211      * Return the content width of this flow (really of the region
212      * in which it is flowing).
213      */

214     public int getContentWidth() {
215         return this.contentWidth;
216     }
217
218     public int getStatus() {
219         return _status;
220     }
221
222
223     public boolean generatesReferenceAreas() {
224         return true;
225     }
226
227 }
228
Popular Tags