KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: BlockContainer.java,v 1.11.2.8 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.properties.*;
56 import org.apache.fop.fo.pagination.PageSequence;
57 import org.apache.fop.layout.*;
58 import org.apache.fop.apps.FOPException;
59
60 public class BlockContainer extends FObj {
61
62     int position;
63
64     int top;
65     int bottom;
66     int left;
67     int right;
68     int width;
69     int height;
70
71     int span;
72
73     AreaContainer areaContainer;
74
75     public static class Maker extends FObj.Maker {
76         public FObj make(FObj parent, PropertyList propertyList,
77                          String JavaDoc systemId, int line, int column)
78             throws FOPException {
79             return new BlockContainer(parent, propertyList,
80                                       systemId, line, column);
81         }
82
83     }
84
85     public static FObj.Maker maker() {
86         return new BlockContainer.Maker();
87     }
88
89     PageSequence pageSequence;
90
91     protected BlockContainer(FObj parent, PropertyList propertyList,
92                              String JavaDoc systemId, int line, int column)
93         throws FOPException {
94         super(parent, propertyList, systemId, line, column);
95         this.span = this.properties.get("span").getEnum();
96     }
97
98     public String JavaDoc getName() {
99         return "fo:block-container";
100     }
101
102     public int layout(Area area) throws FOPException {
103         if (this.marker == START) {
104
105             // Common Accessibility Properties
106
AbsolutePositionProps mAbsProps = propMgr.getAbsolutePositionProps();
107
108             // Common Border, Padding, and Background Properties
109
BorderAndPadding bap = propMgr.getBorderAndPadding();
110             BackgroundProps bProps = propMgr.getBackgroundProps();
111
112             // Common Margin-Block Properties
113
MarginProps mProps = propMgr.getMarginProps();
114
115             // this.properties.get("block-progression-dimension");
116
// this.properties.get("break-after");
117
// this.properties.get("break-before");
118
// this.properties.get("clip");
119
// this.properties.get("display-align");
120
// this.properties.get("height");
121
// this.properties.get("id");
122
// this.properties.get("keep-together");
123
// this.properties.get("keep-with-next");
124
// this.properties.get("keep-with-previous");
125
// this.properties.get("overflow");
126
// this.properties.get("reference-orientation");
127
// this.properties.get("span");
128
// this.properties.get("width");
129
// this.properties.get("writing-mode");
130

131             this.marker = 0;
132
133             this.position = this.properties.get("position").getEnum();
134             this.top = this.properties.get("top").getLength().mvalue();
135             this.bottom = this.properties.get("bottom").getLength().mvalue();
136             this.left = this.properties.get("left").getLength().mvalue();
137             this.right = this.properties.get("right").getLength().mvalue();
138             this.width = this.properties.get("width").getLength().mvalue();
139             this.height = this.properties.get("height").getLength().mvalue();
140             span = this.properties.get("span").getEnum();
141
142             // initialize id
143
String JavaDoc id = this.properties.get("id").getString();
144             try {
145                 area.getIDReferences().initializeID(id, area);
146             }
147             catch(FOPException e) {
148                 if (!e.isLocationSet()) {
149                     e.setLocation(systemId, line, column);
150                 }
151                 throw e;
152             }
153         }
154
155         boolean prevChildMustKeepWithNext = false;
156
157         AreaContainer container = (AreaContainer)area;
158         if ((this.width == 0) && (this.height == 0)) {
159             width = right - left;
160             height = bottom - top;
161         }
162
163         this.areaContainer =
164             new AreaContainer(propMgr.getFontState(container.getFontInfo()),
165                               container.getXPosition() + left,
166                               container.getYPosition() - top, width, height,
167                               position);
168
169         areaContainer.setPage(area.getPage());
170         areaContainer.setBackground(propMgr.getBackgroundProps());
171         areaContainer.setBorderAndPadding(propMgr.getBorderAndPadding());
172         areaContainer.start();
173
174         //areaContainer.setAbsoluteHeight(top);
175
areaContainer.setAbsoluteHeight(0);
176         areaContainer.setIDReferences(area.getIDReferences());
177
178         int numChildren = this.children.size();
179         for (int i = this.marker; i < numChildren; i++) {
180             FObj fo = (FObj)children.get(i);
181             int status;
182             if (Status.isIncomplete((status = fo.layout(areaContainer)))) {
183                 /*
184                  * if ((prevChildMustKeepWithNext) && (status.laidOutNone())) {
185                  * this.marker = i - 1;
186                  * FObj prevChild = (FObj) children.get(this.marker);
187                  * prevChild.removeAreas();
188                  * prevChild.resetMarker();
189                  * return new Status(Status.AREA_FULL_SOME);
190                  * // should probably return AREA_FULL_NONE if first
191                  * // or perhaps an entirely new status code
192                  * } else {
193                  * this.marker = i;
194                  * return status;
195                  * }
196                  */

197             }
198             if (status == Status.KEEP_WITH_NEXT) {
199                 prevChildMustKeepWithNext = true;
200             }
201         }
202
203         areaContainer.end();
204         if (position == Position.ABSOLUTE)
205             areaContainer.setHeight(height);
206         area.addChild(areaContainer);
207
208         return Status.OK;
209     }
210
211     /**
212      * Return the content width of the boxes generated by this block
213      * container FO.
214      */

215     public int getContentWidth() {
216         if (areaContainer != null)
217             return areaContainer.getContentWidth(); // getAllocationWidth()??
218
else
219             return 0; // not laid out yet
220
}
221
222     public boolean generatesReferenceAreas() {
223         return true;
224     }
225
226     public int getSpan() {
227         return this.span;
228     }
229
230 }
231
Popular Tags