]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Code cleanup.
authorJeremias Maerki <jeremias@apache.org>
Wed, 18 May 2005 15:25:52 +0000 (15:25 +0000)
committerJeremias Maerki <jeremias@apache.org>
Wed, 18 May 2005 15:25:52 +0000 (15:25 +0000)
Some style fixes.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198653 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java
src/java/org/apache/fop/layoutmgr/table/Cell.java

index 3c1f090cb4d10e560503cdbe8a91db79814dc550..3399d05e6daa87420c0306472b5125cfd91bbf93 100644 (file)
@@ -23,7 +23,6 @@ import org.apache.fop.fo.pagination.Flow;
 import org.apache.fop.area.Area;
 import org.apache.fop.area.BlockParent;
 
-import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.ListIterator;
@@ -33,39 +32,21 @@ import java.util.ListIterator;
  * Its parent LM is the PageSequenceLayoutManager.
  * This LM is responsible for getting columns of the appropriate size
  * and filling them with block-level areas generated by its children.
+ * @todo Reintroduce emergency counter (generate error to avoid endless loop)
  */
 public class FlowLayoutManager extends BlockStackingLayoutManager
                                implements BlockLevelLayoutManager {
     private Flow fobj;
     
-    /** List of break possibilities */
-    protected List blockBreaks = new java.util.ArrayList();
-
     /** Array of areas currently being filled stored by area class */
     private BlockParent[] currentAreas = new BlockParent[Area.CLASS_MAX];
 
-    private int iStartPos = 0;
-
     /**
      * Used to count the number of subsequent times to layout child areas on
      * multiple pages.
      */
     private int numSubsequentOverflows = 0;
     
-    private static class StackingIter extends PositionIterator {
-        StackingIter(Iterator parentIter) {
-            super(parentIter);
-        }
-
-        protected LayoutManager getLM(Object nextObj) {
-            return ((Position) nextObj).getLM();
-        }
-
-        protected Position getPos(Object nextObj) {
-            return ((Position) nextObj);
-        }
-    }
-
     /**
      * This is the top level layout manager.
      * It is created by the PageSequence FO.
@@ -76,77 +57,6 @@ public class FlowLayoutManager extends BlockStackingLayoutManager
         fobj = node;
     }
 
-    /*
-    public BreakPoss getNextBreakPoss(LayoutContext context) {
-
-        // currently active LM
-        LayoutManager curLM;
-        MinOptMax stackSize = new MinOptMax();
-
-        fobj.setLayoutDimension(PercentBase.BLOCK_IPD, context.getRefIPD());
-        fobj.setLayoutDimension(PercentBase.BLOCK_BPD, context.getStackLimit().opt);
-
-        while ((curLM = getChildLM()) != null) {
-            if (curLM.generatesInlineAreas()) {
-                log.error("inline area not allowed under flow - ignoring");
-                curLM.setFinished(true);
-                continue;
-            }
-
-            // Make break positions and return page break
-            // Set up a LayoutContext
-            MinOptMax bpd = context.getStackLimit();
-            BreakPoss bp;
-
-            LayoutContext childLC = new LayoutContext(0);
-            boolean breakPage = false;
-            childLC.setStackLimit(MinOptMax.subtract(bpd, stackSize));
-            childLC.setRefIPD(context.getRefIPD());
-
-            if (!curLM.isFinished()) {
-                if ((bp = curLM.getNextBreakPoss(childLC)) != null) {
-                    stackSize.add(bp.getStackingSize());
-                    blockBreaks.add(bp);
-                    // set stackLimit for remaining space
-                    childLC.setStackLimit(MinOptMax.subtract(bpd, stackSize));
-
-                    if (bp.isForcedBreak() || bp.nextBreakOverflows()) {
-                        if (log.isDebugEnabled()) {
-                            log.debug("BreakPoss signals " + (bp.isForcedBreak() 
-                                    ? "forced break" : "next break overflows"));
-                        }
-                        breakPage = true;
-                    }
-                }
-            }
-
-            // check the stack bpd and if greater than available
-            // height then go to the last best break and return
-            // break position
-            if (stackSize.opt > context.getStackLimit().opt) {
-                breakPage = true;
-            }
-            if (breakPage) {
-                numSubsequentOverflows++;
-                if (numSubsequentOverflows > 50) {
-                    log.error("Content overflows available area. Giving up after 50 attempts.");
-                    setFinished(true);
-                    return null;
-                }
-                return new BreakPoss(
-                      new LeafPosition(this, blockBreaks.size() - 1));
-            }
-            numSubsequentOverflows = 0; //Reset emergency counter
-        }
-        setFinished(true);
-        if (blockBreaks.size() > 0) {
-            return new BreakPoss(
-                             new LeafPosition(this, blockBreaks.size() - 1));
-        }
-        return null;
-    }*/
-
-
     /**
      * "wrap" the Position inside each element moving the elements from 
      * SourceList to targetList
@@ -166,8 +76,7 @@ public class FlowLayoutManager extends BlockStackingLayoutManager
         }
     }
 
-    
-//TODO Reintroduce emergency counter (generate error to avoid endless loop)
+    /** @see org.apache.fop.layoutmgr.LayoutManager */
     public LinkedList getNextKnuthElements(LayoutContext context, int alignment) {
         // set layout dimensions
         fobj.setLayoutDimension(PercentBase.BLOCK_IPD, context.getRefIPD());
@@ -215,16 +124,19 @@ public class FlowLayoutManager extends BlockStackingLayoutManager
                     if (prevLM.mustKeepWithNext()
                         || curLM.mustKeepWithPrevious()) {
                         // add an infinite penalty to forbid a break between blocks
-                        returnList.add(new KnuthPenalty(0, KnuthElement.INFINITE, false, new Position(this), false));
+                        returnList.add(new KnuthPenalty(0, KnuthElement.INFINITE, false, 
+                                new Position(this), false));
                     } else if (!((KnuthElement) returnList.getLast()).isGlue()) {
                         // add a null penalty to allow a break between blocks
-                        returnList.add(new KnuthPenalty(0, 0, false, new Position(this), false));
+                        returnList.add(new KnuthPenalty(0, 0, false, 
+                                new Position(this), false));
                     }
                 }
                 if (returnedList.size() > 0) { // controllare!
                     returnList.addAll(returnedList);
                     if (((KnuthElement)returnedList.getLast()).isPenalty()
-                        && ((KnuthPenalty)returnedList.getLast()).getP() == -KnuthElement.INFINITE) {
+                        && ((KnuthPenalty)returnedList.getLast()).getP() 
+                                == -KnuthElement.INFINITE) {
                         // a descendant of this flow has break-after
                         return returnList;
                     }
@@ -242,6 +154,9 @@ public class FlowLayoutManager extends BlockStackingLayoutManager
         }
     }
 
