You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2010/06/08 21:01:57 UTC
svn commit: r952770 - in /xmlgraphics/fop/trunk: ./
src/java/org/apache/fop/render/awt/viewer/
Author: jeremias
Date: Tue Jun 8 19:01:56 2010
New Revision: 952770
URL: http://svn.apache.org/viewvc?rev=952770&view=rev
Log:
Bugzilla #42306:
Fix for AWT viewer to correctly track page numbers in continuous display mode.
Submitted by: Richard Wheeldon <ri...@geoquip-rnd.demon.co.uk>
Modifications to original patch:
- Small adjustments for out code conventions.
- Added some missing Javadocs.
Added:
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/awt/viewer/PageChangeEvent.java (with props)
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/awt/viewer/PageChangeListener.java (with props)
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java
xmlgraphics/fop/trunk/status.xml
Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/awt/viewer/PageChangeEvent.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/awt/viewer/PageChangeEvent.java?rev=952770&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/awt/viewer/PageChangeEvent.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/awt/viewer/PageChangeEvent.java Tue Jun 8 19:01:56 2010
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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$ */
+
+package org.apache.fop.render.awt.viewer;
+
+import java.util.EventObject;
+
+/**
+ * Swing event fired whenever the current page selection of a
+ * {@link PreviewPanel} changes. Page numbers are 0-based.
+ */
+public class PageChangeEvent extends EventObject {
+
+ private int oldPage;
+ private int newPage;
+
+ /**
+ * Creates an new page change event.
+ * @param panel the preview panel the event is produced for.
+ * @param oldPage the old page (zero based)
+ * @param newPage the new page (zero based)
+ */
+ public PageChangeEvent(PreviewPanel panel, int oldPage, int newPage) {
+ super(panel);
+ this.oldPage = oldPage;
+ this.newPage = newPage;
+ }
+
+ /**
+ * Returns the new page.
+ * @return the new page (zero based)
+ */
+ public int getNewPage() {
+ return newPage;
+ }
+
+ /**
+ * Returns the old page.
+ * @return the old page (zero based)
+ */
+ public int getOldPage() {
+ return oldPage;
+ }
+
+}
Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/awt/viewer/PageChangeEvent.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/awt/viewer/PageChangeEvent.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/awt/viewer/PageChangeListener.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/awt/viewer/PageChangeListener.java?rev=952770&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/awt/viewer/PageChangeListener.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/awt/viewer/PageChangeListener.java Tue Jun 8 19:01:56 2010
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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$ */
+
+package org.apache.fop.render.awt.viewer;
+
+import java.util.EventListener;
+
+/**
+ * Swing listener interface for classes which wish to receive
+ * notification of page change events.
+ */
+public interface PageChangeListener extends EventListener {
+
+ /**
+ * Called whenever the current page is changed.
+ * @param pce the page change event
+ */
+ void pageChanged(PageChangeEvent pce);
+
+}
Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/awt/viewer/PageChangeListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/awt/viewer/PageChangeListener.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java?rev=952770&r1=952769&r2=952770&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java Tue Jun 8 19:01:56 2010
@@ -171,6 +171,11 @@ public class PreviewDialog extends JFram
//Page view stuff
previewPanel = new PreviewPanel(foUserAgent, renderable, renderer);
getContentPane().add(previewPanel, BorderLayout.CENTER);
+ previewPanel.addPageChangeListener(new PageChangeListener() {
+ public void pageChanged(PageChangeEvent pce) {
+ new ShowInfo().run();
+ }
+ });
// Keyboard shortcuts - pgup/pgdn
InputMap im = previewPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
@@ -260,6 +265,7 @@ public class PreviewDialog extends JFram
* Creates and initialize the AWT Viewer main window.
* @param foUserAgent the FO user agent
* @param renderable the target for the rendering
+ * @param asMainWindow true if the window shall act as the main application window.
* @return the newly initialized preview dialog
*/
public static PreviewDialog createPreviewDialog(FOUserAgent foUserAgent,
@@ -530,12 +536,18 @@ public class PreviewDialog extends JFram
goToPage(currentPage);
}
- /** Scales page image */
+ /**
+ * Scales page image.
+ * @param scaleFactor the scale factor
+ */
public void setScale(double scaleFactor) {
scale.setSelectedItem(percentFormat.format(scaleFactor) + "%");
previewPanel.setScaleFactor(scaleFactor / 100d);
}
+ /**
+ * Sets the scaling so the contents fit into the window.
+ */
public void setScaleToFitWindow() {
try {
setScale(previewPanel.getScaleToFitWindow() * 100);
@@ -544,6 +556,9 @@ public class PreviewDialog extends JFram
}
}
+ /**
+ * Sets the scaling so the contents are spread over the whole width available.
+ */
public void setScaleToFitWidth() {
try {
setScale(previewPanel.getScaleToFitWidth() * 100);
@@ -569,7 +584,7 @@ public class PreviewDialog extends JFram
//Restore originally configured target resolution
float saveResolution = foUserAgent.getTargetResolution();
foUserAgent.setTargetResolution(this.configuredTargetResolution);
-
+
PrinterJob pj = PrinterJob.getPrinterJob();
pj.setPageable(renderer);
if (!showDialog || pj.printDialog()) {
@@ -579,7 +594,7 @@ public class PreviewDialog extends JFram
e.printStackTrace();
}
}
-
+
foUserAgent.setTargetResolution(saveResolution);
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java?rev=952770&r1=952769&r2=952770&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java Tue Jun 8 19:01:56 2010
@@ -19,11 +19,14 @@
package org.apache.fop.render.awt.viewer;
+import java.awt.Adjustable;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Point;
import java.awt.Toolkit;
+import java.awt.event.AdjustmentEvent;
+import java.awt.event.AdjustmentListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
@@ -166,6 +169,8 @@ public class PreviewPanel extends JPanel
previewArea = new JScrollPane(gridPanel);
previewArea.getViewport().setBackground(Color.gray);
+ previewArea.getVerticalScrollBar().addAdjustmentListener(new PageNumberListener());
+
// FIXME should add scroll wheel support here at some point.
scroller = new ViewportScroller(previewArea.getViewport());
previewArea.addMouseListener(scroller);
@@ -188,6 +193,7 @@ public class PreviewPanel extends JPanel
* @param number the page number
*/
public void setPage(int number) {
+ int oldPage = currentPage;
if (displayMode == CONTINUOUS || displayMode == CONT_FACING) {
currentPage = number;
gridPanel.scrollRectToVisible(pagePanels[currentPage].getBounds());
@@ -196,6 +202,7 @@ public class PreviewPanel extends JPanel
firstPage = currentPage;
}
showPage();
+ firePageChange(oldPage, currentPage);
}
/**
@@ -237,6 +244,42 @@ public class PreviewPanel extends JPanel
}
/**
+ * Add a listener to receive notification of page change events. Events will
+ * be fired whenever the currentPage value is changed. The values recorded
+ * are 0-based.
+ * @param l the page change listener to add
+ */
+ public void addPageChangeListener(PageChangeListener l) {
+ listenerList.add(PageChangeListener.class, l);
+ }
+
+ /**
+ * Removes a page change listener.
+ * @param l the page change listener to remove
+ */
+ public void removePageChangeListener(PageChangeListener l) {
+ listenerList.remove(PageChangeListener.class, l);
+ }
+
+ /**
+ * Notify all registered listeners of a page change event.
+ * @param oldPage the old page
+ * @param newPage the new page
+ */
+ protected void firePageChange(int oldPage, int newPage) {
+ Object[] listeners = listenerList.getListenerList();
+ PageChangeEvent e = null;
+ for (int i = listeners.length - 2; i >= 0; i -= 2) {
+ if (listeners[i] == PageChangeListener.class) {
+ if (e == null) {
+ e = new PageChangeEvent(this, newPage, oldPage);
+ }
+ ((PageChangeListener)listeners[i + 1]).pageChanged(e);
+ }
+ }
+ }
+
+ /**
* Allows any mouse drag on the page area to scroll the display window.
*/
private class ViewportScroller implements MouseListener, MouseMotionListener {
@@ -352,6 +395,23 @@ public class PreviewPanel extends JPanel
}
}
+ private class PageNumberListener implements AdjustmentListener {
+ public void adjustmentValueChanged(AdjustmentEvent e) {
+ if (displayMode == PreviewPanel.CONTINUOUS || displayMode == PreviewPanel.CONT_FACING) {
+ Adjustable a = e.getAdjustable();
+ int value = +e.getValue();
+ int min = a.getMinimum();
+ int max = a.getMaximum();
+ int page = ( (renderer.getNumberOfPages() * value) / (max - min) );
+ if (page != currentPage) {
+ int oldPage = currentPage;
+ currentPage = page;
+ firePageChange(oldPage, currentPage);
+ }
+ }
+ }
+ }
+
/**
* Scales page image
* @param scale [0;1]
Modified: xmlgraphics/fop/trunk/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=952770&r1=952769&r2=952770&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Tue Jun 8 19:01:56 2010
@@ -58,6 +58,9 @@
documents. Example: the fix of marks layering will be such a case when it's done.
-->
<release version="FOP Trunk" date="TBD">
+ <action context="Renderers" dev="JM" type="fix" fixes-bug="42306" due-to="Richard Wheeldon">
+ Fix for AWT viewer to correctly track page numbers in continuous display mode.
+ </action>
<action context="Renderers" dev="JM" type="fix">
Bugfix for formatting of floating point numbers which could lead to invalid PDFs.
</action>
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org