improved PDF view
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>BelegScanner</groupId>
|
<groupId>BelegScanner</groupId>
|
||||||
<artifactId>BelegScanner</artifactId>
|
<artifactId>BelegScanner</artifactId>
|
||||||
<version>0.0.6</version>
|
<version>0.0.7</version>
|
||||||
|
|
||||||
<name>BelegScanner</name>
|
<name>BelegScanner</name>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import javax.swing.JPanel;
|
|||||||
import org.icepdf.ri.common.ComponentKeyBinding;
|
import org.icepdf.ri.common.ComponentKeyBinding;
|
||||||
import org.icepdf.ri.common.SwingController;
|
import org.icepdf.ri.common.SwingController;
|
||||||
import org.icepdf.ri.common.SwingViewBuilder;
|
import org.icepdf.ri.common.SwingViewBuilder;
|
||||||
|
import org.icepdf.ri.common.views.DocumentViewController;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -92,7 +93,7 @@ public class MainFrame extends JFrame {
|
|||||||
.addPathListener(this::setPath)
|
.addPathListener(this::setPath)
|
||||||
.addScanListener(this::scan);
|
.addScanListener(this::scan);
|
||||||
|
|
||||||
docTable.addPreviewListener(pdfViewer::openDocument);
|
docTable.addPreviewListener(this::preview);
|
||||||
|
|
||||||
int x = config.getOrCreate(APP_X, 20);
|
int x = config.getOrCreate(APP_X, 20);
|
||||||
int y = config.getOrCreate(APP_Y, 20);
|
int y = config.getOrCreate(APP_Y, 20);
|
||||||
@@ -103,20 +104,6 @@ public class MainFrame extends JFrame {
|
|||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private JPanel preview() {
|
|
||||||
// https://stackoverflow.com/a/48248739/1285585
|
|
||||||
|
|
||||||
pdfViewer = new SwingController();
|
|
||||||
SwingViewBuilder factory = new SwingViewBuilder(pdfViewer);
|
|
||||||
|
|
||||||
JPanel viewerComponentPanel = factory.buildViewerPanel();
|
|
||||||
|
|
||||||
ComponentKeyBinding.install(pdfViewer, viewerComponentPanel);
|
|
||||||
// add interactive mouse link annotation support via callback
|
|
||||||
pdfViewer.getDocumentViewController().setAnnotationCallback(new org.icepdf.ri.common.MyAnnotationCallback(pdfViewer.getDocumentViewController()));
|
|
||||||
return viewerComponentPanel;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addFieldsFor(String path) {
|
private void addFieldsFor(String path) {
|
||||||
Vector<String> marks = new Vector<>();
|
Vector<String> marks = new Vector<>();
|
||||||
Matcher matches = MARKEN.matcher(path);
|
Matcher matches = MARKEN.matcher(path);
|
||||||
@@ -219,6 +206,26 @@ public class MainFrame extends JFrame {
|
|||||||
docTable.preview(path);
|
docTable.preview(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private JPanel preview() {
|
||||||
|
// https://stackoverflow.com/a/48248739/1285585
|
||||||
|
|
||||||
|
pdfViewer = new SwingController();
|
||||||
|
SwingViewBuilder factory = new SwingViewBuilder(pdfViewer);
|
||||||
|
|
||||||
|
JPanel viewerComponentPanel = factory.buildViewerPanel();
|
||||||
|
|
||||||
|
ComponentKeyBinding.install(pdfViewer, viewerComponentPanel);
|
||||||
|
// add interactive mouse link annotation support via callback
|
||||||
|
pdfViewer.getDocumentViewController().setAnnotationCallback(new org.icepdf.ri.common.MyAnnotationCallback(pdfViewer.getDocumentViewController()));
|
||||||
|
return viewerComponentPanel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void preview(String file) {
|
||||||
|
pdfViewer.openDocument(file);
|
||||||
|
//pdfViewer.setToolBarVisible(false);
|
||||||
|
pdfViewer.setPageFitMode(DocumentViewController.PAGE_FIT_WINDOW_WIDTH, false);
|
||||||
|
}
|
||||||
|
|
||||||
private void scan(ActionEvent ev) {
|
private void scan(ActionEvent ev) {
|
||||||
updateConfig();
|
updateConfig();
|
||||||
new Thread(() -> performScan(patchedPath,dimension)).start();
|
new Thread(() -> performScan(patchedPath,dimension)).start();
|
||||||
@@ -253,6 +260,7 @@ public class MainFrame extends JFrame {
|
|||||||
updatePath();
|
updatePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void updateConfig() {
|
private void updateConfig() {
|
||||||
|
|
||||||
String prefix = "app.categories."+category+".";
|
String prefix = "app.categories."+category+".";
|
||||||
@@ -298,5 +306,4 @@ public class MainFrame extends JFrame {
|
|||||||
for (Entry<String, String> entry : fields.entrySet()) patchedPath = patchedPath.replace("$"+entry.getKey(), entry.getValue());
|
for (Entry<String, String> entry : fields.entrySet()) patchedPath = patchedPath.replace("$"+entry.getKey(), entry.getValue());
|
||||||
statusBar.setPath(patchedPath);
|
statusBar.setPath(patchedPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import java.util.Date;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -121,18 +122,6 @@ public class Toolbar extends JPanel {
|
|||||||
height.addKeyListener(dimensionListener);
|
height.addKeyListener(dimensionListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void updateDimensions() {
|
|
||||||
LOG.debug("updateDimensions()");
|
|
||||||
try {
|
|
||||||
int w = Integer.parseInt(width.getText().trim());
|
|
||||||
int h = Integer.parseInt(height.getText().trim());
|
|
||||||
dimensionListeners.forEach(listener -> listener.setDimension(new Dimension(w < 0 ? 0 : w, h < 0 ? 0 : h)));
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
LOG.warn("Invalid dimensions!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addFieldsFor(Vector<String> marks) {
|
public void addFieldsFor(Vector<String> marks) {
|
||||||
LOG.debug("addFieldsFor({})",marks);
|
LOG.debug("addFieldsFor({})",marks);
|
||||||
|
|
||||||
@@ -182,7 +171,9 @@ public class Toolbar extends JPanel {
|
|||||||
|
|
||||||
private Component categoryPicker(Configuration config) {
|
private Component categoryPicker(Configuration config) {
|
||||||
JSONObject elements = config.getOrCreate("app.categories",new JSONObject());
|
JSONObject elements = config.getOrCreate("app.categories",new JSONObject());
|
||||||
elements.keySet().forEach(categories::add);
|
Set<String> cats = elements.keySet().stream().map(Object::toString).map(String::trim).collect(Collectors.toSet());
|
||||||
|
categories = new Vector<>(cats);
|
||||||
|
categories.sort((a,b)->a.toString().compareTo(b.toString()));
|
||||||
return new SelectComboBox(categories).onUpdateText(this::updateCat);
|
return new SelectComboBox(categories).onUpdateText(this::updateCat);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,6 +275,18 @@ public class Toolbar extends JPanel {
|
|||||||
} else LOG.debug("newCat is empty!");
|
} else LOG.debug("newCat is empty!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void updateDimensions() {
|
||||||
|
LOG.debug("updateDimensions()");
|
||||||
|
try {
|
||||||
|
int w = Integer.parseInt(width.getText().trim());
|
||||||
|
int h = Integer.parseInt(height.getText().trim());
|
||||||
|
dimensionListeners.forEach(listener -> listener.setDimension(new Dimension(w < 0 ? 0 : w, h < 0 ? 0 : h)));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
LOG.warn("Invalid dimensions!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void updateField(String name, String val) {
|
private void updateField(String name, String val) {
|
||||||
LOG.debug("updateField({},{})",name,val);
|
LOG.debug("updateField({},{})",name,val);
|
||||||
fieldListeners.forEach(l -> l.setField(name,val));
|
fieldListeners.forEach(l -> l.setField(name,val));
|
||||||
|
|||||||
Reference in New Issue
Block a user