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 2019/09/29 12:22:29 UTC

svn commit: r1867722 - in /pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger: PDFDebugger.java ui/DebugLog.java ui/LogDialog.java ui/ReaderBottomPanel.java

Author: tilman
Date: Sun Sep 29 12:22:29 2019
New Revision: 1867722

URL: http://svn.apache.org/viewvc?rev=1867722&view=rev
Log:
PDFBOX-2941: add log window code from trunk

Added:
    pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/DebugLog.java
      - copied unchanged from r1867719, pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/DebugLog.java
    pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/LogDialog.java
      - copied, changed from r1867719, pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/LogDialog.java
Modified:
    pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java
    pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/ReaderBottomPanel.java

Modified: pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java?rev=1867722&r1=1867721&r2=1867722&view=diff
==============================================================================
--- pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java (original)
+++ pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java Sun Sep 29 12:22:29 2019
@@ -97,6 +97,7 @@ import org.apache.pdfbox.debugger.ui.Doc
 import org.apache.pdfbox.debugger.ui.ErrorDialog;
 import org.apache.pdfbox.debugger.ui.ExtensionFileFilter;
 import org.apache.pdfbox.debugger.ui.FileOpenSaveDialog;
+import org.apache.pdfbox.debugger.ui.LogDialog;
 import org.apache.pdfbox.debugger.ui.MapEntry;
 import org.apache.pdfbox.debugger.ui.OSXAdapter;
 import org.apache.pdfbox.debugger.ui.PDFTreeCellRenderer;
@@ -1213,17 +1214,6 @@ public class PDFDebugger extends JFrame
             }
         });
 
-        // trigger premature initializations for more accurate rendering benchmarks
-        // See discussion in PDFBOX-3988
-        if (PDType1Font.COURIER.isStandard14())
-        {
-            // Yes this is always true
-            PDDeviceCMYK.INSTANCE.toRGB(new float[] { 0, 0, 0, 0} );
-            PDDeviceRGB.INSTANCE.toRGB(new float[] { 0, 0, 0 } );
-            IIORegistry.getDefaultInstance();
-            FilterFactory.INSTANCE.getFilter(COSName.FLATE_DECODE);
-        }
-
         // open file, if any
         String filename = null;
         @SuppressWarnings({"squid:S2068"})
@@ -1251,8 +1241,25 @@ public class PDFDebugger extends JFrame
             }
         }
         final PDFDebugger viewer = new PDFDebugger(viewPages);
