Browse Source

Fixups, type safety...

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1067691 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-1_1rc1old
Andreas L. Delmelle 13 years ago
parent
commit
57b24da133
1 changed files with 30 additions and 41 deletions
  1. 30
    41
      src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java

+ 30
- 41
src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java View File

package org.apache.fop.layoutmgr; package org.apache.fop.layoutmgr;


import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.Map; import java.util.Map;
import org.apache.fop.fo.Constants; import org.apache.fop.fo.Constants;
import org.apache.fop.fo.FONode; import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FObj; import org.apache.fop.fo.FObj;
import org.apache.fop.fo.flow.Marker;
import org.apache.fop.fo.flow.RetrieveMarker; import org.apache.fop.fo.flow.RetrieveMarker;
import org.apache.xmlgraphics.util.QName;


/** /**
* The base class for most LayoutManagers. * The base class for most LayoutManagers.
*/ */
public abstract class AbstractLayoutManager extends AbstractBaseLayoutManager public abstract class AbstractLayoutManager extends AbstractBaseLayoutManager
implements Constants {
implements Constants {


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


/** Parent LayoutManager for this LayoutManager */ /** Parent LayoutManager for this LayoutManager */
protected LayoutManager parentLayoutManager; protected LayoutManager parentLayoutManager;
/** List of child LayoutManagers */ /** List of child LayoutManagers */
protected List childLMs;
protected List<LayoutManager> childLMs;
/** Iterator for child LayoutManagers */ /** Iterator for child LayoutManagers */
protected ListIterator fobjIter; protected ListIterator fobjIter;
/** Marker map for markers related to this LayoutManager */ /** 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. */ /** True if this LayoutManager has handled all of its content. */
private boolean isFinished; private boolean isFinished;
protected LayoutManager curChildLM; protected LayoutManager curChildLM;


/** child LM iterator during getNextKnuthElement phase */ /** child LM iterator during getNextKnuthElement phase */
protected ListIterator childLMiter;
protected ListIterator<LayoutManager> childLMiter;


private int lastGeneratedPosition = -1; private int lastGeneratedPosition = -1;
private int smallestPosNumberChecked = Integer.MAX_VALUE; private int smallestPosNumberChecked = Integer.MAX_VALUE;
return curChildLM; return curChildLM;
} }
if (childLMiter.hasNext()) { if (childLMiter.hasNext()) {
curChildLM = (LayoutManager) childLMiter.next();
curChildLM = childLMiter.next();
curChildLM.initialize(); curChildLM.initialize();
return curChildLM; return curChildLM;
} }
curChildLM = childLM; curChildLM = childLM;
childLMiter = new LMiter(this); childLMiter = new LMiter(this);
do { do {
curChildLM = (LayoutManager) childLMiter.next();
curChildLM = childLMiter.next();
} while (curChildLM != childLM); } while (curChildLM != childLM);
} }


} }


