You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2016/07/23 14:36:24 UTC
svn commit: r1753875 -
/pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java
Author: tilman
Date: Sat Jul 23 14:36:24 2016
New Revision: 1753875
URL: http://svn.apache.org/viewvc?rev=1753875&view=rev
Log:
PDFBOX-2941: show PDF coordinates
Modified:
pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java
Modified: pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java?rev=1753875&r1=1753874&r2=1753875&view=diff
==============================================================================
--- pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java (original)
+++ pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java Sat Jul 23 14:36:24 2016
@@ -21,6 +21,9 @@ import java.awt.Component;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
@@ -45,7 +48,7 @@ import org.apache.pdfbox.rendering.PDFRe
* @author Tilman Hausherr
* @author John Hewson
*/
-public class PagePane implements ActionListener, AncestorListener
+public class PagePane implements ActionListener, AncestorListener, MouseMotionListener, MouseListener
{
private JPanel panel;
private int pageIndex = -1;
@@ -54,11 +57,14 @@ public class PagePane implements ActionL
private ZoomMenu zoomMenu;
private RotationMenu rotationMenu;
private final JLabel statuslabel;
+ private final float height, width;
public PagePane(PDDocument document, COSDictionary page, JLabel statuslabel)
{
PDPage pdPage = new PDPage(page);
pageIndex = document.getPages().indexOf(pdPage);
+ height = pdPage.getCropBox().getHeight();
+ width = pdPage.getCropBox().getWidth();
this.document = document;
this.statuslabel = statuslabel;
initUI();
@@ -78,6 +84,8 @@ public class PagePane implements ActionL
panel.add(pageLabel);
label = new JLabel();
+ label.addMouseMotionListener(this);
+ label.addMouseListener(this);
label.setBackground(panel.getBackground());
label.setAlignmentX(Component.CENTER_ALIGNMENT);
panel.add(label);
@@ -135,6 +143,72 @@ public class PagePane implements ActionL
{
}
+ @Override
+ public void mouseDragged(MouseEvent e)
+ {
+ }
+
+ /**
+ * Catch mouse event to display cursor position in PDF coordinates in the status bar.
+ *
+ * @param e mouse event with position
+ */
+ @Override
+ public void mouseMoved(MouseEvent e)
+ {
+ float zoomScale = zoomMenu.getPageZoomScale();
+ float x = e.getX() / zoomScale;
+ float y = e.getY() / zoomScale;
+ int x1, y1;
+ switch (RotationMenu.getRotationDegrees())
+ {
+ case 0:
+ default:
+ x1 = (int) x;
+ y1 = (int) (height - y);
+ break;
+ case 90:
+ x1 = (int) y;
+ y1 = (int) x;
+ break;
+ case 180:
+ x1 = (int) (width - x);
+ y1 = (int) y;
+ break;
+ case 270:
+ x1 = (int) (width - y);
+ y1 = (int) (height - x);
+ break;
+ }
+ statuslabel.setText(x1 + "," + y1);
+ }
+
+ @Override
+ public void mouseClicked(MouseEvent e)
+ {
+ }
+
+ @Override
+ public void mousePressed(MouseEvent e)
+ {
+ }
+
+ @Override
+ public void mouseReleased(MouseEvent e)
+ {
+ }
+
+ @Override
+ public void mouseEntered(MouseEvent e)
+ {
+ }
+
+ @Override
+ public void mouseExited(MouseEvent e)
+ {
+ statuslabel.setText("");
+ }
+
/**
* Note that PDDocument is not officially thread safe, caution advised.
*/
@@ -158,7 +232,7 @@ public class PagePane implements ActionL
long t0 = System.currentTimeMillis();
statuslabel.setText("Rendering...");
BufferedImage bim = renderer.renderImage(pageIndex, scale);
- float t = ((System.currentTimeMillis() - t0) / 1000f);
+ float t = (System.currentTimeMillis() - t0) / 1000f;
statuslabel.setText("Rendered in " + t + " second" + (t > 1 ? "s" : ""));
return ImageUtil.getRotatedImage(bim, rotation);
}