From: Keiron Liddle Date: Thu, 15 Nov 2001 12:40:31 +0000 (+0000) Subject: some comments and cleaned up a bit X-Git-Tag: fop-0_20_4-doc~194 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=16a80413e0fbd2b03f2bd26dd2ac52ea00059e5b;p=xmlgraphics-fop.git some comments and cleaned up a bit git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194569 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java b/src/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java index a614fe21c..359b48996 100644 --- a/src/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java +++ b/src/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java @@ -13,6 +13,14 @@ import org.apache.fop.apps.FOPException; import org.xml.sax.Attributes; +/** + * A conditional-page-master-reference formatting object. + * This is a reference to a page master with a set of conditions. + * The conditions must be satisfied for the referenced master to + * be used. + * This element is must be the child of a repeatable-page-master-alternatives + * element. + */ public class ConditionalPageMasterReference extends FObj { private RepeatablePageMasterAlternatives repeatablePageMasterAlternatives; @@ -25,8 +33,6 @@ public class ConditionalPageMasterReference extends FObj { public ConditionalPageMasterReference(FONode parent) { super(parent); - - this.name = getElementName(); } public void handleAttrs(Attributes attlist) throws FOPException { @@ -53,7 +59,11 @@ public class ConditionalPageMasterReference extends FObj { return masterName; } - + /** + * Check if the conditions for this reference are met. + * checks the page number and emptyness to determine if this + * matches. + */ protected boolean isValid(int currentPageNumber, boolean thisIsFirstPage, boolean isEmptyPage) { // page-position @@ -127,11 +137,10 @@ public class ConditionalPageMasterReference extends FObj { return this.blankOrNotBlank; } - protected String getElementName() { - return "fo:conditional-page-master-reference"; - } - - + /** + * Check that the parent is the right type of formatting object + * repeatable-page-master-alternatives. + */ protected void validateParent(FONode parent) throws FOPException { if (parent.getName().equals("fo:repeatable-page-master-alternatives")) { this.repeatablePageMasterAlternatives = @@ -150,5 +159,4 @@ public class ConditionalPageMasterReference extends FObj { } } - } diff --git a/src/org/apache/fop/fo/pagination/LayoutMasterSet.java b/src/org/apache/fop/fo/pagination/LayoutMasterSet.java index d56e74cb9..62ac8e795 100644 --- a/src/org/apache/fop/fo/pagination/LayoutMasterSet.java +++ b/src/org/apache/fop/fo/pagination/LayoutMasterSet.java @@ -19,34 +19,44 @@ import java.util.Iterator; import org.xml.sax.Attributes; +/** + * The layout-master-set formatting object. + * This class maintains the set of simple page master and + * page sequence masters. + * The masters are stored so that the page sequence can obtain + * the required page master to create a page. + * The page sequence masters can be reset as they hold state + * information for a page sequence. + */ public class LayoutMasterSet extends FObj { - private HashMap simplePageMasters; private HashMap pageSequenceMasters; private HashMap allRegions; - private Root root; - public LayoutMasterSet(FONode parent) { super(parent); } public void handleAttrs(Attributes attlist) throws FOPException { super.handleAttrs(attlist); - this.simplePageMasters = new HashMap(); - this.pageSequenceMasters = new HashMap(); if (parent.getName().equals("fo:root")) { - this.root = (Root)parent; + Root root = (Root)parent; root.setLayoutMasterSet(this); } else { throw new FOPException("fo:layout-master-set must be child of fo:root, not " + parent.getName()); } - allRegions = new HashMap(); + this.simplePageMasters = new HashMap(); + this.pageSequenceMasters = new HashMap(); + allRegions = new HashMap(); } + /** + * Add a simple page master. + * The name is checked to throw an error if already added. + */ protected void addSimplePageMaster(SimplePageMaster simplePageMaster) throws FOPException { // check against duplication of master-name @@ -59,10 +69,19 @@ public class LayoutMasterSet extends FObj { simplePageMaster); } + /** + * Get a simple page master by name. + * This is used by the page sequence to get a page master for + * creating pages. + */ protected SimplePageMaster getSimplePageMaster(String masterName) { return (SimplePageMaster)this.simplePageMasters.get(masterName); } + /** + * Add a page sequence master. + * The name is checked to throw an error if already added. + */ protected void addPageSequenceMaster(String masterName, PageSequenceMaster pageSequenceMaster) throws FOPException { // check against duplication of master-name @@ -73,6 +92,11 @@ public class LayoutMasterSet extends FObj { this.pageSequenceMasters.put(masterName, pageSequenceMaster); } + /** + * Get a page sequence master by name. + * This is used by the page sequence to get a page master for + * creating pages. + */ protected PageSequenceMaster getPageSequenceMaster(String masterName) { return (PageSequenceMaster)this.pageSequenceMasters.get(masterName); } @@ -85,6 +109,10 @@ public class LayoutMasterSet extends FObj { return false; } + /** + * Reset the state of the page sequence masters. + * Use when starting a new page sequence. + */ protected void resetPageMasters() { for (Iterator e = pageSequenceMasters.values().iterator(); e.hasNext(); ) { diff --git a/src/org/apache/fop/fo/pagination/PageMasterReference.java b/src/org/apache/fop/fo/pagination/PageMasterReference.java index 3092429a1..5f9674a49 100644 --- a/src/org/apache/fop/fo/pagination/PageMasterReference.java +++ b/src/org/apache/fop/fo/pagination/PageMasterReference.java @@ -25,7 +25,6 @@ public abstract class PageMasterReference extends FObj public PageMasterReference(FONode parent) { super(parent); - this.name = getElementName(); } public void handleAttrs(Attributes attlist) throws FOPException { @@ -60,15 +59,6 @@ public abstract class PageMasterReference extends FObj boolean thisIsFirstPage, boolean isEmptyPage); - /** - * Gets the formating object name for this object. - * Subclasses must provide this. - * - * @return the element name of this reference. - * e.g. fo:repeatable-page-master-reference - */ - protected abstract String getElementName(); - /** * Checks that the parent is the right element. The default implementation * checks for fo:page-sequence-master @@ -78,13 +68,13 @@ public abstract class PageMasterReference extends FObj _pageSequenceMaster = (PageSequenceMaster)parent; if (getMasterName() == null) { - log.warn("" + getElementName() + log.warn("" + getName() + " does not have a master-reference and so is being ignored"); } else { _pageSequenceMaster.addSubsequenceSpecifier(this); } } else { - throw new FOPException(getElementName() + " must be" + throw new FOPException(getName() + " must be" + "child of fo:page-sequence-master, not " + parent.getName()); } diff --git a/src/org/apache/fop/fo/pagination/PageSequence.java b/src/org/apache/fop/fo/pagination/PageSequence.java index 32aa24897..374b1dd93 100644 --- a/src/org/apache/fop/fo/pagination/PageSequence.java +++ b/src/org/apache/fop/fo/pagination/PageSequence.java @@ -26,7 +26,7 @@ import org.apache.fop.apps.StreamRenderer; import org.apache.fop.layoutmgr.PageLayoutManager; // Java -import java.util.*; +import java.util.HashMap; import org.xml.sax.Attributes; @@ -286,8 +286,6 @@ public class PageSequence extends FObj { } - - // /** // * Return children for layout. Only the main flow is laid out directly. // */ @@ -527,10 +525,9 @@ public class PageSequence extends FObj { // } /** - * Returns the next SubSequenceSpecifier for the given page sequence master. The result - * is bassed on the current state of this page sequence. + * Returns the next SubSequenceSpecifier for the given page sequence master. + * The result is bassed on the current state of this page sequence. */ - // refactored from PageSequenceMaster private SubSequenceSpecifier getNextSubsequence(PageSequenceMaster master) { if (master.getSubSequenceSpecifierCount() > currentSubsequenceNumber + 1) { @@ -542,7 +539,6 @@ public class PageSequence extends FObj { } else { return null; } - } /** @@ -564,6 +560,12 @@ public class PageSequence extends FObj { } + /** + * Get the next page master name. + * This gets the name of the next page master. If the sequence + * is exhausted then an error is indicated and the last page + * master name is used. + */ private String getNextPageMasterName(PageSequenceMaster sequenceMaster, int currentPageNumber, boolean thisIsFirstPage, diff --git a/src/org/apache/fop/fo/pagination/PageSequenceMaster.java b/src/org/apache/fop/fo/pagination/PageSequenceMaster.java index 8ffcbb9b1..0054cb226 100644 --- a/src/org/apache/fop/fo/pagination/PageSequenceMaster.java +++ b/src/org/apache/fop/fo/pagination/PageSequenceMaster.java @@ -14,15 +14,19 @@ import org.apache.fop.layout.PageMaster; import org.apache.fop.apps.FOPException; // Java -import java.util.*; +import java.util.ArrayList; +import java.util.Iterator; import org.xml.sax.Attributes; +/** + * The page-sequence-master formatting object. + * This class handles a list of subsequence specifiers + * which are simple or complex references to page-masters. + */ public class PageSequenceMaster extends FObj { - LayoutMasterSet layoutMasterSet; - Vector subSequenceSpecifiers; - + ArrayList subSequenceSpecifiers; // The terminology may be confusing. A 'page-sequence-master' consists // of a sequence of what the XSL spec refers to as @@ -37,14 +41,14 @@ public class PageSequenceMaster extends FObj { public void handleAttrs(Attributes attlist) throws FOPException { super.handleAttrs(attlist); - subSequenceSpecifiers = new Vector(); + subSequenceSpecifiers = new ArrayList(); if (parent.getName().equals("fo:layout-master-set")) { this.layoutMasterSet = (LayoutMasterSet)parent; String pm = this.properties.get("master-name").getString(); if (pm == null) { log.warn("page-sequence-master does not have " - + "a page-master-name and so is being ignored"); + + "a master-name and so is being ignored"); } else { this.layoutMasterSet.addPageSequenceMaster(pm, this); } @@ -56,17 +60,15 @@ public class PageSequenceMaster extends FObj { } protected void addSubsequenceSpecifier(SubSequenceSpecifier pageMasterReference) { - subSequenceSpecifiers.addElement(pageMasterReference); + subSequenceSpecifiers.add(pageMasterReference); } protected SubSequenceSpecifier getSubSequenceSpecifier(int sequenceNumber) { if (sequenceNumber >= 0 && sequenceNumber < getSubSequenceSpecifierCount()) { - return (SubSequenceSpecifier)subSequenceSpecifiers.elementAt(sequenceNumber); + return (SubSequenceSpecifier)subSequenceSpecifiers.get(sequenceNumber); } return null; - - } protected int getSubSequenceSpecifierCount() { @@ -74,12 +76,10 @@ public class PageSequenceMaster extends FObj { } public void reset() { - for (Enumeration e = subSequenceSpecifiers.elements(); - e.hasMoreElements(); ) { - ((SubSequenceSpecifier)e.nextElement()).reset(); + for (Iterator e = subSequenceSpecifiers.iterator(); + e.hasNext(); ) { + ((SubSequenceSpecifier)e.next()).reset(); } - } - - } + diff --git a/src/org/apache/fop/fo/pagination/Region.java b/src/org/apache/fop/fo/pagination/Region.java index 9afbbaa81..cfbc8c27f 100644 --- a/src/org/apache/fop/fo/pagination/Region.java +++ b/src/org/apache/fop/fo/pagination/Region.java @@ -19,7 +19,6 @@ import org.apache.fop.apps.FOPException; import org.apache.fop.area.RegionViewport; import org.apache.fop.area.RegionReference; - import org.xml.sax.Attributes; /** @@ -71,10 +70,8 @@ public abstract class Region extends FObj { + "of simple-page-master, not " + parent.getName()); } - } - /** * Creates a RegionViewport Area object for this pagination Region. */ @@ -101,9 +98,7 @@ public abstract class Region extends FObj { // this.properties.get("clip"); // this.properties.get("display-align"); - // this.properties.get("overflow"); this.overflow = this.properties.get("overflow").getEnum(); - // this.properties.get("region-name"); // this.properties.get("reference-orientation"); // this.properties.get("writing-mode"); diff --git a/src/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java b/src/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java index de211a05f..1acc24f42 100644 --- a/src/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java +++ b/src/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java @@ -11,10 +11,16 @@ import org.apache.fop.fo.*; import org.apache.fop.apps.FOPException; // Java -import java.util.Vector; +import java.util.ArrayList; import org.xml.sax.Attributes; +/** + * A repeatable-page-master-alternatives formatting object. + * This contains a list of conditional-page-master-reference + * and the page master is found from the reference that + * matches the page number and emptyness. + */ public class RepeatablePageMasterAlternatives extends FObj implements SubSequenceSpecifier { @@ -29,7 +35,7 @@ public class RepeatablePageMasterAlternatives extends FObj private int maximumRepeats; private int numberConsumed = 0; - private Vector conditionalPageMasterRefs; + private ArrayList conditionalPageMasterRefs; public RepeatablePageMasterAlternatives(FONode parent) { super(parent); @@ -38,7 +44,7 @@ public class RepeatablePageMasterAlternatives extends FObj public void handleAttrs(Attributes attlist) throws FOPException { super.handleAttrs(attlist); - conditionalPageMasterRefs = new Vector(); + conditionalPageMasterRefs = new ArrayList(); if (parent.getName().equals("fo:page-sequence-master")) { this.pageSequenceMaster = (PageSequenceMaster)parent; @@ -60,9 +66,12 @@ public class RepeatablePageMasterAlternatives extends FObj + "'maximum-repeats' property"); } } - } + /** + * Get the next matching page master from the conditional + * page master references. + */ public String getNextPageMaster(int currentPageNumber, boolean thisIsFirstPage, boolean isEmptyPage) { @@ -78,7 +87,7 @@ public class RepeatablePageMasterAlternatives extends FObj for (int i = 0; i < conditionalPageMasterRefs.size(); i++) { ConditionalPageMasterReference cpmr = - (ConditionalPageMasterReference)conditionalPageMasterRefs.elementAt(i); + (ConditionalPageMasterReference)conditionalPageMasterRefs.get(i); // 0-indexed page number if (cpmr.isValid(currentPageNumber + 1, thisIsFirstPage, @@ -96,7 +105,6 @@ public class RepeatablePageMasterAlternatives extends FObj } else { this.maximumRepeats = (maximumRepeats < 0) ? 0 : maximumRepeats; } - } private int getMaximumRepeats() { @@ -104,14 +112,13 @@ public class RepeatablePageMasterAlternatives extends FObj } public void addConditionalPageMasterReference(ConditionalPageMasterReference cpmr) { - this.conditionalPageMasterRefs.addElement(cpmr); + this.conditionalPageMasterRefs.add(cpmr); } public void reset() { this.numberConsumed = 0; } - protected PageSequenceMaster getPageSequenceMaster() { return pageSequenceMaster; } diff --git a/src/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java b/src/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java index 77ae63367..5ef14e96b 100644 --- a/src/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java +++ b/src/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java @@ -12,6 +12,11 @@ import org.apache.fop.apps.FOPException; import org.xml.sax.Attributes; +/** + * A repeatable-page-master-reference formatting object. + * This handles a reference with a specified number of repeating + * instances of the referenced page master (may have no limit). + */ public class RepeatablePageMasterReference extends PageMasterReference implements SubSequenceSpecifier { @@ -40,7 +45,6 @@ public class RepeatablePageMasterReference extends PageMasterReference + "'maximum-repeats' property"); } } - } public String getNextPageMaster(int currentPageNumber, @@ -70,10 +74,6 @@ public class RepeatablePageMasterReference extends PageMasterReference return this.maximumRepeats; } - protected String getElementName() { - return "fo:repeatable-page-master-reference"; - } - public void reset() { this.numberConsumed = 0; } diff --git a/src/org/apache/fop/fo/pagination/Root.java b/src/org/apache/fop/fo/pagination/Root.java index 7e501a7e0..7d81f4dbf 100644 --- a/src/org/apache/fop/fo/pagination/Root.java +++ b/src/org/apache/fop/fo/pagination/Root.java @@ -13,14 +13,12 @@ import org.apache.fop.fo.flow.*; import org.apache.fop.fo.properties.*; import org.apache.fop.layout.AreaTree; import org.apache.fop.apps.FOPException; -import org.apache.fop.extensions.ExtensionObj; // Java import java.util.ArrayList; /** - * The fo:root formatting object. Contains page masters, root extensions, - * page-sequences. + * The fo:root formatting object. Contains page masters, page-sequences. */ public class Root extends FObj { diff --git a/src/org/apache/fop/fo/pagination/SimplePageMaster.java b/src/org/apache/fop/fo/pagination/SimplePageMaster.java index e759e31cd..6c01d2e7f 100644 --- a/src/org/apache/fop/fo/pagination/SimplePageMaster.java +++ b/src/org/apache/fop/fo/pagination/SimplePageMaster.java @@ -23,15 +23,17 @@ import java.util.HashMap; import java.util.Iterator; import org.xml.sax.Attributes; - +/** + * A simple-page-master formatting object. + * This creates a simple page from the specified regions + * and attributes. + */ public class SimplePageMaster extends FObj { - /** * Page regions (regionClass, Region) */ private HashMap _regions; - LayoutMasterSet layoutMasterSet; PageMaster pageMaster; String masterName; @@ -43,13 +45,13 @@ public class SimplePageMaster extends FObj { super.handleAttrs(attlist); if (parent.getName().equals("fo:layout-master-set")) { - this.layoutMasterSet = (LayoutMasterSet)parent; + LayoutMasterSet layoutMasterSet = (LayoutMasterSet)parent; masterName = this.properties.get("master-name").getString(); if (masterName == null) { log.warn("simple-page-master does not have " + "a master-name and so is being ignored"); } else { - this.layoutMasterSet.addSimplePageMaster(this); + layoutMasterSet.addSimplePageMaster(this); } } else { throw new FOPException("fo:simple-page-master must be child " @@ -57,9 +59,12 @@ public class SimplePageMaster extends FObj { + parent.getName()); } _regions = new HashMap(); - } + /** + * At the end of this element read all the information and create + * the page master. + */ protected void end() { int pageWidth = this.properties.get("page-width").getLength().mvalue(); @@ -72,7 +77,7 @@ public class SimplePageMaster extends FObj { MarginProps mProps = propMgr.getMarginProps(); /* Create the page reference area rectangle in first quadrant coordinates - * (ie, 0,0 is at bottom,left of the "page meida" and y increases + * (ie, 0,0 is at bottom,left of the "page media" and y increases * when moving towards the top of the page. * The media rectangle itself is (0,0,pageWidth,pageHeight). */ @@ -106,6 +111,10 @@ public class SimplePageMaster extends FObj { this.pageMaster = new PageMaster(new PageViewport(page, new Rectangle(0,0, pageWidth,pageHeight))); + + _regions = null; + children = null; + properties = null; } public PageMaster getPageMaster() { @@ -120,7 +129,6 @@ public class SimplePageMaster extends FObj { return masterName; } - protected void addChild(FONode child) { if (child instanceof Region) { addRegion((Region)child); @@ -162,7 +170,6 @@ public class SimplePageMaster extends FObj { } } return false; - } - } + diff --git a/src/org/apache/fop/fo/pagination/SinglePageMasterReference.java b/src/org/apache/fop/fo/pagination/SinglePageMasterReference.java index 39dfe0bb2..caa7457cf 100644 --- a/src/org/apache/fop/fo/pagination/SinglePageMasterReference.java +++ b/src/org/apache/fop/fo/pagination/SinglePageMasterReference.java @@ -6,9 +6,13 @@ */ package org.apache.fop.fo.pagination; -import org.apache.fop.fo.*; -import org.apache.fop.apps.FOPException; +import org.apache.fop.fo.FONode; +/** + * A single-page-master-reference formatting object. + * This is a reference for a single page. It returns the + * master name only once until reset. + */ public class SinglePageMasterReference extends PageMasterReference implements SubSequenceSpecifier { @@ -31,15 +35,10 @@ public class SinglePageMasterReference extends PageMasterReference } else { return null; } - } public void reset() { this.state = FIRST; } - - protected String getElementName() { - return "fo:single-page-master-reference"; - } - } +