KickJava   Java API By Example, From Geeks To Geeks.

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


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: TableCaptionLayoutManager.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.TableCaption;
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-caption FO.
32  * The table caption contains blocks that are placed beside the
33  * table.
34  * @todo Implement getNextKnuthElements()
35  */

36 public class TableCaptionLayoutManager extends BlockStackingLayoutManager {
37     private TableCaption fobj;
38
39     private Block curBlockArea;
40
41     //private List childBreaks = new ArrayList();
42

43     /**
44      * Create a new Caption layout manager.
45      * @param node table-caption FO
46      */

47     public TableCaptionLayoutManager(TableCaption node) {
48         super(node);
49         fobj = node;
50     }
51
52     /**
53      * Get the next break position for the caption.
54      *
55      * @param context the layout context for finding breaks
56      * @return the next break possibility
57      */

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

126
127     /**
128      * Add the areas to the parent.
129      *
130      * @param parentIter the position iterator of the breaks
131      * @param layoutContext the layout context for adding areas
132      */

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

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

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

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

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