pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1698458 - in /pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger: hexviewer/HexView.java streampane/StreamPane.java streampane/StreamPaneView.java
Date Sat, 29 Aug 2015 11:01:40 GMT
Author: tilman
Date: Sat Aug 29 11:01:40 2015
New Revision: 1698458

URL: http://svn.apache.org/r1698458
Log:
PDFBOX-2941: separate filter choice from hex + text view, as done by Khyrul Bashar

Modified:
    pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/hexviewer/HexView.java
    pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/StreamPane.java
    pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/StreamPaneView.java

Modified: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/hexviewer/HexView.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/hexviewer/HexView.java?rev=1698458&r1=1698457&r2=1698458&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/hexviewer/HexView.java
(original)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/hexviewer/HexView.java
Sat Aug 29 11:01:40 2015
@@ -17,35 +17,24 @@
 
 package org.apache.pdfbox.tools.pdfdebugger.hexviewer;
 
+import java.awt.BorderLayout;
 import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.FlowLayout;
 import java.awt.Font;
 import java.awt.RenderingHints;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.io.IOException;
-import java.io.InputStream;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
-import javax.swing.BoxLayout;
-import javax.swing.JComboBox;
 import javax.swing.JComponent;
 import javax.swing.JPanel;
 import javax.swing.UIManager;
-import org.apache.pdfbox.io.IOUtils;
-import org.apache.pdfbox.tools.pdfdebugger.streampane.Stream;
 
 /**
  * @author Khyrul Bashar
  *
  * HexView takes a byte array or Stream instance and shows them in Hex viewer.
  */
-public class HexView implements ActionListener
+public class HexView
 {
-    private JComponent mainPane;
-    private Stream stream;
+    private final JComponent mainPane;
     
     static final int FONT_SIZE = ((Font)UIManager.get("Label.font")).getSize();
     static final Font FONT = new Font("monospaced", Font.PLAIN, FONT_SIZE);
@@ -65,91 +54,34 @@ public class HexView implements ActionLi
         RENDERING_HINTS.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
     }
 
-    /**
-     * Constructor.
-     * @param bytes takes a byte array.
-     */
-    public HexView(byte[] bytes)
+    public HexView()
     {
-        createView();
-        mainPane.add(createHexEditor(bytes));
+        mainPane = new JPanel(new BorderLayout());
     }
 
     /**
      * Constructor.
-     * @param stream Stream instance.
-     * @throws IOException
+     * @param bytes takes a byte array.
      */
-    public HexView(Stream stream) throws IOException
-    {
-        this.stream = stream;
-        createView();
-        JPanel panel = createHeaderPanel(stream.getFilterList());
-        InputStream is = stream.getStream(stream.getFilterList().get(0));
-        mainPane.add(panel);
-        mainPane.add(createHexEditor(IOUtils.toByteArray(is)));
-    }
-
-
-    private void createView()
+    public HexView(byte[] bytes)
     {
-        mainPane = new JPanel();
-        mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.PAGE_AXIS));
+        mainPane = new JPanel(new BorderLayout());
+        mainPane.add(new HexEditor(new HexModel(bytes)));
     }
 
-    private HexEditor createHexEditor(byte[] bytes)
+    public void changeData(byte[] bytes)
     {
+        if (mainPane.getComponentCount() > 0)
+        {
+            mainPane.removeAll();
+        }
         HexModel model = new HexModel(bytes);
-        return new HexEditor(model);
+        mainPane.add(new HexEditor(model));
+        mainPane.validate();
     }
 
     public JComponent getPane()
     {
         return mainPane;
     }
