1 17 18 19 20 package org.apache.fop.layoutmgr.list; 21 22 import org.apache.fop.fo.flow.AbstractListItemPart; 23 import org.apache.fop.fo.flow.ListItemBody; 24 import org.apache.fop.fo.flow.ListItemLabel; 25 import org.apache.fop.layoutmgr.BlockLevelLayoutManager; 26 import org.apache.fop.layoutmgr.BlockStackingLayoutManager; 27 import org.apache.fop.layoutmgr.LayoutManager; 28 import org.apache.fop.layoutmgr.LayoutContext; 29 import org.apache.fop.layoutmgr.PositionIterator; 30 import org.apache.fop.layoutmgr.Position; 31 import org.apache.fop.layoutmgr.NonLeafPosition; 32 import org.apache.fop.layoutmgr.TraitSetter; 33 import org.apache.fop.layoutmgr.SpaceResolver.SpaceHandlingBreakPosition; 34 import org.apache.fop.area.Area; 35 import org.apache.fop.area.Block; 36 37 import java.util.Iterator ; 38 import java.util.List ; 39 import java.util.LinkedList ; 40 41 44 public class ListItemContentLayoutManager extends BlockStackingLayoutManager { 45 46 private Block curBlockArea; 47 48 private int xoffset; 49 private int itemIPD; 50 51 private static class StackingIter extends PositionIterator { 52 StackingIter(Iterator parentIter) { 53 super(parentIter); 54 } 55 56 protected LayoutManager getLM(Object nextObj) { 57 return ((Position) nextObj).getLM(); 58 } 59 60 protected Position getPos(Object nextObj) { 61 return ((Position) nextObj); 62 } 63 } 64 65 69 public ListItemContentLayoutManager(ListItemLabel node) { 70 super(node); 71 } 72 73 77 public ListItemContentLayoutManager(ListItemBody node) { 78 super(node); 79 } 80 81 85 protected AbstractListItemPart getPartFO() { 86 return (AbstractListItemPart)fobj; 87 } 88 89 96 public void setXOffset(int off) { 97 xoffset = off; 98 } 99 100 101 public LinkedList getChangedKnuthElements(List oldList, int alignment) { 102 return super.getChangedKnuthElements(oldList, alignment); 104 } 105 106 114 public void addAreas(PositionIterator parentIter, 115 LayoutContext layoutContext) { 116 getParentArea(null); 117 118 getPSLM().addIDToPage(getPartFO().getId()); 119 120 LayoutManager childLM = null; 121 LayoutContext lc = new LayoutContext(0); 122 LayoutManager firstLM = null; 123 LayoutManager lastLM = null; 124 Position firstPos = null; 125 Position lastPos = null; 126 127 LinkedList positionList = new LinkedList (); 130 Position pos; 131 while (parentIter.hasNext()) { 132 pos = (Position)parentIter.next(); 133 if (pos == null) { 134 continue; 135 } 136 if (pos.getIndex() >= 0) { 137 if (firstPos == null) { 138 firstPos = pos; 139 } 140 lastPos = pos; 141 } 142 if (pos instanceof NonLeafPosition) { 143 positionList.add(((NonLeafPosition) pos).getPosition()); 145 lastLM = ((NonLeafPosition) pos).getPosition().getLM(); 146 if (firstLM == null) { 147 firstLM = lastLM; 148 } 149 } else if (pos instanceof SpaceHandlingBreakPosition) { 150 positionList.add(pos); 151 } else { 152 } 154 } 155 156 if (markers != null) { 157 getCurrentPV().addMarkers(markers, true, isFirst(firstPos), isLast(lastPos)); 158 } 159 160 StackingIter childPosIter = new StackingIter(positionList.listIterator()); 161 while ((childLM = childPosIter.getNextChildLM()) != null) { 162 lc.setFlags(LayoutContext.FIRST_AREA, childLM == firstLM); 164 lc.setFlags(LayoutContext.LAST_AREA, childLM == lastLM); 165 lc.setSpaceAdjust(layoutContext.getSpaceAdjust()); 167 lc.setStackLimit(layoutContext.getStackLimit()); 168 childLM.addAreas(childPosIter, lc); 169 } 170 171 if (markers != null) { 172 getCurrentPV().addMarkers(markers, false, isFirst(firstPos), isLast(lastPos)); 173 } 174 175 flush(); 176 177 curBlockArea = null; 178 179 getPSLM().notifyEndOfLayout(((AbstractListItemPart)getFObj()).getId()); 180 } 181 182 195 public Area getParentArea(Area childArea) { 196 if (curBlockArea == null) { 197 curBlockArea = new Block(); 198 curBlockArea.setPositioning(Block.ABSOLUTE); 199 curBlockArea.setXOffset(xoffset); 201 curBlockArea.setIPD(itemIPD); 202 204 TraitSetter.setProducerID(curBlockArea, getPartFO().getId()); 205 206 Area parentArea = parentLM.getParentArea(curBlockArea); 208 int referenceIPD = parentArea.getIPD(); 209 curBlockArea.setIPD(referenceIPD); 210 setCurrentArea(curBlockArea); } 213 return curBlockArea; 214 } 215 216 221 public void addChildArea(Area childArea) { 222 if (curBlockArea != null) { 223 curBlockArea.addBlock((Block) childArea); 224 } 225 } 226 227 232 public void resetPosition(Position resetPos) { 233 if (resetPos == null) { 234 reset(null); 235 } else { 236 setFinished(false); 237 } 239 } 240 241 242 public boolean mustKeepTogether() { 243 return ((BlockLevelLayoutManager)getParent()).mustKeepTogether() 245 || !getPartFO().getKeepTogether().getWithinPage().isAuto() 246 || !getPartFO().getKeepTogether().getWithinColumn().isAuto(); 247 } 248 249 } 250 251 | Popular Tags |