xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject cvs commit: xml-fop/src/java/org/apache/fop/render/awt/viewer/resources Viewer_de.properties Viewer_fr.properties Viewer.properties
Date Wed, 15 Jun 2005 12:24:01 GMT
jeremias    2005/06/15 05:24:01

  Modified:    src/java/org/apache/fop/render/awt AWTRenderer.java
               src/java/org/apache/fop/render/java2d Java2DRenderer.java
               src/java/org/apache/fop/render/print PrintRenderer.java
               src/java/org/apache/fop/render/awt/viewer Command.java
                        PreviewDialog.java
               src/java/org/apache/fop/render/awt/viewer/resources
                        Viewer_de.properties Viewer_fr.properties
                        Viewer.properties
  Added:       src/java/org/apache/fop/render/awt/viewer package.html
                        PreviewPanel.java ImageProxyPanel.java
  Log:
  Bugzilla: #35358
  Improvements on Viewer application:
  - Separated out the preview panels and control logic from the buttons and dialog to make it easier to use elsewhere.
  - Added a continuous scrolling mode similar to that used by acrobat reader. Also added continuous facing mode.
  - Added fit-width and fit-to-page zoom options.
  Submitted by: Richard Wheeldon <richardw.at.geoquip-rnd.demon.co.uk>
  
  Updated german and french translations by myself.
  
  Revision  Changes    Path
  1.36      +50 -33    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.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- AWTRenderer.java	9 Jun 2005 08:49:26 -0000	1.35
  +++ AWTRenderer.java	15 Jun 2005 12:24:01 -0000	1.36
  @@ -29,10 +29,10 @@
   import java.awt.Dimension;
   import java.awt.Graphics;
   import java.awt.Graphics2D;
  +import java.awt.geom.Rectangle2D;
   import java.awt.Toolkit;
   import java.awt.event.WindowAdapter;
   import java.awt.event.WindowEvent;
  -import java.awt.geom.Rectangle2D;
   import java.awt.image.BufferedImage;
   import java.awt.print.PageFormat;
   import java.awt.print.Pageable;
  @@ -82,22 +82,34 @@
           createPreviewDialog();
       }
   
  -    public void renderPage(PageViewport pageViewport) throws IOException,
  -            FOPException {
  +    public void renderPage(PageViewport pageViewport) 
  +            throws IOException, FOPException {
   
           super.renderPage(pageViewport);
  -
  -        // Shows the page if it's the first one
  -        if (getCurrentPageNumber() == 1) {
  -            frame.showPage();
  -        }
           frame.setInfo();
  -
       }
   
       public void stopRenderer() throws IOException {
           super.stopRenderer();
           frame.setStatus(translator.getString("Status.Show"));
  +            frame.reload(); // Refreshes view of page
  +        }
  +
  +        /**
  +         * Returns the dimensions of the specified page
  +         * @exception FOPException If the page is out of range or has not been rendered.
  +         */
  +        public Dimension getPageImageSize(int pageNum) throws FOPException {
  +        Rectangle2D bounds = getPageViewport(pageNum).getViewArea();
  +        pageWidth = (int) Math.round(bounds.getWidth() / 1000f);
  +        pageHeight = (int) Math.round(bounds.getHeight() / 1000f);
  +        double scaleX = scaleFactor 
  +                * FOUserAgent.DEFAULT_PX2MM / userAgent.getPixelUnitToMillimeter();
  +        double scaleY = scaleFactor 
  +                * FOUserAgent.DEFAULT_PX2MM / userAgent.getPixelUnitToMillimeter();
  +        int bitmapWidth = (int) ((pageWidth * scaleX) + 0.5);
  +        int bitmapHeight = (int) ((pageHeight * scaleY) + 0.5);
  +                return new Dimension(bitmapWidth, bitmapHeight);
       }
   
       /** Creates and initialize the AWT Viewer main window */
  @@ -153,30 +165,35 @@
       /** @see java.awt.print.Pageable#getPageFormat(int) */
       public PageFormat getPageFormat(int pageIndex)
               throws IndexOutOfBoundsException {
  -        if (pageIndex >= getNumberOfPages())
  -            return null;
  -
  -        PageFormat pageFormat = new PageFormat();
  -
  -        Paper paper = new Paper();
  -        pageFormat.setPaper(paper);
  -
  -        Rectangle2D dim = getPageViewport(pageIndex).getViewArea();
  -        double width = dim.getWidth();
  -        double height = dim.getHeight();
  -
  -        // if the width is greater than the height assume lanscape mode
  -        // and swap the width and height values in the paper format
  -        if (width > height) {
  -            paper.setImageableArea(0, 0, height / 1000d, width / 1000d);
  -            paper.setSize(height / 1000d, width / 1000d);
  -            pageFormat.setOrientation(PageFormat.LANDSCAPE);
  -        } else {
  -            paper.setImageableArea(0, 0, width / 1000d, height / 1000d);
  -            paper.setSize(width / 1000d, height / 1000d);
  -            pageFormat.setOrientation(PageFormat.PORTRAIT);
  +        try {
  +            if (pageIndex >= getNumberOfPages()) {
  +                return null;
  +            }
  +    
  +            PageFormat pageFormat = new PageFormat();
  +    
  +            Paper paper = new Paper();
  +            pageFormat.setPaper(paper);
  +    
  +            Rectangle2D dim = getPageViewport(pageIndex).getViewArea();
  +            double width = dim.getWidth();
  +            double height = dim.getHeight();
  +    
  +            // if the width is greater than the height assume lanscape mode
  +            // and swap the width and height values in the paper format
  +            if (width > height) {
  +                paper.setImageableArea(0, 0, height / 1000d, width / 1000d);
  +                paper.setSize(height / 1000d, width / 1000d);
  +                pageFormat.setOrientation(PageFormat.LANDSCAPE);
  +            } else {
  +                paper.setImageableArea(0, 0, width / 1000d, height / 1000d);
  +                paper.setSize(width / 1000d, height / 1000d);
  +                pageFormat.setOrientation(PageFormat.PORTRAIT);
  +            }
  +            return pageFormat;
  +        } catch (FOPException fopEx) {
  +            throw new IndexOutOfBoundsException(fopEx.getMessage());
           }
  -        return pageFormat;
       }
   
       /** @see java.awt.print.Pageable#getPrintable(int) */
  @@ -207,7 +224,7 @@
        * @see org.apache.fop.render.java2d.Java2DRenderer#drawBackAndBorders(org.apache.fop.area.Area,
        * float, float, float, float)
        *
  -     * @param block the area to get the traits from
  +     * @param area the area to get the traits from
        * @param startx the start x position
        * @param starty the start y position
        * @param width the width of the area
  
  
  
  1.3       +22 -22    xml-fop/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
  
  Index: Java2DRenderer.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/java2d/Java2DRenderer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Java2DRenderer.java	9 Jun 2005 12:45:53 -0000	1.2
  +++ Java2DRenderer.java	15 Jun 2005 12:24:01 -0000	1.3
  @@ -35,7 +35,6 @@
   import java.awt.image.PixelInterleavedSampleModel;
   import java.awt.image.Raster;
   import java.awt.image.SampleModel;
  -import java.awt.image.SinglePixelPackedSampleModel;
   import java.awt.image.WritableRaster;
   import java.io.IOException;
   import java.io.OutputStream;
  @@ -148,7 +147,8 @@
       public boolean renderingDone;
   
       /** Default constructor */
  -    public Java2DRenderer() {}
  +    public Java2DRenderer() {
  +    }
   
       /**
        * @see org.apache.fop.render.Renderer#setUserAgent(org.apache.fop.apps.FOUserAgent)
  @@ -227,14 +227,6 @@
       }
   
       /**
  -     * @param the 0-based pageIndex
  -     * @return the corresponding PageViewport
  -     */
  -    public PageViewport getPageViewport(int pageIndex) {
  -        return (PageViewport) pageViewportList.get(pageIndex);
  -    }
  -
  -    /**
        * This method override only stores the PageViewport in a List. No actual
        * rendering is performed here. A renderer override renderPage() to get the
        * freshly produced PageViewport, and rendere them on the fly (producing the
  @@ -245,9 +237,9 @@
        * the Area Tree
        * @see org.apache.fop.render.Renderer
        */
  -    public void renderPage(PageViewport pageViewport) throws IOException,
  -            FOPException {
  -        pageViewportList.add(pageViewport.clone());// FIXME clone
  +    public void renderPage(PageViewport pageViewport) 
  +                throws IOException, FOPException {
  +        pageViewportList.add(pageViewport.clone()); // FIXME clone
           currentPageNumber++;
       }
   
  @@ -321,6 +313,21 @@
           return currentPageImage;
       }
   
  +        
  +    /**
  +     * Returns the page viewport
  +     * @param pageNum the page number
  +     * @exception FOPException If the page is out of range.
  +     */
  +    public PageViewport getPageViewport(int pageNum) throws FOPException {
  +        if (pageNum < 0 || pageNum >= pageViewportList.size()) {
  +            throw new FOPException("Requested page number is out of range: " + pageNum
  +                     + "; only " + pageViewportList.size()
  +                     + " page(s) available.");
  +        }
  +        return (PageViewport) pageViewportList.get(pageNum);
  +    }
  +
       /**
        * Generates a desired page from the renderer's page viewport list.
        *
  @@ -330,14 +337,7 @@
        * @throws FOPException
        */
       public BufferedImage getPageImage(int pageNum) throws FOPException {
  -        if (pageNum < 0 || pageNum >= pageViewportList.size()) {
  -            throw new FOPException("out-of-range page number (" + pageNum
  -                    + ") requested; only " + pageViewportList.size()
  -                    + " page(s) available.");
  -        }
  -        PageViewport pageViewport = (PageViewport) pageViewportList
  -                .get(pageNum);
  -        return getPageImage(pageViewport);
  +        return getPageImage(getPageViewport(pageNum));
       }
   
       /**
  
  
  
  1.2       +32 -26    xml-fop/src/java/org/apache/fop/render/print/PrintRenderer.java
  
  Index: PrintRenderer.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/print/PrintRenderer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PrintRenderer.java	9 Jun 2005 08:49:27 -0000	1.1
  +++ PrintRenderer.java	15 Jun 2005 12:24:01 -0000	1.2
  @@ -142,7 +142,7 @@
   
       public int print(Graphics g, PageFormat pageFormat, int pageIndex)
               throws PrinterException {
  -        if (pageIndex >= getNumberOfPages()){
  +        if (pageIndex >= getNumberOfPages()) {
               return NO_SUCH_PAGE;
           }
   
  @@ -156,37 +156,43 @@
               return NO_SUCH_PAGE;
           }
   
  -        g2.drawImage(image,null,0,0);
  +        g2.drawImage(image, null, 0, 0);
   
           return PAGE_EXISTS;
       }
   
  +    /** @see java.awt.print.Pageable#getPageFormat(int) */
       public PageFormat getPageFormat(int pageIndex)
               throws IndexOutOfBoundsException {
  -        if (pageIndex >= getNumberOfPages())
  -            return null;
  -
  -        PageFormat pageFormat = new PageFormat();
  -
  -        Paper paper = new Paper();
  -        pageFormat.setPaper(paper);
  -
  -        Rectangle2D dim = getPageViewport(pageIndex).getViewArea();
  -        double width = dim.getWidth();
  -        double height = dim.getHeight();
  -
  -        // if the width is greater than the height assume lanscape mode
  -        // and swap the width and height values in the paper format
  -        if (width > height) {
  -            paper.setImageableArea(0, 0, height / 1000d, width / 1000d);
  -            paper.setSize(height / 1000d, width / 1000d);
  -            pageFormat.setOrientation(PageFormat.LANDSCAPE);
  -        } else {
  -            paper.setImageableArea(0, 0, width / 1000d, height / 1000d);
  -            paper.setSize(width / 1000d, height / 1000d);
  -            pageFormat.setOrientation(PageFormat.PORTRAIT);
  +        try {
  +            if (pageIndex >= getNumberOfPages()) {
  +                return null;
  +            }
  +    
  +            PageFormat pageFormat = new PageFormat();
  +    
  +            Paper paper = new Paper();
  +            pageFormat.setPaper(paper);
  +    
  +            Rectangle2D dim = getPageViewport(pageIndex).getViewArea();
  +            double width = dim.getWidth();
  +            double height = dim.getHeight();
  +    
  +            // if the width is greater than the height assume lanscape mode
  +            // and swap the width and height values in the paper format
  +            if (width > height) {
  +                paper.setImageableArea(0, 0, height / 1000d, width / 1000d);
  +                paper.setSize(height / 1000d, width / 1000d);
  +                pageFormat.setOrientation(PageFormat.LANDSCAPE);
  +            } else {
  +                paper.setImageableArea(0, 0, width / 1000d, height / 1000d);
  +                paper.setSize(width / 1000d, height / 1000d);
  +                pageFormat.setOrientation(PageFormat.PORTRAIT);
  +            }
  +            return pageFormat;
  +        } catch (FOPException fopEx) {
  +            throw new IndexOutOfBoundsException(fopEx.getMessage());
           }
  -        return pageFormat;
       }
   
       public Printable getPrintable(int pageIndex)
  
  
  
  1.3       +7 -3      xml-fop/src/java/org/apache/fop/render/awt/viewer/Command.java
  
  Index: Command.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/awt/viewer/Command.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Command.java	27 Feb 2004 17:51:22 -0000	1.2
  +++ Command.java	15 Jun 2005 12:24:01 -0000	1.3
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 1999-2004 The Apache Software Foundation.
  + * Copyright 1999-2005 The Apache Software Foundation.
    * 
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
  @@ -44,10 +44,14 @@
        * Creates <code>Command</code> object with a given name and
        * sets the name as a tooltip text. No associated icon image.
        * @param name of the command
  +     * @param mnemonic A Key
        */
  -    public Command(String name) {
  +    public Command(String name, int mnemonic) {
           super(name);
           putValue(SHORT_DESCRIPTION, name);
  +        if (mnemonic > 0) {
  +            putValue(MNEMONIC_KEY, new Integer(mnemonic));
  +        }
       }
   
       /**
  
  
  
  1.11      +180 -212  xml-fop/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java
  
  Index: PreviewDialog.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- PreviewDialog.java	10 Jun 2005 15:20:22 -0000	1.10
  +++ PreviewDialog.java	15 Jun 2005 12:24:01 -0000	1.11
  @@ -24,7 +24,6 @@
   
   // Java
   import java.awt.BorderLayout;
  -import java.awt.Color;
   import java.awt.Dimension;
   import java.awt.GridBagConstraints;
   import java.awt.GridBagLayout;
  @@ -33,33 +32,34 @@
   import java.awt.Toolkit;
   import java.awt.event.ActionEvent;
   import java.awt.event.ActionListener;
  -import java.awt.image.BufferedImage;
  +import java.awt.event.KeyEvent;
   import java.awt.print.PrinterException;
   import java.awt.print.PrinterJob;
   
  +import java.text.DecimalFormat;
  +
   import javax.swing.BorderFactory;
  -import javax.swing.ImageIcon;
  +import javax.swing.ButtonGroup;
   import javax.swing.JComboBox;
  +import javax.swing.JRadioButtonMenuItem;
   import javax.swing.JFrame;
   import javax.swing.JLabel;
   import javax.swing.JMenu;
   import javax.swing.JMenuBar;
   import javax.swing.JOptionPane;
   import javax.swing.JPanel;
  -import javax.swing.JScrollPane;
  -import javax.swing.JButton;
   import javax.swing.JToolBar;
   import javax.swing.SwingUtilities;
   import javax.swing.UIManager;
  -import javax.swing.border.EmptyBorder;
   
  -import org.apache.fop.apps.FOPException;
   import org.apache.fop.apps.FOUserAgent;
  -import org.apache.fop.apps.Fop;
  -import org.apache.fop.fo.Constants;
  +import org.apache.fop.apps.FOPException;
   import org.apache.fop.render.awt.AWTRenderer;
   
  -/** AWT Viewer main window. */
  +/**
  + * AWT Viewer main window.
  + * Surrounds a PreviewPanel with a bunch of pretty buttons and controls.
  + */
   public class PreviewDialog extends JFrame {
   
       /** The Translator for localization */
  @@ -68,14 +68,6 @@
       protected AWTRenderer renderer;
       /** The FOUserAgent associated with this window */
       protected FOUserAgent foUserAgent;
  -    /** The Fop object used for refreshing/reloading the view */
  -    protected Fop fop;
  -
  -    /** The number of the page which is currently visible */
  -    private int currentPage = 0;
  -
  -    /** The Reloader, when the user clicks on menu "reload" */
  -    private Reloader reloader;
   
       /** The JCombobox to rescale the rendered page view */
       private JComboBox scale;
  @@ -83,15 +75,18 @@
       /** The JLabel for the process status bar */
       private JLabel processStatus;
   
  -    /** The JLabel that holds the rendered page */
  -    private JLabel pageLabel;
  -
       /** The JLabel information status bar */
       private JLabel infoStatus;
   
  +    /** The main display area */
  +    private PreviewPanel previewPanel;
  +
  +    /** Formats the text in the scale combobox. */
  +    private DecimalFormat percentFormat = new DecimalFormat("###0.0#");
  +
       /**
        * Creates a new PreviewDialog that uses the given renderer.
  -     * @param aRenderer the to use renderer
  +     * @param foUserAgent the user agent
        */
       public PreviewDialog(FOUserAgent foUserAgent) {
           renderer = (AWTRenderer) foUserAgent.getRendererOverride();
  @@ -101,7 +96,7 @@
           //Commands aka Actions
           Command printAction = new Command(translator.getString("Menu.Print"), "Print") {
               public void doit() {
  -                startPrinterJob();
  +                startPrinterJob(true);
               }
           };
           Command firstPageAction = new Command(translator.getString("Menu.First.page"),
  @@ -129,16 +124,16 @@
           };
           Command reloadAction = new Command(translator.getString("Menu.Reload"), "reload") {
               public void doit() {
  -                reload();
  +                previewPanel.reload();
               }
           };
  -        Command debugAction = new Command("Debug", "debug") {
  +        Command debugAction = new Command(translator.getString("Menu.Debug"), "debug") {
               // TODO use Translator
               public void doit() {
  -                debug();
  +                previewPanel.debug();
               }
           };
  -        Command aboutAction = new Command("About FOP", "fopLogo") {
  +        Command aboutAction = new Command(translator.getString("Menu.About"), "fopLogo") {
               public void doit() {
                   startHelpAbout();
               }
  @@ -148,7 +143,9 @@
           try {
               UIManager.setLookAndFeel(
                   UIManager.getSystemLookAndFeelClassName());
  -        } catch (Exception e) { }
  +        } catch (Exception e) {
  +            System.err.println("Couldn't set system look & feel!");
  +        }
   
           setTitle("FOP: AWT-" + translator.getString("Title.Preview"));
           setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  @@ -159,26 +156,23 @@
           setSize(screen.width * 61 / 100, screen.height * 9 / 10);
   
           //Page view stuff
  -        pageLabel = new JLabel();
  -        pageLabel.setHorizontalAlignment(0 /* CENTER */);
  -        pageLabel.setBorder(new EmptyBorder(20, 0, 20, 0));
  -        JScrollPane previewArea = new JScrollPane(pageLabel);
  -        previewArea.getViewport().setBackground(Color.gray);
  -        previewArea.setMinimumSize(new Dimension(50, 50));
  -        getContentPane().add(previewArea, BorderLayout.CENTER);
  +        previewPanel = new PreviewPanel(foUserAgent, renderer);
  +        getContentPane().add(previewPanel, BorderLayout.CENTER);
   
           //Scaling combobox
           scale = new JComboBox();
  +        scale.addItem(translator.getString("Menu.Fit.Window"));
  +        scale.addItem(translator.getString("Menu.Fit.Width"));
           scale.addItem("25%");
           scale.addItem("50%");
           scale.addItem("75%");
           scale.addItem("100%");
           scale.addItem("150%");
           scale.addItem("200%");
  -        scale.addItem("400%");
           scale.setMaximumSize(new Dimension(80, 24));
           scale.setPreferredSize(new Dimension(80, 24));
           scale.setSelectedItem("100%");
  +        scale.setEditable(true);
           scale.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                   scaleActionPerformed(e);
  @@ -197,7 +191,7 @@
           toolBar.add(previousPageAction);
           toolBar.add(nextPageAction);
           toolBar.add(lastPageAction);
  -        toolBar.addSeparator(new Dimension(20,0));
  +        toolBar.addSeparator(new Dimension(20, 0));
           toolBar.add(new JLabel(translator.getString("Menu.Zoom") + " "));
           toolBar.add(scale);
           toolBar.addSeparator();
  @@ -244,101 +238,140 @@
       private JMenuBar setupMenu() {
           JMenuBar menuBar = new JMenuBar();
           JMenu menu = new JMenu(translator.getString("Menu.File"));
  -
  +        menu.setMnemonic(KeyEvent.VK_F);
           //Adds mostly the same actions, but without icons
  -        menu.add(new Command(translator.getString("Menu.Print")) {
  +        menu.add(new Command(translator.getString("Menu.Print"), KeyEvent.VK_P) {
               public void doit() {
  -                startPrinterJob();
  +                startPrinterJob(true);
               }
           });
           // inputHandler must be set to allow reloading
           if (foUserAgent.getInputHandler() != null) {
  -            menu.add(new Command(translator.getString("Menu.Reload")) {
  +            menu.add(new Command(translator.getString("Menu.Reload"), KeyEvent.VK_R) {
                   public void doit() {
                       reload();
                   }
               });
           }
           menu.addSeparator();
  -        menu.add(new Command(translator.getString("Menu.Exit")) {
  +        menu.add(new Command(translator.getString("Menu.Exit"), KeyEvent.VK_X) {
               public void doit() {
                   dispose();
               }
           });
           menuBar.add(menu);
  +
           menu = new JMenu(translator.getString("Menu.View"));
  -        menu.add(new Command(translator.getString("Menu.First.page")) {
  +        menu.setMnemonic(KeyEvent.VK_V);
  +        menu.add(new Command(translator.getString("Menu.First.page"), KeyEvent.VK_F) {
               public void doit() {
                   goToFirstPage();
               }
           });
  -        menu.add(new Command(translator.getString("Menu.Prev.page")) {
  +        menu.add(new Command(translator.getString("Menu.Prev.page"), KeyEvent.VK_P) {
               public void doit() {
                   goToPreviousPage();
               }
           });
  -        menu.add(new Command(translator.getString("Menu.Next.page")) {
  +        menu.add(new Command(translator.getString("Menu.Next.page"), KeyEvent.VK_N) {
               public void doit() {
                   goToNextPage();
               }
           });
  -        menu.add(new Command(translator.getString("Menu.Last.page")) {
  +        menu.add(new Command(translator.getString("Menu.Last.page"), KeyEvent.VK_L) {
               public void doit() {
                   goToLastPage();
               }
           });
  -        menu.add(new Command(translator.getString("Menu.Go.to.Page") + " ...") {
  +        menu.add(new Command(translator.getString("Menu.Go.to.Page"), KeyEvent.VK_G) {
               public void doit() {
                   showGoToPageDialog();
               }
           });
           menu.addSeparator();
           JMenu subMenu = new JMenu(translator.getString("Menu.Zoom"));
  -        subMenu.add(new Command("25%") {
  +        subMenu.setMnemonic(KeyEvent.VK_Z);
  +        subMenu.add(new Command("25%", 0) {
               public void doit() {
                   setScale(25.0);
               }
           });
  -        subMenu.add(new Command("50%") {
  +        subMenu.add(new Command("50%", 0) {
               public void doit() {
                   setScale(50.0);
               }
           });
  -        subMenu.add(new Command("75%") {
  +        subMenu.add(new Command("75%", 0) {
               public void doit() {
                   setScale(75.0);
               }
           });
  -        subMenu.add(new Command("100%") {
  +        subMenu.add(new Command("100%", 0) {
               public void doit() {
                   setScale(100.0);
               }
           });
  -        subMenu.add(new Command("150%") {
  +        subMenu.add(new Command("150%", 0) {
               public void doit() {
                   setScale(150.0);
               }
           });
  -        subMenu.add(new Command("200%") {
  +        subMenu.add(new Command("200%", 0) {
               public void doit() {
                   setScale(200.0);
               }
           });
  -        subMenu.add(new Command("400%") {
  +        menu.add(subMenu);
  +        menu.addSeparator();
  +        menu.add(new Command(translator.getString("Menu.Default.zoom"), KeyEvent.VK_D) {
               public void doit() {
  -                setScale(400.0);
  +                setScale(100.0);
  +            }
  +        });
  +        menu.add(new Command(translator.getString("Menu.Fit.Window"), KeyEvent.VK_F) {
  +            public void doit() {
  +                setScaleToFitWindow();
  +            }
  +        });
  +        menu.add(new Command(translator.getString("Menu.Fit.Width"), KeyEvent.VK_W) {
  +            public void doit() {
  +                setScaleToFitWidth();
               }
           });
  -        menu.add(subMenu);
           menu.addSeparator();
  -        menu.add(new Command(translator.getString("Menu.Default.zoom")) {
  +
  +        ButtonGroup group = new ButtonGroup();
  +        JRadioButtonMenuItem single = new JRadioButtonMenuItem(
  +                new Command(translator.getString("Menu.Single"), KeyEvent.VK_S) {
               public void doit() {
  -                setScale(100.0);
  +                previewPanel.setDisplayMode(PreviewPanel.SINGLE);
               }
           });
  +        JRadioButtonMenuItem cont = new JRadioButtonMenuItem(
  +                new Command(translator.getString("Menu.Continuous"), KeyEvent.VK_C) {
  +            public void doit() {
  +                previewPanel.setDisplayMode(PreviewPanel.CONTINUOUS);
  +            }
  +        });
  +        JRadioButtonMenuItem facing = new JRadioButtonMenuItem(
  +                new Command(translator.getString("Menu.Facing"), 0) {
  +            public void doit() {
  +                previewPanel.setDisplayMode(PreviewPanel.CONT_FACING);
  +            }
  +        });
  +        single.setSelected(true);
  +        group.add(single);
  +        group.add(cont);
  +        group.add(facing);
  +        menu.add(single);
  +        menu.add(cont);
  +        menu.add(facing);
  +
           menuBar.add(menu);
  +
           menu = new JMenu(translator.getString("Menu.Help"));
  -        menu.add(new Command(translator.getString("Menu.About")) {
  +        menu.setMnemonic(KeyEvent.VK_H);
  +        menu.add(new Command(translator.getString("Menu.About"), KeyEvent.VK_A) {
               public void doit() {
                   startHelpAbout();
               }
  @@ -347,119 +380,70 @@
           return menuBar;
       }
   
  -    /** Shows the About box */
  -    private void startHelpAbout() {
  -        PreviewDialogAboutBox dlg = new PreviewDialogAboutBox(this, translator);
  -        //Centers the box
  -        Dimension dlgSize = dlg.getPreferredSize();
  -        Dimension frmSize = getSize();
  -        Point loc = getLocation();
  -        dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
  -                        (frmSize.height - dlgSize.height) / 2 + loc.y);
  -        dlg.setVisible(true);
  +    public void reload() {
  +        previewPanel.reload();
       }
   
       /**
        * Changes the current visible page
        * @param number the page number to go to
        */
  -      private void goToPage(int number) {
  -        currentPage = number;
  -        showPage();
  -        setInfo();
  +    public void goToPage(int number) {
  +        if (number != previewPanel.getPage()) {
  +            previewPanel.setPage(number);
  +            setInfo();
  +        }
       }
   
       /**
        * Shows the previous page.
        */
  -    private void goToPreviousPage() {
  -        if (currentPage <= 0) {
  -            return;
  +    public void goToPreviousPage() {
  +        int page = previewPanel.getPage();
  +        if (page > 0) {
  +            goToPage(page - 1);
           }
  -        currentPage--;
  -        goToPage(currentPage);
       }
   
       /**
        * Shows the next page.
        */
  -    private void goToNextPage() {
  -        if (currentPage >= renderer.getNumberOfPages() - 1) {
  -            return;
  +    public void goToNextPage() {
  +        int page = previewPanel.getPage();
  +        if (page < renderer.getNumberOfPages() - 1) {
  +            goToPage(page + 1);
           }
  -        currentPage++;
  -        goToPage(currentPage);
       }
   
  -    /**
  -     * Shows the last page.
  -     */
  -    private void goToLastPage() {
  -        if (currentPage == renderer.getNumberOfPages() - 1) {
  -            return;
  -        }
  -        currentPage = renderer.getNumberOfPages() - 1;
  -        goToPage(currentPage);
  -    }
  -
  -    /**
  -     * Reloads and reformats document.
  -     */
  -    private synchronized void reload() {
  -        if (reloader == null || !reloader.isAlive()) {
  -            reloader = new Reloader();
  -            reloader.start();
  -        }
  +    /** Shows the first page. */
  +    public void goToFirstPage() {
  +        goToPage(0);
       }
   
       /**
  -     * Allows a (yet) simple visual debug of the document.
  +     * Shows the last page.
        */
  -    private void debug(){
  -        renderer.debug = !renderer.debug;
  -        reload();
  +    public void goToLastPage() {
  +        goToPage(renderer.getNumberOfPages() - 1);
       }
   
  -    /**
  -     * This class is used to reload document in a thread safe way.
  -     */
  -    private class Reloader extends Thread {
  -        public void run() {
  -
  -            if (!renderer.renderingDone) {
  -                // do not allow the reloading while FOP is
  -                // still rendering
  -                JOptionPane.showMessageDialog(getContentPane(),
  -                        "Cannot perform the requested operation until "
  -                                + "all page are rendererd. Please wait",
  -                        "Please wait ", 1 /* INFORMATION_MESSAGE */);
  -                return;
  -            }
  -
  -            if (fop == null) {
  -                fop = new Fop(Constants.RENDER_AWT, foUserAgent);
  -            }
  -
  -            pageLabel.setIcon(null);
  -            int savedCurrentPage = currentPage;
  -            currentPage = 0;
  -            renderer.clearViewportList();
  -
  -            try {
  -                setStatus(translator.getString("Status.Build.FO.tree"));
  -                foUserAgent.getInputHandler().render(fop);
  -                goToPage(savedCurrentPage);
  -                setStatus(translator.getString("Status.Show"));
  -            } catch (FOPException e) {
  -                reportException(e);
  -            }
  -        }
  +    /** Shows the About box */
  +    private void startHelpAbout() {
  +        PreviewDialogAboutBox dlg = new PreviewDialogAboutBox(this, translator);
  +        //Centers the box
  +        Dimension dlgSize = dlg.getPreferredSize();
  +        Dimension frmSize = getSize();
  +        Point loc = getLocation();
  +        dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
  +                        (frmSize.height - dlgSize.height) / 2 + loc.y);
  +        dlg.setVisible(true);
       }
   
       /**
        * Shows "go to page" dialog and then goes to the selected page
        */
       private void showGoToPageDialog() {
  +                int currentPage = previewPanel.getPage();
           GoToPageDialog d = new GoToPageDialog(this,
               translator.getString("Menu.Go.to.Page"), translator);
           d.setLocation((int)getLocation().getX() + 50,
  @@ -473,20 +457,65 @@
           goToPage(currentPage);
       }
   
  -    /** Shows the first page. */
  -    private void goToFirstPage() {
  -        if (currentPage == 0) {
  -            return;
  +    /** Scales page image */
  +    public void setScale(double scaleFactor) {
  +//         if (scaleFactor == 25.0) {
  +//             scale.setSelectedIndex(0);
  +//         } else if (scaleFactor == 50.0) {
  +//             scale.setSelectedIndex(1);
  +//         } else if (scaleFactor == 75.0) {
  +//             scale.setSelectedIndex(2);
  +//         } else if (scaleFactor == 100.0) {
  +//             scale.setSelectedIndex(3);
  +//         } else if (scaleFactor == 150.0) {
  +//             scale.setSelectedIndex(4);
  +//         } else if (scaleFactor == 200.0) {
  +//             scale.setSelectedIndex(5);
  +//         } else if (scaleFactor == 400.0) {
  +//             scale.setSelectedIndex(6);
  +//         } else {
  +        scale.setSelectedItem(percentFormat.format(scaleFactor) + "%");
  +//              }
  +        previewPanel.setScaleFactor(scaleFactor / 100d);
  +    }
  +
  +    public void setScaleToFitWindow() {
  +        try {
  +            setScale(previewPanel.getScaleToFitWindow() * 100);
  +        } catch (FOPException fopEx) {
  +            fopEx.printStackTrace();
  +        }
  +    }
  +    
  +    public void setScaleToFitWidth() {
  +        try {
  +            setScale(previewPanel.getScaleToFitWidth() * 100);
  +        } catch (FOPException fopEx) {
  +            fopEx.printStackTrace();
  +        }
  +    }
  +
  +    private void scaleActionPerformed(ActionEvent e) {
  +        try {
  +            int index = scale.getSelectedIndex();
  +            if (index == 0) {
  +                setScale(previewPanel.getScaleToFitWindow() * 100);
  +            } else if (index == 1) {
  +                setScale(previewPanel.getScaleToFitWidth() * 100);
  +            } else {
  +                String item = (String)scale.getSelectedItem();
  +                setScale(Double.parseDouble(item.substring(0, item.indexOf('%'))));
  +            }
  +        } catch (FOPException fopEx) {
  +            fopEx.printStackTrace();
           }
  -        currentPage = 0;
  -        goToPage(currentPage);
       }
   
       /** Prints the document */
  -    private void startPrinterJob() {
  +    public void startPrinterJob(boolean showDialog) {
           PrinterJob pj = PrinterJob.getPrinterJob();
           pj.setPageable(renderer);
  -        if (pj.printDialog()) {
  +        if (!showDialog || pj.printDialog()) {
               try {
                   pj.print();
               } catch (PrinterException e) {
  @@ -495,32 +524,6 @@
           }
       }
   
  -    /** Scales page image */
  -    private void setScale(double scaleFactor) {
  -        if (scaleFactor == 25.0) {
  -            scale.setSelectedIndex(0);
  -        } else if (scaleFactor == 50.0) {
  -            scale.setSelectedIndex(1);
  -        } else if (scaleFactor == 75.0) {
  -            scale.setSelectedIndex(2);
  -        } else if (scaleFactor == 100.0) {
  -            scale.setSelectedIndex(3);
  -        } else if (scaleFactor == 150.0) {
  -            scale.setSelectedIndex(4);
  -        } else if (scaleFactor == 200.0) {
  -            scale.setSelectedIndex(5);
  -        } else if (scaleFactor == 400.0) {
  -            scale.setSelectedIndex(6);
  -        }
  -        renderer.setScaleFactor(scaleFactor / 100d);
  -        reload();
  -    }
  -
  -    private void scaleActionPerformed(ActionEvent e) {
  -        String item = (String)scale.getSelectedItem();
  -        setScale(Double.parseDouble(item.substring(0, item.indexOf('%'))));
  -    }
  -
       /**
        * Sets message to be shown in the status bar in a thread safe way.
        * @param message the message
  @@ -559,49 +562,14 @@
       private class ShowInfo implements Runnable {
   
           public void run() {
  -
               String message = translator.getString("Status.Page") + " "
  -                    + (currentPage + 1) + " "
  +                    + (previewPanel.getPage() + 1) + " "
                       + translator.getString("Status.of") + " "
  -                    + renderer.getCurrentPageNumber();
  -
  +                    + (renderer.getNumberOfPages());
               infoStatus.setText(message);
           }
       }
   
  -    /** Starts rendering process and shows the current page. */
  -    public synchronized void showPage() {
  -        ShowPageImage viewer = new ShowPageImage();
  -
  -        if (SwingUtilities.isEventDispatchThread()) {
  -            viewer.run();
  -        } else {
  -            SwingUtilities.invokeLater(viewer);
  -        }
  -    }
  -
  -    /** This class is used to render the page image in a thread safe way. */
  -    private class ShowPageImage implements Runnable {
  -
  -        /**
  -         * The run method that does the actual rendering of the viewed page
  -         */
  -        public void run() {
  -
  -            setStatus(translator.getString("Status.Build.FO.tree"));
  -
  -            BufferedImage pageImage = null;
  -            try {
  -                pageImage = renderer.getPageImage(currentPage);
  -            } catch (FOPException e) {
  -                reportException(e);
  -            }
  -            pageLabel.setIcon(new ImageIcon(pageImage));
  -
  -            setStatus(translator.getString("Status.Show"));
  -        }
  -    }
  -
       /**
        * Opens standard Swing error dialog box and reports given exception details.
        * @param e the Exception
  
  
  
  1.1                  xml-fop/src/java/org/apache/fop/render/awt/viewer/package.html
  
  Index: package.html
  ===================================================================
  <html>
  <title>org.apache.fop.render.awt.viewer</title>
  <body>
  <p>AWT Viewer PreviewDialog and PreviewPanel.</p>
  <p>The PreviewPanel allows users to embed FOP previews in their own
  applications. The PreviewDialog is the default viewer for the -awt
  switch and surrounds the PreviewPanel with a bunch of controls, menu
  items etc.</p>
  </body>
  </html>
  
  
  
  1.1                  xml-fop/src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java
  
  Index: PreviewPanel.java
  ===================================================================
  /*
   * Copyright 1999-2005 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.fop.render.awt.viewer;
  
  import java.awt.Color;
  import java.awt.Dimension;
  import java.awt.GridLayout;
  import java.awt.Point;
  import java.awt.event.MouseEvent;
  import java.awt.event.MouseListener;
  import java.awt.event.MouseMotionListener;
  import java.awt.geom.Rectangle2D;
  
  import javax.swing.JLabel;
  import javax.swing.JOptionPane;
  import javax.swing.JPanel;
  import javax.swing.JScrollPane;
  import javax.swing.JViewport;
  import javax.swing.SwingUtilities;
  import javax.swing.border.EmptyBorder;
  
  import org.apache.fop.apps.Fop;
  import org.apache.fop.apps.FOPException;
  import org.apache.fop.apps.FOUserAgent;
  import org.apache.fop.area.PageViewport;
  
  import org.apache.fop.fo.Constants;
  import org.apache.fop.render.awt.AWTRenderer;
  
  
  /**
   * Holds a scrollpane with the rendered page(s) and handles actions performed
   * to alter the display of the page.
   *    
   * Use PreviewPanel when you want to embed a preview in your own application
   * with your own controls. Use PreviewDialog when you want to use the standard
   * Fop controls.
   *    
   * In order to embed a PreviewPanel in your own app, use the following:
   * <pre>
   * FOUserAgent ua = new FOUserAgent();
   * ua.setRendererOverride(new AWTRenderer());
   * previewPanel = new PreviewPanel(ua);
   * </pre>
   */
  public class PreviewPanel extends JPanel {
  
      /** Constant for setting single page display. */
      public static final int SINGLE = 1;
      /** Constant for setting continuous page display. */
      public static final int CONTINUOUS = 2;
      /** Constant for displaying even/odd pages side by side in continuous form. */
      public static final int CONT_FACING = 3;
  
      /** The number of pixels left empty at the top bottom and sides of the page. */
      private static final int BORDER_SPACING = 10;
  
      /** The main display area */
      private JScrollPane previewArea;
  
      /** The AWT renderer - often shared with PreviewDialog */
      private AWTRenderer renderer;
  
      /** The FOUserAgent associated with this panel - often shared with PreviewDialog */
      protected FOUserAgent foUserAgent;
      /** The number of the page which is currently selected */
      private int currentPage = 0;
  
      /** The index of the first page displayed on screen. */
      private int firstPage = 0;
  
      /** The number of pages concurrently displayed on screen. */
      private int pageRange = 1;
  
      /** The display mode. One of SINGLE, CONTINUOUS or CONT_FACING. */
      private int displayMode = SINGLE;
  
      /** The component(s) that hold the rendered page(s) */
      private ImageProxyPanel[] pagePanels = null;
  
      /**
       * Panel showing the page panels in a grid. Usually the dimensions
       * of the grid are 1x1, nx1 or nx2.
       */
      private JPanel gridPanel = null;
  
      /** Asynchronous reloader thread, used when reload() method is called. */
      private Reloader reloader;
  
      /** The Fop object used for refreshing/reloading the view */
      protected Fop fop;
  
      /**
       * Allows any mouse drag on the page area to scroll the display window.
       */
      private ViewportScroller scroller;
  
          
      public PreviewPanel(FOUserAgent foUserAgent, AWTRenderer renderer) {
          super(new GridLayout(1, 1));
          this.renderer = renderer;
          this.foUserAgent = foUserAgent;
  
          gridPanel = new JPanel();
          gridPanel.setLayout(new GridLayout(0, 1)); // rows, cols
  
          previewArea = new JScrollPane(gridPanel);
          previewArea.getViewport().setBackground(Color.gray);
  
          // FIXME should add scroll wheel support here at some point.
          scroller = new ViewportScroller(previewArea.getViewport());
          previewArea.addMouseListener(scroller);
          previewArea.addMouseMotionListener(scroller);
  
          previewArea.setMinimumSize(new Dimension(50, 50));
          add(previewArea);
      }
          
      /**
       * @return the currently visible page
       */
      public int getPage() {
          return currentPage;
      }
  
      /**
       * Selects the given page, displays it on screen and notifies
       * listeners about the change in selection.
       * @param number the page number
       */
      public void setPage(int number) {
          if (displayMode == CONTINUOUS || displayMode == CONT_FACING) {
              // FIXME Should scroll so page is visible
              currentPage = number;
          } else { // single page mode
              currentPage = number;
              firstPage = currentPage;
          }
          showPage();
      }
  
      /**
       * Sets the display mode.
       * @param mode One of SINGLE, CONTINUOUS or CONT_FACING.
       */
      public void setDisplayMode(int mode) {
          if (mode != displayMode) {
              displayMode = mode;
              gridPanel.setLayout(new GridLayout(0, displayMode == CONT_FACING ? 2 : 1));
              reload();
          }
      }
  
      /**
       * Returns the display mode.
       * @return mode One of SINGLE, CONTINUOUS or CONT_FACING.
       */
      public int getDisplayMode() {
          return displayMode;
      }
  
      /**
       * Reloads and reformats document.
       */
      public synchronized void reload() {
          if (reloader == null || !reloader.isAlive()) {
              reloader = new Reloader();
              reloader.start();
          }
      }
  
      /**
       * Allows a (yet) simple visual debug of the document.
       */
      void debug() {
          renderer.debug = !renderer.debug;
          reload();
      }
  
      /**
       * Allows any mouse drag on the page area to scroll the display window.
       */
      private class ViewportScroller implements MouseListener, MouseMotionListener {
          /** The viewport to be scrolled */
          private final JViewport viewport;
          /** Starting position of a mouse drag - X co-ordinate */
          private int startPosX = 0;
          /** Starting position of a mouse drag - Y co-ordinate */
          private int startPosY = 0;
          
          ViewportScroller(JViewport vp) {
              viewport = vp;
          }
  
          // ***** MouseMotionListener *****              
  
          public synchronized void mouseDragged(MouseEvent e) {
              if (viewport == null) {
                  return;
              }
              int x = e.getX();
              int y = e.getY();
              int xmove = x - startPosX;
              int ymove = y - startPosY;
              int viewWidth = viewport.getExtentSize().width;
              int viewHeight = viewport.getExtentSize().height;
              int imageWidth = viewport.getViewSize().width;
              int imageHeight = viewport.getViewSize().height;
              
              Point viewPoint = viewport.getViewPosition();
              int viewX = Math.max(0, Math.min(imageWidth - viewWidth, viewPoint.x - xmove));
              int viewY = Math.max(0, Math.min(imageHeight - viewHeight, viewPoint.y - ymove));
  
              viewport.setViewPosition(new Point(viewX, viewY));
  
              startPosX = x;
              startPosY = y;
          }
  
          public void mouseMoved(MouseEvent e) { }
  
          // ***** MouseListener *****
  
          public void mousePressed(MouseEvent e) {
              startPosX = e.getX();
              startPosY = e.getY();
          }
  
          public void mouseExited(MouseEvent e) { }
          public void mouseEntered(MouseEvent e) { }
          public void mouseClicked(MouseEvent e) { }
          public void mouseReleased(MouseEvent e) {   }
      }
  
      /**
       * This class is used to reload document in a thread safe way.
       */
      private class Reloader extends Thread {
  
          public void run() {
              if (!renderer.renderingDone) {
                  // do not allow the reloading while FOP is still rendering
                  JOptionPane.showMessageDialog(previewArea,
                          "Cannot perform the requested operation until "
                                  + "all page are rendererd. Please wait",
                          "Please wait ", 1 /* INFORMATION_MESSAGE */);
                  return;
              }
  
              if (fop == null) {
                  fop = new Fop(Constants.RENDER_AWT, foUserAgent);
              }
  
              pagePanels = null;
  
              int savedCurrentPage = currentPage;
              currentPage = 0;
  
              gridPanel.removeAll();
              switch(displayMode) {
                  case CONT_FACING:
                      // This page intentionally left blank
                      // Makes 0th/1st page on rhs
                      gridPanel.add(new JLabel(""));
                  case CONTINUOUS:
                      currentPage = 0;
                      firstPage = 0;
                      pageRange = renderer.getNumberOfPages();
                      break;
                  case SINGLE:
                  default:
                      currentPage = 0;
                      firstPage = 0;
                      pageRange = 1;
                      break;
              }
  
              pagePanels = new ImageProxyPanel[pageRange];
              for (int pg = 0; pg < pageRange; pg++) {
                  pagePanels[pg] = new ImageProxyPanel(renderer, pg + firstPage);
                  pagePanels[pg].setBorder(new EmptyBorder(
                          BORDER_SPACING, BORDER_SPACING, BORDER_SPACING, BORDER_SPACING));
                  gridPanel.add(pagePanels[pg]);
              }
  
              renderer.clearViewportList();
  
              try {
                  foUserAgent.getInputHandler().render(fop);
                  setPage(savedCurrentPage);
              } catch (FOPException e) {
                  e.printStackTrace();
                  // FIXME Should show exception in gui - was reportException(e);
              }
          }
      }
  
      /**
       * Scales page image
       * @param scale [0;1]
       */
      public void setScaleFactor(double scale) {
          renderer.setScaleFactor(scale);
          reload();
      }
  
      /**
       * Returns the scale factor required in order to fit either the current
       * page within the current window or to fit two adjacent pages within
       * the display if the displaymode is continuous.
       */
      public double getScaleToFitWindow() throws FOPException {
          Dimension extents = previewArea.getViewport().getExtentSize();
          return getScaleToFit(extents.getWidth() - 2 * BORDER_SPACING,
                      extents.getHeight() - 2 * BORDER_SPACING);
      }
  
      /**
       * As getScaleToFitWindow, but ignoring the Y axis.
       */
      public double getScaleToFitWidth() throws FOPException {
          Dimension extents = previewArea.getViewport().getExtentSize();
          return getScaleToFit(extents.getWidth() - 2 * BORDER_SPACING, Double.MAX_VALUE);
      }
  
      /**
       * Returns the scale factor required in order to fit either the current page or
       * two adjacent pages within a window of the given height and width, depending
       * on the display mode. In order to ignore either dimension,
       * just specify it as Double.MAX_VALUE.
       */
      public double getScaleToFit(double viewWidth, double viewHeight) throws FOPException {
          PageViewport pageViewport = renderer.getPageViewport(currentPage);
          Rectangle2D pageSize = pageViewport.getViewArea();
          double widthScale = viewWidth / (pageSize.getWidth() / 1000f);
          double heightScale = viewHeight / (pageSize.getHeight() / 1000f);
          return Math.min(displayMode == CONT_FACING ? widthScale / 2 : widthScale, heightScale);
      }
  
      /** Starts rendering process and shows the current page. */
      public synchronized void showPage() {
          ShowPageImage viewer = new ShowPageImage();
  
          if (SwingUtilities.isEventDispatchThread()) {
              viewer.run();
          } else {
              SwingUtilities.invokeLater(viewer);
          }
      }
  
      /** This class is used to render the page image in a thread safe way. */
      private class ShowPageImage implements Runnable {
  
          /**
           * The run method that does the actual rendering of the viewed page
           */
          public void run() {
              for (int pg = firstPage; pg < firstPage + pageRange; pg++) {
                  pagePanels[pg - firstPage].setPage(pg);
              }
              revalidate();
          }
      }
  }
  
  
  
  1.1                  xml-fop/src/java/org/apache/fop/render/awt/viewer/ImageProxyPanel.java
  
  Index: ImageProxyPanel.java
  ===================================================================
  /*
   * Copyright 1999-2005 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  /* $Id: ImageProxyPanel.java,v 1.1 2005/06/15 12:24:01 jeremias Exp $ */
  
  package org.apache.fop.render.awt.viewer;
  
  import java.awt.Dimension;
  import java.awt.Graphics;
  import java.awt.Insets;
  import java.awt.image.BufferedImage;
  import java.lang.ref.Reference;
  import java.lang.ref.SoftReference;
  import javax.swing.JPanel;
  
  import org.apache.fop.apps.FOPException;
  import org.apache.fop.render.awt.AWTRenderer;
  
  /**
   * Panel used to display a single page of a document.
   * This is basically a lazy-load display panel which
   * gets the size of the image for layout purposes but
   * doesn't get the actual image data until needed.
   * The image data is then accessed via a soft reference,
   * so it will be garbage collected when moving through
   * large documents.
   */
  public class ImageProxyPanel extends JPanel {
  
      /** The reference to the BufferedImage storing the page data */
      private Reference imageRef;
  
      /** The maximum and preferred size of the panel */
      private Dimension size;
  
      /** The renderer. Shared with PreviewPanel and PreviewDialog. */
      private AWTRenderer renderer;
  
      /** The page to be rendered. */
      private int page;
  
      /**
       * Panel constructor. Doesn't allocate anything until needed.
       */
      public ImageProxyPanel(AWTRenderer renderer, int page) {
          this.renderer = renderer;
          this.page = page;
      }
  
      /**
       * Returns the size of the page plus the border.
       */
      public Dimension getMinimumSize() {
          return getPreferredSize();
      }
  
      /**
       * Returns the size of the page plus the border.
       */
      public Dimension getPreferredSize() {
          if (size == null) {
              try {
                  Insets insets = getInsets();
                  size = renderer.getPageImageSize(page);
                  size = new Dimension(size.width + insets.left + insets.right,
                                                           size.height + insets.top + insets.bottom);
              } catch (FOPException fopEx) {
                  // Arbitary size. Doesn't really matter what's returned here.
                  return new Dimension(10, 10);
              }
          }
          return size;
      }
  
      /**
       * Sets the number of the page to be displayed and refreshes the display.
       */
      public void setPage(int pg) {
          if (page != pg) {
              page = pg;
              imageRef = null;
              repaint();
          }
      }
  
      /**
       * Gets the image data and paints it on screen. Will make
       * calls to getPageImage as required.
       * @see org.apache.fop.render.java2d.Java2DRenderer#getPageImage()
       */
      public synchronized void paintComponent(Graphics graphics) {
          try {
              if (isOpaque()) { //paint background
                  graphics.setColor(getBackground());
                  graphics.fillRect(0, 0, getWidth(), getHeight());
              }
  
              super.paintComponent(graphics);
  
              BufferedImage image = null;
              if (imageRef == null || imageRef.get() == null) {
                  image = renderer.getPageImage(page);
                  imageRef = new SoftReference(image);
              } else {
                  image = (BufferedImage)imageRef.get();
              }
  
              int x = (getWidth() - image.getWidth()) / 2;
              int y = (getHeight() - image.getHeight()) / 2;
              
              graphics.drawImage(image, x, y, image.getWidth(), image.getHeight(), null);
          } catch (FOPException fopEx) {
              fopEx.printStackTrace();
          }
      }
  }
  
  
  
  1.2       +33 -12    xml-fop/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_de.properties
  
  Index: Viewer_de.properties
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_de.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Viewer_de.properties	21 Sep 2003 20:56:23 -0000	1.1
  +++ Viewer_de.properties	15 Jun 2005 12:24:01 -0000	1.2
  @@ -1,10 +1,18 @@
  -#############################################################################
  -# Copyright (C) The Apache Software Foundation. All rights reserved.        #
  -# ------------------------------------------------------------------------- #
  -# This software is published under the terms of the Apache Software License #
  -# version 1.1, a copy of which has been included with this distribution in  #
  -# the LICENSE file.                                                         #
  -#############################################################################
  +#
  +# Copyright 1999-2005 The Apache Software Foundation.
  +# 
  +# Licensed under the Apache License, Version 2.0 (the "License");
  +# you may not use this file except in compliance with the License.
  +# You may obtain a copy of the License at
  +# 
  +#      http://www.apache.org/licenses/LICENSE-2.0
  +# 
  +# Unless required by applicable law or agreed to in writing, software
  +# distributed under the License is distributed on an "AS IS" BASIS,
  +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  +# See the License for the specific language governing permissions and
  +# limitations under the License.
  +#
   #
   # AWT viewer's GUI resources. German bundle.
   #
  @@ -15,18 +23,31 @@
   Menu.Prev.page=Vorherige Seite
   Menu.Next.page=N\u00e4chste Seite
   Menu.Last.page=Letzte Seite
  +Menu.Go.to.Page=Gehe zur Seite...
   Menu.Help=Hilfe
   Menu.Default.zoom=Standardzoom
  -Menu.About=\u00dcber
  -Menu.Print=Drucken
  -Menu.Go.to.Page=Gehe zur Seite
  +Menu.About=\u00dcber Apache FOP...
  +Menu.Print=Drucken...
  +Menu.Zoom=Zoom
  +Menu.Reload=Neu laden
  +Menu.Fit.Window=In Fenster einpassen
  +Menu.Fit.Width=Auf Seitenbreite einpassen
  +Menu.Single=Einzelseiten
  +Menu.Continuous=Fortlaufende Seiten
  +Menu.Facing=Seiten nebeneinander und fortlaufend
   
   Title.Preview=Vorschau
   
   Status.Show=Anzeigen
   Status.Page=Seite
   Status.of=von
  -Status.Build.FO.tree=Baue FO-Baum
  +Status.Build.FO.tree=Baue FO-Baum...
  +
  +Exception.Occured=Es wurde ein Fehler festgestellt
  +Exception.Error=Fehler
   
  -Button.Cancel=Abbrechen
   Label.Page.number=Seitennummer
  +Button.Ok=OK
  +Button.Cancel=Abbrechen
  +
  +About.Title=\u00dber Apache FOP
  
  
  
  1.2       +40 -9     xml-fop/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_fr.properties
  
  Index: Viewer_fr.properties
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_fr.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Viewer_fr.properties	21 Sep 2003 20:56:23 -0000	1.1
  +++ Viewer_fr.properties	15 Jun 2005 12:24:01 -0000	1.2
  @@ -1,21 +1,52 @@
  -#############################################################################
  -# Copyright (C) The Apache Software Foundation. All rights reserved.        #
  -# ------------------------------------------------------------------------- #
  -# This software is published under the terms of the Apache Software License #
  -# version 1.1, a copy of which has been included with this distribution in  #
  -# the LICENSE file.                                                         #
  -#############################################################################
  +#
  +# Copyright 1999-2005 The Apache Software Foundation.
  +# 
  +# Licensed under the Apache License, Version 2.0 (the "License");
  +# you may not use this file except in compliance with the License.
  +# You may obtain a copy of the License at
  +# 
  +#      http://www.apache.org/licenses/LICENSE-2.0
  +# 
  +# Unless required by applicable law or agreed to in writing, software
  +# distributed under the License is distributed on an "AS IS" BASIS,
  +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  +# See the License for the specific language governing permissions and
  +# limitations under the License.
  +#
   #
   # AWT viewer's GUI resources. French bundle.
   #
   Menu.File=Fichier
  -Menu.Print=Imprimer
   Menu.Exit=Quitter
   Menu.View=Affichage
   Menu.First.page=Premi\u00e8re page
   Menu.Prev.page=Page pr\u00e9c\u00e9dente
   Menu.Next.page=Page suivante
   Menu.Last.page=Derni\u00e8re page
  +Menu.Go.to.Page=Aller à la page...
   Menu.Help=Aide
   Menu.Default.zoom=Zoom par d\u00e9faut
  -Menu.About=A propos
  +Menu.About=\u00c0 propos Apache FOP
  +Menu.Print=Imprimer...
  +Menu.Reload=Redémarrer
  +Menu.Fit.Window=Ajuster dans la fen\u00eatre
  +Menu.Fit.Width=Ajuster sur la largeur de la page
  +Menu.Single=Pages s\u00e9par\u00e9es
  +Menu.Continuous=Pages continues
  +Menu.Facing=Pages juxtapos\u00e9es
  +
  +Title.Preview=Pr\u00e9sentation
  +
  +Status.Show=Pr\u00e9senter
  +Status.Page=Page
  +Status.of=de
  +Status.Build.FO.tree=Construisant l'arbre FO...
  +
  +Exception.Occured=Une erreur a \u00e9t\u00e9 constatée
  +Exception.Error=Erreur
  +
  +Label.Page.number=Num\u00e9ro de page
  +Button.Ok=OK
  +Button.Cancel=Annuler
  +
  +About.Title=\u00c0 propos Apache FOP
  
  
  
  1.2       +25 -11    xml-fop/src/java/org/apache/fop/render/awt/viewer/resources/Viewer.properties
  
  Index: Viewer.properties
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/awt/viewer/resources/Viewer.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Viewer.properties	21 Sep 2003 20:56:23 -0000	1.1
  +++ Viewer.properties	15 Jun 2005 12:24:01 -0000	1.2
  @@ -1,10 +1,18 @@
  -#############################################################################
  -# Copyright (C) The Apache Software Foundation. All rights reserved.        #
  -# ------------------------------------------------------------------------- #
  -# This software is published under the terms of the Apache Software License #
  -# version 1.1, a copy of which has been included with this distribution in  #
  -# the LICENSE file.                                                         #
  -#############################################################################
  +#
  +# Copyright 1999-2005 The Apache Software Foundation.
  +# 
  +# Licensed under the Apache License, Version 2.0 (the "License");
  +# you may not use this file except in compliance with the License.
  +# You may obtain a copy of the License at
  +# 
  +#      http://www.apache.org/licenses/LICENSE-2.0
  +# 
  +# Unless required by applicable law or agreed to in writing, software
  +# distributed under the License is distributed on an "AS IS" BASIS,
  +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  +# See the License for the specific language governing permissions and
  +# limitations under the License.
  +#
   #
   # AWT viewer's GUI resources. Default bundle.
   #
  @@ -18,10 +26,16 @@
   Menu.Go.to.Page=Go to Page
   Menu.Help=Help
   Menu.Default.zoom=Default zoom
  -Menu.About=About
  -Menu.Print=Print
  +Menu.About=About Apache FOP...
  +Menu.Print=Print...
   Menu.Zoom=Zoom
   Menu.Reload=Reload
  +Menu.Fit.Window=Fit in window
  +Menu.Fit.Width=Fit Width
  +Menu.Single=Single Page
  +Menu.Continuous=Continuous
  +Menu.Facing=Continuous Facing
  +Menu.Debug=Debug
   
   Title.Preview=Preview
   
  @@ -37,8 +51,8 @@
   Button.Ok=Ok
   Button.Cancel=Cancel
   
  -About.Product=FOP AWT Viewer
  +About.Product=Apache FOP - AWT Viewer
   About.Version=Version:
   About.Copyright=See http://xml.apache.org/fop
  -About.Title=About
  +About.Title=About Apache FOP
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org


Mime
View raw message