+    /**
+     * @see org.apache.fop.layoutmgr.BlockLevelLayoutManager
+     */
     public int negotiateBPDAdjustment(int adj, KnuthElement lastElement) {
         log.debug(" FLM.negotiateBPDAdjustment> " + adj);
 
@@ -249,7 +164,8 @@ public class FlowLayoutManager extends BlockStackingLayoutManager
             // this element was not created by this FlowLM
             NonLeafPosition savedPos = (NonLeafPosition)lastElement.getPosition();
             lastElement.setPosition(savedPos.getPosition());
-            int returnValue = ((BlockLevelLayoutManager) lastElement.getLayoutManager()).negotiateBPDAdjustment(adj, lastElement);
+            int returnValue = ((BlockLevelLayoutManager)lastElement.getLayoutManager())
+                    .negotiateBPDAdjustment(adj, lastElement);
             lastElement.setPosition(savedPos);
             log.debug(" FLM.negotiateBPDAdjustment> result " + returnValue);
             return returnValue;
@@ -258,6 +174,9 @@ public class FlowLayoutManager extends BlockStackingLayoutManager
         }
     }
 
+    /**
+     * @see org.apache.fop.layoutmgr.BlockLevelLayoutManager
+     */
     public void discardSpace(KnuthGlue spaceGlue) {
         log.debug(" FLM.discardSpace> ");
 
@@ -270,18 +189,24 @@ public class FlowLayoutManager extends BlockStackingLayoutManager
         }
     }
 
