You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ja...@apache.org on 2016/10/18 22:29:58 UTC
svn commit: r1765524 - in
/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger:
PDFDebugger.java ui/DebugLog.java ui/LogDialog.java ui/ReaderBottomPanel.java
Author: jahewson
Date: Tue Oct 18 22:29:58 2016
New Revision: 1765524
URL: http://svn.apache.org/viewvc?rev=1765524&view=rev
Log:
PDFBOX-2941: add log messages window
Added:
pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/DebugLog.java (with props)
pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/LogDialog.java (with props)
Modified:
pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java
pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/ReaderBottomPanel.java
Modified: pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java?rev=1765524&r1=1765523&r2=1765524&view=diff
==============================================================================
--- pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java (original)
+++ pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java Tue Oct 18 22:29:58 2016
@@ -92,6 +92,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;
@@ -180,6 +181,10 @@ public class PDFDebugger extends JFrame
isPageMode = viewPages;
loadConfiguration();
initComponents();
+
+ // use our custom logger
+ LogDialog.init(this, statusBar.getLogLabel());
+ System.setProperty("org.apache.commons.logging.Log", "org.apache.pdfbox.debugger.ui.DebugLog");
}
/**
@@ -239,7 +244,7 @@ public class PDFDebugger extends JFrame
File file = new File(filename);
if (file.exists())
{
- viewer.readPDFFile( filename, password );
+ viewer.readPDFFile(filename, password);
}
}
viewer.setVisible(true);
@@ -1239,6 +1244,8 @@ public class PDFDebugger extends JFrame
}
currentFilePath = file.getPath();
recentFiles.removeFile(file.getPath());
+ LogDialog.instance().clear();
+
parseDocument( file, password );
initTree();
Added: pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/DebugLog.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/DebugLog.java?rev=1765524&view=auto
==============================================================================
--- pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/DebugLog.java (added)
+++ pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/DebugLog.java Tue Oct 18 22:29:58 2016
@@ -0,0 +1,149 @@
+package org.apache.pdfbox.debugger.ui;
+
+import org.apache.commons.logging.Log;
+
+/**
+ * Custom Log implementation which forwards to LogDialog.
+ *
+ * @author John Hewson
+ */
+public class DebugLog implements Log
+{
+ private final String name;
+
+ // hardcoded, but kept to aid with debugging custom builds
+ private final boolean INFO = true;
+ private final boolean TRACE = false;
+ private final boolean DEBUG = false;
+
+ public DebugLog(String name)
+ {
+ this.name = name;
+ }
+
+ @Override
+ public void debug(Object o)
+ {
+ if (DEBUG)
+ {
+ LogDialog.instance().log(name, "debug", o, null);
+ }
+ }
+
+ @Override
+ public void debug(Object o, Throwable throwable)
+ {
+ if (DEBUG)
+ {
+ LogDialog.instance().log(name, "debug", o, throwable);
+ }
+ }
+
+ @Override
+ public void error(Object o)
+ {
+ LogDialog.instance().log(name, "error", o, null);
+ }
+
+ @Override
+ public void error(Object o, Throwable throwable)
+ {
+ LogDialog.instance().log(name, "error", o, throwable);
+ }
+
+ @Override
+ public void fatal(Object o)
+ {
+ LogDialog.instance().log(name, "fatal", o, null);
+ }
+
+ @Override
+ public void fatal(Object o, Throwable throwable)
+ {
+ LogDialog.instance().log(name, "fatal", o, throwable);
+ }
+
+ @Override
+ public void info(Object o)
+ {
+ if (INFO)
+ {
+ LogDialog.instance().log(name, "info", o, null);
+ }
+ }
+
+ @Override
+ public void info(Object o, Throwable throwable)
+ {
+ if (INFO)
+ {
+ LogDialog.instance().log(name, "info", o, throwable);
+ }
+ }
+
+ @Override
+ public boolean isDebugEnabled()
+ {
+ return DEBUG;
+ }
+
+ @Override
+ public boolean isErrorEnabled()
+ {
+ return true;
+ }
+
+ @Override
+ public boolean isFatalEnabled()
+ {
+ return true;
+ }
+
+ @Override
+ public boolean isInfoEnabled()
+ {
+ return INFO;
+ }
+
+ @Override
+ public boolean isTraceEnabled()
+ {
+ return TRACE;
+ }
+
+ @Override
+ public boolean isWarnEnabled()
+ {
+ return true;
+ }
+
+ @Override
+ public void trace(Object o)
+ {
+ if (TRACE)
+ {
+ LogDialog.instance().log(name, "trace", o, null);
+ }
+ }
+
+ @Override
+ public void trace(Object o, Throwable throwable)
+ {
+ if (TRACE)
+ {
+ LogDialog.instance().log(name, "trace", o, throwable);
+ }
+ }
+
+ @Override
+ public void warn(Object o)
+ {
+ LogDialog.instance().log(name, "warn", o, null);
+ }
+
+ @Override
+ public void warn(Object o, Throwable throwable)
+ {
+ LogDialog.instance().log(name, "warn", o, throwable);
+ }
+}
Propchange: pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/DebugLog.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/LogDialog.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/LogDialog.java?rev=1765524&view=auto
==============================================================================
--- pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/LogDialog.java (added)
+++ pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/LogDialog.java Tue Oct 18 22:29:58 2016
@@ -0,0 +1,193 @@
+package org.apache.pdfbox.debugger.ui;
+
+import java.awt.Color;
+import java.awt.Frame;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextPane;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.StyleConstants;
+import javax.swing.text.StyledDocument;
+
+/**
+ * Custom log dialog.
+ *
+ * @author John Hewson
+ */
+public class LogDialog extends JDialog
+{
+ private static LogDialog instance;
+
+ public static void init(Frame owner, JLabel logLabel)
+ {
+ instance = new LogDialog(owner, logLabel);
+ }
+
+ public static LogDialog instance()
+ {
+ return instance;
+ }
+
+ private final JLabel logLabel;
+ private final JTextPane textPane;
+ private JScrollPane scrollPane;
+ private int fatalCount = 0;
+ private int errorCount = 0;
+ private int warnCount = 0;
+ private int otherCount = 0;
+ private int exceptionCount = 0;
+
+ private LogDialog(Frame owner, JLabel logLabel)
+ {
+ super(owner);
+ this.logLabel = logLabel;
+
+ textPane = new JTextPane();
+ scrollPane = new JScrollPane(textPane);
+ getContentPane().add(scrollPane);
+
+ this.pack();
+ }
+
+ public void log(String name, String level, Object o, Throwable throwable)
+ {
+ StyledDocument doc = textPane.getStyledDocument();
+
+ String levelText;
+ SimpleAttributeSet levelStyle = new SimpleAttributeSet();
+ if (level.equals("fatal"))
+ {
+ levelText = "Fatal";
+ StyleConstants.setForeground(levelStyle, Color.WHITE);
+ StyleConstants.setBackground(levelStyle, Color.BLACK);
+ fatalCount++;
+ }
+ else if (level.equals("error"))
+ {
+ levelText = "Error";
+ StyleConstants.setForeground(levelStyle, new Color(0xFF291F));
+ StyleConstants.setBackground(levelStyle, new Color(0xFFF0F0));
+ errorCount++;
+ }
+ else if (level.equals("warn"))
+ {
+ levelText = "Warning";
+ StyleConstants.setForeground(levelStyle, new Color(0x614201));
+ StyleConstants.setBackground(levelStyle, new Color(0xFFFCE5));
+ warnCount++;
+ }
+ else if (level.equals("info"))
+ {
+ levelText = "Info";
+ StyleConstants.setForeground(levelStyle, new Color(0x203261));
+ StyleConstants.setBackground(levelStyle, new Color(0xE2E8FF));
+ otherCount++;
+ }
+ else if (level.equals("debug"))
+ {
+ levelText = "Debug";
+ StyleConstants.setForeground(levelStyle, new Color(0x32612E));
+ StyleConstants.setBackground(levelStyle, new Color(0xF4FFEC));
+ otherCount++;
+ }
+ else if (level.equals("trace"))
+ {
+ levelText = "Trace";
+ StyleConstants.setForeground(levelStyle, new Color(0x64438D));
+ StyleConstants.setBackground(levelStyle, new Color(0xFEF3FF));
+ otherCount++;
+ }
+ else
+ {
+ throw new Error(level);
+ }
+
+ SimpleAttributeSet nameStyle = new SimpleAttributeSet();
+ StyleConstants.setForeground(nameStyle, new Color(0x6A6A6A));
+
+ String shortName = name.substring(name.lastIndexOf('.') + 1);
+ String message = o.toString();
+
+ if (throwable != null)
+ {
+ StringWriter sw = new StringWriter();
+ throwable.printStackTrace(new PrintWriter(sw));
+ message += "\n " + sw.toString();
+ exceptionCount++;
+ }
+
+ try
+ {
+ doc.insertString(doc.getLength(), " " + levelText + " ", levelStyle);
+ doc.insertString(doc.getLength(), " [" + shortName + "]", nameStyle);
+ doc.insertString(doc.getLength(), " " + message + "\n", null);
+ }
+ catch (BadLocationException e)
+ {
+ throw new Error(e);
+ }
+ textPane.setCaretPosition(doc.getLength());
+
+ // update status bar with new counts
+ updateStatusBar();
+ }
+
+ private void updateStatusBar()
+ {
+ List<String> infos = new ArrayList<String>();
+
+ if (exceptionCount > 0)
+ {
+ infos.add(exceptionCount + " exception" + (errorCount > 1 ? "s" : ""));
+ }
+
+ if (fatalCount > 0)
+ {
+ infos.add(errorCount + " error" + (errorCount > 1 ? "s" : ""));
+ }
+
+ if (errorCount > 0)
+ {
+ infos.add(errorCount + " error" + (errorCount > 1 ? "s" : ""));
+ }
+
+ if (warnCount > 0)
+ {
+ infos.add(warnCount + " warning" + (warnCount > 1 ? "s" : ""));
+ }
+
+ if (otherCount > 0)
+ {
+ infos.add(otherCount + " message" + (otherCount > 1 ? "s" : ""));
+ }
+
+ String info = "";
+ for (String str : infos)
+ {
+ if (info.length() > 0)
+ {
+ info += ", ";
+ }
+ info += str;
+ }
+
+ logLabel.setText(info);
+ }
+
+ public void clear()
+ {
+ fatalCount = 0;
+ errorCount = 0;
+ warnCount = 0;
+ otherCount = 0;
+ exceptionCount = 0;
+ textPane.setText("");
+ logLabel.setText("");
+ }
+}
Propchange: pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/LogDialog.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/ReaderBottomPanel.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/ReaderBottomPanel.java?rev=1765524&r1=1765523&r2=1765524&view=diff
==============================================================================
--- pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/ReaderBottomPanel.java (original)
+++ pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/ReaderBottomPanel.java Tue Oct 18 22:29:58 2016
@@ -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;
+ }
}