Browse Source

Fixups, type safety...


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1069917 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-1_1rc1old
Andreas L. Delmelle 13 years ago
parent
commit
5fad0eeea1
1 changed files with 66 additions and 82 deletions
  1. 66
    82
      src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java

+ 66
- 82
src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java View File

public class ListItemLayoutManager extends BlockStackingLayoutManager public class ListItemLayoutManager extends BlockStackingLayoutManager
implements ConditionalElementListener { implements ConditionalElementListener {


/**
* logging instance
*/
/** logging instance */
private static Log log = LogFactory.getLog(ListItemLayoutManager.class); private static Log log = LogFactory.getLog(ListItemLayoutManager.class);


private ListItemContentLayoutManager label; private ListItemContentLayoutManager label;


private Block curBlockArea = null; 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 discardBorderBefore;
private boolean discardBorderAfter; private boolean discardBorderAfter;
private Keep keepWithNextPendingOnLabel; private Keep keepWithNextPendingOnLabel;
private Keep keepWithNextPendingOnBody; private Keep keepWithNextPendingOnBody;


private int listItemHeight;

private class ListItemPosition extends Position { 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, public ListItemPosition(LayoutManager lm, int labelFirst, int labelLast,
int bodyFirst, int bodyLast) { int bodyFirst, int bodyLast) {
super(lm); super(lm);
iLabelFirstIndex = labelFirst;
iLabelLastIndex = labelLast;
iBodyFirstIndex = bodyFirst;
iBodyLastIndex = bodyLast;
labelFirstIndex = labelFirst;
labelLastIndex = labelLast;
bodyFirstIndex = bodyFirst;
bodyLastIndex = bodyLast;
} }


public int getLabelFirstIndex() { public int getLabelFirstIndex() {
return iLabelFirstIndex;
return labelFirstIndex;
} }


public int getLabelLastIndex() { public int getLabelLastIndex() {
return iLabelLastIndex;
return labelLastIndex;
} }


public int getBodyFirstIndex() { public int getBodyFirstIndex() {
return iBodyFirstIndex;
return bodyFirstIndex;
} }


public int getBodyLastIndex() { public int getBodyLastIndex() {
return iBodyLastIndex;
return bodyLastIndex;
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
public String toString() { public String toString() {
StringBuffer sb = new StringBuffer("ListItemPosition:"); StringBuffer sb = new StringBuffer("ListItemPosition:");
sb.append(getIndex()).append("("); 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(")"); sb.append(")");
return sb.toString(); return sb.toString();
} }
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public void initialize() { public void initialize() {
foSpaceBefore = new SpaceVal( foSpaceBefore = new SpaceVal(
getListItemFO().getCommonMarginBlock().spaceBefore, this).getSpace(); getListItemFO().getCommonMarginBlock().spaceBefore, this).getSpace();
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public List getNextKnuthElements(LayoutContext context, int alignment) { public List getNextKnuthElements(LayoutContext context, int alignment) {
referenceIPD = context.getRefIPD(); referenceIPD = context.getRefIPD();
LayoutContext childLC; 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 // label
childLC = new LayoutContext(0);
childLC.setRefIPD(context.getRefIPD());
childLC = makeChildLayoutContext(context);
label.initialize(); label.initialize();
labelList = label.getNextKnuthElements(childLC, alignment); labelList = label.getNextKnuthElements(childLC, alignment);


this.keepWithNextPendingOnLabel = childLC.getKeepWithNextPending(); this.keepWithNextPendingOnLabel = childLC.getKeepWithNextPending();


// body // body
childLC = new LayoutContext(0);
childLC.setRefIPD(context.getRefIPD());
childLC = makeChildLayoutContext(context);
body.initialize(); body.initialize();
bodyList = body.getNextKnuthElements(childLC, alignment); bodyList = body.getNextKnuthElements(childLC, alignment);


// "wrap" the Position inside each element // "wrap" the Position inside each element
wrapPositionElements(returnedList, returnList, true); wrapPositionElements(returnedList, returnList, true);


addKnuthElementsForBorderPaddingAfter(returnList, true);
addKnuthElementsForSpaceAfter(returnList, alignment);
addLastVisibleMarks(returnList, context, alignment);
addKnuthElementsForBreakAfter(returnList, context); addKnuthElementsForBreakAfter(returnList, context);


context.updateKeepWithNextPending(this.keepWithNextPendingOnLabel); context.updateKeepWithNextPending(this.keepWithNextPendingOnLabel);
return returnList; 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 // 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]), int[] fullHeights = {ElementListUtils.calcContentLength(elementLists[0]),
ElementListUtils.calcContentLength(elementLists[1])}; ElementListUtils.calcContentLength(elementLists[1])};
int[] partialHeights = {0, 0}; int[] partialHeights = {0, 0};
int addedBoxHeight = 0; int addedBoxHeight = 0;
Keep keepWithNextActive = Keep.KEEP_AUTO; Keep keepWithNextActive = Keep.KEEP_AUTO;


LinkedList returnList = new LinkedList();
LinkedList<ListElement> returnList = new LinkedList<ListElement>();
while ((step = getNextStep(elementLists, start, end, partialHeights)) > 0) { while ((step = getNextStep(elementLists, start, end, partialHeights)) > 0) {


if (end[0] + 1 == elementLists[0].size()) { if (end[0] + 1 == elementLists[0].size()) {
// collect footnote information // collect footnote information
// TODO this should really not be done like this. ListItemLM should remain as // TODO this should really not be done like this. ListItemLM should remain as
// footnote-agnostic as possible // footnote-agnostic as possible
LinkedList footnoteList = null;
LinkedList<ListElement> footnoteList = null;
ListElement el; ListElement el;
for (int i = 0; i < elementLists.length; i++) { for (int i = 0; i < elementLists.length; i++) {
for (int j = start[i]; j <= end[i]; j++) { for (int j = start[i]; j <= end[i]; j++) {
el = (ListElement) elementLists[i].get(j); el = (ListElement) elementLists[i].get(j);
if (el instanceof KnuthBlockBox && ((KnuthBlockBox) el).hasAnchors()) { if (el instanceof KnuthBlockBox && ((KnuthBlockBox) el).hasAnchors()) {
if (footnoteList == null) { if (footnoteList == null) {
footnoteList = new LinkedList();
footnoteList = new LinkedList<ListElement>();
} }
footnoteList.addAll(((KnuthBlockBox) el).getFootnoteBodyLMs()); footnoteList.addAll(((KnuthBlockBox) el).getFootnoteBodyLMs());
} }
fullHeights[1] - partialHeights[1]); fullHeights[1] - partialHeights[1]);
} }


/**
* {@inheritDoc}
*/
/** {@inheritDoc} */
@Override
public List getChangedKnuthElements(List oldList, int alignment) { public List getChangedKnuthElements(List oldList, int alignment) {
//log.debug(" LILM.getChanged> label");
// label // label
labelList = label.getChangedKnuthElements(labelList, alignment); labelList = label.getChangedKnuthElements(labelList, alignment);


//log.debug(" LILM.getChanged> body");
// body // body
// "unwrap" the Positions stored in the elements // "unwrap" the Positions stored in the elements
ListIterator oldListIterator = oldList.listIterator(); ListIterator oldListIterator = oldList.listIterator();
while (oldListIterator.hasNext()) { while (oldListIterator.hasNext()) {
oldElement = (KnuthElement)oldListIterator.next(); oldElement = (KnuthElement)oldListIterator.next();
Position innerPosition = oldElement.getPosition().getPosition(); 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) { if (innerPosition != null) {
// oldElement was created by a descendant of this BlockLM // oldElement was created by a descendant of this BlockLM
oldElement.setPosition(innerPosition); oldElement.setPosition(innerPosition);
* @param parentIter the position iterator * @param parentIter the position iterator
* @param layoutContext the layout context for adding areas * @param layoutContext the layout context for adding areas
*/ */
@Override
public void addAreas(PositionIterator parentIter, public void addAreas(PositionIterator parentIter,
LayoutContext layoutContext) { LayoutContext layoutContext) {
getParentArea(null); getParentArea(null);
Position lastPos = null; Position lastPos = null;


// "unwrap" the NonLeafPositions stored in parentIter // "unwrap" the NonLeafPositions stored in parentIter
LinkedList positionList = new LinkedList();
LinkedList<Position> positionList = new LinkedList<Position>();
Position pos; Position pos;
while (parentIter.hasNext()) { while (parentIter.hasNext()) {
pos = (Position) parentIter.next();
pos = parentIter.next();
if (pos.getIndex() >= 0) { if (pos.getIndex() >= 0) {
if (firstPos == null) { if (firstPos == null) {
firstPos = pos; firstPos = pos;
checkEndOfLayout(lastPos); 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 * Return an Area which can contain the passed childArea. The childArea
* may not yet have any content, but it has essential traits set. * may not yet have any content, but it has essential traits set.
* @param childArea the child area * @param childArea the child area
* @return the parent are for the child * @return the parent are for the child
*/ */
@Override
public Area getParentArea(Area childArea) { public Area getParentArea(Area childArea) {
if (curBlockArea == null) { if (curBlockArea == null) {
curBlockArea = new Block(); curBlockArea = new Block();
/*Area parentArea =*/ parentLayoutManager.getParentArea(curBlockArea); /*Area parentArea =*/ parentLayoutManager.getParentArea(curBlockArea);


// set traits // 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); discardBorderBefore, discardBorderAfter, false, false, this);
TraitSetter.addPadding(curBlockArea,
getListItemFO().getCommonBorderPaddingBackground(),
TraitSetter.addPadding(curBlockArea, fo.getCommonBorderPaddingBackground(),
discardPaddingBefore, discardPaddingAfter, false, false, this); 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(); int contentIPD = referenceIPD - getIPIndents();
curBlockArea.setIPD(contentIPD); curBlockArea.setIPD(contentIPD);
* *
* @param childArea the child area * @param childArea the child area
*/ */
@Override
public void addChildArea(Area childArea) { public void addChildArea(Area childArea) {
if (curBlockArea != null) { if (curBlockArea != null) {
curBlockArea.addBlock((Block) childArea); curBlockArea.addBlock((Block) childArea);
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public KeepProperty getKeepTogetherProperty() { public KeepProperty getKeepTogetherProperty() {
return getListItemFO().getKeepTogether(); return getListItemFO().getKeepTogether();
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public KeepProperty getKeepWithPreviousProperty() { public KeepProperty getKeepWithPreviousProperty() {
return getListItemFO().getKeepWithPrevious(); return getListItemFO().getKeepWithPrevious();
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public KeepProperty getKeepWithNextProperty() { public KeepProperty getKeepWithNextProperty() {
return getListItemFO().getKeepWithNext(); return getListItemFO().getKeepWithNext();
} }
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public void reset() { public void reset() {
super.reset(); super.reset();
label.reset(); label.reset();

Loading…
Cancel
Save