KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > area > BodyRegion


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: BodyRegion.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.area;
21
22 import java.util.List JavaDoc;
23
24 import org.apache.fop.fo.pagination.RegionBody;
25
26 /**
27  * This class is a container for the areas that may be generated by
28  * an fo:region-body. It extends the RegionReference that is used
29  * directly by the other region classes.
30  * See fo:region-body definition in the XSL Rec for more information.
31  */

32 public class BodyRegion extends RegionReference {
33     private BeforeFloat beforeFloat; // optional
34
private MainReference mainReference; // mandatory
35
private Footnote footnote; // optional
36
private int columnGap;
37     private int columnCount;
38
39     /**
40      * Constructor which can read traits directly
41      * from an fo:region-body formatting object.
42      * @param rb the region-body FO node
43      * @param parent the parent region viewport
44      */

45     public BodyRegion(RegionBody rb, RegionViewport parent) {
46         this(rb.getNameId(), rb.getRegionName(), parent, rb.getColumnCount(), rb.getColumnGap());
47     }
48
49     /**
50      * Constructor which can read traits directly
51      * from an fo:region-body formatting object.
52      * @param regionClass the region class (as returned by Region.getNameId())
53      * @param regionName the name of the region (as returned by Region.getRegionName())
54      * @param parent the parent region viewport
55      * @param columnCount the number of columns
56      * @param columnGap the gap between columns
57      */

58     public BodyRegion(int regionClass, String JavaDoc regionName, RegionViewport parent,
59             int columnCount, int columnGap) {
60         super(regionClass, regionName, parent);
61         this.columnCount = columnCount;
62         this.columnGap = columnGap;
63         mainReference = new MainReference(this);
64     }
65
66     /**
67      * Get the number of columns when not spanning
68      *
69      * @return the number of columns
70      */

71     public int getColumnCount() {
72         return this.columnCount;
73     }
74
75     /** @return the column-gap value */
76     public int getColumnGap() {
77         return this.columnGap;
78     }
79    
80     /**
81      * Get the main reference area.
82      *
83      * @return the main reference area
84      */

85     public MainReference getMainReference() {
86         return mainReference;
87     }
88
89     /**
90      * indicates whether the main reference area has any child areas added to it
91      *
92      * @return whether the main reference area has any child areas added to it
93      */

94     public boolean isEmpty() {
95         return (mainReference == null || mainReference.isEmpty())
96                && (footnote == null || footnote.isEmpty())
97                && (beforeFloat == null || beforeFloat.isEmpty());
98     }
99
100
101     /**
102      * Get the before float area.
103      *
104      * @return the before float area
105      */

106     public BeforeFloat getBeforeFloat() {
107         if (beforeFloat == null) {
108             beforeFloat = new BeforeFloat();
109         }
110         return beforeFloat;
111     }
112
113     /**
114      * Get the footnote area.
115      *
116      * @return the footnote area
117      */

118     public Footnote getFootnote() {
119         if (footnote == null) {
120             footnote = new Footnote();
121         }
122         return footnote;
123     }
124
125     /**
126      * @return the available BPD in the main reference area after the previous span reference
127      * areas are subtracted.
128      */

129     public int getRemainingBPD() {
130         int usedBPD = 0;
131         List JavaDoc spans = getMainReference().getSpans();
132         int previousSpanCount = spans.size() - 1;
133         for (int i = 0; i < previousSpanCount; i++) {
134             usedBPD += ((Span)spans.get(i)).getHeight();
135         }
136         return getBPD() - usedBPD;
137     }
138     
139     /**
140      * Clone this object.
141      *
142      * @return a shallow copy of this object
143      */

144     public Object JavaDoc clone() {
145         BodyRegion br = new BodyRegion(getRegionClass(), getRegionName(), regionViewport,
146                 getColumnCount(), getColumnGap());
147         br.setCTM(getCTM());
148         br.setIPD(getIPD());
149         br.beforeFloat = beforeFloat;
150         br.mainReference = mainReference;
151         br.footnote = footnote;
152         return br;
153     }
154 }
155
Popular Tags