-        
-        
+
+        // use our custom logger
+        // this works only if there is no "LogFactory.getLog()" in this class,
+        // and if there are no methods that call logging, even invisible
+        // use reduced file from PDFBOX-3653 to see logging
+        LogDialog.init(viewer, viewer.statusBar.getLogLabel());
+        System.setProperty("org.apache.commons.logging.Log", "org.apache.pdfbox.debugger.ui.DebugLog");
+
+        // trigger premature initializations for more accurate rendering benchmarks
+        // See discussion in PDFBOX-3988
+        if (PDType1Font.COURIER.isStandard14())
+        {
+            // Yes this is always true
+            PDDeviceCMYK.INSTANCE.toRGB(new float[] { 0, 0, 0, 0} );
+            PDDeviceRGB.INSTANCE.toRGB(new float[] { 0, 0, 0 } );
+            IIORegistry.getDefaultInstance();
+            FilterFactory.INSTANCE.getFilter(COSName.FLATE_DECODE);
+        }
+
         if (filename != null)
         {
             File file = new File(filename);

Copied: pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/LogDialog.java (from r1867719, pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/LogDialog.java)
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/LogDialog.java?p2=pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/LogDialog.java&p1=pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/LogDialog.java&r1=1867719&r2=1867722&rev=1867722&view=diff
==============================================================================
--- pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/LogDialog.java (original)
+++ pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/LogDialog.java Sun Sep 29 12:22:29 2019
@@ -74,49 +74,54 @@ public class LogDialog extends JDialog
     public void log(String name, String level, Object o, Throwable throwable)
     {
         StyledDocument doc = textPane.getStyledDocument();
-        
+
         String levelText;
         SimpleAttributeSet levelStyle = new SimpleAttributeSet();
-        switch (level)
+        if ("fatal".equals(level))
+        {
+            levelText = "Fatal";
+            StyleConstants.setForeground(levelStyle, Color.WHITE);
+            StyleConstants.setBackground(levelStyle, Color.BLACK);
+            fatalCount++;
+        }
+        else if ("error".equals(level))
+        {
+            levelText = "Error";
+            StyleConstants.setForeground(levelStyle, new Color(0xFF291F));
+            StyleConstants.setBackground(levelStyle, new Color(0xFFF0F0));
+            errorCount++;
+        }
+        else if ("warn".equals(level))
+        {
+            levelText = "Warning";
+            StyleConstants.setForeground(levelStyle, new Color(0x614201));
+            StyleConstants.setBackground(levelStyle, new Color(0xFFFCE5));
+            warnCount++;
+        }
+        else if ("info".equals(level))
+        {
+            levelText = "Info";
+            StyleConstants.setForeground(levelStyle, new Color(0x203261));
+            StyleConstants.setBackground(levelStyle, new Color(0xE2E8FF));
+            otherCount++;
+        }
+        else if ("debug".equals(level))
+        {
+            levelText = "Debug";
+            StyleConstants.setForeground(levelStyle, new Color(0x32612E));
+            StyleConstants.setBackground(levelStyle, new Color(0xF4FFEC));
+            otherCount++;
+        }
+        else if ("trace".equals(level))
+        {
+            levelText = "Trace";
+            StyleConstants.setForeground(levelStyle, new Color(0x64438D));
+            StyleConstants.setBackground(levelStyle, new Color(0xFEF3FF));
+            otherCount++;
+        }
+        else
         {
-            case "fatal":
-                levelText = "Fatal";
-                StyleConstants.setForeground(levelStyle, Color.WHITE);
-                StyleConstants.setBackground(levelStyle, Color.BLACK);
-                fatalCount++;
-                break;
-            case "error":
-                levelText = "Error";
-                StyleConstants.setForeground(levelStyle, new Color(0xFF291F));
-                StyleConstants.setBackground(levelStyle, new Color(0xFFF0F0));
-                errorCount++;
-                break;
-            case "warn":
-                levelText = "Warning";
-                StyleConstants.setForeground(levelStyle, new Color(0x614201));
-                StyleConstants.setBackground(levelStyle, new Color(0xFFFCE5));
-                warnCount++;
-                break;
-            case "info":
-                levelText = "Info";
-                StyleConstants.setForeground(levelStyle, new Color(0x203261));
-                StyleConstants.setBackground(levelStyle, new Color(0xE2E8FF));
-                otherCount++;
-                break;
-            case "debug":
-                levelText = "Debug";
-                StyleConstants.setForeground(levelStyle, new Color(0x32612E));
-                StyleConstants.setBackground(levelStyle, new Color(0xF4FFEC));
-                otherCount++;
-                break;
-            case "trace":
-                levelText = "Trace";
-                StyleConstants.setForeground(levelStyle, new Color(0x64438D));
-                StyleConstants.setBackground(levelStyle, new Color(0xFEF3FF));
-                otherCount++;
-                break;
-            default:
-                throw new Error(level);
+            throw new Error(level);
         }
 
         SimpleAttributeSet nameStyle = new SimpleAttributeSet();
@@ -151,7 +156,7 @@ public class LogDialog extends JDialog
     
     private void updateStatusBar()
     {
-        List<String> infos = new ArrayList<>();
+        List<String> infos = new ArrayList<String>();
 
         if (exceptionCount > 0)
         {

Modified: pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/ReaderBottomPanel.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/ReaderBottomPanel.java?rev=1867722&r1=1867721&r2=1867722&view=diff
==============================================================================
--- pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/ReaderBottomPanel.java (original)
+++ pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/ReaderBottomPanel.java Sun Sep 29 12:22:29 2019
@@ -16,12 +16,16 @@
  */
 package org.apache.pdfbox.debugger.ui;
 
+import java.awt.BorderLayout;
+import java.awt.Cursor;
 import java.awt.Dimension;
-
+import java.awt.Window;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import javax.swing.JLabel;
 import javax.swing.JPanel;
+import javax.swing.border.EmptyBorder;
 
-import javax.swing.JLabel;
-import java.awt.FlowLayout;
 /**
  * A panel to display at the bottom of the window for status and other stuff.
  *
@@ -29,31 +33,47 @@ import java.awt.FlowLayout;
  */
 public class ReaderBottomPanel extends JPanel
 {
-
     private JLabel statusLabel = null;
-
-    /**
-     * This is the default constructor.
-     */
+    private JLabel logLabel = null;
+    
     public ReaderBottomPanel()
     {
-        FlowLayout flowLayout = new FlowLayout();
-        this.setLayout(flowLayout);
-        this.setComponentOrientation(java.awt.ComponentOrientation.LEFT_TO_RIGHT);
-        this.setPreferredSize(new Dimension(1000, 24));
-        flowLayout.setAlignment(FlowLayout.LEFT);
+        BorderLayout layout = new BorderLayout();
+        this.setLayout(layout);
+        
         statusLabel = new JLabel();
         statusLabel.setText("Ready");
-        this.add(statusLabel, null);
-    }
+        this.add(statusLabel, BorderLayout.WEST);
 
-    /**
-     * Return the status label.
-     *
-     * @return JLabel The status label.
-     */
+        logLabel = new JLabel();
+        logLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
+        logLabel.addMouseListener(new MouseAdapter()
+        {
+            @Override
+            public void mouseClicked(MouseEvent e)
+            {
+                Window viewer = LogDialog.instance().getOwner();
+                
+                // show the log window
+                LogDialog.instance().setSize(800, 400);
+                LogDialog.instance().setVisible(true);
+                LogDialog.instance().setLocation(viewer.getLocationOnScreen().x + viewer.getWidth() / 2,
+                                                 viewer.getLocationOnScreen().y + viewer.getHeight() / 2);
+            }
+        });
+        this.add(logLabel, BorderLayout.EAST);
+
+        this.setBorder(new EmptyBorder(0, 5, 0, 5));
+        this.setPreferredSize(new Dimension(1000, 24));
+    }
+    
     public JLabel getStatusLabel()
     {
         return statusLabel;
     }
+
+    public JLabel getLogLabel()
+    {
+        return logLabel;
+    }
 }