+    /** @see org.apache.fop.layoutmgr.BlockLevelLayoutManager#mustKeepTogether() */
     public boolean mustKeepTogether() {
         return false;
     }
 
+    /** @see org.apache.fop.layoutmgr.BlockLevelLayoutManager#mustKeepWithPrevious() */
     public boolean mustKeepWithPrevious() {
         return false;
     }
 
+    /** @see org.apache.fop.layoutmgr.BlockLevelLayoutManager#mustKeepWithNext() */
     public boolean mustKeepWithNext() {
         return false;
     }
 
+    /**
+     * @see org.apache.fop.layoutmgr.LayoutManager#getChangedKnuthElements(java.util.List, int)
+     */
     public LinkedList getChangedKnuthElements(List oldList, /*int flaggedPenalty,*/ int alignment) {
         ListIterator oldListIterator = oldList.listIterator();
         KnuthElement returnedElement;
@@ -316,15 +241,16 @@ public class FlowLayoutManager extends BlockStackingLayoutManager
                                                  prevElement.getLayoutManager();
                 BlockLevelLayoutManager currLM = (BlockLevelLayoutManager)
                                                  currElement.getLayoutManager();
-                returnedList.addAll(prevLM.getChangedKnuthElements(oldList.subList(fromIndex, oldListIterator.previousIndex()),
-                                                                   /*flaggedPenalty,*/ alignment));
+                returnedList.addAll(prevLM.getChangedKnuthElements(
+                        oldList.subList(fromIndex, oldListIterator.previousIndex()), alignment));
                 fromIndex = oldListIterator.previousIndex();
 
                 // there is another block after this one
                 if (prevLM.mustKeepWithNext()
                     || currLM.mustKeepWithPrevious()) {
                     // add an infinite penalty to forbid a break between blocks
-                    returnedList.add(new KnuthPenalty(0, KnuthElement.INFINITE, false, new Position(this), false));
+                    returnedList.add(new KnuthPenalty(0, KnuthElement.INFINITE, false, 
+                            new Position(this), false));
                 } else if (!((KnuthElement) returnedList.getLast()).isGlue()) {
                     // add a null penalty to allow a break between blocks
                     returnedList.add(new KnuthPenalty(0, 0, false, new Position(this), false));
@@ -335,8 +261,8 @@ public class FlowLayoutManager extends BlockStackingLayoutManager
         if (currElement != null) {
             BlockLevelLayoutManager currLM = (BlockLevelLayoutManager)
                                              currElement.getLayoutManager();
-            returnedList.addAll(currLM.getChangedKnuthElements(oldList.subList(fromIndex, oldList.size()),
-                                                               /*flaggedPenalty,*/ alignment));
+            returnedList.addAll(currLM.getChangedKnuthElements(
+                    oldList.subList(fromIndex, oldList.size()), alignment));
         }
 
         // "wrap" the Position stored in each element of returnedList
@@ -345,7 +271,8 @@ public class FlowLayoutManager extends BlockStackingLayoutManager
         while (listIter.hasNext()) {
             returnedElement = (KnuthElement)listIter.next();
             if (returnedElement.getLayoutManager() != this) {
-                returnedElement.setPosition(new NonLeafPosition(this, returnedElement.getPosition()));
+                returnedElement.setPosition(
+                        new NonLeafPosition(this, returnedElement.getPosition()));
             }
             returnList.add(returnedElement);
         }
@@ -358,45 +285,6 @@ public class FlowLayoutManager extends BlockStackingLayoutManager
      */
     public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) {
         AreaAdditionUtil.addAreas(parentIter, layoutContext);
-        /*
-        LayoutManager childLM = null;
-        LayoutContext lc = new LayoutContext(0);
-        LayoutManager firstLM = null;
-        LayoutManager lastLM = null;
-
-        // "unwrap" the NonLeafPositions stored in parentIter
-        // and put them in a new list; 
-        LinkedList positionList = new LinkedList();
-        Position pos;
-        while (parentIter.hasNext()) {
-            pos = (Position)parentIter.next();
-            if (pos instanceof NonLeafPosition) {
-                // pos was created by a child of this FlowLM
-                positionList.add(((NonLeafPosition) pos).getPosition());
-                lastLM = ((NonLeafPosition) pos).getPosition().getLM();
-                if (firstLM == null) {
-                    firstLM = lastLM;
-                }
-            } else {
-                // pos was created by this FlowLM, so it must be ignored
-            }
-        }
-
-        StackingIter childPosIter = new StackingIter(positionList.listIterator());
-        while ((childLM = childPosIter.getNextChildLM()) != null) {
-            // Add the block areas to Area
-            lc.setFlags(LayoutContext.FIRST_AREA, childLM == firstLM);
-            lc.setFlags(LayoutContext.LAST_AREA, childLM == lastLM);
-            // set space before for the first LM, in order to implement
-            // display-align = center or after
-            lc.setSpaceBefore((childLM == firstLM ? layoutContext.getSpaceBefore() : 0));
-            // set space after for each LM, in order to implement
-            // display-align = distribute
-            lc.setSpaceAfter(layoutContext.getSpaceAfter());
-            lc.setStackLimit(layoutContext.getStackLimit());
-            childLM.addAreas(childPosIter, lc);
-        }*/
-
         flush();
     }
 
@@ -426,8 +314,8 @@ public class FlowLayoutManager extends BlockStackingLayoutManager
         } else if (aclass == Area.CLASS_FOOTNOTE) {
             parentArea = getCurrentPV().getBodyRegion().getFootnote();
         } else {
-            throw new IllegalStateException("(internal error) Invalid " +
-                    "area class (" + aclass + ") requested.");
+            throw new IllegalStateException("(internal error) Invalid "
+                    "area class (" + aclass + ") requested.");
         }
         
         this.currentAreas[aclass] = parentArea;
