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 2018/04/27 20:14:07 UTC
svn commit: r1830394 -
/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java
Author: tilman
Date: Fri Apr 27 20:14:07 2018
New Revision: 1830394
URL: http://svn.apache.org/viewvc?rev=1830394&view=rev
Log:
PDFBOX-2941: tell field name if we're in a field
Modified:
pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java
Modified: pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java?rev=1830394&r1=1830393&r2=1830394&view=diff
==============================================================================
--- pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java (original)
+++ pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java Fri Apr 27 20:14:07 2018
@@ -47,9 +47,16 @@ import java.awt.event.MouseMotionListene
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import org.apache.pdfbox.debugger.ui.HighResolutionImageIcon;
+import org.apache.pdfbox.pdmodel.common.PDRectangle;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
+import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
+import org.apache.pdfbox.pdmodel.interactive.form.PDField;
/**
* Display the page number and a page rendering.
@@ -69,6 +76,7 @@ public class PagePane implements ActionL
private RotationMenu rotationMenu;
private ViewMenu viewMenu;
private String labelText = "";
+ private final Map<PDRectangle,String> rectMap = new HashMap<>();
public PagePane(PDDocument document, COSDictionary pageDict, JLabel statuslabel)
{
@@ -77,6 +85,27 @@ public class PagePane implements ActionL
this.document = document;
this.statuslabel = statuslabel;
initUI();
+ initRectMap();
+ }
+
+ private void initRectMap()
+ {
+ PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm();
+ if (acroForm == null)
+ {
+ return;
+ }
+ for (PDField field : acroForm.getFieldTree())
+ {
+ String fullyQualifiedName = field.getFullyQualifiedName();
+ for (PDAnnotationWidget widget : field.getWidgets())
+ {
+ if (page.equals(widget.getPage()))
+ {
+ rectMap.put(widget.getRectangle(), fullyQualifiedName);
+ }
+ }
+ }
}
private void initUI()
@@ -250,7 +279,19 @@ public class PagePane implements ActionL
y1 = (int) (height - y + offsetY);
break;
}
- statuslabel.setText("x: " + x1 + ", y: " + y1);
+ String text = "x: " + x1 + ", y: " + y1;
+
+ // are we in a field widget?
+ for (Entry<PDRectangle,String> entry : rectMap.entrySet())
+ {
+ if (entry.getKey().contains(x1, y1))
+ {
+ text += ", field: " + rectMap.get(entry.getKey());
+ break;
+ }
+ }
+
+ statuslabel.setText(text);
}
@Override