package org.apache.fop.layoutmgr;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FObj;
+import org.apache.fop.fo.flow.Marker;
import org.apache.fop.fo.flow.RetrieveMarker;
+import org.apache.xmlgraphics.util.QName;
/**
* The base class for most LayoutManagers.
*/
public abstract class AbstractLayoutManager extends AbstractBaseLayoutManager
- implements Constants {
+ implements Constants {
- /**
- * logging instance
- */
+ /** logging instance */
private static Log log = LogFactory.getLog(AbstractLayoutManager.class);
/** Parent LayoutManager for this LayoutManager */
protected LayoutManager parentLayoutManager;
/** List of child LayoutManagers */
- protected List childLMs;
+ protected List<LayoutManager> childLMs;
/** Iterator for child LayoutManagers */
protected ListIterator fobjIter;
/** Marker map for markers related to this LayoutManager */
- private Map markers;
+ private Map<String, Marker> markers;
/** True if this LayoutManager has handled all of its content. */
private boolean isFinished;
protected LayoutManager curChildLM;
/** child LM iterator during getNextKnuthElement phase */
- protected ListIterator childLMiter;
+ protected ListIterator<LayoutManager> childLMiter;
private int lastGeneratedPosition = -1;
private int smallestPosNumberChecked = Integer.MAX_VALUE;
return curChildLM;
}
if (childLMiter.hasNext()) {
- curChildLM = (LayoutManager) childLMiter.next();
+ curChildLM = childLMiter.next();
curChildLM.initialize();
return curChildLM;
}
curChildLM = childLM;
childLMiter = new LMiter(this);
do {
- curChildLM = (LayoutManager) childLMiter.next();
+ curChildLM = childLMiter.next();
} while (curChildLM != childLM);
}
}
/** {@inheritDoc} */
- public List getNextKnuthElements(LayoutContext context,
- int alignment) {
+ public List getNextKnuthElements(LayoutContext context, int alignment) {
log.warn("null implementation of getNextKnuthElements() called!");
setFinished(true);
return null;
}
/** {@inheritDoc} */
- public List getChangedKnuthElements(List oldList,
- int alignment) {
+ public List getChangedKnuthElements(List oldList, int alignment) {
log.warn("null implementation of getChangeKnuthElement() called!");
return null;
}
* @param size the requested number of child LMs
* @return the list with the preloaded child LMs
*/
- protected List createChildLMs(int size) {
+ protected List<LayoutManager> createChildLMs(int size) {
if (fobjIter == null) {
return null;
}
- List newLMs = new ArrayList(size);
+ List<LayoutManager> newLMs = new ArrayList<LayoutManager>(size);
while (fobjIter.hasNext() && newLMs.size() < size ) {
Object theobj = fobjIter.next();
if (theobj instanceof FONode) {
return getPSLM().getCurrentPage().getPageViewport();
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public boolean createNextChildLMs(int pos) {
- List newLMs = createChildLMs(pos + 1 - childLMs.size());
+ List<LayoutManager> newLMs = createChildLMs(pos + 1 - childLMs.size());
addChildLMs(newLMs);
return pos < childLMs.size();
}
- /**
- * {@inheritDoc}
- */
- public List getChildLMs() {
+ /** {@inheritDoc} */
+ public List<LayoutManager> getChildLMs() {
if (childLMs == null) {
- childLMs = new java.util.ArrayList(10);
+ childLMs = new java.util.ArrayList<LayoutManager>(10);
}
return childLMs;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void addChildLM(LayoutManager lm) {
if (lm == null) {
return;
}
lm.setParent(this);
if (childLMs == null) {
- childLMs = new java.util.ArrayList(10);
+ childLMs = new java.util.ArrayList<LayoutManager>(10);
}
childLMs.add(lm);
if (log.isTraceEnabled()) {
}
}
- /**
- * {@inheritDoc}
- */
- public void addChildLMs(List newLMs) {
+ /** {@inheritDoc} */
+ public void addChildLMs(List<LayoutManager> newLMs) {
if (newLMs == null || newLMs.size() == 0) {
return;
}
- ListIterator iter = newLMs.listIterator();
+ ListIterator<LayoutManager> iter = newLMs.listIterator();
while (iter.hasNext()) {
- LayoutManager lm = (LayoutManager) iter.next();
- addChildLM(lm);
+ addChildLM(iter.next());
}
}
throw new IllegalStateException("Position already got its index");
}
- lastGeneratedPosition++;
- pos.setIndex(lastGeneratedPosition);
+ pos.setIndex(++lastGeneratedPosition);
return pos;
}
* @param targetArea the area to set the attributes on
*/
protected void transferForeignAttributes(AreaTreeObject targetArea) {
- Map atts = fobj.getForeignAttributes();
+ Map<QName, String> atts = fobj.getForeignAttributes();
targetArea.setForeignAttributes(atts);
}
}
/** {@inheritDoc} */
+ @Override
public String toString() {
return (super.toString() + (fobj != null ? "[fobj=" + fobj.toString() + "]" : ""));
}
/** {@inheritDoc} */
+ @Override
public void reset() {
isFinished = false;
curChildLM = null;
childLMiter = new LMiter(this);
/* Reset all the children LM that have been created so far. */
- for (Iterator iter = getChildLMs().iterator(); iter.hasNext();) {
- ((LayoutManager) iter.next()).reset();
+ for (LayoutManager childLM : getChildLMs()) {
+ childLM.reset();
}
if (fobj != null) {
markers = fobj.getMarkers();