From 7fde5817bc810b39a2e5c3bec9e4f3fa25ffe557 Mon Sep 17 00:00:00 2001 From: Simon Pepping Date: Tue, 27 Dec 2005 08:40:09 +0000 Subject: [PATCH] I generalized several casts from KnuthElement to ListElement. This removes a number of ClassCastExceptions in some files with inline block content. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@359189 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/fop/layoutmgr/AbstractBreaker.java | 2 +- .../fop/layoutmgr/BlockKnuthSequence.java | 4 ++-- .../apache/fop/layoutmgr/BreakingAlgorithm.java | 2 +- .../fop/layoutmgr/InlineKnuthSequence.java | 6 +++--- .../org/apache/fop/layoutmgr/KnuthSequence.java | 16 ++++++++-------- .../fop/layoutmgr/PageBreakingAlgorithm.java | 2 +- .../fop/layoutmgr/inline/LineLayoutManager.java | 17 +++++++++++------ 7 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java b/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java index 54cf80ebd..732a0133a 100644 --- a/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java +++ b/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java @@ -332,7 +332,7 @@ public abstract class AbstractBreaker { if (p == 0) { lastBreakClass = effectiveList.getStartOn(); } else { - KnuthElement lastBreakElement = effectiveList.getElement(endElementIndex); + ListElement lastBreakElement = effectiveList.getElement(endElementIndex); if (lastBreakElement.isPenalty()) { KnuthPenalty pen = (KnuthPenalty)lastBreakElement; lastBreakClass = pen.getBreakClass(); diff --git a/src/java/org/apache/fop/layoutmgr/BlockKnuthSequence.java b/src/java/org/apache/fop/layoutmgr/BlockKnuthSequence.java index 1093fee74..c3c837f1e 100644 --- a/src/java/org/apache/fop/layoutmgr/BlockKnuthSequence.java +++ b/src/java/org/apache/fop/layoutmgr/BlockKnuthSequence.java @@ -79,9 +79,9 @@ public class BlockKnuthSequence extends KnuthSequence { */ public static boolean mustKeepTogether(BlockKnuthSequence sequence1, BlockKnuthSequence sequence2) { - KnuthElement element1 = (KnuthElement) sequence1.get(sequence1.size() - 1); + ListElement element1 = (ListElement) sequence1.get(sequence1.size() - 1); LayoutManager lm1 = (LayoutManager) element1.getLayoutManager(); - KnuthElement element2 = (KnuthElement) sequence2.get(0); + ListElement element2 = (ListElement) sequence2.get(0); LayoutManager lm2 = (LayoutManager) element2.getLayoutManager(); if (!lm1.equals(lm2)) { throw new IllegalStateException diff --git a/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java b/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java index c290f5b13..6dc013859 100644 --- a/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java +++ b/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java @@ -474,7 +474,7 @@ public abstract class BreakingAlgorithm { * @return the requested context FO note or null, if no context node could be determined */ private FONode findContextFO(KnuthSequence seq, int position) { - KnuthElement el = seq.getElement(position); + ListElement el = seq.getElement(position); while (el.getLayoutManager() == null && position < seq.size() - 1) { position++; el = seq.getElement(position); diff --git a/src/java/org/apache/fop/layoutmgr/InlineKnuthSequence.java b/src/java/org/apache/fop/layoutmgr/InlineKnuthSequence.java index 6932b7600..788339790 100644 --- a/src/java/org/apache/fop/layoutmgr/InlineKnuthSequence.java +++ b/src/java/org/apache/fop/layoutmgr/InlineKnuthSequence.java @@ -70,11 +70,11 @@ public class InlineKnuthSequence extends KnuthSequence { return false; } // does the first element of the first paragraph add to an existing word? - KnuthElement lastOldElement, firstNewElement; + ListElement lastOldElement, firstNewElement; lastOldElement = getLast(); firstNewElement = sequence.getElement(0); - if (firstNewElement.isBox() && !firstNewElement.isAuxiliary() - && lastOldElement.isBox() && lastOldElement.getW() != 0) { + if (firstNewElement.isBox() && !((KnuthElement) firstNewElement).isAuxiliary() + && lastOldElement.isBox() && ((KnuthElement) lastOldElement).getW() != 0) { addALetterSpace(); } addAll(sequence); diff --git a/src/java/org/apache/fop/layoutmgr/KnuthSequence.java b/src/java/org/apache/fop/layoutmgr/KnuthSequence.java index a063ee9f0..405af1157 100644 --- a/src/java/org/apache/fop/layoutmgr/KnuthSequence.java +++ b/src/java/org/apache/fop/layoutmgr/KnuthSequence.java @@ -88,9 +88,9 @@ public abstract class KnuthSequence extends ArrayList { */ public void wrapPositions(LayoutManager lm) { ListIterator listIter = listIterator(); - KnuthElement element; + ListElement element; while (listIter.hasNext()) { - element = (KnuthElement) listIter.next(); + element = (ListElement) listIter.next(); element.setPosition (lm.notifyPos(new NonLeafPosition(lm, element.getPosition()))); } @@ -99,32 +99,32 @@ public abstract class KnuthSequence extends ArrayList { /** * @return the last element of this sequence. */ - public KnuthElement getLast() { + public ListElement getLast() { int idx = size(); if (idx == 0) { return null; } - return (KnuthElement) get(idx - 1); + return (ListElement) get(idx - 1); } /** * Remove the last element of this sequence. * @return the removed element. */ - public KnuthElement removeLast() { + public ListElement removeLast() { int idx = size(); if (idx == 0) { return null; } - return (KnuthElement) remove(idx - 1); + return (ListElement) remove(idx - 1); } /** * @param index The index of the element to be returned * @return the element at index index. */ - public KnuthElement getElement(int index) { - return (KnuthElement) get(index); + public ListElement getElement(int index) { + return (ListElement) get(index); } /** diff --git a/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java b/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java index 5608b1720..354f2da87 100644 --- a/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java +++ b/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java @@ -367,7 +367,7 @@ class PageBreakingAlgorithm extends BreakingAlgorithm { index ++) { if (par.getElement(index).isGlue() && par.getElement(index - 1).isBox() || par.getElement(index).isPenalty() - && par.getElement(index).getP() < KnuthElement.INFINITE) { + && ((KnuthElement) par.getElement(index)).getP() < KnuthElement.INFINITE) { // break found break; } diff --git a/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java index 9b91e4bee..454cb093b 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java @@ -41,6 +41,7 @@ import org.apache.fop.layoutmgr.KnuthSequence; import org.apache.fop.layoutmgr.LayoutContext; import org.apache.fop.layoutmgr.LayoutManager; import org.apache.fop.layoutmgr.LeafPosition; +import org.apache.fop.layoutmgr.ListElement; import org.apache.fop.layoutmgr.NonLeafPosition; import org.apache.fop.layoutmgr.Position; import org.apache.fop.layoutmgr.PositionIterator; @@ -735,13 +736,13 @@ public class LineLayoutManager extends InlineStackingLayoutManager // the sequence contains inline Knuth elements if (sequence.isInlineSequence()) { // look at the last element - KnuthElement lastElement; - lastElement = (KnuthElement) sequence.getLast(); + ListElement lastElement; + lastElement = sequence.getLast(); if (lastElement == null) { throw new NullPointerException( "Sequence was empty! lastElement is null"); } - bPrevWasKnuthBox = lastElement.isBox() && lastElement.getW() != 0; + bPrevWasKnuthBox = lastElement.isBox() && ((KnuthElement) lastElement).getW() != 0; // if last paragraph is open, add the new elements to the paragraph // else this is the last paragraph @@ -975,7 +976,11 @@ public class LineLayoutManager extends InlineStackingLayoutManager int localLineHeight = 0, lineStretch = 0, lineShrink = 0; ListIterator seqIterator = seq.listIterator(); while (seqIterator.hasNext()) { - KnuthElement element = (KnuthElement) seqIterator.next(); + ListElement elt = (ListElement) seqIterator.next(); + if (!(elt instanceof KnuthElement)) { + continue; + } + KnuthElement element = (KnuthElement) elt; localLineHeight += element.getW(); if (element.isGlue()) { lineStretch += element.getY(); @@ -1130,8 +1135,8 @@ public class LineLayoutManager extends InlineStackingLayoutManager LinkedList targetList = new LinkedList(); ListIterator listIter = seq.listIterator(); while (listIter.hasNext()) { - KnuthElement tempElement; - tempElement = (KnuthElement) listIter.next(); + ListElement tempElement; + tempElement = (ListElement) listIter.next(); if (tempElement.getLayoutManager() != this) { tempElement.setPosition(notifyPos(new NonLeafPosition(this, tempElement.getPosition()))); -- 2.39.5