KickJava   Java API By Example, From Geeks To Geeks.

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


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: FilledArea.java 462812 2006-10-11 14:19:28Z spepping $ */
19  
20 package org.apache.fop.area.inline;
21
22 import java.util.List JavaDoc;
23 import java.util.ListIterator JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.Iterator JavaDoc;
26
27 /**
28  * Filled area.
29  * This inline area contains some inline areas.
30  * When the renderer gets the child areas to render
31  * the inline areas are repeated to fill the ipd of
32  * this inline parent.
33  * This extends InlineParent so that the renderer will render
34  * this as a normal inline parent.
35  */

36 public class FilledArea extends InlineParent {
37     private int unitWidth;
38     
39     /**
40      * Create a new filled area.
41      */

42     public FilledArea() {
43     }
44
45     /**
46      * Set the offset of the descendant TextAreas,
47      * instead of the offset of the FilledArea itself.
48      *
49      * @param v the offset
50      */

51     /*
52     public void setOffset(int v) {
53         setChildOffset(inlines.listIterator(), v);
54     }
55     */

56
57     private void setChildOffset(ListIterator JavaDoc childrenIterator, int v) {
58         while (childrenIterator.hasNext()) {
59             InlineArea child = (InlineArea) childrenIterator.next();
60             if (child instanceof InlineParent) {
61                 setChildOffset(((InlineParent) child).getChildAreas().listIterator(), v);
62             } else if (child instanceof org.apache.fop.area.inline.Viewport) {
63                 // nothing
64
} else {
65                 child.setOffset(v);
66             }
67         }
68     }
69
70     /**
71      * Set the unit width for the areas to fill the full width.
72      *
73      * @param w the unit width
74      */

75     public void setUnitWidth(int w) {
76         unitWidth = w;
77     }
78
79     /**
80      * Return the unit width for the areas to fill the full width.
81      *
82      * @return the unit width
83      */

84     public int getUnitWidth() {
85         return unitWidth;
86     }
87
88     /**
89      * @see org.apache.fop.area.Area#getBPD
90      */

91     public int getBPD() {
92         int bpd = 0;
93         for (Iterator JavaDoc childAreaIt = getChildAreas().iterator(); childAreaIt.hasNext();) {
94             InlineArea area = (InlineArea)childAreaIt.next();
95             if (bpd < area.getBPD()) {
96                 bpd = area.getBPD();
97             }
98         }
99         return bpd;
100     }
101     
102     /**
103      * Get the child areas for this filled area.
104      * This copies the references of the inline areas so that
105      * it fills the total width of the area a whole number of times
106      * for the unit width.
107      *
108      * @return the list of child areas copied to fill the width
109      */

110     public List JavaDoc getChildAreas() {
111         int units = (int)(getIPD() / unitWidth);
112         List JavaDoc newList = new ArrayList JavaDoc();
113         for (int count = 0; count < units; count++) {
114             newList.addAll(inlines);
115         }
116         return newList;
117     }
118     
119     /**
120      * recursively apply the variation factor to all descendant areas
121      * @param variationFactor the variation factor that must be applied to adjustments
122      * @param lineStretch the total stretch of the line
123      * @param lineShrink the total shrink of the line
124      * @return true if there is an UnresolvedArea descendant
125      */

126     public boolean applyVariationFactor(double variationFactor,
127                                         int lineStretch, int lineShrink) {
128         setIPD(getIPD() + adjustingInfo.applyVariationFactor(variationFactor));
129         return false;
130     }
131 }
132
133
Popular Tags