From 9c8674811a32010d6b5c6d843dd27b6cd4991af6 Mon Sep 17 00:00:00 2001
From: Jeremias Maerki
Date: Sun, 12 Nov 2006 15:38:45 +0000
Subject: [PATCH] Bugzilla #40813: 1. The PreviewDialog did not display
correctly under certain Window managers (this is actually a bug in Sun's
JVM). 2. Keyboard shortcuts are added for PageUp/PageDown (prev/next page),
Home (first page) and End (last page). 3. PreviewPanel.setPage() scrolls to
the selected page. Submitted by: Richard Wheeldon
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@473976 13f79535-47bb-0310-9956-ffa450edef68
---
.../fop/render/awt/viewer/PreviewDialog.java | 36 ++++++++++---------
.../fop/render/awt/viewer/PreviewPanel.java | 6 ++--
status.xml | 4 +++
3 files changed, 27 insertions(+), 19 deletions(-)
diff --git a/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java b/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java
index 55ebfc702..5ce3823ec 100644
--- a/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java
+++ b/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java
@@ -41,17 +41,21 @@ import java.awt.print.PrinterJob;
import java.text.DecimalFormat;
+import javax.swing.ActionMap;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
+import javax.swing.InputMap;
import javax.swing.JComboBox;
-import javax.swing.JRadioButtonMenuItem;
+import javax.swing.JComponent;
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.JRadioButtonMenuItem;
import javax.swing.JToolBar;
+import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
@@ -155,6 +159,8 @@ public class PreviewDialog extends JFrame implements StatusListener {
//Sets size to be 61%x90% of the screen size
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
+ // Needed due to bug in Sun's JVM 1.5 (6429775)
+ pack();
//Rather frivolous size - fits A4 page width in 1024x768 screen on my desktop
setSize(screen.width * 61 / 100, screen.height * 9 / 10);
@@ -162,6 +168,18 @@ public class PreviewDialog extends JFrame implements StatusListener {
previewPanel = new PreviewPanel(foUserAgent, renderable, renderer);
getContentPane().add(previewPanel, BorderLayout.CENTER);
+ // Keyboard shortcuts - pgup/pgdn
+ InputMap im = previewPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
+ ActionMap am = previewPanel.getActionMap();
+ im.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), "nextPage");
+ im.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0), "prevPage");
+ im.put(KeyStroke.getKeyStroke(KeyEvent.VK_HOME, 0), "firstPage");
+ im.put(KeyStroke.getKeyStroke(KeyEvent.VK_END, 0), "lastPage");
+ previewPanel.getActionMap().put("nextPage", nextPageAction);
+ previewPanel.getActionMap().put("prevPage", previousPageAction);
+ previewPanel.getActionMap().put("firstPage", firstPageAction);
+ previewPanel.getActionMap().put("lastPage", lastPageAction);
+
//Scaling combobox
scale = new JComboBox();
scale.addItem(translator.getString("Menu.Fit.Window"));
@@ -510,23 +528,7 @@ public class PreviewDialog extends JFrame implements StatusListener {
/** 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);
}
diff --git a/src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java b/src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java
index 1512f4eb9..734dc90dd 100644
--- a/src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java
+++ b/src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java
@@ -61,11 +61,13 @@ import org.apache.fop.render.awt.AWTRenderer;
* renderer and add it to your gui:
*
*
+ * FopFactory fopFactory = FopFactory.newInstance();
* AWTRenderer renderer = new AWTRenderer();
- * FOUserAgent agent = new FOUserAgent();
+ * FOUserAgent agent = fopFactory.newFOUserAgent();
* agent.setRendererOverride(renderer);
* renderer.setPreviewDialogDisplayed(false);
* renderer.setUserAgent(agent);
+ * renderer.setUserAgent(agent);
* previewPanel = new PreviewPanel(agent, null, renderer);
* previewPanel = new PreviewPanel(ua);
* myGui.add(previewPanel);
@@ -183,8 +185,8 @@ public class PreviewPanel extends JPanel {
*/
public void setPage(int number) {
if (displayMode == CONTINUOUS || displayMode == CONT_FACING) {
- // FIXME Should scroll so page is visible
currentPage = number;
+ gridPanel.scrollRectToVisible(pagePanels[currentPage].getBounds());
} else { // single page mode
currentPage = number;
firstPage = currentPage;
diff --git a/status.xml b/status.xml
index 7224186e0..13a81ba02 100644
--- a/status.xml
+++ b/status.xml
@@ -28,6 +28,10 @@
+
+ Minor fixes and improvements for the AWT Preview (keyboard shortcuts, scrolling, windows
+ setup).
+
Added support for SVG in fo:instream-foreign objects for RTF output.
--
2.39.5