aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/render/awt
diff options
context:
space:
mode:
authorGlen Mazza <gmazza@apache.org>2003-09-21 20:56:24 +0000
committerGlen Mazza <gmazza@apache.org>2003-09-21 20:56:24 +0000
commitce37837aaea712ad41ba4caba73e9e8c181e3e97 (patch)
tree9c9c3923b13ce853557ad56d6f553032373710ce /src/java/org/apache/fop/render/awt
parente7bb77d5f945fa50f9600cce9e567de4dc2bf0c1 (diff)
downloadxmlgraphics-fop-ce37837aaea712ad41ba4caba73e9e8c181e3e97.tar.gz
xmlgraphics-fop-ce37837aaea712ad41ba4caba73e9e8c181e3e97.zip
1.) Moved AWT Viewer classes from org.fop.viewer to org.fop.render.awt.viewer
2.) Updated AWT and PDF renderers to draw region borders more accurately. 3.) Rounding errors for determining region sizes in AWT Renderer fixed. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196934 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/render/awt')
-rw-r--r--src/java/org/apache/fop/render/awt/AWTRenderer.java70
-rw-r--r--src/java/org/apache/fop/render/awt/viewer/Command.java114
-rw-r--r--src/java/org/apache/fop/render/awt/viewer/GoToPageDialog.java160
-rw-r--r--src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java603
-rw-r--r--src/java/org/apache/fop/render/awt/viewer/PreviewDialogAboutBox.java150
-rw-r--r--src/java/org/apache/fop/render/awt/viewer/Translator.java91
-rw-r--r--src/java/org/apache/fop/render/awt/viewer/images/Print.gifbin0 -> 992 bytes
-rw-r--r--src/java/org/apache/fop/render/awt/viewer/images/firstpg.gifbin0 -> 885 bytes
-rw-r--r--src/java/org/apache/fop/render/awt/viewer/images/fop.gifbin0 -> 2452 bytes
-rw-r--r--src/java/org/apache/fop/render/awt/viewer/images/lastpg.gifbin0 -> 889 bytes
-rw-r--r--src/java/org/apache/fop/render/awt/viewer/images/nextpg.gifbin0 -> 869 bytes
-rw-r--r--src/java/org/apache/fop/render/awt/viewer/images/prevpg.gifbin0 -> 867 bytes
-rw-r--r--src/java/org/apache/fop/render/awt/viewer/images/reload.gifbin0 -> 889 bytes
-rw-r--r--src/java/org/apache/fop/render/awt/viewer/resources/Viewer.properties44
-rw-r--r--src/java/org/apache/fop/render/awt/viewer/resources/Viewer_cs.properties34
-rw-r--r--src/java/org/apache/fop/render/awt/viewer/resources/Viewer_de.properties32
-rw-r--r--src/java/org/apache/fop/render/awt/viewer/resources/Viewer_fi.properties23
-rw-r--r--src/java/org/apache/fop/render/awt/viewer/resources/Viewer_fr.properties21
-rw-r--r--src/java/org/apache/fop/render/awt/viewer/resources/Viewer_it.properties21
-rw-r--r--src/java/org/apache/fop/render/awt/viewer/resources/Viewer_ja.properties28
-rw-r--r--src/java/org/apache/fop/render/awt/viewer/resources/Viewer_pl.properties24
-rw-r--r--src/java/org/apache/fop/render/awt/viewer/resources/Viewer_ru.properties43
-rw-r--r--src/java/org/apache/fop/render/awt/viewer/resources/Viewer_tr.properties33
23 files changed, 1453 insertions, 38 deletions
diff --git a/src/java/org/apache/fop/render/awt/AWTRenderer.java b/src/java/org/apache/fop/render/awt/AWTRenderer.java
index 7c3ecd116..68b52695f 100644
--- a/src/java/org/apache/fop/render/awt/AWTRenderer.java
+++ b/src/java/org/apache/fop/render/awt/AWTRenderer.java
@@ -91,8 +91,8 @@ import org.apache.fop.image.FopImage;
import org.apache.fop.image.ImageFactory;
import org.apache.fop.render.AbstractRenderer;
import org.apache.fop.traits.BorderProps;
-import org.apache.fop.viewer.PreviewDialog;
-import org.apache.fop.viewer.Translator;
+import org.apache.fop.render.awt.viewer.PreviewDialog;
+import org.apache.fop.render.awt.viewer.Translator;
/**
* This is FOP's AWT renderer.
@@ -266,8 +266,8 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable
Page page = (Page) pageList.get(pageNum);
Rectangle2D bounds = pageViewport.getViewArea();
- int pageWidth = (int)((float) bounds.getWidth() / 1000f + .5);
- int pageHeight = (int)((float) bounds.getHeight() / 1000f + .5);
+ int pageWidth = (int) Math.round(bounds.getWidth() / 1000f );
+ int pageHeight = (int) Math.round(bounds.getHeight() / 1000f );
/*
System.out.println("(Page) X, Y, Width, Height: " + bounds.getX()
+ " " + bounds.getY()
@@ -315,18 +315,25 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable
currentFontSize = 0;
Rectangle2D viewArea = region.getViewArea();
- int startX = (int)(((float) viewArea.getX() / 1000f + .5)
+ int startX = (int) Math.round((viewArea.getX() / 1000f)
* (scaleFactor / 100f));
- int startY = (int)(((float) viewArea.getY() / 1000f + .5)
- * (scaleFactor / 100f));
- int width = (int)(((float) viewArea.getWidth() / 1000f + .5)
- * (scaleFactor / 100f));
- int height = (int)(((float) viewArea.getHeight() / 1000f + .5)
+ int startY = (int) Math.round((viewArea.getY() / 1000f)
* (scaleFactor / 100f));
+ // for rounding to work correctly, need to take into account
+ // fractional portion of X and Y.
+ int width = (int) Math.round(((viewArea.getX() + viewArea.getWidth()) / 1000f)
+ * (scaleFactor / 100f)) - startX;
+ int height = (int) Math.round(((viewArea.getY() + viewArea.getHeight()) / 1000f)
+ * (scaleFactor / 100f)) - startY;
if (region.getRegion() != null) {
System.out.print("\nRegion type = " + region.getRegion().getRegionClass());
}
+/* System.out.println("\nView X, Width, Y, Height: " + viewArea.getX()
+ + " " + viewArea.getWidth()
+ + " " + viewArea.getY()
+ + " " + viewArea.getHeight()
+ ); */
System.out.println(" X, Width, Y, Height: " + startX
+ " " + width
+ " " + startY
@@ -382,46 +389,33 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable
BorderProps bps = (BorderProps) block.getTrait(Trait.BORDER_BEFORE);
if (bps != null) {
- int borderWidth = (int) ((bps.width / 1000f) * (scaleFactor / 100f));
- System.out.println("Before (color/width) " + bps.color.getAWTColor().toString() + " " + bps.width);
+ int borderWidth = (int) Math.round((bps.width / 1000f) * (scaleFactor / 100f));
graphics.setColor(bps.color.getAWTColor());
- // drawLine(x1, y1, x2, y2);
- System.out.println("Draw from (" + startx + "," + (starty + borderWidth/2) +
- ") to (" + (startx+width) + "," + (starty + borderWidth/ 2) + ")");
- graphics.drawLine(startx, starty + borderWidth / 2, startx + width,
- starty + borderWidth / 2);
+// System.out.println("Border at (" + startx + "," + (starty + height - borderWidth) +
+// ") width, height: (" + (width) + "," + (borderWidth) + ")");
+ graphics.fillRect(startx, starty, width, borderWidth);
}
- bps = (BorderProps) block.getTrait(Trait.BORDER_START);
+ bps = (BorderProps) block.getTrait(Trait.BORDER_AFTER);
if (bps != null) {
- int borderWidth = (int) ((bps.width / 1000f) * (scaleFactor / 100f));
- System.out.println("Start (color/width) " + bps.color.getAWTColor().toString() + " " + bps.width);
+ int borderWidth = (int) Math.round((bps.width / 1000f) * (scaleFactor / 100f));
+ int sy = starty + height;
graphics.setColor(bps.color.getAWTColor());
- System.out.println("Draw from (" + (startx + borderWidth / 2) + "," + starty +
- ") to (" + (startx + borderWidth / 2) + "," + (starty + height) + ")");
- graphics.drawLine(startx + borderWidth / 2, starty, startx + borderWidth / 2,
- starty + height);
+ graphics.fillRect(startx, starty + height - borderWidth,
+ width, borderWidth);
}
- bps = (BorderProps) block.getTrait(Trait.BORDER_AFTER);
+ bps = (BorderProps) block.getTrait(Trait.BORDER_START);
if (bps != null) {
- int borderWidth = (int) ((bps.width / 1000f) * (scaleFactor / 100f));
- System.out.println("After (color/width) " + bps.color.getAWTColor().toString() + " " + bps.width);
- int sy = starty + height;
+ int borderWidth = (int) Math.round((bps.width / 1000f) * (scaleFactor / 100f));
graphics.setColor(bps.color.getAWTColor());
- System.out.println("Draw from (" + startx + "," + (sy - borderWidth / 2) +
- ") to (" + (startx+width) + "," + (sy - borderWidth / 2) + ")");
- graphics.drawLine(startx, sy - borderWidth / 2, startx + width,
- sy - borderWidth / 2);
+ graphics.fillRect(startx, starty, borderWidth, height);
}
bps = (BorderProps) block.getTrait(Trait.BORDER_END);
if (bps != null) {
- int borderWidth = (int) ((bps.width / 1000f) * (scaleFactor / 100f));
- System.out.println("End (color/width) " + bps.color.getAWTColor().toString() + " " + bps.width);
+ int borderWidth = (int) Math.round((bps.width / 1000f) * (scaleFactor / 100f));
int sx = startx + width;
graphics.setColor(bps.color.getAWTColor());
- System.out.println("Draw from (" + (sx - borderWidth / 2) + "," + starty +
- ") to (" + (sx - borderWidth / 2) + "," + (starty + height) + ")");
- graphics.drawLine(sx - borderWidth / 2, starty, sx - borderWidth / 2,
- starty + height);
+ graphics.fillRect(startx + width - borderWidth, starty,
+ borderWidth, height);
}
}
}
diff --git a/src/java/org/apache/fop/render/awt/viewer/Command.java b/src/java/org/apache/fop/render/awt/viewer/Command.java
new file mode 100644
index 000000000..efebd77c4
--- /dev/null
+++ b/src/java/org/apache/fop/render/awt/viewer/Command.java
@@ -0,0 +1,114 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+package org.apache.fop.render.awt.viewer;
+
+//Java
+import java.awt.event.ActionEvent;
+import javax.swing.AbstractAction;
+import javax.swing.ImageIcon;
+import java.net.URL;
+
+/**
+ * This class represents UI-commands, which can be used as menu or toolbar
+ * items<br>.
+ * When the <code>Command</code> object receives action event, that object's
+ * <code>doit</code> method is invoked. <code>doit</code> method by default
+ * does nothing and the class customer have to override it to implement
+ * any action handling logic.
+ * Originally contributed by:
+ * Juergen Verwohlt: Juergen.Verwohlt@jcatalog.com,
+ * Rainer Steinkuhle: Rainer.Steinkuhle@jcatalog.com,
+ * Stanislav Gorkhover: Stanislav.Gorkhover@jcatalog.com
+ */
+public class Command extends AbstractAction {
+
+ private static final String IMAGE_DIR = "images/";
+
+ /**
+ * 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
+ */
+ public Command(String name) {
+ super(name);
+ putValue(SHORT_DESCRIPTION, name);
+ }
+
+ /**
+ * Creates <code>Command</code> object with a given name, the same
+ * tooltip text and icon image if appropriate image file is found.
+ * @param name name of the command
+ * @param iconName name of the icon
+ */
+ public Command(String name, String iconName) {
+ super(name);
+ putValue(SHORT_DESCRIPTION, name);
+ URL url = getClass().getResource(IMAGE_DIR + iconName + ".gif");
+ if (url != null) {
+ putValue(SMALL_ICON, new ImageIcon(url));
+ }
+ }
+
+ /**
+ * @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
+ */
+ public void actionPerformed(ActionEvent e) {
+ doit();
+ }
+
+ /**
+ * Action handler, have to be overrided by subclasses.
+ */
+ public void doit() {
+ //Do nothing
+ }
+}
+
diff --git a/src/java/org/apache/fop/render/awt/viewer/GoToPageDialog.java b/src/java/org/apache/fop/render/awt/viewer/GoToPageDialog.java
new file mode 100644
index 000000000..69280d289
--- /dev/null
+++ b/src/java/org/apache/fop/render/awt/viewer/GoToPageDialog.java
@@ -0,0 +1,160 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+package org.apache.fop.render.awt.viewer;
+
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+/**
+ * Go to Page Dialog.
+ * Originally contributed by:
+ * Juergen Verwohlt: Juergen.Verwohlt@jCatalog.com,
+ * Rainer Steinkuhle: Rainer.Steinkuhle@jCatalog.com,
+ * Stanislav Gorkhover: Stanislav.Gorkhover@jCatalog.com
+ */
+public class GoToPageDialog extends JDialog {
+
+ private JTextField pgNbField;
+ private int pageNumber = -1;
+
+ /**
+ * Creates modal dialog with a given title, attached to a given frame.
+ * @param frame Frame to attach to
+ * @param title dialog title
+ * @param translator translator for localization
+ */
+ public GoToPageDialog(Frame frame, String title, Translator translator) {
+ super(frame, title, true);
+ jbInit(translator);
+ pack();
+ }
+
+ private void jbInit(Translator translator) {
+ JPanel panel1 = new JPanel();
+ GridBagLayout gridBagLayout1 = new GridBagLayout();
+ JLabel pgNbLabel = new JLabel();
+ pgNbField = new JTextField();
+ JButton okButton = new JButton();
+ JButton cancelButton = new JButton();
+ panel1.setLayout(gridBagLayout1);
+ pgNbLabel.setText(translator.getString("Label.Page.number"));
+ okButton.setText(translator.getString("Button.Ok"));
+ okButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ okButtonActionPerformed(e);
+ }
+ });
+ cancelButton.setText(translator.getString("Button.Cancel"));
+ cancelButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ cancelButtonActionPerformed(e);
+ }
+ });
+ panel1.setMinimumSize(new Dimension(250, 78));
+ getContentPane().add(panel1);
+ panel1.add(pgNbLabel,
+ new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
+ GridBagConstraints.WEST,
+ GridBagConstraints.NONE,
+ new Insets(10, 10, 10, 5), 0, 0));
+ panel1.add(pgNbField,
+ new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0,
+ GridBagConstraints.WEST,
+ GridBagConstraints.BOTH,
+ new Insets(10, 5, 10, 10), 0, 0));
+ panel1.add(okButton,
+ new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
+ GridBagConstraints.EAST,
+ GridBagConstraints.NONE,
+ new Insets(0, 0, 10, 5), 0, 0));
+ panel1.add(cancelButton,
+ new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
+ GridBagConstraints.WEST,
+ GridBagConstraints.NONE,
+ new Insets(0, 10, 10, 10), 0, 0));
+ }
+
+ private void okButtonActionPerformed(ActionEvent e) {
+ try {
+ pageNumber = Integer.parseInt(pgNbField.getText());
+ dispose();
+ } catch (NumberFormatException nfe) {
+ pgNbField.setText("???");
+ }
+
+ }
+
+ private void cancelButtonActionPerformed(ActionEvent e) {
+ pageNumber = -1;
+ dispose();
+ }
+
+ /**
+ * Returns page number, entered by user.
+ * @return the page number
+ */
+ public int getPageNumber() {
+ return pageNumber;
+ }
+}
+
diff --git a/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java b/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java
new file mode 100644
index 000000000..b0986237b
--- /dev/null
+++ b/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java
@@ -0,0 +1,603 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+package org.apache.fop.render.awt.viewer;
+
+//Java
+import javax.swing.BorderFactory;
+import javax.swing.ImageIcon;
+import javax.swing.JComboBox;
+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.JToolBar;
+import javax.swing.SwingUtilities;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.Point;
+import java.awt.Toolkit;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.image.BufferedImage;
+import java.awt.print.PrinterJob;
+import java.awt.print.PrinterException;
+
+//FOP
+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;
+
+/**
+ * AWT Viewer main window.
+ * Originally contributed by:
+ * Juergen Verwohlt: Juergen.Verwohlt@jCatalog.com,
+ * Rainer Steinkuhle: Rainer.Steinkuhle@jCatalog.com,
+ * Stanislav Gorkhover: Stanislav.Gorkhover@jCatalog.com
+ */
+public class PreviewDialog extends JFrame {
+
+ /** The Translator for localization */
+ protected Translator translator;
+ /** The AWT renderer */
+ protected AWTRenderer renderer;
+ /** 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;
+ private Reloader reloader;
+ private JComboBox scale;
+ private JLabel processStatus;
+ private JLabel pageLabel;
+ private JLabel infoStatus;
+
+ /**
+ * Creates a new PreviewDialog that uses the given renderer.
+ * @param aRenderer the to use renderer
+ */
+ public PreviewDialog(AWTRenderer aRenderer, InputHandler handler) {
+ renderer = aRenderer;
+ inputHandler = handler;
+ translator = renderer.getTranslator();
+
+ //Commands aka Actions
+ Command printAction = new Command(translator.getString("Menu.Print"), "Print") {
+ public void doit() {
+ print();
+ }
+ };
+ Command firstPageAction = new Command(translator.getString("Menu.First.page"),
+ "firstpg") {
+ public void doit() {
+ goToFirstPage();
+ }
+ };
+ Command previousPageAction = new Command(translator.getString("Menu.Prev.page"),
+ "prevpg") {
+ public void doit() {
+ goToPreviousPage();
+ }
+ };
+ Command nextPageAction = new Command(translator.getString("Menu.Next.page"), "nextpg") {
+ public void doit() {
+ goToNextPage();
+ }
+
+ };
+ Command lastPageAction = new Command(translator.getString("Menu.Last.page"), "lastpg") {
+ public void doit() {
+ goToLastPage();
+ }
+ };
+ Command reloadAction = new Command(translator.getString("Menu.Reload"), "reload") {
+ public void doit() {
+ reload();
+ }
+ };
+
+ setTitle("FOP: AWT-" + translator.getString("Title.Preview"));
+ setDefaultCloseOperation(DISPOSE_ON_CLOSE);
+
+ //Sets size to be 61%x90% of the screen size
+ Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
+ //Rather frivolous size - fits A4 page width in 1024x768 screen on my desktop
+ setSize(screen.width * 61 / 100, screen.height * 9 / 10);
+
+ //Page view stuff
+ pageLabel = new JLabel();
+ JScrollPane previewArea = new JScrollPane(pageLabel);
+ previewArea.getViewport().setBackground(Color.gray);
+ previewArea.setMinimumSize(new Dimension(50, 50));
+ getContentPane().add(previewArea, BorderLayout.CENTER);
+
+ //Scaling combobox
+ scale = new JComboBox();
+ scale.addItem("25%");
+ scale.addItem("50%");
+ scale.addItem("75%");
+ scale.addItem("100%");
+ scale.addItem("150%");
+ scale.addItem("200%");
+ scale.setMaximumSize(new Dimension(80, 24));
+ scale.setPreferredSize(new Dimension(80, 24));
+ scale.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ scaleActionPerformed(e);
+ }
+ });
+ scale.setSelectedItem("100%");
+ renderer.setScaleFactor(100.0);
+
+ //Menu
+ setJMenuBar(setupMenu());
+
+ //Toolbar
+ JToolBar toolBar = new JToolBar();
+ toolBar.add(printAction);
+ toolBar.add(reloadAction);
+ toolBar.addSeparator();
+ toolBar.add(firstPageAction);
+ toolBar.add(previousPageAction);
+ toolBar.add(nextPageAction);
+ toolBar.add(lastPageAction);
+ toolBar.addSeparator();
+ toolBar.add(new JLabel(translator.getString("Menu.Zoom")));
+ toolBar.addSeparator();
+ toolBar.add(scale);
+ getContentPane().add(toolBar, BorderLayout.NORTH);
+ //Status bar
+ JPanel statusBar = new JPanel();
+ processStatus = new JLabel();
+ processStatus.setBorder(BorderFactory.createCompoundBorder(
+ BorderFactory.createEtchedBorder(),
+ BorderFactory.createEmptyBorder(0, 3, 0, 0)));
+ infoStatus = new JLabel();
+ infoStatus.setBorder(BorderFactory.createCompoundBorder(
+ BorderFactory.createEtchedBorder(),
+ BorderFactory.createEmptyBorder(0, 3, 0, 0)));
+
+ statusBar.setLayout(new GridBagLayout());
+
+ processStatus.setPreferredSize(new Dimension(200, 21));
+ processStatus.setMinimumSize(new Dimension(200, 21));
+
+ infoStatus.setPreferredSize(new Dimension(100, 21));
+ infoStatus.setMinimumSize(new Dimension(100, 21));
+ statusBar.add(processStatus,
+ new GridBagConstraints(0, 0, 1, 0, 2.0, 0.0,
+ GridBagConstraints.CENTER,
+ GridBagConstraints.HORIZONTAL,
+ new Insets(0, 0, 0, 3), 0, 0));
+ statusBar.add(infoStatus,
+ new GridBagConstraints(1, 0, 1, 0, 1.0, 0.0,
+ GridBagConstraints.CENTER,
+ GridBagConstraints.HORIZONTAL,
+ new Insets(0, 0, 0, 0), 0, 0));
+ getContentPane().add(statusBar, BorderLayout.SOUTH);
+ }
+
+ /**
+ * Creates a new menubar to be shown in this window.
+ * @return the newly created menubar
+ */
+ private JMenuBar setupMenu() {
+ JMenuBar menuBar = new JMenuBar();
+ JMenu menu = new JMenu(translator.getString("Menu.File"));
+
+ //Adds mostly the same actions, but without icons
+ menu.add(new Command(translator.getString("Menu.Print")) {
+ public void doit() {
+ print();
+ }
+ });
+ // 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() {
+ dispose();
+ }
+ });
+ menuBar.add(menu);
+ menu = new JMenu(translator.getString("Menu.View"));
+ menu.add(new Command(translator.getString("Menu.First.page")) {
+ public void doit() {
+ goToFirstPage();
+ }
+ });
+ menu.add(new Command(translator.getString("Menu.Prev.page")) {
+ public void doit() {
+ goToPreviousPage();
+ }
+ });
+ menu.add(new Command(translator.getString("Menu.Next.page")) {
+ public void doit() {
+ goToNextPage();
+ }
+ });
+ menu.add(new Command(translator.getString("Menu.Last.page")) {
+ public void doit() {
+ goToLastPage();
+ }
+ });
+ menu.add(new Command(translator.getString("Menu.Go.to.Page") + " ...") {
+ public void doit() {
+ showGoToPageDialog();
+ }
+ });
+ menu.addSeparator();
+ JMenu subMenu = new JMenu(translator.getString("Menu.Zoom"));
+ subMenu.add(new Command("25%") {
+ public void doit() {
+ setScale(25.0);
+ }
+ });
+ subMenu.add(new Command("50%") {
+ public void doit() {
+ setScale(50.0);
+ }
+ });
+ subMenu.add(new Command("75%") {
+ public void doit() {
+ setScale(75.0);
+ }
+ });
+ subMenu.add(new Command("100%") {
+ public void doit() {
+ setScale(100.0);
+ }
+ });
+ subMenu.add(new Command("150%") {
+ public void doit() {
+ setScale(150.0);
+ }
+ });
+ subMenu.add(new Command("200%") {
+ public void doit() {
+ setScale(200.0);
+ }
+ });
+ menu.add(subMenu);
+ menu.addSeparator();
+ menu.add(new Command(translator.getString("Menu.Default.zoom")) {
+ public void doit() {
+ setScale(100.0);
+ }
+ });
+ menuBar.add(menu);
+ menu = new JMenu(translator.getString("Menu.Help"));
+ menu.add(new Command(translator.getString("Menu.About")) {
+ public void doit() {
+ startHelpAbout();
+ }
+ });
+ menuBar.add(menu);
+ 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);
+ }
+
+ /**
+ * Changes the current visible page
+ * @param number the page number to go to
+ */
+ private void goToPage(int number) {
+ currentPage = number;
+ renderer.setPageNumber(number);
+ showPage();
+ }
+
+ /**
+ * Shows the previous page.
+ */
+ private void goToPreviousPage() {
+ if (currentPage <= 0) {
+ return;
+ }
+ currentPage--;
+ goToPage(currentPage);
+ }
+
+
+ /**
+ * Shows the next page.
+ */
+ private void goToNextPage() {
+ if (currentPage >= pageCount - 1) {
+ return;
+ }
+ currentPage++;
+ goToPage(currentPage);
+ }
+
+ /**
+ * Shows the last page.
+ */
+ private void goToLastPage() {
+ if (currentPage == pageCount - 1) {
+ return;
+ }
+ currentPage = pageCount - 1;
+ goToPage(currentPage);
+ }
+
+ /**
+ * Reloads and reformats document.
+ */
+ private synchronized void reload() {
+ if (reloader == null || !reloader.isAlive()) {
+ reloader = new Reloader();
+ reloader.start();
+ }
+ }
+
+ /**
+ * This class is used to reload document in
+ * a thread safe way.
+ */
+ 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;
+
+ try {
+ setStatus(translator.getString("Status.Build.FO.tree"));
+ driver.render(inputHandler);
+ setStatus(translator.getString("Status.Show"));
+ } catch (FOPException e) {
+ reportException(e);
+ }
+ }
+ }
+
+ /**
+ * Shows "go to page" dialog and then goes to the selected page
+ */
+ private void showGoToPageDialog() {
+ GoToPageDialog d = new GoToPageDialog(this,
+ translator.getString("Menu.Go.to.Page"), translator);
+ d.setLocation((int)getLocation().getX() + 50,
+ (int)getLocation().getY() + 50);
+ d.setVisible(true);
+ currentPage = d.getPageNumber();
+ if (currentPage < 1 || currentPage > pageCount) {
+ return;
+ }
+ currentPage--;
+ goToPage(currentPage);
+ }
+
+ /**
+ * Shows the first page.
+ */
+ private void goToFirstPage() {
+ if (currentPage == 0) {
+ return;
+ }
+ currentPage = 0;
+ goToPage(currentPage);
+ }
+
+ /**
+ * Prints the document
+ */
+ private void print() {
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ pj.setPageable(renderer);
+ if (pj.printDialog()) {
+ try {
+ pj.print();
+ } catch (PrinterException pe) {
+ pe.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * 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);
+ }
+ renderer.setScaleFactor(scaleFactor);
+ if (renderer.getNumberOfPages() != 0) {
+ showPage();
+ }
+ }
+
+ 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
+ */
+ public void setStatus(String message) {
+ SwingUtilities.invokeLater(new ShowStatus(message));
+ }
+
+ /**
+ * This class is used to show status in a thread safe way.
+ */
+ private class ShowStatus implements Runnable {
+ /**
+ * The message to display
+ */
+ private String message;
+ /**
+ * Constructs ShowStatus thread
+ * @param message message to display
+ */
+ public ShowStatus(String message) {
+ this.message = message;
+ }
+
+ public void run() {
+ processStatus.setText(message.toString());
+ }
+ }
+
+ /**
+ * Starts rendering process and shows the current page.
+ */
+ public void showPage() {
+ ShowPageImage viewer = new ShowPageImage();
+ if (SwingUtilities.isEventDispatchThread()) {
+ viewer.run();
+ } else {
+ SwingUtilities.invokeLater(viewer);
+ }
+ }
+
+
+ /**
+ * This class is used to update the page image
+ * in a thread safe way.
+ */
+ private class ShowPageImage implements Runnable {
+ /**
+ * The run method that does the actual updating
+ */
+ public void run() {
+ try {
+ BufferedImage pageImage = null;
+ Graphics graphics = null;
+
+ pageImage = renderer.getPageImage(currentPage);
+ if (pageImage == null)
+ return;
+ graphics = pageImage.getGraphics();
+ graphics.setColor(Color.black);
+ graphics.drawRect(0, 0, pageImage.getWidth() - 1,
+ pageImage.getHeight() - 1);
+
+ pageLabel.setIcon(new ImageIcon(pageImage));
+ pageCount = renderer.getNumberOfPages();
+
+ // Update status bar
+ infoStatus.setText(translator.getString("Status.Page") + " "
+ + (currentPage + 1) + " "
+ + translator.getString("Status.of") + " " + pageCount);
+ } catch (FOPException e) {
+ reportException(e);
+ }
+ }
+ }
+
+ /**
+ * Opens standard Swing error dialog box and reports given exception details.
+ * @param e the Exception
+ */
+ public void reportException(Exception e) {
+ String msg = translator.getString("Exception.Occured");
+ setStatus(msg);
+ JOptionPane.showMessageDialog(
+ getContentPane(),
+ "<html><b>" + msg + ":</b><br>"
+ + e.getClass().getName() + "<br>"
+ + e.getMessage() + "</html>",
+ translator.getString("Exception.Error"),
+ JOptionPane.ERROR_MESSAGE
+ );
+ }
+}
+
diff --git a/src/java/org/apache/fop/render/awt/viewer/PreviewDialogAboutBox.java b/src/java/org/apache/fop/render/awt/viewer/PreviewDialogAboutBox.java
new file mode 100644
index 000000000..4eb75ca1a
--- /dev/null
+++ b/src/java/org/apache/fop/render/awt/viewer/PreviewDialogAboutBox.java
@@ -0,0 +1,150 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+package org.apache.fop.render.awt.viewer;
+
+//Java
+import java.awt.AWTEvent;
+import java.awt.BorderLayout;
+import java.awt.Dialog;
+import java.awt.FlowLayout;
+import java.awt.Frame;
+import java.awt.GridLayout;
+
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.border.EmptyBorder;
+import java.awt.event.ActionListener;
+import java.awt.event.WindowEvent;
+import java.awt.event.ActionEvent;
+
+//FOP
+import org.apache.fop.apps.Version;
+
+/**
+ * AWT Viewer's "About" dialog.
+ * Originally contributed by:
+ * Juergen Verwohlt: Juergen.Verwohlt@jCatalog.com,
+ * Rainer Steinkuhle: Rainer.Steinkuhle@jCatalog.com,
+ * Stanislav Gorkhover: Stanislav.Gorkhover@jCatalog.com
+ */
+public class PreviewDialogAboutBox extends Dialog implements ActionListener {
+ private JButton okButton;
+
+ /**
+ * Creates modal "About" dialog, attached to a given parent frame.
+ * @param parent parent frame
+ * @param translator Translator for localization
+ */
+ public PreviewDialogAboutBox(Frame parent, Translator translator) {
+ super(parent, true);
+ enableEvents(AWTEvent.WINDOW_EVENT_MASK);
+ setTitle(translator.getString("About.Title"));
+ setResizable(false);
+ JPanel panel1 = new JPanel();
+ JPanel panel2 = new JPanel();
+ JPanel insetsPanel1 = new JPanel();
+ JPanel insetsPanel2 = new JPanel();
+ JPanel insetsPanel3 = new JPanel();
+ okButton = new JButton();
+ JLabel imageControl1 = new JLabel();
+ imageControl1.setIcon(new ImageIcon(getClass().getResource("images/fop.gif")));
+ JLabel label1 = new JLabel(translator.getString("About.Product"));
+ JLabel label2 = new JLabel(translator.getString("About.Version")
+ + " " + Version.getVersion());
+ JLabel label3 = new JLabel(translator.getString("About.Copyright"));
+ panel1.setLayout(new BorderLayout());
+ panel2.setLayout(new BorderLayout());
+ insetsPanel1.setLayout(new FlowLayout());
+ insetsPanel2.setLayout(new FlowLayout());
+ insetsPanel2.setBorder(new EmptyBorder(10, 10, 10, 10));
+ insetsPanel3.setLayout(new GridLayout(3, 1));
+ insetsPanel3.setBorder(new EmptyBorder(10, 10, 10, 10));
+ okButton.setText(translator.getString("Button.Ok"));
+ okButton.addActionListener(this);
+ insetsPanel2.add(imageControl1, null);
+ panel2.add(insetsPanel2, BorderLayout.WEST);
+ insetsPanel3.add(label1);
+ insetsPanel3.add(label2);
+ insetsPanel3.add(label3);
+ panel2.add(insetsPanel3, BorderLayout.CENTER);
+ insetsPanel1.add(okButton);
+ panel1.add(insetsPanel1, BorderLayout.SOUTH);
+ panel1.add(panel2, BorderLayout.NORTH);
+ add(panel1);
+ pack();
+ }
+
+ /**
+ * @see java.awt.Window#processWindowEvent(WindowEvent)
+ */
+ protected void processWindowEvent(WindowEvent e) {
+ if (e.getID() == WindowEvent.WINDOW_CLOSING) {
+ cancel();
+ }
+ super.processWindowEvent(e);
+ }
+
+ private void cancel() {
+ dispose();
+ }
+
+ /**
+ * @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
+ */
+ public void actionPerformed(ActionEvent e) {
+ if (e.getSource() == okButton) {
+ cancel();
+ }
+ }
+}
+
diff --git a/src/java/org/apache/fop/render/awt/viewer/Translator.java b/src/java/org/apache/fop/render/awt/viewer/Translator.java
new file mode 100644
index 000000000..251074c42
--- /dev/null
+++ b/src/java/org/apache/fop/render/awt/viewer/Translator.java
@@ -0,0 +1,91 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+package org.apache.fop.render.awt.viewer;
+
+//Java
+import java.util.ResourceBundle;
+import java.util.Locale;
+
+/**
+ * AWT Viewer's localization class, backed up by <code>java.util.ResourceBundle</code>.
+ * Originally contributed by:
+ * Stanislav.Gorkhover@jCatalog.com
+ */
+public class Translator {
+
+ private ResourceBundle bundle;
+ private static String bundleBaseName = "org/apache/fop/render/awt/viewer/resources/Viewer";
+
+ /**
+ * Default constructor, default <code>Locale</code> is used.
+ */
+ public Translator() {
+ this(Locale.getDefault());
+ }
+
+ /**
+ * Constructor for a given <code>Locale</code>.
+ * @param locale Locale to use
+ */
+ public Translator(Locale locale) {
+ bundle = ResourceBundle.getBundle(bundleBaseName, locale);
+ }
+
+ /**
+ * Returns localized <code>String</code> for a given key.
+ * @param key the key
+ * @return the localized String
+ */
+ public String getString(String key) {
+ return bundle.getString(key);
+ }
+}
+
diff --git a/src/java/org/apache/fop/render/awt/viewer/images/Print.gif b/src/java/org/apache/fop/render/awt/viewer/images/Print.gif
new file mode 100644
index 000000000..e715fe67f
--- /dev/null
+++ b/src/java/org/apache/fop/render/awt/viewer/images/Print.gif
Binary files differ
diff --git a/src/java/org/apache/fop/render/awt/viewer/images/firstpg.gif b/src/java/org/apache/fop/render/awt/viewer/images/firstpg.gif
new file mode 100644
index 000000000..1d0315d74
--- /dev/null
+++ b/src/java/org/apache/fop/render/awt/viewer/images/firstpg.gif
Binary files differ
diff --git a/src/java/org/apache/fop/render/awt/viewer/images/fop.gif b/src/java/org/apache/fop/render/awt/viewer/images/fop.gif
new file mode 100644
index 000000000..63aaaae17
--- /dev/null
+++ b/src/java/org/apache/fop/render/awt/viewer/images/fop.gif
Binary files differ
diff --git a/src/java/org/apache/fop/render/awt/viewer/images/lastpg.gif b/src/java/org/apache/fop/render/awt/viewer/images/lastpg.gif
new file mode 100644
index 000000000..082f13a26
--- /dev/null
+++ b/src/java/org/apache/fop/render/awt/viewer/images/lastpg.gif
Binary files differ
diff --git a/src/java/org/apache/fop/render/awt/viewer/images/nextpg.gif b/src/java/org/apache/fop/render/awt/viewer/images/nextpg.gif
new file mode 100644
index 000000000..2e3a2d7b3
--- /dev/null
+++ b/src/java/org/apache/fop/render/awt/viewer/images/nextpg.gif
Binary files differ
diff --git a/src/java/org/apache/fop/render/awt/viewer/images/prevpg.gif b/src/java/org/apache/fop/render/awt/viewer/images/prevpg.gif
new file mode 100644
index 000000000..3c8cce4b6
--- /dev/null
+++ b/src/java/org/apache/fop/render/awt/viewer/images/prevpg.gif
Binary files differ
diff --git a/src/java/org/apache/fop/render/awt/viewer/images/reload.gif b/src/java/org/apache/fop/render/awt/viewer/images/reload.gif
new file mode 100644
index 000000000..405718c1b
--- /dev/null
+++ b/src/java/org/apache/fop/render/awt/viewer/images/reload.gif
Binary files differ
diff --git a/src/java/org/apache/fop/render/awt/viewer/resources/Viewer.properties b/src/java/org/apache/fop/render/awt/viewer/resources/Viewer.properties
new file mode 100644
index 000000000..422dc5c58
--- /dev/null
+++ b/src/java/org/apache/fop/render/awt/viewer/resources/Viewer.properties
@@ -0,0 +1,44 @@
+#############################################################################
+# 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. #
+#############################################################################
+#
+# AWT viewer's GUI resources. Default bundle.
+#
+Menu.File=File
+Menu.Exit=Exit
+Menu.View=View
+Menu.First.page=First page
+Menu.Prev.page=Previous page
+Menu.Next.page=Next page
+Menu.Last.page=Last page
+Menu.Go.to.Page=Go to Page
+Menu.Help=Help
+Menu.Default.zoom=Default zoom
+Menu.About=About
+Menu.Print=Print
+Menu.Zoom=Zoom
+Menu.Reload=Reload
+
+Title.Preview=Preview
+
+Status.Show=Show
+Status.Page=Page
+Status.of=of
+Status.Build.FO.tree=Generating document...
+
+Exception.Occured=An exception has occured
+Exception.Error=Fatal error
+
+Label.Page.number=Page number
+Button.Ok=Ok
+Button.Cancel=Cancel
+
+About.Product=FOP AWT Viewer
+About.Version=Version:
+About.Copyright=See http://xml.apache.org/fop
+About.Title=About
+
diff --git a/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_cs.properties b/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_cs.properties
new file mode 100644
index 000000000..d668e1292
--- /dev/null
+++ b/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_cs.properties
@@ -0,0 +1,34 @@
+#############################################################################
+# 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. #
+#############################################################################
+#
+# AWT viewer's GUI resources. Czech bundle.
+#
+Menu.File=Soubor
+Menu.Print=Tisk
+Menu.Exit=Konec
+Menu.View=Zobrazit
+Menu.First.page=Prvn\u00ed strana
+Menu.Prev.page=P\u0159edchoz\u00ed strana
+Menu.Next.page=Dal\u0161\u00ed strana
+Menu.Last.page=Posledn\u00ed strana
+Menu.Zoom=Lupa
+Menu.Default.zoom=Standardn\u00ed lupa
+Menu.Help=N\u00e1pov\u011bda
+Menu.About=O aplikaci
+Menu.Reload=Obnovit
+Menu.Go.to.Page=Jdi na stranu
+
+Title.Preview=N\u00e1hled
+
+Status.Show=Zobrazen\u00ed
+Status.Page=Strana
+Status.of=z
+Status.Build.FO.tree=Vytv\u00e1\u0159\u00edm strom FO...
+
+Label.Page.number=Strana \u010d\u00edslo
+Button.Cancel=Zru\u0161it
diff --git a/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_de.properties b/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_de.properties
new file mode 100644
index 000000000..63ebb8785
--- /dev/null
+++ b/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_de.properties
@@ -0,0 +1,32 @@
+#############################################################################
+# 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. #
+#############################################################################
+#
+# AWT viewer's GUI resources. German bundle.
+#
+Menu.File=Datei
+Menu.Exit=Beenden
+Menu.View=Anzeige
+Menu.First.page=Erste Seite
+Menu.Prev.page=Vorherige Seite
+Menu.Next.page=N\u00e4chste Seite
+Menu.Last.page=Letzte Seite
+Menu.Help=Hilfe
+Menu.Default.zoom=Standardzoom
+Menu.About=\u00dcber
+Menu.Print=Drucken
+Menu.Go.to.Page=Gehe zur Seite
+
+Title.Preview=Vorschau
+
+Status.Show=Anzeigen
+Status.Page=Seite
+Status.of=von
+Status.Build.FO.tree=Baue FO-Baum
+
+Button.Cancel=Abbrechen
+Label.Page.number=Seitennummer
diff --git a/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_fi.properties b/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_fi.properties
new file mode 100644
index 000000000..4068aad5d
--- /dev/null
+++ b/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_fi.properties
@@ -0,0 +1,23 @@
+#############################################################################
+# 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. #
+#############################################################################
+#
+# AWT viewer's GUI resources. Finnish bundle.
+#
+Menu.File=Tiedosto
+Menu.Print=Tulosta
+Menu.Exit=Poistu
+Menu.View=N\u00e4yt\u00e4
+Menu.First.page=Ensimm\u00e4inen sivu
+Menu.Prev.page=Edellinen sivu
+Menu.Next.page=Seuraava sivu
+Menu.Last.page=Viimeinen sivu
+Menu.Default.zoom=Normaali zoom
+Menu.Help=Ohje
+Menu.About=Tietoja
+
+Status.Page=Sivu
diff --git a/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_fr.properties b/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_fr.properties
new file mode 100644
index 000000000..89bb37a64
--- /dev/null
+++ b/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_fr.properties
@@ -0,0 +1,21 @@
+#############################################################################
+# 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. #
+#############################################################################
+#
+# 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.Help=Aide
+Menu.Default.zoom=Zoom par d\u00e9faut
+Menu.About=A propos
diff --git a/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_it.properties b/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_it.properties
new file mode 100644
index 000000000..fd1bd39e1
--- /dev/null
+++ b/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_it.properties
@@ -0,0 +1,21 @@
+#############################################################################
+# 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. #
+#############################################################################
+#
+# AWT viewer's GUI resources. Italian bundle.
+#
+Menu.File=File
+Menu.Exit=Esci
+Menu.View=Vista
+Menu.First.page=Prima pagina
+Menu.Prev.page=Pagina precedente
+Menu.Next.page=Pagina seguente
+Menu.Last.page=Ultima pagina
+Menu.Help=Aiuto
+Menu.Default.zoom=Zoom di default
+Menu.About=Riguardo a...
+Menu.Print=Stampa
diff --git a/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_ja.properties b/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_ja.properties
new file mode 100644
index 000000000..983a72dcb
--- /dev/null
+++ b/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_ja.properties
@@ -0,0 +1,28 @@
+#############################################################################
+# 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. #
+#############################################################################
+#
+# AWT viewer's GUI resources. Japanese bundle.
+#
+Menu.File=\u30d5\u30a1\u30a4\u30eb
+Menu.Print=\u5370\u5237
+Menu.Exit=\u7d42\u4e86
+Menu.View=\u8868\u793a
+Menu.First.page=\u958b\u59cb\u30da\u30fc\u30b8
+Menu.Prev.page=\u524d\u30da\u30fc\u30b8
+Menu.Next.page=\u6b21\u30da\u30fc\u30b8
+Menu.Last.page=\u6700\u7d42\u30da\u30fc\u30b8
+Menu.Go.to.Page=\u30da\u30fc\u30b8\u6307\u5b9a
+Menu.Zoom=\u30ba\u30fc\u30e0
+Menu.Default.zoom=\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u30ba\u30fc\u30e0
+Menu.Help=\u30d8\u30eb\u30d7
+Menu.About=\u30d0\u30fc\u30b8\u30e7\u30f3\u60c5\u5831
+
+Status.Page=\u30da\u30fc\u30b8
+Status.of=/
+Status.Build.FO.tree=FO\u30c4\u30ea\u30fc\u69cb\u7bc9\u4e2d
+Status.Show=\u5b8c\u4e86
diff --git a/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_pl.properties b/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_pl.properties
new file mode 100644
index 000000000..63bf2de9f
--- /dev/null
+++ b/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_pl.properties
@@ -0,0 +1,24 @@
+#############################################################################
+# 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. #
+#############################################################################
+#
+# AWT viewer's GUI resources. Polish bundle.
+#
+Menu.File=Plik
+Menu.Print=Drukuj
+Menu.Exit=Zako\u00f1cz
+Menu.View=Widok
+Menu.First.page=Pierwsza strona
+Menu.Prev.page=Poprzednia strona
+Menu.Next.page=Nast\u00eapna strona
+Menu.Last.page=Ostatnia strona
+Menu.Zoom=Powi\u00eakszenie
+Menu.Default.zoom=Domy\u00b6lne powiekszenie
+Menu.Help=Pomoc
+Menu.About=O programie
+
+Status.Page=Strona
diff --git a/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_ru.properties b/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_ru.properties
new file mode 100644
index 000000000..509f22935
--- /dev/null
+++ b/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_ru.properties
@@ -0,0 +1,43 @@
+#############################################################################
+# 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. #
+#############################################################################
+#
+# AWT viewer's GUI resources. Russain bundle.
+#
+Menu.File=\u0424\u0430\u0439\u043b
+Menu.Exit=\u0412\u044b\u0445\u043e\u0434
+Menu.View=\u0412\u0438\u0434
+Menu.First.page=\u041f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430
+Menu.Prev.page=\u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0430\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430
+Menu.Next.page=\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430
+Menu.Last.page=\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430
+Menu.Go.to.Page=\u041f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435
+Menu.Help=\u041f\u043e\u043c\u043e\u0449\u044c
+Menu.Default.zoom=\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440
+Menu.About=\u041e \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0435
+Menu.Print=\u041f\u0435\u0447\u0430\u0442\u044c
+Menu.Zoom=\u0420\u0430\u0437\u043c\u0435\u0440
+Menu.Reload=\u041e\u0431\u043d\u043e\u0432\u0438\u0442\u044c
+
+Title.Preview=\u041f\u0440\u043e\u0441\u043c\u043e\u0442\u0440
+
+Status.Show=\u041e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435
+Status.Page=\u0421\u0442\u0440\u0430\u043d\u0438\u0446\u0430
+Status.of=\u0438\u0437
+Status.Build.FO.tree=\u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 FO \u0434\u0435\u0440\u0435\u0432\u0430...
+
+Exception.Occured=\u041f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0430
+Exception.Error=\u041a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430
+
+Label.Page.number=\u041d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b
+Button.Ok=Ok
+Button.Cancel=\u041e\u0442\u043c\u0435\u043d\u0438\u0442\u044c
+
+About.Product=FOP AWT Viewer
+About.Version=\u0412\u0435\u0440\u0441\u0438\u044f:
+About.Copyright=\u0421\u043c\u043e\u0442\u0440\u0438 http://xml.apache.org/fop
+About.Title=\u041e \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0435
diff --git a/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_tr.properties b/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_tr.properties
new file mode 100644
index 000000000..e87b2e10d
--- /dev/null
+++ b/src/java/org/apache/fop/render/awt/viewer/resources/Viewer_tr.properties
@@ -0,0 +1,33 @@
+#############################################################################
+# 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. #
+#############################################################################
+#
+# AWT viewer's GUI resources. Turkish bundle.
+#
+Menu.File=Dosya
+Menu.Exit=\u00c7\u0131k\u0131\u015f
+Menu.View=\u0130zle
+Menu.First.page=\u0130lk Sayfa
+Menu.Prev.page=\u00d6nceki Sayfa
+Menu.Next.page=Sonraki Sayfa
+Menu.Last.page=Son Sayfa
+Menu.Go.to.Page=Sayfaya Git
+Menu.Help=Yard\u0131m
+Menu.Default.zoom=Standart zum
+Menu.About=Hakk\u0131nda
+Menu.Print=Yazd\u0131r
+
+Title.Preview=\u00d6nizleme
+
+Status.Show=G\u00f6ster
+Status.Page=Sayfa
+Status.of=
+Status.Build.FO.tree=FO a\u011fac\u0131n\u0131 yarat
+
+Label.Page.number=Sayfa numaras\u0131
+Button.Cancel=Vazge\u00e7
+