|
|
@ -1,6 +1,7 @@ |
|
|
|
package de.srsoftware.belegscanner.gui; |
|
|
|
package de.srsoftware.belegscanner.gui; |
|
|
|
|
|
|
|
|
|
|
|
import java.awt.BorderLayout; |
|
|
|
import java.awt.BorderLayout; |
|
|
|
|
|
|
|
import java.awt.Color; |
|
|
|
import java.awt.Dimension; |
|
|
|
import java.awt.Dimension; |
|
|
|
import java.awt.Point; |
|
|
|
import java.awt.Point; |
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
import java.awt.event.ActionEvent; |
|
|
@ -15,8 +16,11 @@ import java.util.Vector; |
|
|
|
import java.util.regex.Matcher; |
|
|
|
import java.util.regex.Matcher; |
|
|
|
import java.util.regex.Pattern; |
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.BorderFactory; |
|
|
|
import javax.swing.JFrame; |
|
|
|
import javax.swing.JFrame; |
|
|
|
|
|
|
|
import javax.swing.JLabel; |
|
|
|
import javax.swing.JPanel; |
|
|
|
import javax.swing.JPanel; |
|
|
|
|
|
|
|
import javax.swing.SwingConstants; |
|
|
|
|
|
|
|
|
|
|
|
import org.icepdf.ri.common.ComponentKeyBinding; |
|
|
|
import org.icepdf.ri.common.ComponentKeyBinding; |
|
|
|
import org.icepdf.ri.common.SwingController; |
|
|
|
import org.icepdf.ri.common.SwingController; |
|
|
@ -69,6 +73,10 @@ public class MainFrame extends JFrame { |
|
|
|
|
|
|
|
|
|
|
|
private SwingController pdfViewer; |
|
|
|
private SwingController pdfViewer; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private JLabel fileName; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isScanning = false; |
|
|
|
|
|
|
|
|
|
|
|
public MainFrame(Configuration config) { |
|
|
|
public MainFrame(Configuration config) { |
|
|
|
super("BelegScanner"); |
|
|
|
super("BelegScanner"); |
|
|
|
this.config = config; |
|
|
|
this.config = config; |
|
|
@ -99,11 +107,15 @@ public class MainFrame extends JFrame { |
|
|
|
int y = config.getOrCreate(APP_Y, 20); |
|
|
|
int y = config.getOrCreate(APP_Y, 20); |
|
|
|
setLocation(new Point(x, y)); |
|
|
|
setLocation(new Point(x, y)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
checkScanButton(); |
|
|
|
|
|
|
|
|
|
|
|
setPreferredSize(new Dimension(width,height)); |
|
|
|
setPreferredSize(new Dimension(width,height)); |
|
|
|
pack(); |
|
|
|
pack(); |
|
|
|
setVisible(true); |
|
|
|
setVisible(true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
@ -111,9 +123,14 @@ public class MainFrame extends JFrame { |
|
|
|
toolbar.addFieldsFor(marks); |
|
|
|
toolbar.addFieldsFor(marks); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void checkScanButton() { |
|
|
|
|
|
|
|
toolbar.readyToScanX(!(isScanning || patchedPath==null || patchedPath.isBlank() || patchedPath.contains("$"))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void performScan(String path, Dimension dimension) { |
|
|
|
private void performScan(String path, Dimension dimension) { |
|
|
|
LOG.debug("performScan({})",path); |
|
|
|
LOG.debug("performScan({})",path); |
|
|
|
toolbar.readyToScan(false); |
|
|
|
setScanning(true); |
|
|
|
|
|
|
|
|
|
|
|
File folder = new File(path); |
|
|
|
File folder = new File(path); |
|
|
|
if (!folder.exists()) { |
|
|
|
if (!folder.exists()) { |
|
|
|
LOG.warn("Path '{}' does not exist!",path); |
|
|
|
LOG.warn("Path '{}' does not exist!",path); |
|
|
@ -148,13 +165,14 @@ public class MainFrame extends JFrame { |
|
|
|
if (errorCode != 0) { |
|
|
|
if (errorCode != 0) { |
|
|
|
LOG.error("error code: {} for {}",errorCode,cmd); |
|
|
|
LOG.error("error code: {} for {}",errorCode,cmd); |
|
|
|
docTable.setState(path, "Scannen fehlgeschlagen."); |
|
|
|
docTable.setState(path, "Scannen fehlgeschlagen."); |
|
|
|
toolbar.readyToScan(true); |
|
|
|
setScanning(false); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} catch (InterruptedException | IOException e) { |
|
|
|
} catch (InterruptedException | IOException e) { |
|
|
|
LOG.error("{} terminated: ",builder,e); |
|
|
|
LOG.error("{} terminated: ",builder,e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
setScanning(false); |
|
|
|
|
|
|
|
|
|
|
|
String pdf = "page."+timestamp+".pdf"; |
|
|
|
String pdf = "page."+timestamp+".pdf"; |
|
|
|
cmd = new Vector<>(); |
|
|
|
cmd = new Vector<>(); |
|
|
@ -166,12 +184,10 @@ public class MainFrame extends JFrame { |
|
|
|
try { |
|
|
|
try { |
|
|
|
Process process = builder.start(); |
|
|
|
Process process = builder.start(); |
|
|
|
docTable.setState(path,"Kovertiere zu PDF…"); |
|
|
|
docTable.setState(path,"Kovertiere zu PDF…"); |
|
|
|
toolbar.readyToScan(true); |
|
|
|
|
|
|
|
int errorCode = process.waitFor(); |
|
|
|
int errorCode = process.waitFor(); |
|
|
|
if (errorCode != 0) { |
|
|
|
if (errorCode != 0) { |
|
|
|
LOG.error("error code: {} for {}",errorCode,cmd); |
|
|
|
LOG.error("error code: {} for {}",errorCode,cmd); |
|
|
|
docTable.setState(path, "Konvertierung fehlgeschlagen."); |
|
|
|
docTable.setState(path, "Konvertierung fehlgeschlagen."); |
|
|
|
toolbar.readyToScan(true); |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -197,7 +213,6 @@ public class MainFrame extends JFrame { |
|
|
|
try { |
|
|
|
try { |
|
|
|
Process process = builder.start(); |
|
|
|
Process process = builder.start(); |
|
|
|
docTable.setState(path,"Texterkennung…"); |
|
|
|
docTable.setState(path,"Texterkennung…"); |
|
|
|
toolbar.readyToScan(true); |
|
|
|
|
|
|
|
int errorCode = process.waitFor(); |
|
|
|
int errorCode = process.waitFor(); |
|
|
|
if (errorCode != 0) { |
|
|
|
if (errorCode != 0) { |
|
|
|
LOG.error("error code: {} for {}",errorCode,cmd); |
|
|
|
LOG.error("error code: {} for {}",errorCode,cmd); |
|
|
@ -213,8 +228,16 @@ public class MainFrame extends JFrame { |
|
|
|
docTable.preview(path); |
|
|
|
docTable.preview(path); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void setScanning(boolean scanning) { |
|
|
|
|
|
|
|
isScanning = scanning; |
|
|
|
|
|
|
|
checkScanButton(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private JPanel preview() { |
|
|
|
private JPanel preview() { |
|
|
|
// https://stackoverflow.com/a/48248739/1285585
|
|
|
|
// https://stackoverflow.com/a/48248739/1285585
|
|
|
|
|
|
|
|
JPanel pane = new JPanel(new BorderLayout()); |
|
|
|
|
|
|
|
|
|
|
|
pdfViewer = new SwingController(); |
|
|
|
pdfViewer = new SwingController(); |
|
|
|
SwingViewBuilder factory = new SwingViewBuilder(pdfViewer); |
|
|
|
SwingViewBuilder factory = new SwingViewBuilder(pdfViewer); |
|
|
@ -224,14 +247,21 @@ public class MainFrame extends JFrame { |
|
|
|
ComponentKeyBinding.install(pdfViewer, viewerComponentPanel); |
|
|
|
ComponentKeyBinding.install(pdfViewer, viewerComponentPanel); |
|
|
|
// add interactive mouse link annotation support via callback
|
|
|
|
// add interactive mouse link annotation support via callback
|
|
|
|
pdfViewer.getDocumentViewController().setAnnotationCallback(new org.icepdf.ri.common.MyAnnotationCallback(pdfViewer.getDocumentViewController())); |
|
|
|
pdfViewer.getDocumentViewController().setAnnotationCallback(new org.icepdf.ri.common.MyAnnotationCallback(pdfViewer.getDocumentViewController())); |
|
|
|
return viewerComponentPanel; |
|
|
|
|
|
|
|
|
|
|
|
pane.add(viewerComponentPanel,BorderLayout.CENTER); |
|
|
|
|
|
|
|
pane.setBorder(BorderFactory.createLineBorder(Color.black)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pane.add(fileName = new JLabel(),BorderLayout.SOUTH); |
|
|
|
|
|
|
|
fileName.setHorizontalAlignment(SwingConstants.CENTER); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return pane; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void preview(String file) { |
|
|
|
private void preview(String file) { |
|
|
|
pdfViewer.openDocument(file); |
|
|
|
pdfViewer.openDocument(file); |
|
|
|
//pdfViewer.setToolBarVisible(false);
|
|
|
|
//pdfViewer.setToolBarVisible(false);
|
|
|
|
pdfViewer.setPageFitMode(DocumentViewController.PAGE_FIT_WINDOW_WIDTH, false); |
|
|
|
pdfViewer.setPageFitMode(DocumentViewController.PAGE_FIT_WINDOW_WIDTH, false); |
|
|
|
statusBar.setFile(file); |
|
|
|
fileName.setText(file); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void scan(ActionEvent ev) { |
|
|
|
private void scan(ActionEvent ev) { |
|
|
@ -313,5 +343,6 @@ public class MainFrame extends JFrame { |
|
|
|
addFieldsFor(patchedPath); |
|
|
|
addFieldsFor(patchedPath); |
|
|
|
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); |
|
|
|
|
|
|
|
checkScanButton(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|