KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > layoutmgr > table > TableAndCaptionLayoutManager


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: TableAndCaptionLayoutManager.java 426576 2006-07-28 15:44:37Z jeremias $ */
19  
20 package org.apache.fop.layoutmgr.table;
21
22 import org.apache.fop.fo.flow.TableAndCaption;
23 import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
24 import org.apache.fop.layoutmgr.LayoutContext;
25 import org.apache.fop.layoutmgr.PositionIterator;
26 import org.apache.fop.layoutmgr.Position;
27 import org.apache.fop.area.Area;
28 import org.apache.fop.area.Block;
29
30 /**
31  * LayoutManager for a table-and-caption FO.
32  * A table and caption consists of a table and a caption.
33  * The caption contains blocks that are positioned next to the
34  * table on the caption side.
35  * The caption blocks have an implicit keep with the table.
36  * @todo Implement getNextKnuthElements()
37  */

38 public class TableAndCaptionLayoutManager extends BlockStackingLayoutManager {
39     private TableAndCaption fobj;
40     
41     private Block curBlockArea;
42
43     //private List childBreaks = new java.util.ArrayList();
44

45     /**
46      * Create a new table and caption layout manager.
47      * @param node table-and-caption FO
48      */

49     public TableAndCaptionLayoutManager(TableAndCaption node) {
50         super(node);
51         fobj = node;
52     }
53
54     /**
55      * Get the next break possibility.
56      *
57      * @param context the layout context for getting breaks
58      * @return the next break possibility
59      */

60     /*
61     public BreakPoss getNextBreakPoss(LayoutContext context) {
62         LayoutManager curLM; // currently active LM
63
64         MinOptMax stackSize = new MinOptMax();
65         // if starting add space before
66         // stackSize.add(spaceBefore);
67         BreakPoss lastPos = null;
68
69         // if there is a caption then get the side and work out when
70         // to handle it
71
72         while ((curLM = getChildLM()) != null) {
73             // Make break positions and return blocks!
74             // Set up a LayoutContext
75             int ipd = context.getRefIPD();
76             BreakPoss bp;
77
78             LayoutContext childLC = new LayoutContext(0);
79             // if line layout manager then set stack limit to ipd
80             // line LM actually generates a LineArea which is a block
81             childLC.setStackLimit(
82                   MinOptMax.subtract(context.getStackLimit(),
83                                      stackSize));
84             childLC.setRefIPD(ipd);
85
86             boolean over = false;
87             while (!curLM.isFinished()) {
88                 if ((bp = curLM.getNextBreakPoss(childLC)) != null) {
89                     if (stackSize.opt + bp.getStackingSize().opt > context.getStackLimit().max) {
90                         // reset to last break
91                         if (lastPos != null) {
92                             LayoutManager lm = lastPos.getLayoutManager();
93                             lm.resetPosition(lastPos.getPosition());
94                             if (lm != curLM) {
95                                 curLM.resetPosition(null);
96                             }
97                         } else {
98                             curLM.resetPosition(null);
99                         }
100                         over = true;
101                         break;
102                     }
103                     stackSize.add(bp.getStackingSize());
104                     lastPos = bp;
105                     childBreaks.add(bp);
106
107                     if (bp.nextBreakOverflows()) {
108                         over = true;
109                         break;
110                     }
111
112                     childLC.setStackLimit(MinOptMax.subtract(
113                                              context.getStackLimit(), stackSize));
114                 }
115             }
116             BreakPoss breakPoss = new BreakPoss(
117                                     new LeafPosition(this, childBreaks.size() - 1));
118             if (over) {
119                 breakPoss.setFlag(BreakPoss.NEXT_OVERFLOWS, true);
120             }
121             breakPoss.setStackingSize(stackSize);
122             return breakPoss;
123         }
124         setFinished(true);
125         return null;
126     }*/

127
128     /**
129      * Add the areas.
130      *
131      * @param parentIter the position iterator
132      * @param layoutContext the layout context for adding areas
133      */

134     public void addAreas(PositionIterator parentIter,
135                          LayoutContext layoutContext) {
136         getParentArea(null);
137         getPSLM().addIDToPage(fobj.getId());
138
139         /* TODO: Reimplement using Knuth approach
140         LayoutManager childLM;
141         int iStartPos = 0;
142         LayoutContext lc = new LayoutContext(0);
143         while (parentIter.hasNext()) {
144             LeafPosition lfp = (LeafPosition) parentIter.next();
145             // Add the block areas to Area
146             PositionIterator breakPosIter = new BreakPossPosIter(
147                     childBreaks, iStartPos, lfp.getLeafPos() + 1);
148             iStartPos = lfp.getLeafPos() + 1;
149             while ((childLM = breakPosIter.getNextChildLM()) != null) {
150                 childLM.addAreas(breakPosIter, lc);
151             }
152         }*/

153
154         flush();
155
156         //childBreaks.clear();
157
curBlockArea = null;
158     }
159
160     /**
161      * Return an Area which can contain the passed childArea. The childArea
162      * may not yet have any content, but it has essential traits set.
163      * In general, if the LayoutManager already has an Area it simply returns
164      * it. Otherwise, it makes a new Area of the appropriate class.
165      * It gets a parent area for its area by calling its parent LM.
166      * Finally, based on the dimensions of the parent area, it initializes
167      * its own area. This includes setting the content IPD and the maximum
168      * BPD.
169      *
170      * @param childArea the child area to locate the parent
171      * @return the area for this table and caption
172      */

173     public Area getParentArea(Area childArea) {
174         if (curBlockArea == null) {
175             curBlockArea = new Block();
176             // Set up dimensions
177
// Must get dimensions from parent area
178
Area parentArea = parentLM.getParentArea(curBlockArea);
179             int referenceIPD = parentArea.getIPD();
180             curBlockArea.setIPD(referenceIPD);
181             // Get reference IPD from parentArea
182
setCurrentArea(curBlockArea); // ??? for generic operations
183
}
184         return curBlockArea;
185     }
186
187     /**
188      * Add the child to the current area.
189      *
190      * @param childArea the area to add
191      */

192     public void addChildArea(Area childArea) {
193         if (curBlockArea != null) {
194             curBlockArea.addBlock((Block) childArea);
195         }
196     }
197
198     /**
199      * Reset the position of this layout manager.
200      *
201      * @param resetPos the position to reset to
202      */

203     public void resetPosition(Position resetPos) {
204         if (resetPos == null) {
205             reset(null);
206         }
207     }
208 }
209
210
Popular Tags