--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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);
+
+}
//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);
* 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,
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);
}
}
+ /**
+ * Sets the scaling so the contents are spread over the whole width available.
+ */
public void setScaleToFitWidth() {
try {
setScale(previewPanel.getScaleToFitWidth() * 100);
//Restore originally configured target resolution
float saveResolution = foUserAgent.getTargetResolution();
foUserAgent.setTargetResolution(this.configuredTargetResolution);
-
+
PrinterJob pj = PrinterJob.getPrinterJob();
pj.setPageable(renderer);
if (!showDialog || pj.printDialog()) {
e.printStackTrace();
}
}
-
+
foUserAgent.setTargetResolution(saveResolution);
}
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;
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);
* @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());
firstPage = currentPage;
}
showPage();
+ firePageChange(oldPage, currentPage);
}
/**
reload();
}
+ /**
+ * 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 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]
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>