KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: Area.java,v 1.24.2.7 2003/02/25 14:07:00 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.datatypes.*;
55 //import org.apache.fop.fo.flow.Marker;
56
import org.apache.fop.layout.inline.InlineSpace;
57
58 // Java
59
import java.util.ArrayList JavaDoc;
60 import java.util.Iterator JavaDoc;
61
62 public abstract class Area extends Box {
63
64     /*
65      * nominal font size and nominal font family incorporated in
66      * fontState
67      */

68     protected FontState fontState;
69     protected BorderAndPadding bp = null;
70
71     protected ArrayList JavaDoc children = new ArrayList JavaDoc();
72
73     /* max size in line-progression-direction */
74     protected int maxHeight;
75
76     /**
77      * Total height of content of this area.
78      */

79     protected int currentHeight = 0;
80
81     // used to keep track of the current x position within a table. Required for drawing rectangle links.
82
protected int tableCellXOffset = 0;
83
84     /** Stores position of top of this area relative to page column Ypos.
85      * Used to set the position of link hotspot rectangles.
86      */

87     private int absoluteYtop = 0;
88
89     protected int contentRectangleWidth;
90
91     protected int allocationWidth;
92
93     /* the page this area is on */
94     protected Page page;
95
96     protected BackgroundProps background;
97
98     private IDReferences idReferences;
99
100 // protected ArrayList markers;
101

102     // as defined in Section 6.1.1
103
protected org.apache.fop.fo.FObj generatedBy; // corresponds to 'generated-by' trait
104
// protected HashMap returnedBy;
105

106     // as defined in Section 6.1.1
107
protected String JavaDoc areaClass;
108
109     // as defined in Section 4.2.2
110
protected boolean isFirst = false;
111     protected boolean isLast = false;
112
113     /*
114      * author : Seshadri G
115      * * the fo which created it
116      */

117     // This is deprecated and should be phased out in
118
// favour of using 'generatedBy'
119
public org.apache.fop.fo.FObj foCreator;
120
121     public Area(FontState fontState) {
122         setFontState(fontState);
123 // this.markers = new ArrayList();
124
// this.returnedBy = new HashMap();
125
}
126
127     /**
128      * Creates a new <code>Area</code> instance.
129      *
130      * @param fontState a <code>FontState</code> value
131      * @param allocationWidth the inline-progression dimension of the content
132      * rectangle of the Area
133      * @param maxHeight the maximum block-progression dimension available
134      * for this Area (its allocation rectangle)
135      */

136     public Area(FontState fontState, int allocationWidth, int maxHeight) {
137         setFontState(fontState);
138         this.allocationWidth = allocationWidth;
139         this.contentRectangleWidth = allocationWidth;
140         this.maxHeight = maxHeight;
141 // this.markers = new ArrayList();
142
// this.returnedBy = new HashMap();
143
}
144
145     private void setFontState(FontState fontState) {
146         // fontState.setFontInfo(this.page.getFontInfo());
147
this.fontState = fontState;
148     }
149
150     public void addChild(Box child) {
151         this.children.add(child);
152         child.parent = this;
153     }
154
155     public void addChildAtStart(Box child) {
156         this.children.add(0, child);
157         child.parent = this;
158     }
159
160     public void addDisplaySpace(int size) {
161         this.addChild(new DisplaySpace(size));
162         this.currentHeight += size;
163     }
164
165     public void addInlineSpace(int size) {
166         this.addChild(new InlineSpace(size));
167         // other adjustments...
168
}
169
170     public FontInfo getFontInfo() {
171         return this.page.getFontInfo();
172     }
173
174     public void end() {}
175
176     public int getAllocationWidth() {
177         /*
178          * ATTENTION: this may change your output!! (Karen Lease, 4mar2001)
179          * return this.allocationWidth - getPaddingLeft() - getPaddingRight()
180          * - getBorderLeftWidth() - getBorderRightWidth();
181          */

182         return this.allocationWidth;
183     }
184
185     /**
186      * Set the allocation width.
187      * @param w The new allocation width.
188      * This sets content width to the same value.
189      * Currently only called during layout of Table to set the width
190      * to the total width of all the columns. Note that this assumes the
191      * column widths are explicitly specified.
192      */

193     public void setAllocationWidth(int w) {
194         this.allocationWidth = w;
195         this.contentRectangleWidth = this.allocationWidth;
196     }
197
198     public ArrayList JavaDoc getChildren() {
199         return this.children;
200     }
201
202     public boolean hasChildren() {
203         return (this.children.size() != 0);
204     }
205
206     /**
207      * Tell whether this area contains any children which are not
208      * DisplaySpace. This is used in determining whether to honor
209      * keeps.
210      */

211     public boolean hasNonSpaceChildren() {
212         if (this.children.size() > 0) {
213             Iterator JavaDoc childIter = children.iterator();
214             while (childIter.hasNext()) {
215                 if (! (childIter.next() instanceof DisplaySpace)) {
216                     return true;
217                 }
218             }
219         }
220         return false;
221     }
222
223     public int getContentWidth() {
224         /*
225          * ATTENTION: this may change your output!! (Karen Lease, 4mar2001)
226          * return contentRectangleWidth - getPaddingLeft() - getPaddingRight()
227          * - getBorderLeftWidth() - getBorderRightWidth();
228          */

229         return contentRectangleWidth;
230     }
231
232     public FontState getFontState() {
233         return this.fontState;
234     }
235
236     /**
237      * Returns content height of the area.
238      *
239      * @return Content height in millipoints
240      */

241     public int getContentHeight() {
242         return this.currentHeight;
243     }
244
245     /**
246      * Returns allocation height of this area.
247      * The allocation height is the sum of the content height plus border
248      * and padding in the vertical direction.
249      *
250      * @return allocation height in millipoints
251      */

252     public int getHeight() {
253         return this.currentHeight + getPaddingTop() + getPaddingBottom()
254                + getBorderTopWidth() + getBorderBottomWidth();
255     }
256
257     public int getMaxHeight() {
258         // Change KDL: return max height of content rectangle
259
return this.maxHeight;
260         /*
261          * return this.maxHeight - getPaddingTop() - getPaddingBottom() -
262          * getBorderTopWidth() - getBorderBottomWidth();
263          */

264     }
265
266     public Page getPage() {
267         return this.page;
268     }
269
270     public BackgroundProps getBackground() {
271         return this.background;
272     }
273
274     // Must handle conditionality here, depending on isLast/isFirst
275
public int getPaddingTop() {
276         return (bp == null ? 0 : bp.getPaddingTop(false));
277     }
278
279     public int getPaddingLeft() {
280         return (bp == null ? 0 : bp.getPaddingLeft(false));
281     }
282
283     public int getPaddingBottom() {
284         return (bp == null ? 0 : bp.getPaddingBottom(false));
285     }
286
287     public int getPaddingRight() {
288         return (bp == null ? 0 : bp.getPaddingRight(false));
289     }
290
291     // Handle border-width, including conditionality
292
// For now, just pass false everywhere!
293
public int getBorderTopWidth() {
294         return (bp == null ? 0 : bp.getBorderTopWidth(false));
295     }
296
297     public int getBorderRightWidth() {
298         return (bp == null ? 0 : bp.getBorderRightWidth(false));
299     }
300
301     public int getBorderLeftWidth() {
302         return (bp == null ? 0 : bp.getBorderLeftWidth(false));
303     }
304
305     public int getBorderBottomWidth() {
306         return (bp == null ? 0 : bp.getBorderBottomWidth(false));
307     }
308
309     public int getTableCellXOffset() {
310         return tableCellXOffset;
311     }
312
313     public void setTableCellXOffset(int offset) {
314         tableCellXOffset = offset;
315     }
316
317     /**
318      * Return absolute Y position of the current bottom of this area,
319      * not counting any bottom padding or border. This is used
320      * to set positions for link hotspots.
321      * In fact, the position is not really absolute, but is relative
322      * to the Ypos of the column-level AreaContainer, even when the
323      * area is in a page header or footer!
324      */

325     public int getAbsoluteHeight() {
326         return absoluteYtop + getPaddingTop() + getBorderTopWidth() +
327                 currentHeight;
328     }
329
330     /**
331      * Set "absolute" Y position of the top of this area. In fact, the
332      * position is not really absolute, but relative to the Ypos of
333      * the column-level AreaContainer, even when the area is in a
334      * page header or footer!
335      * It is set from the value of getAbsoluteHeight() on the parent
336      * area, just before adding this area.
337      */

338     public void setAbsoluteHeight(int value) {
339         absoluteYtop = value;
340     }
341
342     public void increaseHeight(int amount) {
343         this.currentHeight += amount;
344     }
345
346     // Remove allocation height of child
347
public void removeChild(Area area) {
348         this.currentHeight -= area.getHeight();
349         this.children.remove(area);
350     }
351
352     public void removeChild(DisplaySpace spacer) {
353         this.currentHeight -= spacer.getSize();
354         this.children.remove(spacer);
355     }
356
357     public void remove() {
358         this.parent.removeChild(this);
359     }
360
361     public void setPage(Page page) {
362         this.page = page;
363     }
364
365     public void setBackground(BackgroundProps bg) {
366         this.background = bg;
367     }
368
369     public void setBorderAndPadding(BorderAndPadding bp) {
370         this.bp = bp;
371     }
372
373     /**
374      * Return space remaining in the vertical direction (height).
375      * This returns maximum available space - current content height
376      * Note: content height should be based on allocation height of content!
377      * @return space remaining in base units (millipoints)
378      */

379     public int spaceLeft() {
380         return maxHeight - currentHeight;
381     }
382
383     public void start() {}
384
385
386     /**
387      * Set the content height to the passed value if that value is
388      * larger than current content height. If the new content height
389      * is greater than the maximum available height, set the content height
390      * to the max. available (!!!)
391      *
392      * @param height allocation height of content in millipoints
393      */

394     public void setHeight(int height) {
395         int prevHeight = currentHeight;
396         if (height > currentHeight) {
397             currentHeight = height;
398         }
399
400         if (currentHeight > getMaxHeight()) {
401             currentHeight = getMaxHeight();
402         }
403     }
404
405     public void setMaxHeight(int height) {
406         this.maxHeight = height;
407     }
408
409     public Area getParent() {
410         return this.parent;
411     }
412
413     public void setParent(Area parent) {
414         this.parent = parent;
415     }
416
417     public void setIDReferences(IDReferences idReferences) {
418         this.idReferences = idReferences;
419     }
420
421     public IDReferences getIDReferences() {
422         return idReferences;
423     }
424
425     /* Author seshadri */
426     public org.apache.fop.fo.FObj getfoCreator() {
427         return this.foCreator;
428     }
429
430     // Function not currently used! (KLease, 16mar01)
431

432     public AreaContainer getNearestAncestorAreaContainer() {
433         Area area = this.getParent();
434         while (area != null && !(area instanceof AreaContainer)) {
435             area = area.getParent();
436         }
437         return (AreaContainer)area;
438     }
439
440     public BorderAndPadding getBorderAndPadding() {
441         return bp;
442     }
443
444 // public void addMarker(Marker marker) {
445
// markers.add(marker);
446
// }
447

448 // public void addMarkers(ArrayList markers) {
449
// markers.addAll(markers);
450
// }
451

452 // public ArrayList getMarkers() {
453
// return markers;
454
// }
455

456 // public void addLineagePair(org.apache.fop.fo.FObj fo, int areaPosition) {
457
// returnedBy.put(fo, new Integer(areaPosition));
458
// }
459

460     public void setGeneratedBy(org.apache.fop.fo.FObj generatedBy) {
461         this.generatedBy = generatedBy;
462     }
463
464     public org.apache.fop.fo.FObj getGeneratedBy() {
465         return generatedBy;
466     }
467
468     public void isFirst(boolean isFirst) {
469         this.isFirst = isFirst;
470     }
471
472     public boolean isFirst() {
473         return isFirst;
474     }
475
476     public void isLast(boolean isLast) {
477         this.isLast = isLast;
478     }
479
480     public boolean isLast() {
481         return isLast;
482     }
483
484 }
485
Popular Tags