gmazza      2004/06/11 10:18:51

  Modified:    src/java/org/apache/fop/apps Document.java Driver.java
               src/java/org/apache/fop/fo FOInputHandler.java
                        FOTreeControl.java FOTreeHandler.java
               src/java/org/apache/fop/fo/pagination Title.java
  Removed:     src/java/org/apache/fop/fo FOTreeEvent.java
                        FOTreeListener.java
  Log:
  Consolidated formatPageSequence() into FOTreeHandler.
  
  Revision  Changes    Path
  1.16      +2 -120    xml-fop/src/java/org/apache/fop/apps/Document.java
  
  Index: Document.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/Document.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- Document.java     8 Jun 2004 02:34:31 -0000       1.15
  +++ Document.java     11 Jun 2004 17:18:51 -0000      1.16
  @@ -20,7 +20,6 @@
   
   // Java
   import java.util.Map;
  -import java.io.IOException;
   import java.util.Set;
   import java.util.HashSet;
   
  @@ -28,20 +27,12 @@
   import org.apache.fop.area.AreaTree;
   import org.apache.fop.area.AreaTreeControl;
   import org.apache.fop.area.AreaTreeModel;
  -import org.apache.fop.area.Title;
   
   import org.apache.fop.fo.FOInputHandler;
   import org.apache.fop.fo.FOTreeControl;
  -import org.apache.fop.fo.FOTreeEvent;
  -import org.apache.fop.fo.FOTreeListener;
   import org.apache.fop.fo.extensions.Bookmarks;
  -import org.apache.fop.fo.pagination.PageSequence;
   import org.apache.fop.fonts.FontInfo;
   import org.apache.fop.layoutmgr.AddLMVisitor;
  -import org.apache.fop.layoutmgr.ContentLayoutManager;
  -import org.apache.fop.layoutmgr.InlineStackingLayoutManager;
  -import org.apache.fop.layoutmgr.LMiter;
  -import org.apache.fop.layoutmgr.PageLayoutManager;
   
   
   import org.apache.commons.logging.Log;
  @@ -53,8 +44,7 @@
    * Class storing information for the FOP Document being processed, and managing
    * the processing of it.
    */
  -public class Document implements FOTreeControl, FOTreeListener,
  -        AreaTreeControl {
  +public class Document implements FOTreeControl, AreaTreeControl {
               
       /** The parent Driver object */
       private Driver driver;
  @@ -112,34 +102,6 @@
       }
   
       /**
  -     * Required by the FOTreeListener interface. It handles an
  -     * FOTreeEvent that is fired when a PageSequence object has been completed.
  -     * @param event the FOTreeEvent that was fired
  -     * @throws FOPException for errors in building the PageSequence
  -     */
  -    public void foPageSequenceComplete (FOTreeEvent event) throws FOPException {
  -        PageSequence pageSeq = event.getPageSequence();
  -        areaTree.addBookmarksToAreaTree();
  -        formatPageSequence(pageSeq, areaTree);
  -    }
  -
  -    /**
  -     * Required by the FOTreeListener interface. It handles an FOTreeEvent that
  -     * is fired when the Document has been completely parsed.
  -     * @param event the FOTreeEvent that was fired
  -     * @throws SAXException for parsing errors
  -     */
  -    public void foDocumentComplete (FOTreeEvent event) throws SAXException {
  -        //processAreaTree(atModel);
  -        try {
  -            areaTree.endDocument();
  -            driver.getRenderer().stopRenderer();
  -        } catch (IOException ex) {
  -            throw new SAXException(ex);
  -        }
  -    }
  -
  -    /**
        * Get the area tree for this layout handler.
        *
        * @return the area tree for this document
  @@ -178,86 +140,6 @@
        */
       public FOInputHandler getFOInputHandler() {
           return foInputHandler;
  -    }
  -
  -    /**
  -     * Runs the formatting of this page sequence into the given area tree
  -     *
  -     * @param pageSeq the PageSequence to be formatted
  -     * @param areaTree the area tree to format this page sequence into
  -     * @throws FOPException if there is an error formatting the contents
  -     */
  -    private void formatPageSequence(PageSequence pageSeq, AreaTree areaTree) 
  -            throws FOPException {
  -        Title title = null;
  -        if (pageSeq.getTitleFO() != null) {
  -            title = getTitleArea(pageSeq.getTitleFO());
  -        }
  -        areaTree.startPageSequence(title);
  -        // Make a new PageLayoutManager and a FlowLayoutManager
  -        // Run the PLM in a thread
  -        // Wait for them to finish.
  -
  -        // If no main flow, nothing to layout!
  -        if (pageSeq.getMainFlow() == null) {
  -            return;
  -        }
  -
  -        // Initialize if already used?
  -        //    this.layoutMasterSet.resetPageMasters();
  -        if (pageSeq.getPageSequenceMaster() != null) {
  -            pageSeq.getPageSequenceMaster().reset();
  -        }
  -
  -        pageSeq.initPageNumber();
  -
  -        // This will layout pages and add them to the area tree
  -        PageLayoutManager pageLM = new PageLayoutManager(areaTree, pageSeq, this);
  -        pageLM.setPageCounting(pageSeq.getCurrentPageNumber(),
  -                               pageSeq.getPageNumberGenerator());
  -
  -        // For now, skip the threading and just call run directly.
  -        pageLM.run();
  -
  -        // Thread layoutThread = new Thread(pageLM);
  -        //  layoutThread.start();
  -        // log.debug("Layout thread started");
  -        
  -        // // wait on both managers
  -        // try {
  -        //     layoutThread.join();
  -        //     log.debug("Layout thread done");
  -        // } catch (InterruptedException ie) {
  -        //     log.error("PageSequence.format() interrupted waiting on layout");
  -        // }
  -        
  -        pageSeq.setCurrentPageNumber(pageLM.getPageCount());
  -        // Tell the root the last page number we created.
  -        
pageSeq.getRoot().setRunningPageNumberCounter(pageSeq.getCurrentPageNumber());
  -    }
  -
  -    /**
  -     * @return the Title area
  -     */
  -    public org.apache.fop.area.Title 
getTitleArea(org.apache.fop.fo.pagination.Title foTitle) {
  -        // use special layout manager to add the inline areas
  -        // to the Title.
  -        InlineStackingLayoutManager lm;
  -        lm = new InlineStackingLayoutManager(foTitle);
  -        lm.setLMiter(new LMiter(lm, foTitle.children.listIterator()));
  -        lm.initialize();
  -
  -        // get breaks then add areas to title
  -        org.apache.fop.area.Title title =
  -                 new org.apache.fop.area.Title();
  -
  -        ContentLayoutManager clm = new ContentLayoutManager(title);
  -        clm.setUserAgent(foTitle.getUserAgent());
  -        lm.setParent(clm);
  -
  -        clm.fillArea(lm);
  -
  -        return title;
       }
   
       /**
  
  
  
  1.62      +8 -2      xml-fop/src/java/org/apache/fop/apps/Driver.java
  
  Index: Driver.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/Driver.java,v
  retrieving revision 1.61
  retrieving revision 1.62
  diff -u -r1.61 -r1.62
  --- Driver.java       8 Jun 2004 02:28:37 -0000       1.61
  +++ Driver.java       11 Jun 2004 17:18:51 -0000      1.62
  @@ -518,7 +518,6 @@
               public void startDocument() throws SAXException {
                   if (foInputHandler instanceof FOTreeHandler) {
                       FOTreeHandler foTreeHandler = (FOTreeHandler)foInputHandler;
  -                    foTreeHandler.addFOTreeListener(currentDocument);
                   }
                   super.startDocument();
               }
  @@ -527,7 +526,6 @@
                   super.endDocument();
                   if (foInputHandler instanceof FOTreeHandler) {
                       FOTreeHandler foTreeHandler = (FOTreeHandler)foInputHandler;
  -                    foTreeHandler.removeFOTreeListener(currentDocument);
                   }
               }
                   
  @@ -638,4 +636,12 @@
           }
       }
   
  +    /**   
  +      * Public accessor for getting the document used by this generation
  +      * @return the current Document object
  +      */   
  +     public Document getCurrentDocument() {
  +        return currentDocument;
  +     }
  +     
   }
  
  
  
  1.16      +29 -10    xml-fop/src/java/org/apache/fop/fo/FOInputHandler.java
  
  Index: FOInputHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/FOInputHandler.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- FOInputHandler.java       31 Mar 2004 10:55:06 -0000      1.15
  +++ FOInputHandler.java       11 Jun 2004 17:18:51 -0000      1.16
  @@ -19,7 +19,10 @@
   package org.apache.fop.fo;
   
   // FOP
  +import org.apache.fop.apps.Document;
  +import org.apache.fop.apps.Driver;
   import org.apache.fop.apps.FOPException;
  +import org.apache.fop.area.AreaTree;
   import org.apache.fop.fo.flow.BasicLink;
   import org.apache.fop.fo.flow.Block;
   import org.apache.fop.fo.flow.ExternalGraphic;
  @@ -54,10 +57,11 @@
    * as our MIF and RTF output targets.
    */
   public abstract class FOInputHandler {
  +    
       /**
  -     * The FOTreeControl object that is controlling the FO Tree being built
  +     * The Document object that is controlling the FO Tree being built
        */
  -    public FOTreeControl foTreeControl = null;
  +    public Document doc = null;
   
       /**
        * logging instance
  @@ -66,11 +70,11 @@
   
       /**
        * Main constructor
  -     * @param foTreeControl the FOTreeControl implementation that is controlling
  +     * @param document the apps.Document implementation that is controlling
        * the FO Tree being built
        */
  -    public FOInputHandler(FOTreeControl foTreeControl) {
  -        this.foTreeControl = foTreeControl;
  +    public FOInputHandler(Document document) {
  +        doc = document;
       }
   
       /**
  @@ -90,11 +94,26 @@
       }
   
       /**
  -     * Returns the FontInfo object associated with this FOInputHandler.
  -     * @return the FontInof object
  +     * Returns the FOTreeControl object associated with this FOInputHandler.
  +     * @return the FOTreeControl object
        */
  -    public FOTreeControl getFontInfo() {
  -        return null;
  +    public Document getDocument() {
  +        return doc;
  +    }
  +
  +    /**   
  +      * @return the current Area Tree object
  +      */   
  +     public AreaTree getAreaTree() {
  +        return doc.getAreaTree();
  +     } 
  +    
  +    /**
  +     * Returns the Driver object associated with this FOInputHandler.
  +     * @return the Driver object
  +     */
  +    public Driver getDriver() {
  +        return doc.getDriver();
       }
   
       /**
  
  
  
  1.12      +2 -2      xml-fop/src/java/org/apache/fop/fo/FOTreeControl.java
  
  Index: FOTreeControl.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/FOTreeControl.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- FOTreeControl.java        22 Apr 2004 21:38:39 -0000      1.11
  +++ FOTreeControl.java        11 Jun 2004 17:18:51 -0000      1.12
  @@ -72,5 +72,5 @@
        * @return the FontInfo object associated with this FOTree
        */
       FontInfo getFontInfo();
  -
  +    
   }
  
  
  
  1.16      +91 -58    xml-fop/src/java/org/apache/fop/fo/FOTreeHandler.java
  
  Index: FOTreeHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/FOTreeHandler.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- FOTreeHandler.java        31 Mar 2004 10:55:06 -0000      1.15
  +++ FOTreeHandler.java        11 Jun 2004 17:18:51 -0000      1.16
  @@ -19,6 +19,7 @@
   package org.apache.fop.fo;
   
   // Java
  +import java.io.IOException;
   import java.util.HashSet;
   import java.util.Iterator;
   
  @@ -26,7 +27,11 @@
   import org.xml.sax.SAXException;
   
   // FOP
  +import org.apache.fop.apps.Document;
   import org.apache.fop.apps.FOPException;
  +import org.apache.fop.area.AreaTree;
  +import org.apache.fop.area.Title;
  +import org.apache.fop.fo.extensions.Bookmarks;
   import org.apache.fop.fo.flow.BasicLink;
   import org.apache.fop.fo.flow.Block;
   import org.apache.fop.fo.flow.ExternalGraphic;
  @@ -45,6 +50,11 @@
   import org.apache.fop.fo.flow.TableRow;
   import org.apache.fop.fo.pagination.Flow;
   import org.apache.fop.fo.pagination.PageSequence;
  +import org.apache.fop.layoutmgr.ContentLayoutManager;
  +import org.apache.fop.layoutmgr.InlineStackingLayoutManager;
  +import org.apache.fop.layoutmgr.LMiter;
  +import org.apache.fop.layoutmgr.PageLayoutManager;
  +
   
   /**
    * Defines how SAX events specific to XSL-FO input should be handled when
  @@ -81,20 +91,14 @@
       private long startTime;
   
       /**
  -     * Collection of objects that have registered to be notified about
  -     * FOTreeEvent firings.
  -     */
  -    private HashSet foTreeListeners = new HashSet();
  -
  -    /**
        * Main constructor
        * @param foTreeControl the FOTreeControl implementation that governs this
        * FO Tree
        * @param store if true then use the store pages model and keep the
        *              area tree in memory
        */
  -    public FOTreeHandler(FOTreeControl foTreeControl, boolean store) {
  -        super(foTreeControl);
  +    public FOTreeHandler(Document doc, boolean store) {
  +        super(doc);
           if (collectStatistics) {
               runtime = Runtime.getRuntime();
           }
  @@ -125,7 +129,12 @@
        * @throws SAXException if there is some error
        */
       public void endDocument() throws SAXException {
  -        notifyDocumentComplete();
  +        try {
  +            getAreaTree().endDocument();
  +            getDriver().getRenderer().stopRenderer();
  +        } catch (IOException ex) {
  +            throw new SAXException(ex);
  +        }
   
           if (collectStatistics) {
               if (MEM_PROFILE_WITH_GC) {
  @@ -184,7 +193,9 @@
                   logger.debug("Current heap size: " + (memoryNow / 1024L) + "Kb");
               }
           }
  -        notifyPageSequenceComplete(pageSequence);
  +
  +        getAreaTree().addBookmarksToAreaTree();
  +        formatPageSequence(pageSequence, getAreaTree());
       }
   
       /**
  @@ -457,66 +468,88 @@
        * @return the font information
        */
       public FOTreeControl getFontInfo() {
  -        return foTreeControl;
  +        return doc;
       }
   
       /**
  -     * Add an object to the collection of objects that should be notified about
  -     * FOTreeEvent firings.
  -     * @param listener the Object which should be notified
  +     * Runs the formatting of this page sequence into the given area tree
  +     *
  +     * @param pageSeq the PageSequence to be formatted
  +     * @param areaTree the area tree to format this page sequence into
  +     * @throws FOPException if there is an error formatting the contents
        */
  -    public void addFOTreeListener (FOTreeListener listener) {
  -        if (listener == null) {
  -            return;
  +    private void formatPageSequence(PageSequence pageSeq, AreaTree areaTree) 
  +            throws FOPException {
  +        Title title = null;
  +        if (pageSeq.getTitleFO() != null) {
  +            title = getTitleArea(pageSeq.getTitleFO());
           }
  -        foTreeListeners.add(listener);
  -    }
  +        areaTree.startPageSequence(title);
  +        // Make a new PageLayoutManager and a FlowLayoutManager
  +        // Run the PLM in a thread
  +        // Wait for them to finish.
   
  -    /**
  -     * Remove an object from the collection of objects that should be notified
  -     * about FOTreeEvent firings.
  -     * @param listener the Object which should no longer be notified
  -     */
  -    public void removeFOTreeListener (FOTreeListener listener) {
  -        if (listener == null) {
  +        // If no main flow, nothing to layout!
  +        if (pageSeq.getMainFlow() == null) {
               return;
           }
  -        foTreeListeners.remove(listener);
  -    }
   
  -    /**
  -     * Notify all objects in the foTreeListeners that a "Page Sequence Complete"
  -     * FOTreeEvent has been fired.
  -     * @param eventType integer indicating which type of event is created
  -     * @param event the Event object that should be passed to the listeners
  -     */
  -    private void notifyPageSequenceComplete(PageSequence pageSequence)
  -            throws FOPException {
  -        FOTreeEvent event = new FOTreeEvent(this);
  -        event.setPageSequence(pageSequence);
  -        Iterator iterator = foTreeListeners.iterator();
  -        FOTreeListener foTreeListenerItem = null;
  -        while (iterator.hasNext()) {
  -            foTreeListenerItem = (FOTreeListener)iterator.next();
  -            foTreeListenerItem.foPageSequenceComplete(event);
  +        // Initialize if already used?
  +        //    this.layoutMasterSet.resetPageMasters();
  +        if (pageSeq.getPageSequenceMaster() != null) {
  +            pageSeq.getPageSequenceMaster().reset();
           }
  +
  +        pageSeq.initPageNumber();
  +
  +        // This will layout pages and add them to the area tree
  +        PageLayoutManager pageLM = new PageLayoutManager(areaTree, pageSeq, 
  +            getDocument());
  +        pageLM.setPageCounting(pageSeq.getCurrentPageNumber(),
  +                               pageSeq.getPageNumberGenerator());
  +
  +        // For now, skip the threading and just call run directly.
  +        pageLM.run();
  +
  +        // Thread layoutThread = new Thread(pageLM);
  +        //  layoutThread.start();
  +        // log.debug("Layout thread started");
  +        
  +        // // wait on both managers
  +        // try {
  +        //     layoutThread.join();
  +        //     log.debug("Layout thread done");
  +        // } catch (InterruptedException ie) {
  +        //     log.error("PageSequence.format() interrupted waiting on layout");
  +        // }
  +        
  +        pageSeq.setCurrentPageNumber(pageLM.getPageCount());
  +        // Tell the root the last page number we created.
  +        
pageSeq.getRoot().setRunningPageNumberCounter(pageSeq.getCurrentPageNumber());
       }
   
       /**
  -     * Notify all objects in the foTreeListeners that a "Document Complete"
  -     * FOTreeEvent has been fired.
  -     * @param eventType integer indicating which type of event is created
  -     * @param event the Event object that should be passed to the listeners
  -     */
  -    private void notifyDocumentComplete()
  -            throws SAXException {
  -        FOTreeEvent event = new FOTreeEvent(this);
  -        Iterator iterator = foTreeListeners.iterator();
  -        FOTreeListener foTreeListenerItem = null;
  -        while (iterator.hasNext()) {
  -            foTreeListenerItem = (FOTreeListener)iterator.next();
  -            foTreeListenerItem.foDocumentComplete(event);
  -        }
  +     * @return the Title area
  +     */
  +    private org.apache.fop.area.Title 
getTitleArea(org.apache.fop.fo.pagination.Title foTitle) {
  +        // use special layout manager to add the inline areas
  +        // to the Title.
  +        InlineStackingLayoutManager lm;
  +        lm = new InlineStackingLayoutManager(foTitle);
  +        lm.setLMiter(new LMiter(lm, foTitle.children.listIterator()));
  +        lm.initialize();
  +
  +        // get breaks then add areas to title
  +        org.apache.fop.area.Title title =
  +                 new org.apache.fop.area.Title();
  +
  +        ContentLayoutManager clm = new ContentLayoutManager(title);
  +        clm.setUserAgent(foTitle.getUserAgent());
  +        lm.setParent(clm);
  +
  +        clm.fillArea(lm);
  +
  +        return title;
       }
   
       /**
  
  
  
  1.15      +2 -2      xml-fop/src/java/org/apache/fop/fo/pagination/Title.java
  
  Index: Title.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/pagination/Title.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Title.java        27 Feb 2004 17:45:13 -0000      1.14
  +++ Title.java        11 Jun 2004 17:18:51 -0000      1.15
  @@ -59,7 +59,7 @@
           CommonBackground bProps = propMgr.getBackgroundProps();
   
           // Common Font Properties
  -        Font fontState = 
propMgr.getFontState(getFOTreeControl().getFOInputHandler().getFontInfo());
  +        Font fontState = propMgr.getFontState(getFOTreeControl());
   
           // Common Margin Properties-Inline
           CommonMarginInline mProps = propMgr.getMarginInlineProps();
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to