gmazza      2003/08/11 16:47:22

  Modified:    src/java/org/apache/fop/apps CommandLineStarter.java
                        Fop.java
               src/java/org/apache/fop/render/awt AWTRenderer.java
               src/java/org/apache/fop/viewer PreviewDialog.java
  Removed:     src/java/org/apache/fop/apps AWTStarter.java
  Log:
  1.  AWT PreviewDialog creation shifted from AWTStarter to AWTRenderer.
  2.  New AWTRenderer constructor -- takes an InputHandler object which
      is used for the document refreshing/reloading.
  3.  PreviewDialog's reload() functionality now handled via Driver instead of
      AWTStarter.
  4.  Class AWTStarter removed:  AWT generation now activated via CommandLineStarter.
  
  Revision  Changes    Path
  1.6       +7 -2      xml-fop/src/java/org/apache/fop/apps/CommandLineStarter.java
  
  Index: CommandLineStarter.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/CommandLineStarter.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- CommandLineStarter.java   27 Jul 2003 20:16:03 -0000      1.5
  +++ CommandLineStarter.java   11 Aug 2003 23:47:22 -0000      1.6
  @@ -54,6 +54,8 @@
   import java.io.BufferedOutputStream;
   import java.io.FileOutputStream;
   
  +// FOP
  +import org.apache.fop.render.awt.AWTRenderer;
   
   /**
    * super class for all classes which start Fop from the commandline
  @@ -88,7 +90,11 @@
           setupLogger(driver);
   
           try {
  -            driver.setRenderer(commandLineOptions.getRenderer());
  +            if (commandLineOptions.getOutputMode() == 
CommandLineOptions.AWT_OUTPUT) {
  +                driver.setRenderer(new AWTRenderer(inputHandler));
  +            } else { 
  +                driver.setRenderer(commandLineOptions.getRenderer());
  +            }
   
               try {
                   if (commandLineOptions.getOutputFile() != null) {
  @@ -107,7 +113,6 @@
                       bos.close();
                   }
               }
  -            System.exit(0);
           } catch (Exception e) {
               if (e instanceof FOPException) {
                   throw (FOPException) e;
  
  
  
  1.3       +1 -5      xml-fop/src/java/org/apache/fop/apps/Fop.java
  
  Index: Fop.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/Fop.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Fop.java  29 Jul 2003 22:08:54 -0000      1.2
  +++ Fop.java  11 Aug 2003 23:47:22 -0000      1.3
  @@ -67,11 +67,7 @@
   
           try {
               options = new CommandLineOptions(args);
  -            if (options.getOutputMode() == CommandLineOptions.AWT_OUTPUT) {
  -                starter = new AWTStarter(options);
  -            } else {
  -                starter = new CommandLineStarter(options);
  -            }
  +            starter = new CommandLineStarter(options);
               starter.enableLogging(new ConsoleLogger(ConsoleLogger.LEVEL_INFO));
               starter.run();
           } catch (FOPException e) {
  
  
  
  1.4       +44 -9     xml-fop/src/java/org/apache/fop/render/awt/AWTRenderer.java
  
  Index: AWTRenderer.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/awt/AWTRenderer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AWTRenderer.java  10 Aug 2003 15:43:13 -0000      1.3
  +++ AWTRenderer.java  11 Aug 2003 23:47:22 -0000      1.4
  @@ -57,10 +57,15 @@
    * Stanislav Gorkhover: [EMAIL PROTECTED]
    */
   
  +// Java
   import java.awt.Color;
   import java.awt.Component;
  +import java.awt.Dimension;
   import java.awt.Graphics;
   import java.awt.Graphics2D;
  +import java.awt.Toolkit;
  +import java.awt.event.WindowAdapter;
  +import java.awt.event.WindowEvent;
   import java.awt.image.BufferedImage;
   import java.awt.print.PageFormat;
   import java.awt.print.Pageable;
  @@ -70,6 +75,8 @@
   import java.util.List;
   import java.util.Map;
   
  +// FOP
  +import org.apache.fop.apps.InputHandler;
   import org.apache.fop.layout.FontInfo;
   import org.apache.fop.render.AbstractRenderer;
   import org.apache.fop.viewer.PreviewDialog;
  @@ -87,6 +94,12 @@
       protected List pageList = new java.util.Vector();
       //protected ProgressListener progressListener = null;
   
  +    /** 
  +        The InputHandler associated with this Renderer.  
  +        Sent to the PreviewDialog for document reloading.
  +    */
  +    protected InputHandler inputHandler;
  +    
       /**
        * The resource bundle used for AWT messages.
        */
  @@ -127,8 +140,15 @@
        */
       protected PreviewDialog frame;
       
  +    public AWTRenderer(InputHandler handler) {
  +        inputHandler = handler;
  +        translator = new Translator();
  +        createPreviewDialog(inputHandler);
  +    }
  +
       public AWTRenderer() {
           translator = new Translator();
  +        createPreviewDialog(null);
       }
   
       public Translator getTranslator() {
  @@ -146,15 +166,6 @@
           FontSetup.setup(fontInfo, fontImage.createGraphics());
       }
   
  -    /**
  -     * Sets the preview dialog frame used for display of the documents.
  -     * @param frame the PreviewDialog frame
  -     */
  -    public void setPreviewDialog(PreviewDialog frame) {
  -        this.frame = frame;
  -        frame.setStatus(translator.getString("Status.Build.FO.tree"));
  -    }
  -
       public int getPageNumber() {
           return pageNumber;
       }
  @@ -200,5 +211,29 @@
   
       public int print(Graphics g, PageFormat format, int pos) {
           return 0;
  +    }
  +    
  +    private PreviewDialog createPreviewDialog(InputHandler handler) {
  +        frame = new PreviewDialog(this, handler);
  +        frame.addWindowListener(new WindowAdapter() {
  +            public void windowClosed(WindowEvent we) {
  +                System.exit(0);
  +            }
  +        });
  +
  +        //Centers the window
  +        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  +        Dimension frameSize = frame.getSize();
  +        if (frameSize.height > screenSize.height) {
  +            frameSize.height = screenSize.height;
  +        }
  +        if (frameSize.width > screenSize.width) {
  +            frameSize.width = screenSize.width;
  +        }
  +        frame.setLocation((screenSize.width - frameSize.width) / 2,
  +                          (screenSize.height - frameSize.height) / 2);
  +        frame.setVisible(true);
  +        frame.setStatus(translator.getString("Status.Build.FO.tree"));        
  +        return frame;
       }
   }
  
  
  
  1.3       +24 -20    xml-fop/src/java/org/apache/fop/viewer/PreviewDialog.java
  
  Index: PreviewDialog.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/viewer/PreviewDialog.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PreviewDialog.java        10 Aug 2003 15:43:13 -0000      1.2
  +++ PreviewDialog.java        11 Aug 2003 23:47:22 -0000      1.3
  @@ -77,7 +77,8 @@
   import java.awt.print.PrinterException;
   
   //FOP
  -import org.apache.fop.apps.AWTStarter;
  +import org.apache.fop.apps.Driver;
  +import org.apache.fop.apps.InputHandler;
   import org.apache.fop.apps.FOPException;
   import org.apache.fop.render.awt.AWTRenderer;
   
  @@ -94,8 +95,10 @@
       protected Translator translator;
       /** The AWT renderer */
       protected AWTRenderer renderer;
  -    /** The AWT starter */
  -    protected AWTStarter starter;
  +    /** The InputHandler associated with this window */
  +    protected InputHandler inputHandler;
  +    /** The Driver used for refreshing/reloading the view */
  +    protected Driver driver;
   
       private int currentPage = 0;
       private int pageCount = 0;
  @@ -106,21 +109,12 @@
       private JLabel infoStatus;
   
       /**
  -     *  Creates a new PreviewDialog that uses the given starter and renderer.
  -     *  @param aStarter the to use starter
  -     *  @param aRenderer the to use renderer
  -     */
  -    public PreviewDialog(AWTStarter aStarter, AWTRenderer aRenderer) {
  -        this(aRenderer);
  -        starter = aStarter;
  -    }
  -
  -    /**
        * Creates a new PreviewDialog that uses the given renderer.
        * @param aRenderer the to use renderer
        */
  -    public PreviewDialog(AWTRenderer aRenderer) {
  +    public PreviewDialog(AWTRenderer aRenderer, InputHandler handler) {
           renderer = aRenderer;
  +        inputHandler = handler;
           translator = renderer.getTranslator();
   
           //Commands aka Actions
  @@ -253,11 +247,14 @@
                   print();
               }
           });
  -        menu.add(new Command(translator.getString("Menu.Reload")) {
  -            public void doit() {
  -                reload();
  -            }
  -        });
  +        // inputHandler must be set to allow reloading
  +        if (inputHandler != null) {
  +            menu.add(new Command(translator.getString("Menu.Reload")) {
  +                public void doit() {
  +                    reload();
  +                }
  +            });
  +        }
           menu.addSeparator();
           menu.add(new Command(translator.getString("Menu.Exit")) {
               public void doit() {
  @@ -415,6 +412,13 @@
        */
       private class Reloader extends Thread {
           public void run() {
  +            if (driver == null) {
  +                driver = new Driver();
  +                driver.setRenderer(renderer);
  +            } else {
  +                driver.reset();
  +            }
  +            
               pageLabel.setIcon(null);
               infoStatus.setText("");
               currentPage = 0;
  @@ -423,7 +427,7 @@
               //    renderer.removePage(0);
               try {
                   setStatus(translator.getString("Status.Build.FO.tree"));
  -                starter.run();
  +                driver.render(inputHandler);
                   setStatus(translator.getString("Status.Show"));
               } catch (FOPException e) {
                   reportException(e);
  
  
  

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

Reply via email to