-
-    @Override
-    public void actionPerformed(ActionEvent actionEvent)
-    {
-        if (actionEvent.getActionCommand().equals("comboBoxChanged"))
-        {
-            JComboBox comboBox = (JComboBox) actionEvent.getSource();
-            String currentFilter = (String) comboBox.getSelectedItem();
-            try
-            {
-                HexEditor editor = createHexEditor(IOUtils.toByteArray(stream.getStream(currentFilter)));
-                mainPane.remove(1);
-                mainPane.add(editor);
-                mainPane.revalidate();
-            }
-            catch (IOException e)
-            {
-                e.printStackTrace();
-            }
-        }
-    }
-
-    private JPanel createHeaderPanel(List<String> availableFilters)
-    {
-        if (availableFilters.contains("Image"))
-        {
-            availableFilters.remove("Image");
-        }
-        JComboBox filters = new JComboBox(availableFilters.toArray());
-        filters.setSelectedItem(0);
-        filters.addActionListener(this);
-
-        JPanel panel = new JPanel()
-        {
-            @Override
-            public Dimension getMaximumSize()
-            {
-                return new Dimension(HexView.TOTAL_WIDTH, 45);
-            }
-        };
-        panel.setLayout(new FlowLayout());
-        panel.add(filters);
-        panel.setPreferredSize(new Dimension(HexView.TOTAL_WIDTH, 45));
-        return panel;
-    }
 }

Modified: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/StreamPane.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/StreamPane.java?rev=1698458&r1=1698457&r2=1698458&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/StreamPane.java
(original)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/StreamPane.java
Sat Aug 29 11:01:40 2015
@@ -19,16 +19,22 @@ package org.apache.pdfbox.tools.pdfdebug
 
 import java.awt.Color;
 import java.awt.Dimension;
+import java.awt.FlowLayout;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.awt.image.BufferedImage;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ExecutionException;
+import javax.imageio.ImageIO;
+import javax.swing.BoxLayout;
 import javax.swing.JComboBox;
 import javax.swing.JComponent;
+import javax.swing.JPanel;
 import javax.swing.JTabbedPane;
 import javax.swing.SwingWorker;
 import javax.swing.text.BadLocationException;
@@ -90,7 +96,9 @@ public class StreamPane implements Actio
         StyleConstants.setForeground(INLINE_IMAGE_STYLE, new Color(116, 113, 39));
     }
 
-    private final JTabbedPane tabbedPane;
+    private final JPanel panel;
+    private final HexView hexView;
+    private JTabbedPane tabbedPane;
     private final StreamPaneView view;
     private final Stream stream;
     private ToolTipController tTController;
@@ -117,25 +125,46 @@ public class StreamPane implements Actio
             tTController = new ToolTipController(resources);
         }
 
+        panel = new JPanel();
+        panel.setPreferredSize(new Dimension(300, 500));
+        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
+
+        view = new StreamPaneView();
+        hexView = new HexView();
+
         if (stream.isImage())
         {
-            view = new StreamPaneView(stream.getFilterList(), Stream.IMAGE, this);
+            panel.add(createHeaderPanel(stream.getFilterList(), Stream.IMAGE, this));
             requestImageShowing();
         }
         else
         {
-            view = new StreamPaneView(stream.getFilterList(), Stream.UNFILTERED, this);
+            panel.add(createHeaderPanel(stream.getFilterList(), Stream.UNFILTERED, this));
             requestStreamText(Stream.UNFILTERED);
         }
+
         tabbedPane = new JTabbedPane();
-        tabbedPane.setPreferredSize(new Dimension(300, 500));
         tabbedPane.add("Text view", view.getStreamPanel());
-        tabbedPane.add("Hex view", new HexView(stream).getPane());
+        tabbedPane.add("Hex view", hexView.getPane());
+
+        panel.add(tabbedPane);
     }
 
     public JComponent getPanel()
     {
-        return tabbedPane;
+        return panel;
+    }
+
+    private JPanel createHeaderPanel(List<String> availableFilters, String i, ActionListener
actionListener)
+    {
+        JComboBox filters = new JComboBox(availableFilters.toArray());
+        filters.setSelectedItem(i);
+        filters.addActionListener(actionListener);
+
+        JPanel panel = new JPanel(new FlowLayout());
+        panel.add(filters);
+
+        return panel;
     }
 
     @Override
@@ -146,26 +175,42 @@ public class StreamPane implements Actio
             JComboBox comboBox = (JComboBox) actionEvent.getSource();
             String currentFilter = (String) comboBox.getSelectedItem();
 
