001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /* $Id: TableCaptionLayoutManager.java 426576 2006-07-28 15:44:37Z jeremias $ */
019:
020: package org.apache.fop.layoutmgr.table;
021:
022: import org.apache.fop.fo.flow.TableCaption;
023: import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
024: import org.apache.fop.layoutmgr.LayoutContext;
025: import org.apache.fop.layoutmgr.PositionIterator;
026: import org.apache.fop.layoutmgr.Position;
027: import org.apache.fop.area.Area;
028: import org.apache.fop.area.Block;
029:
030: /**
031: * LayoutManager for a table-caption FO.
032: * The table caption contains blocks that are placed beside the
033: * table.
034: * @todo Implement getNextKnuthElements()
035: */
036: public class TableCaptionLayoutManager extends
037: BlockStackingLayoutManager {
038: private TableCaption fobj;
039:
040: private Block curBlockArea;
041:
042: //private List childBreaks = new ArrayList();
043:
044: /**
045: * Create a new Caption layout manager.
046: * @param node table-caption FO
047: */
048: public TableCaptionLayoutManager(TableCaption node) {
049: super (node);
050: fobj = node;
051: }
052:
053: /**
054: * Get the next break position for the caption.
055: *
056: * @param context the layout context for finding breaks
057: * @return the next break possibility
058: */
059: /*
060: public BreakPoss getNextBreakPoss(LayoutContext context) {
061: LayoutManager curLM; // currently active LM
062:
063: MinOptMax stackSize = new MinOptMax();
064: // if starting add space before
065: // stackSize.add(spaceBefore);
066: BreakPoss lastPos = null;
067:
068: // if there is a caption then get the side and work out when
069: // to handle it
070:
071: while ((curLM = getChildLM()) != null) {
072: // Make break positions and return blocks!
073: // Set up a LayoutContext
074: int ipd = context.getRefIPD();
075: BreakPoss bp;
076:
077: LayoutContext childLC = new LayoutContext(0);
078: // if line layout manager then set stack limit to ipd
079: // line LM actually generates a LineArea which is a block
080: childLC.setStackLimit(
081: MinOptMax.subtract(context.getStackLimit(),
082: stackSize));
083: childLC.setRefIPD(ipd);
084:
085: boolean over = false;
086:
087: while (!curLM.isFinished()) {
088: if ((bp = curLM.getNextBreakPoss(childLC)) != null) {
089: if (stackSize.opt + bp.getStackingSize().opt > context.getStackLimit().max) {
090: // reset to last break
091: if (lastPos != null) {
092: LayoutManager lm = lastPos.getLayoutManager();
093: lm.resetPosition(lastPos.getPosition());
094: if (lm != curLM) {
095: curLM.resetPosition(null);
096: }
097: } else {
098: curLM.resetPosition(null);
099: }
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 to the parent.
130: *
131: * @param parentIter the position iterator of the breaks
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
171: * @return the parent area from this 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 caption area.
189: *
190: * @param childArea the child 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 layout position.
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: }
|