KickJava   Java API By Example, From Geeks To Geeks.

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


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: MainReference.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.area;
21
22 import java.util.List JavaDoc;
23 import java.util.Iterator JavaDoc;
24
25 /**
26  * The main-reference-area generated by an fo:region-body
27  * This object holds one or more span-reference-areas (block-areas
28  * stacked in the block progression direction)
29  * See fo:region-body definition in the XSL Rec for more information.
30  */

31 public class MainReference extends Area {
32
33     private BodyRegion parent;
34     private List JavaDoc spanAreas = new java.util.ArrayList JavaDoc();
35     private boolean isEmpty = true;
36
37     /**
38      * Constructor
39      *
40      * @param parent the body region this reference area is placed in.
41      */

42     public MainReference(BodyRegion parent) {
43         this.parent = parent;
44         addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE);
45     }
46       
47     /**
48      * Add a span area to this area.
49      *
50      * @param spanAll whether to make a single-column span
51      * @return the created span area.
52      */

53     public Span createSpan(boolean spanAll) {
54         if (spanAreas.size() > 0 && getCurrentSpan().isEmpty()) {
55             //Remove the current one if it is empty
56
spanAreas.remove(spanAreas.size() - 1);
57         }
58         RegionViewport rv = parent.getRegionViewport();
59         int ipdWidth = (int) parent.getIPD()
60             - rv.getBorderAndPaddingWidthStart() - rv.getBorderAndPaddingWidthEnd();
61         
62         Span newSpan = new Span(((spanAll) ? 1 : getColumnCount()),
63                 getColumnGap(), ipdWidth);
64         spanAreas.add(newSpan);
65         return getCurrentSpan();
66     }
67
68     /**
69      * Get the span areas from this area.
70      *
71      * @return the list of span areas
72      */

73     public List JavaDoc getSpans() {
74         return spanAreas;
75     }
76
77     /**
78      * Get the span area currently being filled (i.e., the last span created).
79      * @return the active span.
80      */

81     public Span getCurrentSpan() {
82         return (Span) spanAreas.get(spanAreas.size() - 1);
83     }
84
85     /**
86      * Indicates whether any child areas have been added to this reference area.
87      *
88      * This is achieved by looping through each span.
89      * @return true if no child areas have been added yet.
90      */

91     public boolean isEmpty() {
92         if (isEmpty) {
93             boolean nonEmptyFound = false;
94             if (spanAreas != null) {
95                 for (Iterator JavaDoc spaniter = spanAreas.iterator(); spaniter.hasNext();) {
96                     Span spanArea = (Span) spaniter.next();
97                     nonEmptyFound |= !spanArea.isEmpty();
98                 }
99             }
100
101             isEmpty = !nonEmptyFound;
102         }
103         return isEmpty;
104     }
105
106     /** @return the number of columns */
107     public int getColumnCount() {
108         return parent.getColumnCount();
109     }
110
111     /** @return the column gap in millipoints */
112     public int getColumnGap() {
113         return parent.getColumnGap();
114     }
115
116 }
117
118
Popular Tags