KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > fo > FONode


1 /*
2  * $Id: FONode.java,v 1.21.2.10 2003/02/25 12:56:54 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.fo;
52
53 // FOP
54
import org.apache.fop.apps.FOPException;
55 import org.apache.fop.layout.Area;
56 import org.apache.fop.layout.AreaClass;
57 import org.apache.fop.layout.LinkSet;
58
59 // Avalon
60
import org.apache.avalon.framework.logger.Logger;
61
62 // Java
63
import java.util.ArrayList JavaDoc;
64
65 /**
66  * base class for nodes in the formatting object tree
67  *
68  * Modified by Mark Lillywhite mark-fop@inomial.com. Made
69  * ArrayList a protected member. (/me things this should be
70  * a private member with an API for adding children;
71  * this woudl save a lot of memory because the ArrayList
72  * would not have to be instantiated unless the node had
73  * children).
74  */

75 public abstract class FONode {
76
77     protected FObj parent;
78
79     protected String JavaDoc areaClass = AreaClass.UNASSIGNED;
80
81     protected ArrayList JavaDoc children = new ArrayList JavaDoc(); // made public for searching for id's
82

83     /**
84      * value of marker before layout begins
85      */

86     public static final int START = -1000;
87
88     /**
89      * value of marker after break-after
90      */

91     public static final int BREAK_AFTER = -1001;
92
93     /**
94      * where the layout was up to.
95      * for FObjs it is the child number
96      * for FOText it is the character number
97      */

98     protected int marker = START;
99
100     protected boolean isInTableCell = false;
101
102     protected int forcedStartOffset = 0;
103     protected int forcedWidth = 0;
104
105     protected LinkSet linkSet;
106
107     // count of areas generated-by/returned-by
108
public int areasGenerated = 0;
109
110     protected Logger log;
111
112     protected FONode(FObj parent) {
113         this.parent = parent;
114
115         if (parent != null) {
116             this.areaClass = parent.areaClass;
117             log = parent.log;
118         }
119     }
120
121     public void setLogger(Logger logger) {
122         log = logger;
123     }
124
125     public void setIsInTableCell() {
126         this.isInTableCell = true;
127         // made recursive by Eric Schaeffer
128
for (int i = 0; i < this.children.size(); i++) {
129             FONode child = (FONode)this.children.get(i);
130             child.setIsInTableCell();
131         }
132     }
133
134     public void forceStartOffset(int offset) {
135         this.forcedStartOffset = offset;
136         // made recursive by Eric Schaeffer
137
for (int i = 0; i < this.children.size(); i++) {
138             FONode child = (FONode)this.children.get(i);
139             child.forceStartOffset(offset);
140         }
141     }
142
143     public void forceWidth(int width) {
144         this.forcedWidth = width;
145         // made recursive by Eric Schaeffer
146
for (int i = 0; i < this.children.size(); i++) {
147             FONode child = (FONode)this.children.get(i);
148             child.forceWidth(width);
149         }
150     }
151
152     public void resetMarker() {
153         this.marker = START;
154         this.areasGenerated=0;
155         int numChildren = this.children.size();
156         for (int i = 0; i < numChildren; i++) {
157             ((FONode)children.get(i)).resetMarker();
158         }
159     }
160
161     public void removeAreas() {
162         // still to do
163
}
164
165
166     protected void addChild(FONode child) {
167         children.add(child);
168     }
169
170     public FObj getParent() {
171         return this.parent;
172     }
173
174     public void setLinkSet(LinkSet linkSet) {
175         this.linkSet = linkSet;
176         for (int i = 0; i < this.children.size(); i++) {
177             FONode child = (FONode)this.children.get(i);
178             child.setLinkSet(linkSet);
179         }
180     }
181
182     public LinkSet getLinkSet() {
183         return this.linkSet;
184     }
185
186     public abstract int layout(Area area) throws FOPException;
187
188     /**
189      * lets outside sources access the property list
190      * first used by PageNumberCitation to find the "id" property
191      * returns null by default, overide this function when there is a property list
192      * @param name - the name of the desired property to obtain
193      * @return the property
194      */

195     public Property getProperty(String JavaDoc name) {
196         return (null);
197     }
198
199     /**
200      * At the start of a new span area layout may be partway through a
201      * nested FO, and balancing requires rollback to this known point.
202      * The snapshot records exactly where layout is at.
203      * @param snapshot a ArrayList of markers (Integer)
204      * @return the updated ArrayList of markers (Integers)
205      */

206     public ArrayList JavaDoc getMarkerSnapshot(ArrayList JavaDoc snapshot) {
207         snapshot.add(new Integer JavaDoc(this.marker));
208
209         // terminate if no kids or child not yet accessed
210
if (this.marker < 0)
211             return snapshot;
212         else if (children.isEmpty())
213             return snapshot;
214         else
215             return ((FONode)children.get(this.marker)).getMarkerSnapshot(snapshot);
216     }
217
218     /**
219      * When balancing occurs, the flow layout() method restarts at the
220      * point specified by the current marker snapshot, which is retrieved
221      * and restored using this method.
222      * @param snapshot the ArrayList of saved markers (Integers)
223      */

224     public void rollback(ArrayList JavaDoc snapshot) {
225         this.marker = ((Integer JavaDoc)snapshot.get(0)).intValue();
226         snapshot.remove(0);
227
228         if (this.marker == START) {
229             // make sure all the children of this FO are also reset
230
resetMarker();
231             return;
232         } else if ((this.marker == -1) || children.isEmpty())
233             return;
234
235         int numChildren = this.children.size();
236
237         if (this.marker <= START) {
238             return;
239         }
240
241         for (int i = this.marker + 1; i < numChildren; i++) {
242             FONode fo = (FONode)children.get(i);
243             fo.resetMarker();
244         }
245         ((FONode)children.get(this.marker)).rollback(snapshot);
246     }
247
248
249     public boolean mayPrecedeMarker() {
250         return false;
251     }
252
253 }
254
Popular Tags