public class ListItemLayoutManager extends BlockStackingLayoutManager
implements ConditionalElementListener {
- /**
- * logging instance
- */
+ /** logging instance */
private static Log log = LogFactory.getLog(ListItemLayoutManager.class);
private ListItemContentLayoutManager label;
private Block curBlockArea = null;
- private List labelList = null;
- private List bodyList = null;
+ private List<ListElement> labelList = null;
+ private List<ListElement> bodyList = null;
private boolean discardBorderBefore;
private boolean discardBorderAfter;
private Keep keepWithNextPendingOnLabel;
private Keep keepWithNextPendingOnBody;
- private int listItemHeight;
-
private class ListItemPosition extends Position {
- private int iLabelFirstIndex;
- private int iLabelLastIndex;
- private int iBodyFirstIndex;
- private int iBodyLastIndex;
+ private int labelFirstIndex;
+ private int labelLastIndex;
+ private int bodyFirstIndex;
+ private int bodyLastIndex;
public ListItemPosition(LayoutManager lm, int labelFirst, int labelLast,
int bodyFirst, int bodyLast) {
super(lm);
- iLabelFirstIndex = labelFirst;
- iLabelLastIndex = labelLast;
- iBodyFirstIndex = bodyFirst;
- iBodyLastIndex = bodyLast;
+ labelFirstIndex = labelFirst;
+ labelLastIndex = labelLast;
+ bodyFirstIndex = bodyFirst;
+ bodyLastIndex = bodyLast;
}
public int getLabelFirstIndex() {
- return iLabelFirstIndex;
+ return labelFirstIndex;
}
public int getLabelLastIndex() {
- return iLabelLastIndex;
+ return labelLastIndex;
}
public int getBodyFirstIndex() {
- return iBodyFirstIndex;
+ return bodyFirstIndex;
}
public int getBodyLastIndex() {
- return iBodyLastIndex;
+ return bodyLastIndex;
}
/** {@inheritDoc} */
public String toString() {
StringBuffer sb = new StringBuffer("ListItemPosition:");
sb.append(getIndex()).append("(");
- sb.append("label:").append(iLabelFirstIndex).append("-").append(iLabelLastIndex);
- sb.append(" body:").append(iBodyFirstIndex).append("-").append(iBodyLastIndex);
+ sb.append("label:").append(labelFirstIndex).append("-").append(labelLastIndex);
+ sb.append(" body:").append(bodyFirstIndex).append("-").append(bodyLastIndex);
sb.append(")");
return sb.toString();
}
}
/** {@inheritDoc} */
+ @Override
public void initialize() {
foSpaceBefore = new SpaceVal(
getListItemFO().getCommonMarginBlock().spaceBefore, this).getSpace();
}
/** {@inheritDoc} */
+ @Override
public List getNextKnuthElements(LayoutContext context, int alignment) {
referenceIPD = context.getRefIPD();
LayoutContext childLC;
- List returnList = new LinkedList();
+ List<ListElement> returnList = new LinkedList<ListElement>();
- if (!breakBeforeServed) {
- breakBeforeServed = true;
- if (!context.suppressBreakBefore()) {
- if (addKnuthElementsForBreakBefore(returnList, context)) {
- return returnList;
- }
- }
+ if (!breakBeforeServed(context, returnList)) {
+ return returnList;
}
- addKnuthElementsForSpaceBefore(returnList, alignment);
-
- addKnuthElementsForBorderPaddingBefore(returnList, !firstVisibleMarkServed);
- firstVisibleMarkServed = true;
-
- //Spaces, border and padding to be repeated at each break
- addPendingMarks(context);
+ addFirstVisibleMarks(returnList, context, alignment);
// label
- childLC = new LayoutContext(0);
- childLC.setRefIPD(context.getRefIPD());
+ childLC = makeChildLayoutContext(context);
label.initialize();
labelList = label.getNextKnuthElements(childLC, alignment);
this.keepWithNextPendingOnLabel = childLC.getKeepWithNextPending();
// body
- childLC = new LayoutContext(0);
- childLC.setRefIPD(context.getRefIPD());
+ childLC = makeChildLayoutContext(context);
body.initialize();
bodyList = body.getNextKnuthElements(childLC, alignment);
// "wrap" the Position inside each element
wrapPositionElements(returnedList, returnList, true);
- addKnuthElementsForBorderPaddingAfter(returnList, true);
- addKnuthElementsForSpaceAfter(returnList, alignment);
+ addLastVisibleMarks(returnList, context, alignment);
+
addKnuthElementsForBreakAfter(returnList, context);
context.updateKeepWithNextPending(this.keepWithNextPendingOnLabel);
return returnList;
}
- private List getCombinedKnuthElementsForListItem(List labelElements,
- List bodyElements, LayoutContext context) {
+ /**
+ * Overridden to unconditionally add elements for space-before.
+ * {@inheritDoc}
+ */
+ @Override
+ protected void addFirstVisibleMarks(List<ListElement> elements,
+ LayoutContext context, int alignment) {
+ addKnuthElementsForSpaceBefore(elements, alignment);
+ addKnuthElementsForBorderPaddingBefore(elements, !firstVisibleMarkServed);
+ firstVisibleMarkServed = true;
+ //Spaces, border and padding to be repeated at each break
+ addPendingMarks(context);
+ }
+
+ private List getCombinedKnuthElementsForListItem(List<ListElement> labelElements,
+ List<ListElement> bodyElements, LayoutContext context) {
// Copy elements to array lists to improve element access performance
- List[] elementLists = {new ArrayList(labelElements),
- new ArrayList(bodyElements)};
+ List[] elementLists = {new ArrayList<ListElement>(labelElements),
+ new ArrayList<ListElement>(bodyElements)};
int[] fullHeights = {ElementListUtils.calcContentLength(elementLists[0]),
ElementListUtils.calcContentLength(elementLists[1])};
int[] partialHeights = {0, 0};
int addedBoxHeight = 0;
Keep keepWithNextActive = Keep.KEEP_AUTO;
- LinkedList returnList = new LinkedList();
+ LinkedList<ListElement> returnList = new LinkedList<ListElement>();
while ((step = getNextStep(elementLists, start, end, partialHeights)) > 0) {
if (end[0] + 1 == elementLists[0].size()) {
// collect footnote information
// TODO this should really not be done like this. ListItemLM should remain as
// footnote-agnostic as possible
- LinkedList footnoteList = null;
+ LinkedList<ListElement> footnoteList = null;
ListElement el;
for (int i = 0; i < elementLists.length; i++) {
for (int j = start[i]; j <= end[i]; j++) {
el = (ListElement) elementLists[i].get(j);
if (el instanceof KnuthBlockBox && ((KnuthBlockBox) el).hasAnchors()) {
if (footnoteList == null) {
- footnoteList = new LinkedList();
+ footnoteList = new LinkedList<ListElement>();
}
footnoteList.addAll(((KnuthBlockBox) el).getFootnoteBodyLMs());
}
fullHeights[1] - partialHeights[1]);
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
+ @Override
public List getChangedKnuthElements(List oldList, int alignment) {
- //log.debug(" LILM.getChanged> label");
// label
labelList = label.getChangedKnuthElements(labelList, alignment);
- //log.debug(" LILM.getChanged> body");
// body
// "unwrap" the Positions stored in the elements
ListIterator oldListIterator = oldList.listIterator();
while (oldListIterator.hasNext()) {
oldElement = (KnuthElement)oldListIterator.next();
Position innerPosition = oldElement.getPosition().getPosition();
- //log.debug(" BLM> unwrapping: " + (oldElement.isBox()
- // ? "box " : (oldElement.isGlue() ? "glue " : "penalty"))
- // + " creato da " + oldElement.getLayoutManager().getClass().getName());
- //log.debug(" BLM> unwrapping: "
- // + oldElement.getPosition().getClass().getName());
if (innerPosition != null) {
// oldElement was created by a descendant of this BlockLM
oldElement.setPosition(innerPosition);
* @param parentIter the position iterator
* @param layoutContext the layout context for adding areas
*/
+ @Override
public void addAreas(PositionIterator parentIter,
LayoutContext layoutContext) {
getParentArea(null);
Position lastPos = null;
// "unwrap" the NonLeafPositions stored in parentIter
- LinkedList positionList = new LinkedList();
+ LinkedList<Position> positionList = new LinkedList<Position>();
Position pos;
while (parentIter.hasNext()) {
- pos = (Position) parentIter.next();
+ pos = parentIter.next();
if (pos.getIndex() >= 0) {
if (firstPos == null) {
firstPos = pos;
checkEndOfLayout(lastPos);
}
- /**
- * Get the height of the list item after adjusting.
- * Should only be called after adding the list item areas.
- *
- * @return the height of this list item after adjustment
- */
- public int getListItemHeight() {
- return listItemHeight;
- }
-
/**
* Return an Area which can contain the passed childArea. The childArea
* may not yet have any content, but it has essential traits set.
* @param childArea the child area
* @return the parent are for the child
*/
+ @Override
public Area getParentArea(Area childArea) {
if (curBlockArea == null) {
curBlockArea = new Block();
/*Area parentArea =*/ parentLayoutManager.getParentArea(curBlockArea);
// set traits
- TraitSetter.setProducerID(curBlockArea, getListItemFO().getId());
- TraitSetter.addBorders(curBlockArea,
- getListItemFO().getCommonBorderPaddingBackground(),
+ ListItem fo = getListItemFO();
+ TraitSetter.setProducerID(curBlockArea, fo.getId());
+ TraitSetter.addBorders(curBlockArea, fo.getCommonBorderPaddingBackground(),
discardBorderBefore, discardBorderAfter, false, false, this);
- TraitSetter.addPadding(curBlockArea,
- getListItemFO().getCommonBorderPaddingBackground(),
+ TraitSetter.addPadding(curBlockArea, fo.getCommonBorderPaddingBackground(),
discardPaddingBefore, discardPaddingAfter, false, false, this);
- TraitSetter.addMargins(curBlockArea,
- getListItemFO().getCommonBorderPaddingBackground(),
- getListItemFO().getCommonMarginBlock(), this);
- TraitSetter.addBreaks(curBlockArea,
- getListItemFO().getBreakBefore(),
- getListItemFO().getBreakAfter());
+ TraitSetter.addMargins(curBlockArea, fo.getCommonBorderPaddingBackground(),
+ fo.getCommonMarginBlock(), this);
+ TraitSetter.addBreaks(curBlockArea, fo.getBreakBefore(), fo.getBreakAfter());
int contentIPD = referenceIPD - getIPIndents();
curBlockArea.setIPD(contentIPD);
*
* @param childArea the child area
*/
+ @Override
public void addChildArea(Area childArea) {
if (curBlockArea != null) {
curBlockArea.addBlock((Block) childArea);
}
/** {@inheritDoc} */
+ @Override
public KeepProperty getKeepTogetherProperty() {
return getListItemFO().getKeepTogether();
}
/** {@inheritDoc} */
+ @Override
public KeepProperty getKeepWithPreviousProperty() {
return getListItemFO().getKeepWithPrevious();
}
/** {@inheritDoc} */
+ @Override
public KeepProperty getKeepWithNextProperty() {
return getListItemFO().getKeepWithNext();
}
}
/** {@inheritDoc} */
+ @Override
public void reset() {
super.reset();
label.reset();