KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > area > inline > InlineParent


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: InlineParent.java 453920 2006-10-07 14:29:54Z spepping $ */
19
20 package org.apache.fop.area.inline;
21
22 import org.apache.fop.area.Area;
23
24 import java.util.List JavaDoc;
25 import java.util.ArrayList JavaDoc;
26
27 /**
28  * Inline parent area.
29  * This is an inline area that can have other inlines as children.
30  */

31 public class InlineParent extends InlineArea {
32     /**
33      * The list of inline areas added to this inline parent.
34      */

35     protected List JavaDoc inlines = new ArrayList JavaDoc();
36
37     /** Controls whether the IPD is automatically adjusted based on the area's children. */
38     protected transient boolean autoSize;
39     
40     /**
41      * Create a new inline parent to add areas to.
42      */

43     public InlineParent() {
44     }
45
46     /**
47      * Override generic Area method.
48      *
49      * @param childArea the child area to add
50      */

51     public void addChildArea(Area childArea) {
52         if (inlines.size() == 0) {
53             autoSize = (getIPD() == 0);
54         }
55         if (childArea instanceof InlineArea) {
56             InlineArea inlineChildArea = (InlineArea) childArea;
57             inlines.add(childArea);
58             // set the parent area for the child area
59
inlineChildArea.setParentArea(this);
60             if (autoSize) {
61                 increaseIPD(inlineChildArea.getAllocIPD());
62             }
63         }
64     }
65
66     /**
67      * Get the child areas for this inline parent.
68      *
69      * @return the list of child areas
70      */

71     public List JavaDoc getChildAreas() {
72         return inlines;
73     }
74
75     /**
76      * recursively apply the variation factor to all descendant areas
77      * @param variationFactor the variation factor that must be applied to adjustments
78      * @param lineStretch the total stretch of the line
79      * @param lineShrink the total shrink of the line
80      * @return true if there is an UnresolvedArea descendant
81      */

82     public boolean applyVariationFactor(double variationFactor,
83                                         int lineStretch, int lineShrink) {
84         boolean bUnresolvedAreasPresent = false;
85         // recursively apply variation factor to descendant areas
86
for (int i = 0, len = inlines.size(); i < len; i++) {
87             bUnresolvedAreasPresent |= ((InlineArea)inlines.get(i))
88                 .applyVariationFactor(variationFactor, lineStretch, lineShrink);
89         }
90         return bUnresolvedAreasPresent;
91     }
92 }
93
94
Popular Tags