/** {@inheritDoc} */ /** {@inheritDoc} */
public List getNextKnuthElements(LayoutContext context,
int alignment) {
public List getNextKnuthElements(LayoutContext context, int alignment) {
log.warn("null implementation of getNextKnuthElements() called!"); log.warn("null implementation of getNextKnuthElements() called!");
setFinished(true); setFinished(true);
return null; return null;
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
public List getChangedKnuthElements(List oldList,
int alignment) {
public List getChangedKnuthElements(List oldList, int alignment) {
log.warn("null implementation of getChangeKnuthElement() called!"); log.warn("null implementation of getChangeKnuthElement() called!");
return null; return null;
} }
* @param size the requested number of child LMs * @param size the requested number of child LMs
* @return the list with the preloaded child LMs * @return the list with the preloaded child LMs
*/ */
protected List createChildLMs(int size) {
protected List<LayoutManager> createChildLMs(int size) {
if (fobjIter == null) { if (fobjIter == null) {
return null; return null;
} }
List newLMs = new ArrayList(size);
List<LayoutManager> newLMs = new ArrayList<LayoutManager>(size);
while (fobjIter.hasNext() && newLMs.size() < size ) { while (fobjIter.hasNext() && newLMs.size() < size ) {
Object theobj = fobjIter.next(); Object theobj = fobjIter.next();
if (theobj instanceof FONode) { if (theobj instanceof FONode) {
return getPSLM().getCurrentPage().getPageViewport(); return getPSLM().getCurrentPage().getPageViewport();
} }


/**
* {@inheritDoc}
*/
/** {@inheritDoc} */
public boolean createNextChildLMs(int pos) { public boolean createNextChildLMs(int pos) {
List newLMs = createChildLMs(pos + 1 - childLMs.size());
List<LayoutManager> newLMs = createChildLMs(pos + 1 - childLMs.size());
addChildLMs(newLMs); addChildLMs(newLMs);
return pos < childLMs.size(); return pos < childLMs.size();
} }


/**
* {@inheritDoc}
*/
public List getChildLMs() {
/** {@inheritDoc} */
public List<LayoutManager> getChildLMs() {
if (childLMs == null) { if (childLMs == null) {
childLMs = new java.util.ArrayList(10);
childLMs = new java.util.ArrayList<LayoutManager>(10);
} }
return childLMs; return childLMs;
} }


/**
* {@inheritDoc}
*/
/** {@inheritDoc} */
public void addChildLM(LayoutManager lm) { public void addChildLM(LayoutManager lm) {
if (lm == null) { if (lm == null) {
return; return;
} }
lm.setParent(this); lm.setParent(this);
if (childLMs == null) { if (childLMs == null) {
childLMs = new java.util.ArrayList(10);
childLMs = new java.util.ArrayList<LayoutManager>(10);
} }
childLMs.add(lm); childLMs.add(lm);
if (log.isTraceEnabled()) { if (log.isTraceEnabled()) {
} }
} }


/**
* {@inheritDoc}
*/
public void addChildLMs(List newLMs) {
/** {@inheritDoc} */
public void addChildLMs(List<LayoutManager> newLMs) {
if (newLMs == null || newLMs.size() == 0) { if (newLMs == null || newLMs.size() == 0) {
return; return;
} }
ListIterator iter = newLMs.listIterator();
ListIterator<LayoutManager> iter = newLMs.listIterator();
while (iter.hasNext()) { while (iter.hasNext()) {
LayoutManager lm = (LayoutManager) iter.next();
addChildLM(lm);
addChildLM(iter.next());
} }
} }


throw new IllegalStateException("Position already got its index"); throw new IllegalStateException("Position already got its index");
} }


lastGeneratedPosition++;
pos.setIndex(lastGeneratedPosition);
pos.setIndex(++lastGeneratedPosition);
return pos; return pos;
} }


* @param targetArea the area to set the attributes on * @param targetArea the area to set the attributes on
*/ */
protected void transferForeignAttributes(AreaTreeObject targetArea) { protected void transferForeignAttributes(AreaTreeObject targetArea) {
Map atts = fobj.getForeignAttributes();
Map<QName, String> atts = fobj.getForeignAttributes();
targetArea.setForeignAttributes(atts); targetArea.setForeignAttributes(atts);
} }


} }


/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public String toString() { public String toString() {
return (super.toString() + (fobj != null ? "[fobj=" + fobj.toString() + "]" : "")); return (super.toString() + (fobj != null ? "[fobj=" + fobj.toString() + "]" : ""));
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public void reset() { public void reset() {
isFinished = false; isFinished = false;
curChildLM = null; curChildLM = null;
childLMiter = new LMiter(this); childLMiter = new LMiter(this);
/* Reset all the children LM that have been created so far. */ /* 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) { if (fobj != null) {
markers = fobj.getMarkers(); markers = fobj.getMarkers();

Loading…
Cancel
Save