index 32096098b80479ebae4b76f99701052fcf903942..fd15cc9023e8138bb49afee5bdfc0c00115ba1a1 100644 (file)
@@ -18,6 +18,9 @@
  
 package org.apache.fop.layoutmgr.table;
 
+import java.util.LinkedList;
+import java.util.List;
+
 import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.flow.Table;
 import org.apache.fop.fo.flow.TableCell;
@@ -37,10 +40,6 @@ import org.apache.fop.area.Block;
 import org.apache.fop.area.Trait;
 import org.apache.fop.traits.MinOptMax;
 
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-
 /**
  * LayoutManager for a table-cell FO.
  * A cell contains blocks. These blocks fill the cell.
@@ -52,13 +51,10 @@ public class Cell extends BlockStackingLayoutManager implements BlockLevelLayout
     
     private Block curBlockArea;
 
-    private List childBreaks = new ArrayList();
-
     private int inRowIPDOffset;
     
     private int xoffset;
     private int yoffset;
-    private int referenceIPD;
     private int cellIPD;
     private int rowHeight;
     private int usedBPD;
@@ -413,7 +409,6 @@ public class Cell extends BlockStackingLayoutManager implements BlockLevelLayout
 
         flush();
 
-        childBreaks.clear();
         curBlockArea = null;
     }
 
@@ -489,7 +484,6 @@ public class Cell extends BlockStackingLayoutManager implements BlockLevelLayout
     public void resetPosition(Position resetPos) {
         if (resetPos == null) {
             reset(null);
-            childBreaks.clear();
         }
     }