-            if (currentFilter.equals(Stream.IMAGE))
+            try
             {
-                requestImageShowing();
-                return;
+                if (currentFilter.equals(Stream.IMAGE))
+                {
+                    requestImageShowing();
+                    return;
+                }
+                requestStreamText(currentFilter);
+            }
+            catch (IOException e)
+            {
+                e.printStackTrace();
             }
-            requestStreamText(currentFilter);
         }
     }
 
-    private void requestImageShowing()
+    private void requestImageShowing() throws IOException
     {
         if (stream.isImage())
         {
-            view.showStreamImage(stream.getImage(resources));
+            BufferedImage image = stream.getImage(resources);
+            view.showStreamImage(image);
+
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            ImageIO.write(image, "jpg", baos);
+            baos.flush();
+            byte[] bytes = baos.toByteArray();
+            baos.close();
+            hexView.changeData(bytes);
         }
     }
 
-    private void requestStreamText(String command)
+    private void requestStreamText(String command) throws IOException
     {
         new DocumentCreator(command).execute();
+        hexView.changeData(IOUtils.toByteArray(stream.getStream(command)));
     }
 
     /**

Modified: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/StreamPaneView.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/StreamPaneView.java?rev=1698458&r1=1698457&r2=1698458&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/StreamPaneView.java
(original)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/StreamPaneView.java
Sat Aug 29 11:01:40 2015
@@ -17,13 +17,7 @@
 package org.apache.pdfbox.tools.pdfdebugger.streampane;
 
 import java.awt.BorderLayout;
-import java.awt.Dimension;
-import java.awt.FlowLayout;
-import java.awt.event.ActionListener;
 import java.awt.image.BufferedImage;
-import java.util.List;
-import javax.swing.BoxLayout;
-import javax.swing.JComboBox;
 import javax.swing.JPanel;
 import javax.swing.text.StyledDocument;
 import org.apache.pdfbox.tools.pdfdebugger.streampane.tooltip.ToolTipController;
@@ -31,22 +25,16 @@ import org.apache.pdfbox.tools.pdfdebugg
 /**
  * @author Khyrul Bashar
  */
-class StreamPaneView extends JPanel
+class StreamPaneView
 {
-    private final JPanel headerPanel;
     private final JPanel contentPanel;
 
     /**
      * Constructor.
-     * @param filterTypes String array that provides a list of key for available stream versions.
-     * @param initialChoice String instance. Initial choice for showing in the pane.
-     * @param listener ActionListener that listens for stream version choice changing.
      */
-    StreamPaneView(List<String> filterTypes, String initialChoice, ActionListener listener)
+    StreamPaneView()
     {
-        headerPanel = createHeaderPanel(filterTypes, initialChoice, listener);
         contentPanel = new JPanel(new BorderLayout());
-        initUI();
     }
 
     /**
@@ -57,10 +45,9 @@ class StreamPaneView extends JPanel
     void showStreamText(StyledDocument document, ToolTipController toolTipController)
     {
         contentPanel.removeAll();
-
         StreamTextView textView = new StreamTextView(document, toolTipController);
         contentPanel.add(textView.getView(), BorderLayout.CENTER);
-        this.validate();
+        contentPanel.validate();
     }
 
 
@@ -72,31 +59,11 @@ class StreamPaneView extends JPanel
     {
         contentPanel.removeAll();
         contentPanel.add(new StreamImageView(image).getView(), BorderLayout.CENTER);
-        this.validate();
-    }
-
-    private JPanel createHeaderPanel(List<String> availableFilters, String i, ActionListener
actionListener)
-    {
-        JComboBox filters = new JComboBox(availableFilters.toArray());
-        filters.setSelectedItem(i);
-        filters.addActionListener(actionListener);
-
-        JPanel panel = new JPanel(new FlowLayout());
-        panel.add(filters);
-
-        return panel;
+        contentPanel.validate();
     }
 
     public JPanel getStreamPanel()
     {
-        return this;
-    }
-
-    private void initUI()
-    {
-        this.setPreferredSize(new Dimension(300, 500));
-        this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
-        this.add(headerPanel);
-        this.add(contentPanel);
+        return contentPanel;
     }
 }



Mime
View raw message