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 2020/09/25 15:59:50 UTC

svn commit: r1882022 - /pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/streampane/StreamPane.java

Author: tilman
Date: Fri Sep 25 15:59:50 2020
New Revision: 1882022

URL: http://svn.apache.org/viewvc?rev=1882022&view=rev
Log:
PDFBOX-4971: parametrize DocumentCreator class, add a raw view for content streams

Modified:
    pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/streampane/StreamPane.java

Modified: pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/streampane/StreamPane.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/streampane/StreamPane.java?rev=1882022&r1=1882021&r2=1882022&view=diff
==============================================================================
--- pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/streampane/StreamPane.java (original)
+++ pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/streampane/StreamPane.java Fri Sep 25 15:59:50 2020
@@ -94,7 +94,8 @@ public class StreamPane implements Actio
     private final JPanel panel;
     private final HexView hexView;
     private final JTabbedPane tabbedPane;
-    private final StreamPaneView view;
+    private final StreamPaneView rawView;
+    private final StreamPaneView niceView;
     private final Stream stream;
     private ToolTipController tTController;
     private PDResources resources;
@@ -125,8 +126,16 @@ public class StreamPane implements Actio
         panel.setPreferredSize(new Dimension(300, 500));
         panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
 
-        view = new StreamPaneView();
+        rawView = new StreamPaneView();
         hexView = new HexView();
+        if (isContentStream)
+        {
+            niceView = new StreamPaneView();
+        }
+        else
+        {
+            niceView = null;
+        }
 
         if (stream.isImage())
         {
@@ -142,11 +151,17 @@ public class StreamPane implements Actio
         tabbedPane = new JTabbedPane();
         if (stream.isImage())
         {
-            tabbedPane.add("Image view", view.getStreamPanel());
+            tabbedPane.add("Image view", rawView.getStreamPanel());
+        }
+        else if (isContentStream)
+        {
+            tabbedPane.add("Nice view", niceView.getStreamPanel());
+            tabbedPane.add("Raw view", rawView.getStreamPanel());
+            tabbedPane.add("Hex view", hexView.getPane());
         }
         else
         {
-            tabbedPane.add("Text view", view.getStreamPanel());
+            tabbedPane.add("Text view", rawView.getStreamPanel());
             tabbedPane.add("Hex view", hexView.getPane());
         }
 
@@ -184,12 +199,21 @@ public class StreamPane implements Actio
                 {
                     requestImageShowing();
                     tabbedPane.removeAll();
-                    tabbedPane.add("Image view", view.getStreamPanel());
+                    tabbedPane.add("Image view", rawView.getStreamPanel());
                     return;
                 }
                 tabbedPane.removeAll();
-                tabbedPane.add("Text view", view.getStreamPanel());
-                tabbedPane.add("Hex view", hexView.getPane());
+                if (isContentStream)
+                {
+                    tabbedPane.add("Nice view", rawView.getStreamPanel());
+                    tabbedPane.add("Raw view", niceView.getStreamPanel());
+                    tabbedPane.add("Hex view", hexView.getPane());
+                }
+                else
+                {
+                    tabbedPane.add("Text view", rawView.getStreamPanel());
+                    tabbedPane.add("Hex view", hexView.getPane());
+                }
                 requestStreamText(currentFilter);
             }
             catch (IOException e)
@@ -213,13 +237,17 @@ public class StreamPane implements Actio
                 JOptionPane.showMessageDialog(panel, "image not available (filter missing?)");
                 return;
             }
-            view.showStreamImage(image);
+            rawView.showStreamImage(image);
         }
     }
 
     private void requestStreamText(String command) throws IOException
     {
-        new DocumentCreator(command).execute();
+        new DocumentCreator(rawView, command, false).execute();
+        if (niceView != null)
+        {
+            new DocumentCreator(niceView, command, true).execute();
+        }
         synchronized (stream)
         {
             InputStream is = stream.getStream(command);
@@ -237,13 +265,17 @@ public class StreamPane implements Actio
      */
     private final class DocumentCreator extends SwingWorker<StyledDocument, Integer>
     {
+        private final StreamPaneView targetView;
         private final String filterKey;
+        private final boolean nice;
         private int indent;
         private boolean needIndent;
 
-        private DocumentCreator(String filterKey)
+        private DocumentCreator(StreamPaneView targetView, String filterKey, boolean nice)
         {
+            this.targetView = targetView;
             this.filterKey = filterKey;
+            this.nice = nice;
         }
 
         @Override
@@ -258,7 +290,7 @@ public class StreamPane implements Actio
                     encoding = "UTF-8";
                 }
                 InputStream inputStream = stream.getStream(filterKey);
-                if (isContentStream && Stream.DECODED.equals(filterKey))
+                if (nice && Stream.DECODED.equals(filterKey))
                 {
                     StyledDocument document = getContentStreamDocument(inputStream);
                     if (document != null)
@@ -276,7 +308,7 @@ public class StreamPane implements Actio
         {
             try
             {
-                view.showStreamText(get(), tTController);
+                targetView.showStreamText(get(), tTController);
             }
             catch (InterruptedException | ExecutionException e)
             {