Skip to content
Commits on Source (4)
......@@ -60,7 +60,7 @@ Known Limitations and Problems
See the issue tracker at https://issues.apache.org/jira/browse/PDFBOX for
the full list of known issues and requested features. Some of the more
commont issues are:
common issues are:
1. You get text like "G38G43G36G51G5" instead of what you expect when you are
extracting text. This is because the characters are a meaningless internal
......
Release Notes -- Apache PDFBox -- Version 2.0.17
Release Notes -- Apache PDFBox -- Version 2.0.18
Introduction
------------
The Apache PDFBox library is an open source Java tool for working with PDF documents.
This is an incremental bugfix release based on the earlier 2.0.16 release. It contains
This is an incremental bugfix release based on the earlier 2.0.17 release. It contains
a couple of fixes and small improvements.
For more details on these changes and all the other fixes and improvements
......@@ -14,47 +14,58 @@ PDFBox issue tracker at https://issues.apache.org/jira/browse/PDFBOX.
Bug
[PDFBOX-4579] - IndexOutOfBoundsException when setting DefaultFontProvider in FontMapper
[PDFBOX-4580] - PDFTextStripper::getText() lead to OutOfMemoryError: Java heap space
[PDFBOX-4581] - Exception XRSurfaceData.getRaster not implemented yet on Swing, Linux
[PDFBOX-4584] - Java 7 compile error
[PDFBOX-4585] - remove message "OpenType Layout tables used in font ... are not implemented"
[PDFBOX-4586] - Annotation widgets without AP not detected by preflight
[PDFBOX-4587] - SASLPrep declares that u2070E is private use
[PDFBOX-4589] - PDPageContent stream warns about overwriting in overwrite mode
[PDFBOX-4592] - Preflight does not check process colorspace in DeviceN
[PDFBOX-4595] - PDCIDFontType0 getHeight return 0
[PDFBOX-4596] - Overlays with /Rotate value appear rotated in result file
[PDFBOX-4604] - Used type0 for cyrillic, losting font on android
[PDFBOX-4607] - Transparent 16 bit image doesn't display in Adobe Reader
[PDFBOX-4608] - ImageToPDF fails with single image
[PDFBOX-4610] - Copy&Paste in IOUtils.closeAndLogException()'s Javadoc
[PDFBOX-4611] - PDF validates despite wrong /Alternate in ICC colorspace
[PDFBOX-4615] - AppearanceGeneratorHelper.setAppearanceValue doesn't set the bounding box on the appearance stream correctly
[PDFBOX-4622] - Various exceptions in TTFParser.parse
[PDFBOX-4624] - COSParser: NullPointerException
[PDFBOX-4626] - ArrayIndexOutOfBounds exceptions in CmapSubtable parsing
[PDFBOX-4631] - NPE due to bounding box not being set on PDAppearanceStream
[PDFBOX-4636] - "There has been a widget with a missing page reference" and non widget annotation gets flattened
[PDFBOX-4638] - no field content after PDAcroForm.refreshAppearances() call if BBox empty
[PDFBOX-4646] - PDFToImage not working with certain formfields
[PDFBOX-4654] - PDFToImage shows reader image formats in usage
[PDFBOX-4655] - ImageIOUtil.WriteImage creates huge PNG images when used with default quality on jdk11
[PDFBOX-4659] - PDFBOX-3531 has re-appeared when trying to use "sun.java2d.cmm.kcms.KcmsServiceProvider" in JAVA 1.8_222
[PDFBOX-4661] - Regression No Unicode mapping with Identity-H font
[PDFBOX-4662] - ClassCastException: org.bouncycastle.asn1.DLTaggedObject cannot be cast to org.bouncycastle.asn1.DERTaggedObject
[PDFBOX-4665] - PDImageXObject createFromFileByExtension does not close FileInputStream in event of error
[PDFBOX-4666] - StackOverflowError with PDFTextStripper.getText()
[PDFBOX-4667] - Issue in FontMapperImpl#isCharSetMatch when font codePageRange is -1
[PDFBOX-4672] - Draws the attachment image to the PDF document, and the image displays as a black block
[PDFBOX-4674] - PDF Page Render Background Image has Gray Smudges
[PDFBOX-4678] - Use PDFontFactory. CreateDefaultFont font to render text, the exported PDF document has a mistake
[PDFBOX-4683] - Could not find referenced cmap stream Adobe-Japan1-7
[PDFBOX-4687] - "Iterator.next()" methods should throw "NoSuchElementException"
[PDFBOX-4688] - "BigDecimal(double)" should not be used
[PDFBOX-4693] - PDF documents with rotated form field(90° degrees in my case) that apply form flattening appear squ
[PDFBOX-4696] - Endless loop in OCSP certificate check
[PDFBOX-4701] - TextPosition.equal() fails after getDir()
[PDFBOX-4706] - support /UserUnit
[PDFBOX-4711] - java.lang.ClassCastException: org.apache.pdfbox.cos.COSDictionary cannot be cast to org.apache.pdfbox.cos.COSStream
[PDFBOX-4712] - Appearance dictionary should not be empty
[PDFBOX-4713] - /AS is required if /AP contains a subdictionary
[PDFBOX-4716] - ipag00303.php does not exist, mvn clean install!
New Feature
[PDFBOX-4639] - Please add Automatic-Module-Name to MANIFEST.MF
[PDFBOX-4682] - NPE at PDSimpleFont.isStandard14()
Improvement
[PDFBOX-4080] - Improve memory consumption of PDAbstractAppearanceHandler
[PDFBOX-4597] - TextPosition.getX() vs getXDirAdj()
[PDFBOX-4600] - Please clarify CTM terminology in Javadoc
[PDFBOX-4632] - Create example of PDF creation with page labels
[PDFBOX-4637] - improve exception message "IOException: Could not find font: /Helvetica"
[PDFBOX-4641] - Keywords created using PDFBox are not visible in Acrobat
[PDFBOX-4341] - [Patch] PNGConverter: PNG bytes to PDImageXObject converter
[PDFBOX-4653] - Clarify what font is missing when not in resources
[PDFBOX-4657] - Use smooth interpolation for stencils too
[PDFBOX-4685] - Add example of usage of separation color (spot color)
[PDFBOX-4686] - Add text to AcroForm examples
[PDFBOX-4689] - Invisible Signature should have empty Appearance Dictionary
[PDFBOX-4691] - JPEGFactory should not decode JPEG files when only meta data is needed
[PDFBOX-4694] - LockedContents flag
[PDFBOX-4695] - PDPropBuildDataDict missing setNonEFontNoWarn
[PDFBOX-4710] - allow precise RGB stroke colors with setStrokingColor
Wish
[PDFBOX-4699] - ERROR FeatureRecord array not alphabetically sorted by FeatureTag
Task
[PDFBOX-4625] - remove Netbeans warning: Exporting non-public type through public API
[PDFBOX-4708] - Add PDAcroFormFlattenTest to 2.0 branch
[PDFBOX-4715] - Need to add release version for maven-compiler-plugin
Sub-task
[PDFBOX-4703] - Support acroform /Ff flag for signature fields
Release Contents
----------------
......
......@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox-parent</artifactId>
<version>2.0.17</version>
<version>2.0.18</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
......
libpdfbox2-java (2.0.18-1) unstable; urgency=medium
* New upstream version 2.0.18.
* Declare compliance with Debian Policy 4.4.1.
-- Markus Koschany <apo@debian.org> Tue, 07 Jan 2020 23:58:45 +0100
libpdfbox2-java (2.0.17-1) unstable; urgency=medium
* New upstream version 2.0.17.
......
......@@ -18,7 +18,7 @@ Build-Depends:
libmaven-javadoc-plugin-java,
libpdfbox2-java,
maven-debian-helper
Standards-Version: 4.4.0
Standards-Version: 4.4.1
Vcs-Git: https://salsa.debian.org/java-team/libpdfbox2-java.git
Vcs-Browser: https://salsa.debian.org/java-team/libpdfbox2-java
Homepage: http://pdfbox.apache.org
......
......@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox-parent</artifactId>
<version>2.0.17</version>
<version>2.0.18</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
......
......@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox-parent</artifactId>
<version>2.0.17</version>
<version>2.0.18</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
......
......@@ -33,7 +33,6 @@ import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
......@@ -97,6 +96,7 @@ import org.apache.pdfbox.debugger.ui.DocumentEntry;
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;
......@@ -155,10 +155,9 @@ public class PDFDebugger extends JFrame
private static final String OS_NAME = System.getProperty("os.name").toLowerCase();
private static final boolean IS_MAC_OS = OS_NAME.startsWith("mac os x");
private JScrollPane jScrollPane1;
private JScrollPane jScrollPane2;
private javax.swing.JSplitPane jSplitPane1;
private javax.swing.JTextPane jTextPane1;
private JScrollPane jScrollPaneRight;
private javax.swing.JSplitPane jSplitPane;
private javax.swing.JTextPane jTextPane;
private ReaderBottomPanel statusBar;
private Tree tree;
private final JPanel documentPanel = new JPanel();
......@@ -203,11 +202,11 @@ public class PDFDebugger extends JFrame
*/
private void initComponents()
{
jSplitPane1 = new javax.swing.JSplitPane();
jScrollPane1 = new JScrollPane();
jSplitPane = new javax.swing.JSplitPane();
JScrollPane jScrollPaneLeft = new JScrollPane();
tree = new Tree(this);
jScrollPane2 = new JScrollPane();
jTextPane1 = new javax.swing.JTextPane();
jScrollPaneRight = new JScrollPane();
jTextPane = new javax.swing.JTextPane();
tree.setCellRenderer(new PDFTreeCellRenderer());
tree.setModel(null);
......@@ -226,14 +225,14 @@ public class PDFDebugger extends JFrame
@Override
public void windowClosing(WindowEvent evt)
{
exitForm(evt);
exitMenuItemActionPerformed(null);
}
});
windowPrefs = new WindowPrefs(this.getClass());
jScrollPane1.setBorder(new BevelBorder(BevelBorder.RAISED));
jSplitPane1.setDividerLocation(windowPrefs.getDividerLocation());
jScrollPaneLeft.setBorder(new BevelBorder(BevelBorder.RAISED));
jSplitPane.setDividerLocation(windowPrefs.getDividerLocation());
tree.addTreeSelectionListener(new TreeSelectionListener()
{
@Override
......@@ -243,14 +242,14 @@ public class PDFDebugger extends JFrame
}
});
jScrollPane1.setViewportView(tree);
jScrollPaneLeft.setViewportView(tree);
jSplitPane1.setRightComponent(jScrollPane2);
jSplitPane1.setDividerSize(3);
jSplitPane.setRightComponent(jScrollPaneRight);
jSplitPane.setDividerSize(3);
jScrollPane2.setViewportView(jTextPane1);
jScrollPaneRight.setViewportView(jTextPane);
jSplitPane1.setLeftComponent(jScrollPane1);
jSplitPane.setLeftComponent(jScrollPaneLeft);
JScrollPane documentScroller = new JScrollPane();
documentScroller.setViewportView(documentPanel);
......@@ -260,7 +259,7 @@ public class PDFDebugger extends JFrame
statusPane.getPanel().setPreferredSize(new Dimension(300, 25));
getContentPane().add(statusPane.getPanel(), BorderLayout.PAGE_START);
getContentPane().add(jSplitPane1, BorderLayout.CENTER);
getContentPane().add(jSplitPane, BorderLayout.CENTER);
statusBar = new ReaderBottomPanel();
getContentPane().add(statusBar, BorderLayout.SOUTH);
......@@ -711,12 +710,12 @@ public class PDFDebugger extends JFrame
showString(selectedNode);
return;
}
if (jSplitPane1.getRightComponent() == null
|| !jSplitPane1.getRightComponent().equals(jScrollPane2))
if (jSplitPane.getRightComponent() == null
|| !jSplitPane.getRightComponent().equals(jScrollPaneRight))
{
replaceRightComponent(jScrollPane2);
replaceRightComponent(jScrollPaneRight);
}
jTextPane1.setText(convertToString(selectedNode));
jTextPane.setText(convertToString(selectedNode));
}
catch (Exception e)
{
......@@ -978,7 +977,7 @@ public class PDFDebugger extends JFrame
if (pane == null)
{
// unsupported font type
replaceRightComponent(jScrollPane2);
replaceRightComponent(jScrollPaneRight);
return;
}
replaceRightComponent(pane);
......@@ -987,9 +986,9 @@ public class PDFDebugger extends JFrame
// replace the right component while keeping divider position
private void replaceRightComponent(Component pane)
{
int div = jSplitPane1.getDividerLocation();
jSplitPane1.setRightComponent(pane);
jSplitPane1.setDividerLocation(div);
int div = jSplitPane.getDividerLocation();
jSplitPane.setRightComponent(pane);
jSplitPane.setDividerLocation(div);
}
private void showString(Object selectedNode)
......@@ -1068,18 +1067,21 @@ public class PDFDebugger extends JFrame
}
else if( selectedNode instanceof COSStream )
{
COSStream stream = (COSStream) selectedNode;
InputStream in = null;
try
{
COSStream stream = (COSStream) selectedNode;
InputStream in = stream.createInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copy(in, baos);
data = baos.toString();
in = stream.createInputStream();
data = new String(IOUtils.toByteArray(in));
}
catch (IOException e)
{
throw new RuntimeException(e);
}
finally
{
IOUtils.closeQuietly(in);
}
}
else if( selectedNode instanceof MapEntry )
{
......@@ -1113,7 +1115,7 @@ public class PDFDebugger extends JFrame
windowPrefs.setExtendedState(getExtendedState());
this.setExtendedState(Frame.NORMAL);
windowPrefs.setBounds(getBounds());
windowPrefs.setDividerLocation(jSplitPane1.getDividerLocation());
windowPrefs.setDividerLocation(jSplitPane.getDividerLocation());
performApplicationExit();
}
......@@ -1181,14 +1183,6 @@ public class PDFDebugger extends JFrame
}
}
/**
* Exit the Application.
*/
private void exitForm(WindowEvent evt)
{
exitMenuItemActionPerformed(null);
}
/**
* Entry point.
*
......@@ -1213,17 +1207,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"})
......@@ -1252,6 +1235,23 @@ 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)
{
......
......@@ -26,6 +26,7 @@ import javax.swing.table.AbstractTableModel;
/**
* This the table model for showing DeviceN color space which extends AbstractTableModel.
*/
@SuppressWarnings({"serial","squid:S1948"})
public class DeviceNTableModel extends AbstractTableModel
{
private static final String[] COLUMNNAMES = new String[] { "Colorant", "Maximum", "Minimum"};
......
......@@ -67,7 +67,7 @@ class AnnotFlag extends Flag
new Object[]{7, "ReadOnly", annotation.isReadOnly()},
new Object[]{8, "Locked", annotation.isLocked()},
new Object[]{9, "ToggleNoView", annotation.isToggleNoView()},
new Object[]{10, "LockedContents", annotation.isLocked()}
new Object[]{10, "LockedContents", annotation.isLockedContents()}
};
}
}
......@@ -53,7 +53,7 @@ class FieldFlag extends Flag
{
return "Choice field flag";
}
return null;
return "Field flag";
}
@Override
......@@ -80,7 +80,7 @@ class FieldFlag extends Flag
{
return getChoiceFieldFlagBits(flagValue);
}
return null;
return getFieldFlagBits(flagValue);
}
private Object[][] getTextFieldFlagBits(final int flagValue)
......@@ -127,6 +127,15 @@ class FieldFlag extends Flag
};
}
private Object[][] getFieldFlagBits(final int flagValue)
{
return new Object[][]{
new Object[]{1, "ReadOnly", isFlagBitSet(flagValue, 1)},
new Object[]{2, "Required", isFlagBitSet(flagValue, 2)},
new Object[]{3, "NoExport", isFlagBitSet(flagValue, 3)}
};
}
/**
* Check the corresponding flag bit if set or not
* @param flagValue the flag integer
......
......@@ -37,7 +37,7 @@ import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
/**
* @author Khyrul Bashar
*
* A class that provides the COSStream in different version and related informations.
* A class that provides the COSStream in various views and related information.
*/
public class Stream
{
......@@ -97,12 +97,7 @@ public class Stream
*/
public List<String> getFilterList()
{
List<String> list = new ArrayList<String>();
for (Map.Entry<String, List<String>> entry : filters.entrySet())
{
list.add(entry.getKey());
}
return list;
return new ArrayList(filters.keySet());
}
/**
......
......@@ -101,7 +101,7 @@ class StreamImageView implements ActionListener, AncestorListener
BufferedImage rotatedImage = ImageUtil.getRotatedImage(origin, rotation);
int resizedWidth = (int) (rotatedImage.getWidth() * scale);
int resizedHeight = (int) (rotatedImage.getHeight() * scale);
return rotatedImage.getScaledInstance(resizedWidth, resizedHeight, BufferedImage.SCALE_SMOOTH);
return rotatedImage.getScaledInstance(resizedWidth, resizedHeight, Image.SCALE_SMOOTH);
}
@Override
......
......@@ -219,7 +219,7 @@ public class StreamPane implements ActionListener
}
}
private void requestImageShowing() throws IOException
private void requestImageShowing()
{
if (stream.isImage())
{
......
/*
* Copyright 2016 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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 static final boolean INFO = true;
private static final boolean TRACE = false;
private static 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);
}
}
......@@ -39,6 +39,8 @@ import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.KeyStroke;
import javax.swing.ScrollPaneConstants;
import javax.swing.WindowConstants;
/**
* A dialog to display a runtime exception stack trace.
......@@ -110,7 +112,7 @@ public class ErrorDialog extends JDialog
{
setIconImage(((ImageIcon) icon).getImage());
}
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
error = t;
message = createErrorMessage(error);
main = createContent();
......@@ -252,8 +254,8 @@ public class ErrorDialog extends JDialog
stacktrace = new JTextPane();
stacktrace.setEditable(false);
return new JScrollPane(stacktrace,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
}
/**
......
/*
* Copyright 2016 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.pdfbox.debugger.ui;
import java.awt.Color;
import java.awt.Container;
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
*/
@SuppressWarnings({"serial","squid:MaximumInheritanceDepth"})
public class LogDialog extends JDialog
{
private static LogDialog instance;
private final JLabel logLabel;
private final JTextPane textPane;
private final 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 static void init(Frame owner, JLabel logLabel)
{
instance = new LogDialog(owner, logLabel);
}
public static LogDialog instance()
{
return instance;
}
public void log(String name, String level, Object o, Throwable throwable)
{
StyledDocument doc = textPane.getStyledDocument();
String levelText;
SimpleAttributeSet levelStyle = new SimpleAttributeSet();
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
{
throw new Error(level);
}
SimpleAttributeSet nameStyle = new SimpleAttributeSet();
StyleConstants.setForeground(nameStyle, new Color(0x6A6A6A));
String shortName = name.substring(name.lastIndexOf('.') + 1);
String message = o == null ? "(null)" : 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("");
}
// these two just to avoid the "overridable method call in constructor" warning
@Override
public final Container getContentPane()
{
return super.getContentPane();
}
@Override
public final void pack()
{
super.pack();
}
}
......@@ -306,7 +306,7 @@ public class PDFTreeModel implements TreeModel
@Override
public boolean isLeaf(Object node)
{
boolean isLeaf = !(node instanceof COSDictionary ||
return !(node instanceof COSDictionary ||
node instanceof COSArray ||
node instanceof COSDocument ||
node instanceof DocumentEntry ||
......@@ -314,7 +314,6 @@ public class PDFTreeModel implements TreeModel
node instanceof COSObject ||
(node instanceof MapEntry && !isLeaf(((MapEntry)node).getValue()) ) ||
(node instanceof ArrayEntry && !isLeaf(((ArrayEntry)node).getValue()) ));
return isLeaf;
}
/** Removes a listener previously added with
......
......@@ -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;
private JLabel logLabel = null;
/**
* This is the default constructor.
*/
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);
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));
}
/**
* Return the status label.
*
* @return JLabel The status label.
*/
public JLabel getStatusLabel()
{
return statusLabel;
}
public JLabel getLogLabel()
{
return logLabel;
}
}
......@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox-parent</artifactId>
<version>2.0.17</version>
<version>2.0.18</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
......