Skip to content

Commit

Permalink
Merge branch 'master' of github.com:pcorless/icepdf
Browse files Browse the repository at this point in the history
  • Loading branch information
gtache committed Feb 28, 2020
2 parents 693213f + 25234f1 commit db0b33f
Show file tree
Hide file tree
Showing 24 changed files with 4,002 additions and 4,429 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ public class FontFactory {

// dynamic property to switch between font engine and awt font substitution.
private static boolean awtFontSubstitution;
private static boolean useNFontIfAvailable;

static {
// turn on font file loading using awt, can cause the jvm to crash
// if the font file is corrupt.
awtFontLoading =
Defs.sysPropertyBoolean("org.icepdf.core.awtFontLoading",
false);
useNFontIfAvailable = Defs.sysPropertyBoolean("org.icepdf.core.useNFont", true);

}

Expand Down Expand Up @@ -76,6 +78,7 @@ public class FontFactory {
"org.icepdf.core.pobjects.fonts.nfont.NFontType1";
private static final String NFONT_TRUE_TYPE_3 =
"org.icepdf.core.pobjects.fonts.nfont.NFontType3";

static {
// check class bath for NFont library, and declare results.
try {
Expand Down Expand Up @@ -312,7 +315,7 @@ public boolean foundFontEngine() {
// keep quiet
}

return foundNFont && !awtFontSubstitution;
return foundNFont && !awtFontSubstitution && useNFontIfAvailable;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.icepdf.core.util.content;

import org.icepdf.core.pobjects.Resources;
import org.icepdf.core.util.Defs;
import org.icepdf.core.util.Library;

import java.lang.reflect.Constructor;
Expand Down Expand Up @@ -44,7 +45,7 @@ public class ContentParserFactory {
// check class bath for NFont library, and declare results.
try {
Class.forName(N_CONTENT_PARSER);
foundPro = true;
foundPro = Defs.sysPropertyBoolean("org.icepdf.core.useNFont", true);
} catch (ClassNotFoundException e) {
logger.log(Level.FINE, "ICEpdf PRO was not found on the class path");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.icepdf.ri.common;

import javax.swing.*;
import javax.swing.plaf.basic.BasicCheckBoxMenuItemUI;
import javax.swing.plaf.synth.SynthCheckBoxMenuItemUI;

/**
Expand All @@ -19,11 +20,20 @@ public PersistentJCheckBoxMenuItem(String title, boolean b) {
@Override
public void updateUI() {
super.updateUI();
setUI(new SynthCheckBoxMenuItemUI() {
@Override
protected void doClick(MenuSelectionManager msm) {
menuItem.doClick(0);
}
});
if (getUI() instanceof SynthCheckBoxMenuItemUI) {
setUI(new SynthCheckBoxMenuItemUI() {
@Override
protected void doClick(MenuSelectionManager msm) {
menuItem.doClick(0);
}
});
} else {
setUI(new BasicCheckBoxMenuItemUI() {
@Override
protected void doClick(MenuSelectionManager msm) {
menuItem.doClick(0);
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
*/
package org.icepdf.ri.common;

import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.stage.FileChooser;
import org.icepdf.core.SecurityCallback;
import org.icepdf.core.exceptions.PDFException;
import org.icepdf.core.exceptions.PDFSecurityException;
Expand Down Expand Up @@ -53,9 +50,9 @@
import org.icepdf.ri.common.views.annotations.summary.AnnotationSummaryFrame;
import org.icepdf.ri.common.views.destinations.DestinationComponent;
import org.icepdf.ri.util.BareBonesBrowserLaunch;
import org.icepdf.ri.util.ViewerPropertiesManager;
import org.icepdf.ri.util.TextExtractionTask;
import org.icepdf.ri.util.URLAccess;
import org.icepdf.ri.util.ViewerPropertiesManager;
import org.icepdf.ri.viewer.WindowManager;

import javax.print.attribute.PrintRequestAttributeSet;
Expand Down Expand Up @@ -3089,12 +3086,15 @@ public void commonNewDocumentHandling(String fileDescription) {
// add to the main pdfContentPanel the document peer
if (viewer != null) {
File f = new File(fileDescription);
String argument = f.exists() ? f.getName() : fileDescription;
Object[] messageArguments = {argument};
MessageFormat formatter = new MessageFormat(
messageBundle.getString("viewer.window.title.open.default"));
String title = null;
if (document.getInfo() != null) {
title = document.getInfo().getTitle();
}
String filename = f.exists() ? f.getName() : fileDescription;
Object[] messageArguments = title == null ? new String[]{filename} : new String[]{title, filename};
String titleResource = title == null ? "notitle" : "default";
MessageFormat formatter = new MessageFormat(messageBundle.getString("viewer.window.title.open." + titleResource));
viewer.setTitle(formatter.format(messageArguments));

}

// disable the annotation properties panel by default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Arrays;
import java.util.ResourceBundle;
import java.util.prefs.Preferences;

Expand Down Expand Up @@ -113,8 +114,38 @@ public AnnotationPreferencesPanel(SwingController controller, ViewerPropertiesMa
"viewer.dialog.viewerPreferences.section.annotations.recent.colors.label")),
0, 0, 1, 1);
addGB(recentColorsPanel, resetResentColorsButton, 1, 0, 1, 1);
constraints.fill = GridBagConstraints.BOTH;
constraints.weightx = 1.0;
constraints.weighty = 1.0;
constraints.anchor = GridBagConstraints.NORTH;
constraints.insets = new Insets(5, 5, 5, 5);
JPanel miscSettingsPanel = new JPanel(new GridBagLayout());
miscSettingsPanel.setBorder(new TitledBorder(
new EtchedBorder(EtchedBorder.LOWERED),
messageBundle.getString("viewer.dialog.viewerPreferences.section.annotations.misc.border.label"),
TitledBorder.LEFT,
TitledBorder.DEFAULT_POSITION));
JCheckBox autoselectBox = new JCheckBox(messageBundle.getString(
"viewer.dialog.viewerPreferences.section.annotations.misc.autoselect.checkbox"));
autoselectBox.setSelected(ViewerPropertiesManager.getInstance().getPreferences().
getBoolean(ViewerPropertiesManager.PROPERTY_ANNOTATION_INK_SELECTION_ENABLED, false));
autoselectBox.addActionListener(actionEvent -> {
JCheckBox box = (JCheckBox) actionEvent.getSource();
boolean selected = box.isSelected();
String[] allProperties = {
ViewerPropertiesManager.PROPERTY_ANNOTATION_CIRCLE_SELECTION_ENABLED,
ViewerPropertiesManager.PROPERTY_ANNOTATION_HIGHLIGHT_SELECTION_ENABLED,
ViewerPropertiesManager.PROPERTY_ANNOTATION_INK_SELECTION_ENABLED,
ViewerPropertiesManager.PROPERTY_ANNOTATION_LINE_SELECTION_ENABLED,
ViewerPropertiesManager.PROPERTY_ANNOTATION_LINK_SELECTION_ENABLED,
ViewerPropertiesManager.PROPERTY_ANNOTATION_SQUARE_SELECTION_ENABLED,
ViewerPropertiesManager.PROPERTY_ANNOTATION_TEXT_SELECTION_ENABLED,
ViewerPropertiesManager.PROPERTY_ANNOTATION_FREE_TEXT_SELECTION_ENABLED};
Arrays.stream(allProperties).forEach(p -> ViewerPropertiesManager.getInstance().getPreferences().putBoolean(p, selected));
});
addGB(miscSettingsPanel, autoselectBox, 0, 0, 1, 1);

// add the two panels.
// add the panels.
constraints.fill = GridBagConstraints.BOTH;
constraints.weightx = 1.0;
constraints.weighty = 1.0;
Expand All @@ -123,10 +154,11 @@ public AnnotationPreferencesPanel(SwingController controller, ViewerPropertiesMa

addGB(this, namedColorsPanel, 0, 0, 1, 1);
addGB(this, recentColorsPanel, 0, 1, 1, 1);
addGB(this, miscSettingsPanel, 0, 2, 1, 1);

// little spacer
constraints.weighty = 1.0;
addGB(this, new Label(" "), 0, 2, 1, 1);
addGB(this, new Label(" "), 0, 3, 1, 1);
}

private void buildNamedColors(JPanel panel, ResourceBundle messageBundle) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package org.icepdf.ri.common.preferences;

import org.icepdf.ri.common.views.Controller;
import org.icepdf.ri.util.ViewerPropertiesManager;

import javax.swing.*;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.io.File;
import java.util.ResourceBundle;

public class ExImportPreferencesPanel extends JPanel {

private final GridBagConstraints constraints;

public ExImportPreferencesPanel(Controller controller, ViewerPropertiesManager propertiesManager,
ResourceBundle messageBundle, Dialog parent) {
super(new GridBagLayout());
setAlignmentY(JPanel.TOP_ALIGNMENT);
final JButton exportButton = new JButton(messageBundle.getString(
"viewer.dialog.viewerPreferences.section.eximport.export.button.label"));
final JButton importButton = new JButton(messageBundle.getString(
"viewer.dialog.viewerPreferences.section.eximport.import.button.label"));

final JPanel panel = new JPanel(new GridBagLayout());
panel.setAlignmentY(JPanel.TOP_ALIGNMENT);
panel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED),
messageBundle.getString("viewer.dialog.viewerPreferences.section.eximport.border.label"),
TitledBorder.LEFT,
TitledBorder.DEFAULT_POSITION));

constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.NONE;
constraints.weightx = 1;
constraints.weighty = 0;
constraints.anchor = GridBagConstraints.CENTER;
constraints.insets = new Insets(5, 5, 5, 5);

exportButton.addActionListener(actionEvent -> {
final FileDialog chooser = new FileDialog(parent);
chooser.setMultipleMode(false);
chooser.setMode(FileDialog.SAVE);
chooser.setVisible(true);
final String dir = chooser.getDirectory();
final String file = chooser.getFile();
if (dir != null && file != null) {
if (ViewerPropertiesManager.exportProperties(new File(dir + file))) {
showSuccess(messageBundle, "export");
} else {
showFailure(messageBundle, "export");
}
}
});
importButton.addActionListener(actionEvent -> {
final FileDialog chooser = new FileDialog(parent);
chooser.setMultipleMode(false);
chooser.setMode(FileDialog.LOAD);
chooser.setVisible(true);
final String dir = chooser.getDirectory();
final String file = chooser.getFile();
if (dir != null && file != null) {
if (ViewerPropertiesManager.importProperties(new File(dir + file))) {
showSuccess(messageBundle, "import");
} else {
showFailure(messageBundle, "import");
}
}
});
addGB(panel, exportButton, 0, 0, 1, 1);
addGB(panel, importButton, 1, 0, 1, 1);
constraints.anchor = GridBagConstraints.NORTHWEST;
constraints.fill = GridBagConstraints.BOTH;
addGB(this, panel, 0, 0, 1, 1);
constraints.weighty = 1.0;
addGB(this, new JLabel(" "), 0, 1, 1, 1);
}

private void showSuccess(ResourceBundle messageBundle, String action) {
JOptionPane.showMessageDialog(this,
messageBundle.getString("viewer.dialog.viewerPreferences.section.eximport." + action + ".success.label"),
messageBundle.getString("viewer.dialog.viewerPreferences.section.eximport." + action + ".success.title"),
JOptionPane.INFORMATION_MESSAGE);
}

private void showFailure(ResourceBundle messageBundle, String action) {
JOptionPane.showMessageDialog(this,
messageBundle.getString("viewer.dialog.viewerPreferences.section.eximport." + action + ".fail.label"),
messageBundle.getString("viewer.dialog.viewerPreferences.section.eximport." + action + ".fail.title"),
JOptionPane.ERROR_MESSAGE);
}

private void addGB(JPanel layout, Component component,
int x, int y,
int rowSpan, int colSpan) {
constraints.gridx = x;
constraints.gridy = y;
constraints.gridwidth = rowSpan;
constraints.gridheight = colSpan;
layout.add(component, constraints);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
* The PreferencesDialog exposes numbers settings that would normally only be configurable with system properties.
* Default values can still be added to the ICEpdfDefault.properties. As a general rule system properties should
* be used when using the rendering core only and the PreferenceDialog should be used when configuring the Viewer RI.
*
* Panel visibility can be controlled with the followign preference values.
* <p>
* Panel visibility can be controlled with the following preference values.
* <ul>
* <li>PropertiesManager.PROPERTY_SHOW_PREFERENCES_GENERAL</li>
* <li>PropertiesManager.PROPERTY_SHOW_PREFERENCES_ANNOTATIONS</li>
Expand Down Expand Up @@ -101,6 +101,12 @@ public PreferencesDialog(JFrame frame, SwingController controller,
messageBundle.getString("viewer.dialog.viewerPreferences.section.advanced.title"),
new AdvancedPreferencesPanel(controller, propertiesManager, messageBundle));
}
if (propertiesManager.checkAndStoreBooleanProperty(ViewerPropertiesManager.PROPERTY_SHOW_PREFERENCES_EXIMPORT, true)) {
propertiesTabbedPane.addTab(
messageBundle.getString("viewer.dialog.viewerPreferences.section.eximport.title"),
new ExImportPreferencesPanel(controller, propertiesManager, messageBundle, this));
}


JPanel layoutPanel = new JPanel(new GridBagLayout());

Expand All @@ -117,9 +123,7 @@ public PreferencesDialog(JFrame frame, SwingController controller,

this.setLayout(new BorderLayout(5, 5));
this.add(layoutPanel, BorderLayout.NORTH);
// this.pack();
setSize(575, 475);
validate();
this.pack();
setLocationRelativeTo(frame);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.KeyListener;
import java.awt.event.*;
import java.awt.geom.Point2D;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
Expand Down Expand Up @@ -137,7 +134,7 @@ public void actionPerformed(ActionEvent e) {
}
};
InputMap inputMap = documentViewScrollPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
inputMap.put(KeyStroke.getKeyStroke("DELETE"), "removeSelectedAnnotation");
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "removeSelectedAnnotation");
documentViewScrollPane.getActionMap().put("removeSelectedAnnotation", deleteAnnotation);
}

Expand Down Expand Up @@ -1304,7 +1301,7 @@ public void addPropertyChangeListener(PropertyChangeListener l) {
public void deleteCurrentAnnotation() {
AbstractAnnotationComponent annotationComponent = (AbstractAnnotationComponent)
documentViewModel.getCurrentAnnotation();
if (!(annotationComponent instanceof PopupAnnotationComponent)) {
if (annotationComponent != null && !(annotationComponent instanceof PopupAnnotationComponent)) {
deleteAnnotation(annotationComponent);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,7 @@ public void mousePressed(MouseEvent e) {
annotation.setCurrentAppearance(Annotation.APPEARANCE_STREAM_DOWN_KEY);
}

if (documentViewController.getDocumentViewModel().getViewToolMode() ==
DocumentViewModel.DISPLAY_TOOL_SELECTION &&
isInteractiveAnnotationsEnabled &&
if (isInteractiveAnnotationsEnabled &&
!annotation.getFlagReadOnly()) {
initiateMouseMoved(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.icepdf.ri.common.views.annotations.summary;

import org.icepdf.core.pobjects.Document;
import org.icepdf.ri.common.MutableDocument;
import org.icepdf.ri.common.views.Controller;
import org.icepdf.ri.images.Images;
Expand All @@ -39,9 +40,13 @@ public AnnotationSummaryFrame(Controller controller) {

@Override
public void refreshDocumentInstance() {
if (controller.getDocument() != null) {

Object[] messageArguments = new Object[]{controller.getViewerFrame().getTitle()};
Document document = controller.getDocument();
if (document != null) {
String title = null;
if (document.getInfo() != null) {
title = document.getInfo().getTitle();
}
Object[] messageArguments = {title != null ? title : controller.getViewerFrame().getTitle()};
MessageFormat formatter = new MessageFormat(
messageBundle.getString("viewer.window.annotationSummary.title.open.default"));
setTitle(formatter.format(messageArguments));
Expand Down
Loading

0 comments on commit db0b33f

Please sign in to comment.