pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1830395 - /pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java
Date Fri, 27 Apr 2018 20:19:20 GMT
Author: tilman
Date: Fri Apr 27 20:19:20 2018
New Revision: 1830395

URL: http://svn.apache.org/viewvc?rev=1830395&view=rev
Log:
PDFBOX-2941: tell field name if we're in a field

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=1830395&r1=1830394&r2=1830395&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
Fri Apr 27 20:19:20 2018
@@ -28,6 +28,8 @@ 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.concurrent.ExecutionException;
 import javax.swing.BoxLayout;
 import javax.swing.JLabel;
@@ -44,6 +46,10 @@ import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.rendering.PDFRenderer;
 import org.apache.pdfbox.debugger.PDFDebugger;
 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.
@@ -62,6 +68,7 @@ public class PagePane implements ActionL
     private final JLabel statuslabel;
     private final PDPage page;
     private String labelText = "";
+    private final Map<PDRectangle, String> rectMap = new HashMap<PDRectangle, String>();
 
     public PagePane(PDDocument document, COSDictionary pageDict, JLabel statuslabel)
     {
@@ -70,6 +77,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()
@@ -209,7 +237,19 @@ public class PagePane implements ActionL
                 y1 = (int) (height - y + offsetY);
                 break;
         }
-        statuslabel.setText(x1 + "," + y1);
+        String text = "x: " + x1 + ", y: " + y1;
+
+        // are we in a field widget?
+        for (Map.Entry<PDRectangle, String> entry : rectMap.entrySet())
+        {
+            if (entry.getKey().contains(x1, y1))
+            {
+                text += ", field: " + rectMap.get(entry.getKey());
+                break;
+            }
+        }
+
+        statuslabel.setText(text);
     }
 
     @Override



Mime
View raw message