From c9292bcd2eff8ea9eeef82ddaef3329e73c8ee9b Mon Sep 17 00:00:00 2001 From: LS31 Date: Tue, 26 May 2020 19:55:21 +0200 Subject: [PATCH 01/10] Show detailed results after scanning or renaming. --- src/main/java/module-info.java | 1 + .../java/nl/ls31/qrscan/core/CreateTask.java | 8 +- .../nl/ls31/qrscan/core/CsvLogWriter.java | 2 + src/main/java/nl/ls31/qrscan/core/QrPdf.java | 4 +- .../java/nl/ls31/qrscan/core/ScanTask.java | 12 +-- .../nl/ls31/qrscan/core/SingleResult.java | 75 +++++++++++++---- .../ls31/qrscan/ui/view/ProgressDialog.java | 6 ++ .../nl/ls31/qrscan/ui/view/ResultsDialog.java | 81 +++++++++++++++++++ .../ls31/qrscan/ui/view/ScanController.java | 22 +++-- 9 files changed, 170 insertions(+), 41 deletions(-) create mode 100644 src/main/java/nl/ls31/qrscan/ui/view/ResultsDialog.java diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 42fa3e4..8db208e 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -9,5 +9,6 @@ requires java.prefs; opens nl.ls31.qrscan.ui.view to javafx.fxml; + opens nl.ls31.qrscan.core to javafx.base; exports nl.ls31.qrscan; } \ No newline at end of file diff --git a/src/main/java/nl/ls31/qrscan/core/CreateTask.java b/src/main/java/nl/ls31/qrscan/core/CreateTask.java index d71302c..82b42d6 100644 --- a/src/main/java/nl/ls31/qrscan/core/CreateTask.java +++ b/src/main/java/nl/ls31/qrscan/core/CreateTask.java @@ -25,10 +25,10 @@ public class CreateTask extends Task> { final static private String LSEP = System.lineSeparator(); - private Path inputFile; - private Path outputDir; - private int size; - private boolean withText; + private final Path inputFile; + private final Path outputDir; + private final int size; + private final boolean withText; /** * This task imports creates GIF image files displaying QR codes (with or without an human-readable annotation). diff --git a/src/main/java/nl/ls31/qrscan/core/CsvLogWriter.java b/src/main/java/nl/ls31/qrscan/core/CsvLogWriter.java index 5ea4d6b..be92199 100644 --- a/src/main/java/nl/ls31/qrscan/core/CsvLogWriter.java +++ b/src/main/java/nl/ls31/qrscan/core/CsvLogWriter.java @@ -8,6 +8,8 @@ /** * This class provides a way to write a CSV file with a log of the scanned or renamed PDF files with QR codes. + *

+ * TODO Migrate to Apache Open CSV implementation * * @author Lars Steggink */ diff --git a/src/main/java/nl/ls31/qrscan/core/QrPdf.java b/src/main/java/nl/ls31/qrscan/core/QrPdf.java index 0d0f472..15b404f 100644 --- a/src/main/java/nl/ls31/qrscan/core/QrPdf.java +++ b/src/main/java/nl/ls31/qrscan/core/QrPdf.java @@ -31,8 +31,8 @@ public class QrPdf { * This custom file attribute is used to add the QR code to the PDF file meta data. */ final static public String FILE_ATTRIBUTE = "custom.qrcode"; - private Path docPath; - private Map qrCodeMap; + private final Path docPath; + private final Map qrCodeMap; /** * PDF file containing a QR code. diff --git a/src/main/java/nl/ls31/qrscan/core/ScanTask.java b/src/main/java/nl/ls31/qrscan/core/ScanTask.java index 5542b97..2e833ed 100644 --- a/src/main/java/nl/ls31/qrscan/core/ScanTask.java +++ b/src/main/java/nl/ls31/qrscan/core/ScanTask.java @@ -27,11 +27,11 @@ */ public class ScanTask extends Task> { final static private String LSEP = System.lineSeparator(); - protected Path inputDir; - private int qrCodePage; - private boolean writeFileAttributes; - private boolean useFileAttributes; - private boolean openLogFile; + protected final Path inputDir; + private final int qrCodePage; + private final boolean writeFileAttributes; + private final boolean useFileAttributes; + private final boolean openLogFile; /** * @param inputDir Input directory with PDF files. @@ -62,6 +62,8 @@ protected List call() { /** * Logs the results by logging to a CSV file. + *

+ * TODO Move logging outside of task * * @param results Results from scanning. * @param dir Directory to save CSV file into. diff --git a/src/main/java/nl/ls31/qrscan/core/SingleResult.java b/src/main/java/nl/ls31/qrscan/core/SingleResult.java index f14ef7e..709b469 100644 --- a/src/main/java/nl/ls31/qrscan/core/SingleResult.java +++ b/src/main/java/nl/ls31/qrscan/core/SingleResult.java @@ -1,5 +1,9 @@ package nl.ls31.qrscan.core; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; + import java.io.IOException; import java.nio.file.Path; @@ -13,13 +17,14 @@ */ public class SingleResult { - private ResultStatus resultStatus; - private int qrCodePage; - private String qrCode; - private Path inputFilePath; - private Path outputFilePath; + private final SimpleObjectProperty resultStatus; + private final int qrCodePage; + private final SimpleStringProperty qrCode; + + private final SimpleObjectProperty inputFilePath; + private final SimpleObjectProperty outputFilePath; private String creation; - private boolean isRenamed; + private final SimpleBooleanProperty isRenamed; private int pageCount; /** @@ -29,9 +34,9 @@ public class SingleResult { * @param qrCode the QR code, if found, otherwise "" */ public SingleResult(QrPdf pdf, ResultStatus resultStatus, int qrCodePage, String qrCode) { - this.inputFilePath = pdf.getPath(); + this.inputFilePath = new SimpleObjectProperty<>(pdf.getPath()); this.outputFilePath = inputFilePath; - this.isRenamed = false; + this.isRenamed = new SimpleBooleanProperty(false); try { this.creation = pdf.getCreationTime().toString(); } catch (IOException e) { @@ -43,9 +48,9 @@ public SingleResult(QrPdf pdf, ResultStatus resultStatus, int qrCodePage, String } catch (IOException e) { this.pageCount = -9; } - this.resultStatus = resultStatus; + this.resultStatus = new SimpleObjectProperty<>(resultStatus); this.qrCodePage = qrCodePage; - this.qrCode = qrCode; + this.qrCode = new SimpleStringProperty(qrCode); } /** @@ -54,7 +59,7 @@ public SingleResult(QrPdf pdf, ResultStatus resultStatus, int qrCodePage, String * @return whether a QR code was found */ public boolean isQRCodeFound() { - return (resultStatus == ResultStatus.QR_CODE_FOUND); + return (resultStatus.get() == ResultStatus.QR_CODE_FOUND); } /** @@ -63,7 +68,7 @@ public boolean isQRCodeFound() { * @return QR code */ public String getQrCode() { - return qrCode; + return qrCode.get(); } /** @@ -72,7 +77,7 @@ public String getQrCode() { * @return file path */ public Path getInputFilePath() { - return inputFilePath; + return inputFilePath.get(); } /** @@ -81,7 +86,7 @@ public Path getInputFilePath() { * @return whether the file was renamed */ public boolean isFileRenamed() { - return isRenamed; + return isRenamed.get(); } /** @@ -91,7 +96,7 @@ public boolean isFileRenamed() { * @return output file path */ public Path getOutputFilePath() { - return outputFilePath; + return outputFilePath.get(); } /** @@ -100,8 +105,8 @@ public Path getOutputFilePath() { * @param outputFilePath the new file path */ public void setOutputFilePath(Path outputFilePath) { - this.outputFilePath = outputFilePath; - this.isRenamed = true; + this.outputFilePath.set(outputFilePath); + this.isRenamed.set(true); } /** @@ -137,6 +142,42 @@ public int getQrCodePage() { * @return status */ public ResultStatus getQrCodeScanStatus() { + return resultStatus.get(); + } + + /** + * Present a property object to use the input file path in JavaFX. + * + * @return input file path + */ + public SimpleObjectProperty inputFilePathProperty() { + return inputFilePath; + } + + /** + * Present a property object to use the renamed file path in JavaFX. + * + * @return renamed file path + */ + public SimpleObjectProperty renamedFilePathProperty() { + return outputFilePath; + } + + /** + * Present a property object to use the QR code in JavaFX. + * + * @return qr code + */ + public SimpleStringProperty qrCodeProperty() { + return qrCode; + } + + /** + * Present a property object to use the QR code status in JavaFX. + * + * @return qr code status report + */ + public SimpleObjectProperty qrCodeStatusProperty() { return resultStatus; } diff --git a/src/main/java/nl/ls31/qrscan/ui/view/ProgressDialog.java b/src/main/java/nl/ls31/qrscan/ui/view/ProgressDialog.java index 3d2bbfa..95a8318 100644 --- a/src/main/java/nl/ls31/qrscan/ui/view/ProgressDialog.java +++ b/src/main/java/nl/ls31/qrscan/ui/view/ProgressDialog.java @@ -17,6 +17,12 @@ public class ProgressDialog { private final Stage dialogStage; + /** + * A simple dialog window with a progress bar. + * + * @param title Title of the dialog + * @param taskProgressProperty Progress Property of the task that is monitored + */ public ProgressDialog(String title, ReadOnlyDoubleProperty taskProgressProperty) { dialogStage = new Stage(); dialogStage.initStyle(StageStyle.UTILITY); diff --git a/src/main/java/nl/ls31/qrscan/ui/view/ResultsDialog.java b/src/main/java/nl/ls31/qrscan/ui/view/ResultsDialog.java new file mode 100644 index 0000000..6699915 --- /dev/null +++ b/src/main/java/nl/ls31/qrscan/ui/view/ResultsDialog.java @@ -0,0 +1,81 @@ +package nl.ls31.qrscan.ui.view; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.geometry.Insets; +import javafx.scene.Scene; +import javafx.scene.control.Label; +import javafx.scene.control.TableColumn; +import javafx.scene.control.TableView; +import javafx.scene.control.cell.PropertyValueFactory; +import javafx.scene.layout.VBox; +import javafx.stage.Modality; +import javafx.stage.Stage; +import javafx.stage.StageStyle; +import nl.ls31.qrscan.core.SingleResult; + +import java.util.List; + +/** + * A dialog window with the results of a ScanTask or RenameTask. + */ +public class ResultsDialog { + private final Stage dialogStage; + + /** + * A dialog window with the results of a ScanTask or RenameTask. + */ + public ResultsDialog(List results, boolean showRenamedColumn, String summary) { + ObservableList resultList = FXCollections.observableArrayList(results); + + dialogStage = new Stage(); + dialogStage.initStyle(StageStyle.DECORATED); + dialogStage.setMinWidth(600); + dialogStage.setMinHeight(400); + dialogStage.setResizable(true); + dialogStage.initModality(Modality.APPLICATION_MODAL); + dialogStage.setTitle("Result overview"); + + final Label label = new Label(summary); + TableView table = new TableView<>(); + + TableColumn inputPathCol = new TableColumn<>("File path"); + inputPathCol.setMinWidth(400); + inputPathCol.setCellValueFactory(new PropertyValueFactory<>("inputFilePath")); + inputPathCol.setSortType(TableColumn.SortType.DESCENDING); + + TableColumn renamedPathCol = new TableColumn<>("Renamed file path"); + renamedPathCol.setVisible(showRenamedColumn); + renamedPathCol.setMinWidth(400); + renamedPathCol.setCellValueFactory(new PropertyValueFactory<>("renamedFilePath")); + renamedPathCol.setSortType(TableColumn.SortType.DESCENDING); + + TableColumn qrCodeStatusCol = new TableColumn<>("QR code status"); + qrCodeStatusCol.setMinWidth(40); + qrCodeStatusCol.setCellValueFactory(new PropertyValueFactory<>("qrCodeStatus")); + renamedPathCol.setSortType(TableColumn.SortType.DESCENDING); + + TableColumn qrCodeCol = new TableColumn<>("QR code"); + qrCodeCol.setMinWidth(60); + qrCodeCol.setCellValueFactory(new PropertyValueFactory<>("qrCode")); + renamedPathCol.setSortType(TableColumn.SortType.DESCENDING); + + table.setItems(resultList); + table.getColumns().addAll(inputPathCol, renamedPathCol, qrCodeStatusCol, qrCodeCol); + + final VBox vbox = new VBox(); + vbox.setSpacing(5); + vbox.setPadding(new Insets(10, 10, 10, 10)); + vbox.getChildren().addAll(label, table); + + Scene scene = new Scene(vbox); + dialogStage.setScene(scene); + } + + /** + * Show the window. + */ + public void show() { + dialogStage.show(); + } +} diff --git a/src/main/java/nl/ls31/qrscan/ui/view/ScanController.java b/src/main/java/nl/ls31/qrscan/ui/view/ScanController.java index 7346f0a..51f70cb 100644 --- a/src/main/java/nl/ls31/qrscan/ui/view/ScanController.java +++ b/src/main/java/nl/ls31/qrscan/ui/view/ScanController.java @@ -3,7 +3,6 @@ import javafx.concurrent.Task; import javafx.fxml.FXML; import javafx.scene.control.*; -import javafx.scene.layout.Region; import javafx.stage.DirectoryChooser; import nl.ls31.qrscan.App; import nl.ls31.qrscan.core.RenameTask; @@ -172,22 +171,19 @@ private void handleScanButton() { task = new ScanTask(inputDir, qrPage, useFileAttributes, writeFileAttributes, openLogFile); } - ProgressDialog pForm = new ProgressDialog("Processing...", task.progressProperty()); - pForm.show(); + ProgressDialog pDialog = new ProgressDialog("Processing...", task.progressProperty()); + pDialog.show(); scanButton.setDisable(true); task.setOnSucceeded(event -> { - pForm.close(); + pDialog.close(); scanButton.setDisable(false); - }); - - task.messageProperty().addListener((observable, oldValue, newValue) -> { - Alert alert = new Alert(Alert.AlertType.INFORMATION); - alert.setTitle("Task finished."); - alert.setHeaderText("Scanned and/or renamed PDF files."); - alert.setContentText(newValue); - alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE); - alert.showAndWait(); + ResultsDialog rDialog = new ResultsDialog( + task.getValue(), + task instanceof RenameTask, + task.getMessage()); + rDialog.show(); + // TODO Move code to create CSV log file here. }); new Thread(task).start(); From 76e779a4e6f326c16a694c2f3e847deada11a31a Mon Sep 17 00:00:00 2001 From: LS31 Date: Wed, 27 May 2020 23:09:13 +0200 Subject: [PATCH 02/10] Refactor (slightly) to MVC pattern. Unify all settings in one class. --- README.md | 2 +- pom.xml | 2 +- src/main/java/module-info.java | 4 +- src/main/java/nl/ls31/qrscan/Launcher.java | 2 +- .../nl/ls31/qrscan/{App.java => MainApp.java} | 50 +-- .../view => controller}/CreateController.java | 33 +- .../ManualTagController.java | 22 +- .../view => controller}/RootController.java | 12 +- .../view => controller}/ScanController.java | 62 ++-- .../java/nl/ls31/qrscan/core/CreateTask.java | 1 + .../nl/ls31/qrscan/core/CsvLogWriter.java | 2 + .../java/nl/ls31/qrscan/core/RenameTask.java | 2 + .../java/nl/ls31/qrscan/core/ScanTask.java | 2 + .../nl/ls31/qrscan/model/AppSettings.java | 314 ++++++++++++++++++ .../nl/ls31/qrscan/{core => model}/QrPdf.java | 2 +- .../qrscan/{core => model}/SingleResult.java | 4 +- .../ls31/qrscan/ui/model/CreateSettings.java | 114 ------- .../qrscan/ui/model/ManualTagSettings.java | 71 ---- .../nl/ls31/qrscan/ui/model/ScanSettings.java | 175 ---------- .../qrscan/{ui => }/view/ProgressDialog.java | 2 +- .../qrscan/{ui => }/view/ResultsDialog.java | 4 +- src/main/resources/fxml/CreateView.fxml | 2 +- src/main/resources/fxml/ManualTagView.fxml | 2 +- src/main/resources/fxml/RootLayout.fxml | 2 +- src/main/resources/fxml/ScanView.fxml | 2 +- 25 files changed, 415 insertions(+), 475 deletions(-) rename src/main/java/nl/ls31/qrscan/{App.java => MainApp.java} (57%) rename src/main/java/nl/ls31/qrscan/{ui/view => controller}/CreateController.java (74%) rename src/main/java/nl/ls31/qrscan/{ui/view => controller}/ManualTagController.java (87%) rename src/main/java/nl/ls31/qrscan/{ui/view => controller}/RootController.java (89%) rename src/main/java/nl/ls31/qrscan/{ui/view => controller}/ScanController.java (67%) create mode 100644 src/main/java/nl/ls31/qrscan/model/AppSettings.java rename src/main/java/nl/ls31/qrscan/{core => model}/QrPdf.java (99%) rename src/main/java/nl/ls31/qrscan/{core => model}/SingleResult.java (98%) delete mode 100644 src/main/java/nl/ls31/qrscan/ui/model/CreateSettings.java delete mode 100644 src/main/java/nl/ls31/qrscan/ui/model/ManualTagSettings.java delete mode 100644 src/main/java/nl/ls31/qrscan/ui/model/ScanSettings.java rename src/main/java/nl/ls31/qrscan/{ui => }/view/ProgressDialog.java (98%) rename src/main/java/nl/ls31/qrscan/{ui => }/view/ResultsDialog.java (97%) diff --git a/README.md b/README.md index 7adc6cf..927c340 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ A big thanks to the following projects: [PDFBox by The Apache Software Foundatio * Update to JDK/JRE 13; use Java Platform Module System. * Minor changes in lay-out. * **2.1.0** - * Remember previous settings when restarting program. + * Remember previous appSettings when restarting program. * Added progress dialog windows. * Updated logging (and simplified for end user). * Updated to JDK/JRE 14. diff --git a/pom.xml b/pom.xml index 6eb5afd..924cb9e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ nl.ls31 qrscan - 2.1.0 + 2.2.0-SNAPSHOT QRScan https://github.com/LS31/qrscan diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 8db208e..ada4a83 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -8,7 +8,7 @@ requires org.tinylog.api; requires java.prefs; - opens nl.ls31.qrscan.ui.view to javafx.fxml; - opens nl.ls31.qrscan.core to javafx.base; + opens nl.ls31.qrscan.controller to javafx.fxml; + opens nl.ls31.qrscan.model to javafx.base; exports nl.ls31.qrscan; } \ No newline at end of file diff --git a/src/main/java/nl/ls31/qrscan/Launcher.java b/src/main/java/nl/ls31/qrscan/Launcher.java index d76d6b4..3b04598 100644 --- a/src/main/java/nl/ls31/qrscan/Launcher.java +++ b/src/main/java/nl/ls31/qrscan/Launcher.java @@ -10,6 +10,6 @@ public class Launcher { public static void main(String[] args) { - App.main(args); + MainApp.main(args); } } \ No newline at end of file diff --git a/src/main/java/nl/ls31/qrscan/App.java b/src/main/java/nl/ls31/qrscan/MainApp.java similarity index 57% rename from src/main/java/nl/ls31/qrscan/App.java rename to src/main/java/nl/ls31/qrscan/MainApp.java index 09f5aa9..90a266a 100644 --- a/src/main/java/nl/ls31/qrscan/App.java +++ b/src/main/java/nl/ls31/qrscan/MainApp.java @@ -6,11 +6,9 @@ import javafx.scene.layout.AnchorPane; import javafx.scene.layout.BorderPane; import javafx.stage.Stage; -import nl.ls31.qrscan.ui.model.CreateSettings; -import nl.ls31.qrscan.ui.model.ManualTagSettings; -import nl.ls31.qrscan.ui.model.ScanSettings; -import nl.ls31.qrscan.ui.view.RootController; -import nl.ls31.qrscan.ui.view.ScanController; +import nl.ls31.qrscan.controller.RootController; +import nl.ls31.qrscan.controller.ScanController; +import nl.ls31.qrscan.model.AppSettings; import org.tinylog.Logger; import java.io.IOException; @@ -20,20 +18,16 @@ * * @author Lars Steggink */ -public class App extends Application { +public class MainApp extends Application { private Stage primaryStage; private BorderPane rootLayout; - private final ScanSettings scanSettings; - private final CreateSettings createSettings; - private final ManualTagSettings manualTagSettings; + private final AppSettings appSettings; /** * Main application. */ - public App() { - this.scanSettings = new ScanSettings(); - this.createSettings = new CreateSettings(); - this.manualTagSettings = new ManualTagSettings(); + public MainApp() { + this.appSettings = new AppSettings(); } /** @@ -46,21 +40,12 @@ public static void main(String[] args) { } /** - * Gets the current create settings. + * Gets the current settings. * - * @return create settings + * @return current settings */ - public CreateSettings getCreateSettings() { - return createSettings; - } - - /** - * Gets the current manual tagging settings. - * - * @return manual tagging settings - */ - public ManualTagSettings getManualTagSettings() { - return manualTagSettings; + public AppSettings getAppSettings() { + return appSettings; } /** @@ -72,15 +57,6 @@ public Stage getPrimaryStage() { return primaryStage; } - /** - * Gets the current scan settings. - * - * @return scan settings - */ - public ScanSettings getScanSettings() { - return scanSettings; - } - /** * Starts the main application. */ @@ -90,8 +66,8 @@ public void start(Stage primaryStage) { this.primaryStage.setTitle("QRScan"); // Load layouts from FXML file. - FXMLLoader loader = new FXMLLoader(App.class.getResource("/fxml/RootLayout.fxml")); - FXMLLoader scanViewLoader = new FXMLLoader(App.class.getResource("/fxml/ScanView.fxml")); + FXMLLoader loader = new FXMLLoader(MainApp.class.getResource("/fxml/RootLayout.fxml")); + FXMLLoader scanViewLoader = new FXMLLoader(MainApp.class.getResource("/fxml/ScanView.fxml")); try { rootLayout = loader.load(); } catch (IOException e) { diff --git a/src/main/java/nl/ls31/qrscan/ui/view/CreateController.java b/src/main/java/nl/ls31/qrscan/controller/CreateController.java similarity index 74% rename from src/main/java/nl/ls31/qrscan/ui/view/CreateController.java rename to src/main/java/nl/ls31/qrscan/controller/CreateController.java index e85f22d..4f99553 100644 --- a/src/main/java/nl/ls31/qrscan/ui/view/CreateController.java +++ b/src/main/java/nl/ls31/qrscan/controller/CreateController.java @@ -1,4 +1,4 @@ -package nl.ls31.qrscan.ui.view; +package nl.ls31.qrscan.controller; import javafx.concurrent.Task; import javafx.fxml.FXML; @@ -7,8 +7,9 @@ import javafx.stage.DirectoryChooser; import javafx.stage.FileChooser; import javafx.stage.Stage; -import nl.ls31.qrscan.App; +import nl.ls31.qrscan.MainApp; import nl.ls31.qrscan.core.CreateTask; +import nl.ls31.qrscan.view.ProgressDialog; import java.io.File; import java.nio.file.Path; @@ -21,7 +22,7 @@ */ public class CreateController { - private App mainApp; + private MainApp mainApp; @FXML private TextField inputFileTextField; @FXML @@ -42,7 +43,7 @@ public class CreateController { * * @param mainApp the main application */ - public void setMainApp(App mainApp) { + public void setMainApp(MainApp mainApp) { this.mainApp = mainApp; } @@ -50,10 +51,10 @@ public void setMainApp(App mainApp) { * Update all control states using the model as reference. */ public void updateControlsByModel() { - inputFileTextField.setText(mainApp.getCreateSettings().getInputFile().toAbsolutePath().toString()); - outputDirTextField.setText(mainApp.getCreateSettings().getOutputDirectory().toAbsolutePath().toString()); - annotationCheckBox.setSelected(mainApp.getCreateSettings().getWithAnnotation()); - sizeSpinner.getValueFactory().setValue(mainApp.getCreateSettings().getImageSize()); + inputFileTextField.setText(mainApp.getAppSettings().getInputFile().toAbsolutePath().toString()); + outputDirTextField.setText(mainApp.getAppSettings().getOutputDirectory().toAbsolutePath().toString()); + annotationCheckBox.setSelected(mainApp.getAppSettings().getWithAnnotation()); + sizeSpinner.getValueFactory().setValue(mainApp.getAppSettings().getImageSize()); } /** @@ -67,7 +68,7 @@ private void handleInputFileButton() { if (file != null) { // Change the text field and update the model. inputFileTextField.setText(file.toPath().toAbsolutePath().toString()); - mainApp.getCreateSettings().setInputFile(file.toPath()); + mainApp.getAppSettings().setInputFile(file.toPath()); } } @@ -82,7 +83,7 @@ private void handleOutputDirButton() { if (dir != null) { // Change the text field and update the model. outputDirTextField.setText(dir.toPath().toAbsolutePath().toString()); - mainApp.getCreateSettings().setOutputDirectory(dir.toPath()); + mainApp.getAppSettings().setOutputDirectory(dir.toPath()); } } @@ -91,7 +92,7 @@ private void handleOutputDirButton() { */ @FXML private void handleAnnotationCheckBox() { - mainApp.getCreateSettings().setWithAnnotation(annotationCheckBox.isSelected()); + mainApp.getAppSettings().setWithAnnotation(annotationCheckBox.isSelected()); } /** @@ -99,11 +100,11 @@ private void handleAnnotationCheckBox() { */ @FXML private void handleCreateButton() { - Path inputFile = mainApp.getCreateSettings().getInputFile(); - Path outputDir = mainApp.getCreateSettings().getOutputDirectory(); - boolean withAnnotation = mainApp.getCreateSettings().getWithAnnotation(); - mainApp.getCreateSettings().setImageSize(sizeSpinner.getValue()); - int size = mainApp.getCreateSettings().getImageSize(); + Path inputFile = mainApp.getAppSettings().getInputFile(); + Path outputDir = mainApp.getAppSettings().getOutputDirectory(); + boolean withAnnotation = mainApp.getAppSettings().getWithAnnotation(); + mainApp.getAppSettings().setImageSize(sizeSpinner.getValue()); + int size = mainApp.getAppSettings().getImageSize(); Task> createTask = new CreateTask(inputFile, outputDir, size, withAnnotation); diff --git a/src/main/java/nl/ls31/qrscan/ui/view/ManualTagController.java b/src/main/java/nl/ls31/qrscan/controller/ManualTagController.java similarity index 87% rename from src/main/java/nl/ls31/qrscan/ui/view/ManualTagController.java rename to src/main/java/nl/ls31/qrscan/controller/ManualTagController.java index ce1b72f..f134993 100644 --- a/src/main/java/nl/ls31/qrscan/ui/view/ManualTagController.java +++ b/src/main/java/nl/ls31/qrscan/controller/ManualTagController.java @@ -1,4 +1,4 @@ -package nl.ls31.qrscan.ui.view; +package nl.ls31.qrscan.controller; import javafx.fxml.FXML; import javafx.scene.control.Alert; @@ -9,9 +9,9 @@ import javafx.stage.FileChooser; import javafx.stage.FileChooser.ExtensionFilter; import javafx.stage.Stage; -import nl.ls31.qrscan.App; -import nl.ls31.qrscan.core.QrPdf; -import nl.ls31.qrscan.ui.model.ManualTagSettings; +import nl.ls31.qrscan.MainApp; +import nl.ls31.qrscan.model.AppSettings; +import nl.ls31.qrscan.model.QrPdf; import org.tinylog.Logger; import java.io.File; @@ -25,7 +25,7 @@ */ public class ManualTagController { - private App mainApp; + private MainApp mainApp; @FXML private TextField pdfPathField; @FXML @@ -60,7 +60,7 @@ private void handlePDFPathButton() { if (file != null) { // Change the text field and update the model. pdfPathField.setText(file.toPath().toAbsolutePath().toString()); - mainApp.getManualTagSettings().setPDFPath(file.toPath()); + mainApp.getAppSettings().setPDFPath(file.toPath()); } } @@ -70,7 +70,7 @@ private void handlePDFPathButton() { @FXML private void handleTagButton() { try { - mainApp.getManualTagSettings().setCode(codeField.getText()); + mainApp.getAppSettings().setCode(codeField.getText()); tagFile(); } catch (IllegalArgumentException e) { Alert alert = new Alert(AlertType.ERROR); @@ -86,7 +86,7 @@ private void handleTagButton() { * * @param mainApp main application */ - public void setMainApp(App mainApp) { + public void setMainApp(MainApp mainApp) { this.mainApp = mainApp; } @@ -94,7 +94,7 @@ public void setMainApp(App mainApp) { * Tags a PDF file according to the current settings in the settings model. */ private void tagFile() { - ManualTagSettings settings = mainApp.getManualTagSettings(); + AppSettings settings = mainApp.getAppSettings(); QrPdf pdf = new QrPdf(settings.getPDFPath()); try { pdf.setQRCodeFileAttribute(settings.getCode()); @@ -121,7 +121,7 @@ private void tagFile() { } public void updateControlsByModel() { - pdfPathField.setText(mainApp.getManualTagSettings().getPDFPath().toAbsolutePath().toString()); - codeField.setText(mainApp.getManualTagSettings().getCode()); + pdfPathField.setText(mainApp.getAppSettings().getPDFPath().toAbsolutePath().toString()); + codeField.setText(mainApp.getAppSettings().getCode()); } } diff --git a/src/main/java/nl/ls31/qrscan/ui/view/RootController.java b/src/main/java/nl/ls31/qrscan/controller/RootController.java similarity index 89% rename from src/main/java/nl/ls31/qrscan/ui/view/RootController.java rename to src/main/java/nl/ls31/qrscan/controller/RootController.java index 5804b5e..089a643 100644 --- a/src/main/java/nl/ls31/qrscan/ui/view/RootController.java +++ b/src/main/java/nl/ls31/qrscan/controller/RootController.java @@ -1,4 +1,4 @@ -package nl.ls31.qrscan.ui.view; +package nl.ls31.qrscan.controller; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; @@ -9,7 +9,7 @@ import javafx.scene.layout.AnchorPane; import javafx.stage.Modality; import javafx.stage.Stage; -import nl.ls31.qrscan.App; +import nl.ls31.qrscan.MainApp; import java.io.IOException; @@ -22,7 +22,7 @@ public class RootController { @FXML private MenuItem exitItem; - private App mainApp; + private MainApp mainApp; @FXML private MenuItem aboutItem; @FXML @@ -35,7 +35,7 @@ public class RootController { * * @param mainApp main application */ - public void setMainApp(App mainApp) { + public void setMainApp(MainApp mainApp) { this.mainApp = mainApp; } @@ -70,7 +70,7 @@ public void handleCreateItem() { try { Stage stage = new Stage(); stage.initModality(Modality.APPLICATION_MODAL); - FXMLLoader createViewLoader = new FXMLLoader(App.class.getResource("/fxml/CreateView.fxml")); + FXMLLoader createViewLoader = new FXMLLoader(MainApp.class.getResource("/fxml/CreateView.fxml")); AnchorPane createView = createViewLoader.load(); stage.setScene(new Scene(createView)); @@ -92,7 +92,7 @@ public void handleManualTagItem() { try { Stage stage = new Stage(); stage.initModality(Modality.APPLICATION_MODAL); - FXMLLoader manualTagViewLoader = new FXMLLoader(App.class.getResource("/fxml/ManualTagView.fxml")); + FXMLLoader manualTagViewLoader = new FXMLLoader(MainApp.class.getResource("/fxml/ManualTagView.fxml")); AnchorPane manualTagView = manualTagViewLoader.load(); stage.setScene(new Scene(manualTagView)); diff --git a/src/main/java/nl/ls31/qrscan/ui/view/ScanController.java b/src/main/java/nl/ls31/qrscan/controller/ScanController.java similarity index 67% rename from src/main/java/nl/ls31/qrscan/ui/view/ScanController.java rename to src/main/java/nl/ls31/qrscan/controller/ScanController.java index 51f70cb..f3eba82 100644 --- a/src/main/java/nl/ls31/qrscan/ui/view/ScanController.java +++ b/src/main/java/nl/ls31/qrscan/controller/ScanController.java @@ -1,14 +1,16 @@ -package nl.ls31.qrscan.ui.view; +package nl.ls31.qrscan.controller; import javafx.concurrent.Task; import javafx.fxml.FXML; import javafx.scene.control.*; import javafx.stage.DirectoryChooser; -import nl.ls31.qrscan.App; +import nl.ls31.qrscan.MainApp; import nl.ls31.qrscan.core.RenameTask; import nl.ls31.qrscan.core.ScanTask; -import nl.ls31.qrscan.core.SingleResult; -import nl.ls31.qrscan.ui.model.ScanSettings; +import nl.ls31.qrscan.model.AppSettings; +import nl.ls31.qrscan.model.SingleResult; +import nl.ls31.qrscan.view.ProgressDialog; +import nl.ls31.qrscan.view.ResultsDialog; import java.io.File; import java.nio.file.Path; @@ -21,7 +23,7 @@ */ public class ScanController { - private App mainApp; + private MainApp mainApp; @FXML private TextField inputDirTextField; @FXML @@ -50,7 +52,7 @@ public class ScanController { * * @param mainApp main application */ - public void setMainApp(App mainApp) { + public void setMainApp(MainApp mainApp) { this.mainApp = mainApp; } @@ -58,14 +60,14 @@ public void setMainApp(App mainApp) { * Update all control states using the model as reference. */ public void updateControlsByModel() { - inputDirTextField.setText(mainApp.getScanSettings().getInputDirectory().toAbsolutePath().toString()); - targetDirTextField.setText(mainApp.getScanSettings().getTargetDirectory().toAbsolutePath().toString()); - useFileAttributeCheckBox.setSelected(mainApp.getScanSettings().getUseFileAttributes()); - writeFileAttributeCheckBox.setSelected(mainApp.getScanSettings().getWriteFileAttributes()); - renameCheckBox.setSelected(mainApp.getScanSettings().getWithRenaming()); + inputDirTextField.setText(mainApp.getAppSettings().getInputDirectory().toAbsolutePath().toString()); + targetDirTextField.setText(mainApp.getAppSettings().getTargetDirectory().toAbsolutePath().toString()); + useFileAttributeCheckBox.setSelected(mainApp.getAppSettings().getUseFileAttributes()); + writeFileAttributeCheckBox.setSelected(mainApp.getAppSettings().getWriteFileAttributes()); + renameCheckBox.setSelected(mainApp.getAppSettings().getWithRenaming()); toggleRenaming(); - openLogFileCheckBox.setSelected(mainApp.getScanSettings().getOpenLogFile()); - qrPageSpinner.getValueFactory().setValue(mainApp.getScanSettings().getQRPage()); + openLogFileCheckBox.setSelected(mainApp.getAppSettings().getOpenLogFile()); + qrPageSpinner.getValueFactory().setValue(mainApp.getAppSettings().getQRPage()); } /** @@ -78,8 +80,8 @@ private void handleInputDirButton() { File dir = dirChooser.showDialog(mainApp.getPrimaryStage()); if (dir != null) { // Change the text field and update the model. - mainApp.getScanSettings().setInputDirectory(dir.toPath()); - inputDirTextField.setText(mainApp.getScanSettings().getInputDirectory().toAbsolutePath().toString()); + mainApp.getAppSettings().setInputDirectory(dir.toPath()); + inputDirTextField.setText(mainApp.getAppSettings().getInputDirectory().toAbsolutePath().toString()); } } @@ -93,8 +95,8 @@ private void handleTargetDirButton() { File dir = dirChooser.showDialog(mainApp.getPrimaryStage()); if (dir != null) { // Change the text field and update the model. - mainApp.getScanSettings().setTargetDirectory(dir.toPath()); - targetDirTextField.setText(mainApp.getScanSettings().getTargetDirectory().toAbsolutePath().toString()); + mainApp.getAppSettings().setTargetDirectory(dir.toPath()); + targetDirTextField.setText(mainApp.getAppSettings().getTargetDirectory().toAbsolutePath().toString()); } } @@ -103,7 +105,7 @@ private void handleTargetDirButton() { */ @FXML private void handleUseFileAttributeCheckBox() { - mainApp.getScanSettings().setUseFileAttributes(useFileAttributeCheckBox.isSelected()); + mainApp.getAppSettings().setUseFileAttributes(useFileAttributeCheckBox.isSelected()); } /** @@ -112,7 +114,7 @@ private void handleUseFileAttributeCheckBox() { */ @FXML private void handleWriteFileAttributeCheckBox() { - mainApp.getScanSettings().setWriteFileAttributes(writeFileAttributeCheckBox.isSelected()); + mainApp.getAppSettings().setWriteFileAttributes(writeFileAttributeCheckBox.isSelected()); } /** @@ -120,7 +122,7 @@ private void handleWriteFileAttributeCheckBox() { */ @FXML private void handleOpenLogFileCheckBox() { - mainApp.getScanSettings().setOpenLogFile(openLogFileCheckBox.isSelected()); + mainApp.getAppSettings().setOpenLogFile(openLogFileCheckBox.isSelected()); } /** @@ -128,7 +130,7 @@ private void handleOpenLogFileCheckBox() { */ @FXML private void handleRenameCheckBox() { - mainApp.getScanSettings().setWithRenaming(renameCheckBox.isSelected()); + mainApp.getAppSettings().setWithRenaming(renameCheckBox.isSelected()); toggleRenaming(); } @@ -152,20 +154,20 @@ private void toggleRenaming() { */ @FXML private void handleScanButton() { - ScanSettings settings = mainApp.getScanSettings(); + AppSettings appSettings = mainApp.getAppSettings(); // Spinner has no nice listener, update value first. - settings.setQRPage(qrPageSpinner.getValue()); + appSettings.setQRPage(qrPageSpinner.getValue()); - Path inputDir = settings.getInputDirectory(); - int qrPage = settings.getQRPage(); - boolean useFileAttributes = settings.getUseFileAttributes(); - boolean writeFileAttributes = settings.getWriteFileAttributes(); - boolean openLogFile = settings.getOpenLogFile(); + Path inputDir = appSettings.getInputDirectory(); + int qrPage = appSettings.getQRPage(); + boolean useFileAttributes = appSettings.getUseFileAttributes(); + boolean writeFileAttributes = appSettings.getWriteFileAttributes(); + boolean openLogFile = appSettings.getOpenLogFile(); Task> task; - if (settings.getWithRenaming()) { - Path targetDir = settings.getTargetDirectory(); + if (appSettings.getWithRenaming()) { + Path targetDir = appSettings.getTargetDirectory(); task = new RenameTask(inputDir, targetDir, qrPage, useFileAttributes, writeFileAttributes, openLogFile); } else { task = new ScanTask(inputDir, qrPage, useFileAttributes, writeFileAttributes, openLogFile); diff --git a/src/main/java/nl/ls31/qrscan/core/CreateTask.java b/src/main/java/nl/ls31/qrscan/core/CreateTask.java index 82b42d6..5fdcea2 100644 --- a/src/main/java/nl/ls31/qrscan/core/CreateTask.java +++ b/src/main/java/nl/ls31/qrscan/core/CreateTask.java @@ -2,6 +2,7 @@ import com.google.zxing.WriterException; import javafx.concurrent.Task; +import nl.ls31.qrscan.model.QrPdf; import org.tinylog.Logger; import java.io.IOException; diff --git a/src/main/java/nl/ls31/qrscan/core/CsvLogWriter.java b/src/main/java/nl/ls31/qrscan/core/CsvLogWriter.java index be92199..bb4dde8 100644 --- a/src/main/java/nl/ls31/qrscan/core/CsvLogWriter.java +++ b/src/main/java/nl/ls31/qrscan/core/CsvLogWriter.java @@ -1,5 +1,7 @@ package nl.ls31.qrscan.core; +import nl.ls31.qrscan.model.SingleResult; + import java.io.BufferedWriter; import java.io.IOException; import java.nio.file.Files; diff --git a/src/main/java/nl/ls31/qrscan/core/RenameTask.java b/src/main/java/nl/ls31/qrscan/core/RenameTask.java index 96dd799..f9cf67a 100644 --- a/src/main/java/nl/ls31/qrscan/core/RenameTask.java +++ b/src/main/java/nl/ls31/qrscan/core/RenameTask.java @@ -1,5 +1,7 @@ package nl.ls31.qrscan.core; +import nl.ls31.qrscan.model.QrPdf; +import nl.ls31.qrscan.model.SingleResult; import org.tinylog.Logger; import java.io.IOException; diff --git a/src/main/java/nl/ls31/qrscan/core/ScanTask.java b/src/main/java/nl/ls31/qrscan/core/ScanTask.java index 2e833ed..85e3191 100644 --- a/src/main/java/nl/ls31/qrscan/core/ScanTask.java +++ b/src/main/java/nl/ls31/qrscan/core/ScanTask.java @@ -2,6 +2,8 @@ import com.google.zxing.NotFoundException; import javafx.concurrent.Task; +import nl.ls31.qrscan.model.QrPdf; +import nl.ls31.qrscan.model.SingleResult; import org.tinylog.Logger; import java.awt.*; diff --git a/src/main/java/nl/ls31/qrscan/model/AppSettings.java b/src/main/java/nl/ls31/qrscan/model/AppSettings.java new file mode 100644 index 0000000..51cbb8d --- /dev/null +++ b/src/main/java/nl/ls31/qrscan/model/AppSettings.java @@ -0,0 +1,314 @@ +package nl.ls31.qrscan.model; + +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; + +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.prefs.Preferences; + +/** + * This model holds all settings set by the user. + * + * @author Lars Steggink + */ +public class AppSettings { + + private final Preferences storedSettings; + private final SimpleObjectProperty inputFile; + private final SimpleObjectProperty outputDir; + private final SimpleIntegerProperty imageSize; + private final SimpleBooleanProperty withAnnotation; + private final SimpleObjectProperty pdfPath; + private final SimpleStringProperty code; + private final SimpleObjectProperty inputDir; + private final SimpleObjectProperty targetDir; + private final SimpleIntegerProperty qrPage; + private final SimpleBooleanProperty withRenaming; + private final SimpleBooleanProperty useFileAttributes; + private final SimpleBooleanProperty writeFileAttributes; + private final SimpleBooleanProperty openLogFile; + + public AppSettings() { + storedSettings = Preferences.userNodeForPackage(this.getClass()); + + inputFile = new SimpleObjectProperty<>(Paths.get(storedSettings.get("LAST_INPUT_FILE", ""))); + outputDir = new SimpleObjectProperty<>(Paths.get(storedSettings.get("LAST_OUTPUT_DIR", ""))); + imageSize = new SimpleIntegerProperty(storedSettings.getInt("LAST_IMAGE_SIZE", 50)); + withAnnotation = new SimpleBooleanProperty(storedSettings.getBoolean("LAST_WITH_ANNOTATION", true)); + pdfPath = new SimpleObjectProperty<>(Paths.get(storedSettings.get("LAST_PDF_PATH", ""))); + code = new SimpleStringProperty(storedSettings.get("LAST_CODE", "")); + inputDir = new SimpleObjectProperty<>(Paths.get(storedSettings.get("LAST_INPUT_DIR", ""))); + targetDir = new SimpleObjectProperty<>(Paths.get(storedSettings.get("LAST_TARGET_DIR", ""))); + qrPage = new SimpleIntegerProperty(storedSettings.getInt("LAST_QR_PAGE", 1)); + withRenaming = new SimpleBooleanProperty(storedSettings.getBoolean("LAST_WITH_RENAMING", false)); + useFileAttributes = new SimpleBooleanProperty(storedSettings.getBoolean("LAST_USE_FILE_ATTRIBUTES", true)); + writeFileAttributes = new SimpleBooleanProperty(storedSettings.getBoolean("LAST_WRITE_FILE_ATTRIBUTES", true)); + openLogFile = new SimpleBooleanProperty(storedSettings.getBoolean("LAST_OPEN_LOG_FILE", true)); + } + + /** + * Gets image size setting (in px). + * + * @return image size + */ + public final int getImageSize() { + return imageSize.get(); + } + + /** + * Sets the image size setting (in px). + * + * @param size image size + * @throws IllegalArgumentException if size was negative or zero + */ + public final void setImageSize(int size) { + if (size < 1) { + throw new IllegalArgumentException("Size is negative or zero."); + } + this.imageSize.set(size); + storedSettings.putInt("LAST_IMAGE_SIZE", size); + } + + /** + * Gets the input file path setting. The path may be invalid and the file may not exist. + * + * @return input file path + */ + public final Path getInputFile() { + return inputFile.get(); + } + + /** + * Sets the input file path setting where a text file with requested QR codes can be found. This does not check the + * validity of the path. + * + * @param file input file path + */ + public final void setInputFile(Path file) { + inputFile.set(file); + storedSettings.put("LAST_INPUT_FILE", file.toAbsolutePath().toString()); + } + + /** + * Gets the output directory setting. The path may be invalid and the directory may not exist. + * + * @return output directory path + */ + public final Path getOutputDirectory() { + return outputDir.get(); + } + + /** + * Sets the output directory path setting, where QR images will be stored. This does not check the validity of the + * path. + * + * @param directory directory path setting + */ + public final void setOutputDirectory(Path directory) { + outputDir.set(directory); + storedSettings.put("LAST_OUTPUT_DIR", directory.toAbsolutePath().toString()); + } + + /** + * Gets the setting whether the images should be annotated with human readable text. + * + * @return whether to add annotation + */ + public final boolean getWithAnnotation() { + return withAnnotation.get(); + } + + /** + * Sets the setting whether the images should be annotated with human readable text. + * + * @param withAnnotation whether to add annotation + */ + public final void setWithAnnotation(boolean withAnnotation) { + this.withAnnotation.set(withAnnotation); + storedSettings.putBoolean("LAST_WITH_ANNOTATION", withAnnotation); + } + + /** + * Gets the PDF path. The path may not be valid. + * + * @return PDF path + */ + public final Path getPDFPath() { + return pdfPath.get(); + } + + /** + * Sets the PDF path. This does not check the path for validity. + * + * @param file PDF path + */ + public final void setPDFPath(Path file) { + pdfPath.set(file); + storedSettings.put("LAST_PDF_PATH", file.toAbsolutePath().toString()); + } + + /** + * Gets the code to use as the custom file attribute. + * + * @return code + */ + public final String getCode() { + return code.get(); + } + + /** + * Sets the code to use as the custom file attribute. + * + * @param code the code + * @throws IllegalArgumentException if the provided code had invalid characters + */ + public final void setCode(String code) { + if (!QrPdf.isValidQRCode(code)) { + throw new IllegalArgumentException("Invalid characters in code."); + } + + this.code.set(code); + storedSettings.put("LAST_CODE", code); + } + + + /** + * Gets the input directory path setting. The path may be invalid and the directory may not exist. + * + * @return input directory path + */ + public final Path getInputDirectory() { + return inputDir.get(); + } + + /** + * Sets the input directory path. This does not check the path for validity. + * + * @param path input directory path + */ + public final void setInputDirectory(Path path) { + this.inputDir.set(path); + storedSettings.put("LAST_INPUT_DIR", path.toAbsolutePath().toString()); + } + + /** + * Gets the page number where the QR code should be, according to the user. + * + * @return page number + */ + public final int getQRPage() { + return qrPage.get(); + } + + /** + * Sets the page number where the QR code should be, according to the user. + * + * @param page the page number + * @throws IllegalArgumentException if the page number is negative or zero + */ + public final void setQRPage(int page) { + if (page < 1) { + throw new IllegalArgumentException("Page is negative or zero."); + } + this.qrPage.set(page); + storedSettings.putInt("LAST_QR_PAGE", page); + } + + /** + * Gets the target directory path setting. The path may be invalid and the directory may not exist. + * + * @return target directory path + */ + public final Path getTargetDirectory() { + return targetDir.get(); + } + + /** + * Sets the target directory path. This does not check the path for validity. + * + * @param path target directory path + */ + public final void setTargetDirectory(Path path) { + this.targetDir.set(path); + storedSettings.put("LAST_TARGET_DIR", path.toAbsolutePath().toString()); + } + + /** + * Gets whether the custom file attributes should be used to detect the QR code. + * + * @return whether to use the custom file attributes + */ + public final boolean getUseFileAttributes() { + return useFileAttributes.getValue(); + } + + /** + * Sets whether the custom file attributes should be used to detect the QR code. + * + * @param useFileAttributes whether to use the custom file attributes + */ + public final void setUseFileAttributes(boolean useFileAttributes) { + this.useFileAttributes.set(useFileAttributes); + storedSettings.putBoolean("LAST_USE_FILE_ATTRIBUTES", useFileAttributes); + } + + /** + * Gets whether the PDF files should be renamed according to the found QR code. + * + * @return whether to rename + */ + public final boolean getWithRenaming() { + return withRenaming.getValue(); + } + + /** + * Sets whether the PDF files should be renamed according to the found QR code. + * + * @param withRenaming whether to rename + */ + public final void setWithRenaming(boolean withRenaming) { + this.withRenaming.set(withRenaming); + storedSettings.putBoolean("LAST_WITH_RENAMING", withRenaming); + } + + /** + * Gets whether the custom file attributes should be written when a QR code was detected. + * + * @return whether to write the custom file attributes + */ + public final boolean getWriteFileAttributes() { + return writeFileAttributes.getValue(); + } + + /** + * Sets whether the custom file attributes should be written when a QR code was detected. + * + * @param writeFileAttributes whether to write the custom file attributes + */ + public final void setWriteFileAttributes(boolean writeFileAttributes) { + this.writeFileAttributes.set(writeFileAttributes); + storedSettings.putBoolean("LAST_WRITE_FILE_ATTRIBUTES", writeFileAttributes); + } + + /** + * Gets whether the CSV log file should be opened externally at the end. + * + * @return whether to open the file + */ + public final boolean getOpenLogFile() { + return openLogFile.getValue(); + } + + /** + * Sets whether to open the CSV log file after all operations. + * + * @param openLogFile whether to open the file + */ + public final void setOpenLogFile(boolean openLogFile) { + this.openLogFile.set(openLogFile); + storedSettings.putBoolean("LAST_OPEN_LOG_FILE", openLogFile); + } +} diff --git a/src/main/java/nl/ls31/qrscan/core/QrPdf.java b/src/main/java/nl/ls31/qrscan/model/QrPdf.java similarity index 99% rename from src/main/java/nl/ls31/qrscan/core/QrPdf.java rename to src/main/java/nl/ls31/qrscan/model/QrPdf.java index 15b404f..27d4530 100644 --- a/src/main/java/nl/ls31/qrscan/core/QrPdf.java +++ b/src/main/java/nl/ls31/qrscan/model/QrPdf.java @@ -1,4 +1,4 @@ -package nl.ls31.qrscan.core; +package nl.ls31.qrscan.model; import com.google.zxing.*; import com.google.zxing.client.j2se.BufferedImageLuminanceSource; diff --git a/src/main/java/nl/ls31/qrscan/core/SingleResult.java b/src/main/java/nl/ls31/qrscan/model/SingleResult.java similarity index 98% rename from src/main/java/nl/ls31/qrscan/core/SingleResult.java rename to src/main/java/nl/ls31/qrscan/model/SingleResult.java index 709b469..9fbb537 100644 --- a/src/main/java/nl/ls31/qrscan/core/SingleResult.java +++ b/src/main/java/nl/ls31/qrscan/model/SingleResult.java @@ -1,4 +1,4 @@ -package nl.ls31.qrscan.core; +package nl.ls31.qrscan.model; import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleObjectProperty; @@ -184,7 +184,7 @@ public SimpleObjectProperty qrCodeStatusProperty() { /** * Possible status reports for QR code scanned PDF files. */ - enum ResultStatus { + public enum ResultStatus { QR_CODE_FOUND, NO_FILE_ACCESS, NO_QR_CODE, } } diff --git a/src/main/java/nl/ls31/qrscan/ui/model/CreateSettings.java b/src/main/java/nl/ls31/qrscan/ui/model/CreateSettings.java deleted file mode 100644 index 2a4cf3c..0000000 --- a/src/main/java/nl/ls31/qrscan/ui/model/CreateSettings.java +++ /dev/null @@ -1,114 +0,0 @@ -package nl.ls31.qrscan.ui.model; - -import javafx.beans.property.SimpleBooleanProperty; -import javafx.beans.property.SimpleIntegerProperty; -import javafx.beans.property.SimpleObjectProperty; - -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.prefs.Preferences; - -/** - * This model holds all settings regarding the creation of new QR images. - * - * @author Lars Steggink - */ -public class CreateSettings { - - private final Preferences storedPreferences; - private final SimpleObjectProperty inputFile; - private final SimpleObjectProperty outputDir; - private final SimpleIntegerProperty imageSize; - private final SimpleBooleanProperty withAnnotation; - - public CreateSettings() { - storedPreferences = Preferences.userNodeForPackage(this.getClass()); - - inputFile = new SimpleObjectProperty<>(Paths.get(storedPreferences.get("LAST_INPUT_FILE", ""))); - outputDir = new SimpleObjectProperty<>(Paths.get(storedPreferences.get("LAST_OUTPUT_DIR", ""))); - imageSize = new SimpleIntegerProperty(storedPreferences.getInt("LAST_IMAGE_SIZE", 50)); - withAnnotation = new SimpleBooleanProperty(storedPreferences.getBoolean("LAST_WITH_ANNOTATION", true)); - } - - /** - * Gets image size setting (in px). - * - * @return image size - */ - public final int getImageSize() { - return imageSize.get(); - } - - /** - * Sets the image size setting (in px). - * - * @param size image size - * @throws IllegalArgumentException if size was negative or zero - */ - public final void setImageSize(int size) { - if (size < 1) { - throw new IllegalArgumentException("Size is negative or zero."); - } - this.imageSize.set(size); - storedPreferences.putInt("LAST_IMAGE_SIZE", size); - } - - /** - * Gets the input file path setting. The path may be invalid and the file may not exist. - * - * @return input file path - */ - public final Path getInputFile() { - return inputFile.get(); - } - - /** - * Sets the input file path setting where a text file with requested QR codes can be found. This does not check the - * validity of the path. - * - * @param file input file path - */ - public final void setInputFile(Path file) { - inputFile.set(file); - storedPreferences.put("LAST_INPUT_FILE", file.toAbsolutePath().toString()); - } - - /** - * Gets the output directory setting. The path may be invalid and the directory may not exist. - * - * @return output directory path - */ - public final Path getOutputDirectory() { - return outputDir.get(); - } - - /** - * Sets the output directory path setting, where QR images will be stored. This does not check the validity of the - * path. - * - * @param directory directory path setting - */ - public final void setOutputDirectory(Path directory) { - outputDir.set(directory); - storedPreferences.put("LAST_OUTPUT_DIR", directory.toAbsolutePath().toString()); - } - - /** - * Gets the setting whether the images should be annotated with human readable text. - * - * @return whether to add annotation - */ - public final boolean getWithAnnotation() { - return withAnnotation.get(); - } - - /** - * Sets the setting whether the images should be annotated with human readable text. - * - * @param withAnnotation whether to add annotation - */ - public final void setWithAnnotation(boolean withAnnotation) { - this.withAnnotation.set(withAnnotation); - storedPreferences.putBoolean("LAST_WITH_ANNOTATION", withAnnotation); - } -} diff --git a/src/main/java/nl/ls31/qrscan/ui/model/ManualTagSettings.java b/src/main/java/nl/ls31/qrscan/ui/model/ManualTagSettings.java deleted file mode 100644 index d8984a2..0000000 --- a/src/main/java/nl/ls31/qrscan/ui/model/ManualTagSettings.java +++ /dev/null @@ -1,71 +0,0 @@ -package nl.ls31.qrscan.ui.model; - -import javafx.beans.property.SimpleObjectProperty; -import javafx.beans.property.SimpleStringProperty; -import nl.ls31.qrscan.core.QrPdf; - -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.prefs.Preferences; - -/** - * This model holds all settings regarding the manual tagging operation. - * - * @author Lars Steggink - */ -public class ManualTagSettings { - - private final Preferences storedPreferences; - private final SimpleObjectProperty pdfPath; - private final SimpleStringProperty code; - - public ManualTagSettings() { - storedPreferences = Preferences.userNodeForPackage(this.getClass()); - - pdfPath = new SimpleObjectProperty<>(Paths.get(storedPreferences.get("LAST_PDF_PATH", ""))); - code = new SimpleStringProperty(storedPreferences.get("LAST_CODE", "")); - } - - /** - * Gets the PDF path. The path may not be valid. - * - * @return PDF path - */ - public final Path getPDFPath() { - return pdfPath.get(); - } - - /** - * Sets the PDF path. This does not check the path for validity. - * - * @param file PDF path - */ - public final void setPDFPath(Path file) { - pdfPath.set(file); - storedPreferences.put("LAST_PDF_PATH", file.toAbsolutePath().toString()); - } - - /** - * Gets the code to use as the custom file attribute. - * - * @return code - */ - public final String getCode() { - return code.get(); - } - - /** - * Sets the code to use as the custom file attribute. - * - * @param code the code - * @throws IllegalArgumentException if the provided code had invalid characters - */ - public final void setCode(String code) { - if (!QrPdf.isValidQRCode(code)) { - throw new IllegalArgumentException("Invalid characters in code."); - } - - this.code.set(code); - storedPreferences.put("LAST_CODE", code); - } -} diff --git a/src/main/java/nl/ls31/qrscan/ui/model/ScanSettings.java b/src/main/java/nl/ls31/qrscan/ui/model/ScanSettings.java deleted file mode 100644 index 97ea3ce..0000000 --- a/src/main/java/nl/ls31/qrscan/ui/model/ScanSettings.java +++ /dev/null @@ -1,175 +0,0 @@ -package nl.ls31.qrscan.ui.model; - -import javafx.beans.property.SimpleBooleanProperty; -import javafx.beans.property.SimpleIntegerProperty; -import javafx.beans.property.SimpleObjectProperty; - -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.prefs.Preferences; - -/** - * This model hold all settings regarding the scan task. - * - * @author Lars Steggink - */ -public class ScanSettings { - - private final Preferences storedPreferences; - private final SimpleObjectProperty inputDir; - private final SimpleObjectProperty targetDir; - private final SimpleIntegerProperty qrPage; - private final SimpleBooleanProperty withRenaming; - private final SimpleBooleanProperty useFileAttributes; - private final SimpleBooleanProperty writeFileAttributes; - private final SimpleBooleanProperty openLogFile; - - public ScanSettings() { - storedPreferences = Preferences.userNodeForPackage(this.getClass()); - - inputDir = new SimpleObjectProperty<>(Paths.get(storedPreferences.get("LAST_INPUT_DIR", ""))); - targetDir = new SimpleObjectProperty<>(Paths.get(storedPreferences.get("LAST_TARGET_DIR", ""))); - qrPage = new SimpleIntegerProperty(storedPreferences.getInt("LAST_QR_PAGE", 1)); - withRenaming = new SimpleBooleanProperty(storedPreferences.getBoolean("LAST_WITH_RENAMING", false)); - useFileAttributes = new SimpleBooleanProperty(storedPreferences.getBoolean("LAST_USE_FILE_ATTRIBUTES", true)); - writeFileAttributes = new SimpleBooleanProperty(storedPreferences.getBoolean("LAST_WRITE_FILE_ATTRIBUTES", true)); - openLogFile = new SimpleBooleanProperty(storedPreferences.getBoolean("LAST_OPEN_LOG_FILE", true)); - } - - /** - * Gets the input directory path setting. The path may be invalid and the directory may not exist. - * - * @return input directory path - */ - public final Path getInputDirectory() { - return inputDir.get(); - } - - /** - * Sets the input directory path. This does not check the path for validity. - * - * @param path input directory path - */ - public final void setInputDirectory(Path path) { - this.inputDir.set(path); - storedPreferences.put("LAST_INPUT_DIR", path.toAbsolutePath().toString()); - } - - /** - * Gets the page number where the QR code should be, according to the user. - * - * @return page number - */ - public final int getQRPage() { - return qrPage.get(); - } - - /** - * Sets the page number where the QR code should be, according to the user. - * - * @param page the page number - * @throws IllegalArgumentException if the page number is negative or zero - */ - public final void setQRPage(int page) { - if (page < 1) { - throw new IllegalArgumentException("Page is negative or zero."); - } - this.qrPage.set(page); - storedPreferences.putInt("LAST_QR_PAGE", page); - } - - /** - * Gets the target directory path setting. The path may be invalid and the directory may not exist. - * - * @return target directory path - */ - public final Path getTargetDirectory() { - return targetDir.get(); - } - - /** - * Sets the target directory path. This does not check the path for validity. - * - * @param path target directory path - */ - public final void setTargetDirectory(Path path) { - this.targetDir.set(path); - storedPreferences.put("LAST_TARGET_DIR", path.toAbsolutePath().toString()); - } - - /** - * Gets whether the custom file attributes should be used to detect the QR code. - * - * @return whether to use the custom file attributes - */ - public final boolean getUseFileAttributes() { - return useFileAttributes.getValue(); - } - - /** - * Sets whether the custom file attributes should be used to detect the QR code. - * - * @param useFileAttributes whether to use the custom file attributes - */ - public final void setUseFileAttributes(boolean useFileAttributes) { - this.useFileAttributes.set(useFileAttributes); - storedPreferences.putBoolean("LAST_USE_FILE_ATTRIBUTES", useFileAttributes); - } - - /** - * Gets whether the PDF files should be renamed according to the found QR code. - * - * @return whether to rename - */ - public final boolean getWithRenaming() { - return withRenaming.getValue(); - } - - /** - * Sets whether the PDF files should be renamed according to the found QR code. - * - * @param withRenaming whether to rename - */ - public final void setWithRenaming(boolean withRenaming) { - this.withRenaming.set(withRenaming); - storedPreferences.putBoolean("LAST_WITH_RENAMING", withRenaming); - } - - /** - * Gets whether the custom file attributes should be written when a QR code was detected. - * - * @return whether to write the custom file attributes - */ - public final boolean getWriteFileAttributes() { - return writeFileAttributes.getValue(); - } - - /** - * Sets whether the custom file attributes should be written when a QR code was detected. - * - * @param writeFileAttributes whether to write the custom file attributes - */ - public final void setWriteFileAttributes(boolean writeFileAttributes) { - this.writeFileAttributes.set(writeFileAttributes); - storedPreferences.putBoolean("LAST_WRITE_FILE_ATTRIBUTES", writeFileAttributes); - } - - /** - * Gets whether the CSV log file should be opened externally at the end. - * - * @return whether to open the file - */ - public final boolean getOpenLogFile() { - return openLogFile.getValue(); - } - - /** - * Sets whether to open the CSV log file after all operations. - * - * @param openLogFile whether to open the file - */ - public final void setOpenLogFile(boolean openLogFile) { - this.openLogFile.set(openLogFile); - storedPreferences.putBoolean("LAST_OPEN_LOG_FILE", openLogFile); - } -} diff --git a/src/main/java/nl/ls31/qrscan/ui/view/ProgressDialog.java b/src/main/java/nl/ls31/qrscan/view/ProgressDialog.java similarity index 98% rename from src/main/java/nl/ls31/qrscan/ui/view/ProgressDialog.java rename to src/main/java/nl/ls31/qrscan/view/ProgressDialog.java index 95a8318..4d16e36 100644 --- a/src/main/java/nl/ls31/qrscan/ui/view/ProgressDialog.java +++ b/src/main/java/nl/ls31/qrscan/view/ProgressDialog.java @@ -1,4 +1,4 @@ -package nl.ls31.qrscan.ui.view; +package nl.ls31.qrscan.view; import javafx.beans.property.ReadOnlyDoubleProperty; import javafx.geometry.Pos; diff --git a/src/main/java/nl/ls31/qrscan/ui/view/ResultsDialog.java b/src/main/java/nl/ls31/qrscan/view/ResultsDialog.java similarity index 97% rename from src/main/java/nl/ls31/qrscan/ui/view/ResultsDialog.java rename to src/main/java/nl/ls31/qrscan/view/ResultsDialog.java index 6699915..99b5a19 100644 --- a/src/main/java/nl/ls31/qrscan/ui/view/ResultsDialog.java +++ b/src/main/java/nl/ls31/qrscan/view/ResultsDialog.java @@ -1,4 +1,4 @@ -package nl.ls31.qrscan.ui.view; +package nl.ls31.qrscan.view; import javafx.collections.FXCollections; import javafx.collections.ObservableList; @@ -12,7 +12,7 @@ import javafx.stage.Modality; import javafx.stage.Stage; import javafx.stage.StageStyle; -import nl.ls31.qrscan.core.SingleResult; +import nl.ls31.qrscan.model.SingleResult; import java.util.List; diff --git a/src/main/resources/fxml/CreateView.fxml b/src/main/resources/fxml/CreateView.fxml index c410225..c22f3c2 100644 --- a/src/main/resources/fxml/CreateView.fxml +++ b/src/main/resources/fxml/CreateView.fxml @@ -6,7 +6,7 @@ + xmlns="http://javafx.com/javafx/11.0.1" fx:controller="nl.ls31.qrscan.controller.CreateController">

diff --git a/src/main/resources/fxml/ManualTagView.fxml b/src/main/resources/fxml/ManualTagView.fxml index 474b8e3..af01396 100644 --- a/src/main/resources/fxml/ManualTagView.fxml +++ b/src/main/resources/fxml/ManualTagView.fxml @@ -6,7 +6,7 @@ + xmlns="http://javafx.com/javafx/11.0.1" fx:controller="nl.ls31.qrscan.controller.ManualTagController">
diff --git a/src/main/resources/fxml/RootLayout.fxml b/src/main/resources/fxml/RootLayout.fxml index e69d043..29a487d 100644 --- a/src/main/resources/fxml/RootLayout.fxml +++ b/src/main/resources/fxml/RootLayout.fxml @@ -4,7 +4,7 @@ + xmlns="http://javafx.com/javafx/11.0.1" fx:controller="nl.ls31.qrscan.controller.RootController"> diff --git a/src/main/resources/fxml/ScanView.fxml b/src/main/resources/fxml/ScanView.fxml index b7478b1..ae4aaf2 100644 --- a/src/main/resources/fxml/ScanView.fxml +++ b/src/main/resources/fxml/ScanView.fxml @@ -7,7 +7,7 @@ + fx:controller="nl.ls31.qrscan.controller.ScanController">
From cd6b5760ba3ca99c478fba913c85380ea252cd9b Mon Sep 17 00:00:00 2001 From: LS31 Date: Thu, 28 May 2020 00:02:32 +0200 Subject: [PATCH 03/10] Rename settings for clarity. --- .../qrscan/controller/CreateController.java | 24 +- .../controller/ManualTagController.java | 16 +- .../qrscan/controller/ScanController.java | 18 +- .../nl/ls31/qrscan/model/AppSettings.java | 218 +++++++++--------- 4 files changed, 139 insertions(+), 137 deletions(-) diff --git a/src/main/java/nl/ls31/qrscan/controller/CreateController.java b/src/main/java/nl/ls31/qrscan/controller/CreateController.java index 4f99553..9418499 100644 --- a/src/main/java/nl/ls31/qrscan/controller/CreateController.java +++ b/src/main/java/nl/ls31/qrscan/controller/CreateController.java @@ -51,10 +51,10 @@ public void setMainApp(MainApp mainApp) { * Update all control states using the model as reference. */ public void updateControlsByModel() { - inputFileTextField.setText(mainApp.getAppSettings().getInputFile().toAbsolutePath().toString()); - outputDirTextField.setText(mainApp.getAppSettings().getOutputDirectory().toAbsolutePath().toString()); - annotationCheckBox.setSelected(mainApp.getAppSettings().getWithAnnotation()); - sizeSpinner.getValueFactory().setValue(mainApp.getAppSettings().getImageSize()); + inputFileTextField.setText(mainApp.getAppSettings().getCodesInputFile().toAbsolutePath().toString()); + outputDirTextField.setText(mainApp.getAppSettings().getQrcodeImageOutputDirectory().toAbsolutePath().toString()); + annotationCheckBox.setSelected(mainApp.getAppSettings().getQrcodeImageWithAnnotation()); + sizeSpinner.getValueFactory().setValue(mainApp.getAppSettings().getQrcodeImageSize()); } /** @@ -68,7 +68,7 @@ private void handleInputFileButton() { if (file != null) { // Change the text field and update the model. inputFileTextField.setText(file.toPath().toAbsolutePath().toString()); - mainApp.getAppSettings().setInputFile(file.toPath()); + mainApp.getAppSettings().setCodesInputFile(file.toPath()); } } @@ -83,7 +83,7 @@ private void handleOutputDirButton() { if (dir != null) { // Change the text field and update the model. outputDirTextField.setText(dir.toPath().toAbsolutePath().toString()); - mainApp.getAppSettings().setOutputDirectory(dir.toPath()); + mainApp.getAppSettings().setQrcodeImageOutputDirectory(dir.toPath()); } } @@ -92,7 +92,7 @@ private void handleOutputDirButton() { */ @FXML private void handleAnnotationCheckBox() { - mainApp.getAppSettings().setWithAnnotation(annotationCheckBox.isSelected()); + mainApp.getAppSettings().setQrcodeImageWithAnnotation(annotationCheckBox.isSelected()); } /** @@ -100,11 +100,11 @@ private void handleAnnotationCheckBox() { */ @FXML private void handleCreateButton() { - Path inputFile = mainApp.getAppSettings().getInputFile(); - Path outputDir = mainApp.getAppSettings().getOutputDirectory(); - boolean withAnnotation = mainApp.getAppSettings().getWithAnnotation(); - mainApp.getAppSettings().setImageSize(sizeSpinner.getValue()); - int size = mainApp.getAppSettings().getImageSize(); + Path inputFile = mainApp.getAppSettings().getCodesInputFile(); + Path outputDir = mainApp.getAppSettings().getQrcodeImageOutputDirectory(); + boolean withAnnotation = mainApp.getAppSettings().getQrcodeImageWithAnnotation(); + mainApp.getAppSettings().setQrcodeImageSize(sizeSpinner.getValue()); + int size = mainApp.getAppSettings().getQrcodeImageSize(); Task> createTask = new CreateTask(inputFile, outputDir, size, withAnnotation); diff --git a/src/main/java/nl/ls31/qrscan/controller/ManualTagController.java b/src/main/java/nl/ls31/qrscan/controller/ManualTagController.java index f134993..9602fb7 100644 --- a/src/main/java/nl/ls31/qrscan/controller/ManualTagController.java +++ b/src/main/java/nl/ls31/qrscan/controller/ManualTagController.java @@ -60,7 +60,7 @@ private void handlePDFPathButton() { if (file != null) { // Change the text field and update the model. pdfPathField.setText(file.toPath().toAbsolutePath().toString()); - mainApp.getAppSettings().setPDFPath(file.toPath()); + mainApp.getAppSettings().setManualPdf(file.toPath()); } } @@ -70,7 +70,7 @@ private void handlePDFPathButton() { @FXML private void handleTagButton() { try { - mainApp.getAppSettings().setCode(codeField.getText()); + mainApp.getAppSettings().setManualCode(codeField.getText()); tagFile(); } catch (IllegalArgumentException e) { Alert alert = new Alert(AlertType.ERROR); @@ -95,11 +95,11 @@ public void setMainApp(MainApp mainApp) { */ private void tagFile() { AppSettings settings = mainApp.getAppSettings(); - QrPdf pdf = new QrPdf(settings.getPDFPath()); + QrPdf pdf = new QrPdf(settings.getManualPdf()); try { - pdf.setQRCodeFileAttribute(settings.getCode()); - String message = "Successfully tagged " + settings.getPDFPath().getFileName().toString() + " with code " - + settings.getCode() + ". "; + pdf.setQRCodeFileAttribute(settings.getManualCode()); + String message = "Successfully tagged " + settings.getManualPdf().getFileName().toString() + " with code " + + settings.getManualCode() + ". "; Logger.info(message); Alert alert = new Alert(AlertType.INFORMATION); alert.setTitle("Task finished."); @@ -121,7 +121,7 @@ private void tagFile() { } public void updateControlsByModel() { - pdfPathField.setText(mainApp.getAppSettings().getPDFPath().toAbsolutePath().toString()); - codeField.setText(mainApp.getAppSettings().getCode()); + pdfPathField.setText(mainApp.getAppSettings().getManualPdf().toAbsolutePath().toString()); + codeField.setText(mainApp.getAppSettings().getManualCode()); } } diff --git a/src/main/java/nl/ls31/qrscan/controller/ScanController.java b/src/main/java/nl/ls31/qrscan/controller/ScanController.java index f3eba82..373eb04 100644 --- a/src/main/java/nl/ls31/qrscan/controller/ScanController.java +++ b/src/main/java/nl/ls31/qrscan/controller/ScanController.java @@ -62,9 +62,9 @@ public void setMainApp(MainApp mainApp) { public void updateControlsByModel() { inputDirTextField.setText(mainApp.getAppSettings().getInputDirectory().toAbsolutePath().toString()); targetDirTextField.setText(mainApp.getAppSettings().getTargetDirectory().toAbsolutePath().toString()); - useFileAttributeCheckBox.setSelected(mainApp.getAppSettings().getUseFileAttributes()); - writeFileAttributeCheckBox.setSelected(mainApp.getAppSettings().getWriteFileAttributes()); - renameCheckBox.setSelected(mainApp.getAppSettings().getWithRenaming()); + useFileAttributeCheckBox.setSelected(mainApp.getAppSettings().getUseFileAttribute()); + writeFileAttributeCheckBox.setSelected(mainApp.getAppSettings().getWriteFileAttribute()); + renameCheckBox.setSelected(mainApp.getAppSettings().getWithFileRenaming()); toggleRenaming(); openLogFileCheckBox.setSelected(mainApp.getAppSettings().getOpenLogFile()); qrPageSpinner.getValueFactory().setValue(mainApp.getAppSettings().getQRPage()); @@ -105,7 +105,7 @@ private void handleTargetDirButton() { */ @FXML private void handleUseFileAttributeCheckBox() { - mainApp.getAppSettings().setUseFileAttributes(useFileAttributeCheckBox.isSelected()); + mainApp.getAppSettings().setUseFileAttribute(useFileAttributeCheckBox.isSelected()); } /** @@ -114,7 +114,7 @@ private void handleUseFileAttributeCheckBox() { */ @FXML private void handleWriteFileAttributeCheckBox() { - mainApp.getAppSettings().setWriteFileAttributes(writeFileAttributeCheckBox.isSelected()); + mainApp.getAppSettings().setWriteFileAttribute(writeFileAttributeCheckBox.isSelected()); } /** @@ -130,7 +130,7 @@ private void handleOpenLogFileCheckBox() { */ @FXML private void handleRenameCheckBox() { - mainApp.getAppSettings().setWithRenaming(renameCheckBox.isSelected()); + mainApp.getAppSettings().setWithFileRenaming(renameCheckBox.isSelected()); toggleRenaming(); } @@ -161,12 +161,12 @@ private void handleScanButton() { Path inputDir = appSettings.getInputDirectory(); int qrPage = appSettings.getQRPage(); - boolean useFileAttributes = appSettings.getUseFileAttributes(); - boolean writeFileAttributes = appSettings.getWriteFileAttributes(); + boolean useFileAttributes = appSettings.getUseFileAttribute(); + boolean writeFileAttributes = appSettings.getWriteFileAttribute(); boolean openLogFile = appSettings.getOpenLogFile(); Task> task; - if (appSettings.getWithRenaming()) { + if (appSettings.getWithFileRenaming()) { Path targetDir = appSettings.getTargetDirectory(); task = new RenameTask(inputDir, targetDir, qrPage, useFileAttributes, writeFileAttributes, openLogFile); } else { diff --git a/src/main/java/nl/ls31/qrscan/model/AppSettings.java b/src/main/java/nl/ls31/qrscan/model/AppSettings.java index 51cbb8d..e9aa6ac 100644 --- a/src/main/java/nl/ls31/qrscan/model/AppSettings.java +++ b/src/main/java/nl/ls31/qrscan/model/AppSettings.java @@ -10,75 +10,76 @@ import java.util.prefs.Preferences; /** - * This model holds all settings set by the user. + * This model holds all settings set by the user in the application. Last used values are stored for future reference. * * @author Lars Steggink */ public class AppSettings { private final Preferences storedSettings; - private final SimpleObjectProperty inputFile; - private final SimpleObjectProperty outputDir; - private final SimpleIntegerProperty imageSize; - private final SimpleBooleanProperty withAnnotation; - private final SimpleObjectProperty pdfPath; - private final SimpleStringProperty code; - private final SimpleObjectProperty inputDir; - private final SimpleObjectProperty targetDir; - private final SimpleIntegerProperty qrPage; - private final SimpleBooleanProperty withRenaming; - private final SimpleBooleanProperty useFileAttributes; - private final SimpleBooleanProperty writeFileAttributes; + private final SimpleObjectProperty codesInputFile; + private final SimpleObjectProperty qrcodeImageOutputDirectory; + private final SimpleIntegerProperty qrcodeImageSize; + private final SimpleBooleanProperty qrcodeImageWithAnnotation; + private final SimpleObjectProperty manualPdf; + private final SimpleStringProperty manualCode; + private final SimpleObjectProperty pdfInputDirectory; + private final SimpleObjectProperty pdfTargetDirectory; + private final SimpleIntegerProperty searchAtPage; + private final SimpleBooleanProperty withFileRenaming; + private final SimpleBooleanProperty useFileAttribute; + private final SimpleBooleanProperty writeFileAttribute; private final SimpleBooleanProperty openLogFile; public AppSettings() { storedSettings = Preferences.userNodeForPackage(this.getClass()); - inputFile = new SimpleObjectProperty<>(Paths.get(storedSettings.get("LAST_INPUT_FILE", ""))); - outputDir = new SimpleObjectProperty<>(Paths.get(storedSettings.get("LAST_OUTPUT_DIR", ""))); - imageSize = new SimpleIntegerProperty(storedSettings.getInt("LAST_IMAGE_SIZE", 50)); - withAnnotation = new SimpleBooleanProperty(storedSettings.getBoolean("LAST_WITH_ANNOTATION", true)); - pdfPath = new SimpleObjectProperty<>(Paths.get(storedSettings.get("LAST_PDF_PATH", ""))); - code = new SimpleStringProperty(storedSettings.get("LAST_CODE", "")); - inputDir = new SimpleObjectProperty<>(Paths.get(storedSettings.get("LAST_INPUT_DIR", ""))); - targetDir = new SimpleObjectProperty<>(Paths.get(storedSettings.get("LAST_TARGET_DIR", ""))); - qrPage = new SimpleIntegerProperty(storedSettings.getInt("LAST_QR_PAGE", 1)); - withRenaming = new SimpleBooleanProperty(storedSettings.getBoolean("LAST_WITH_RENAMING", false)); - useFileAttributes = new SimpleBooleanProperty(storedSettings.getBoolean("LAST_USE_FILE_ATTRIBUTES", true)); - writeFileAttributes = new SimpleBooleanProperty(storedSettings.getBoolean("LAST_WRITE_FILE_ATTRIBUTES", true)); - openLogFile = new SimpleBooleanProperty(storedSettings.getBoolean("LAST_OPEN_LOG_FILE", true)); + codesInputFile = new SimpleObjectProperty<>(Paths.get(storedSettings.get("CODES_INPUT_FILE", ""))); + qrcodeImageOutputDirectory = new SimpleObjectProperty<>(Paths.get(storedSettings.get("QRCODE_IMAGE_OUTPUT_DIR", ""))); + qrcodeImageSize = new SimpleIntegerProperty(storedSettings.getInt("QRCODE_IMAGE_SIZE", 50)); + qrcodeImageWithAnnotation = new SimpleBooleanProperty(storedSettings.getBoolean("QRCODE_IMAGE_WITH_ANNOTATION", true)); + manualPdf = new SimpleObjectProperty<>(Paths.get(storedSettings.get("MANUAL_PDF", ""))); + manualCode = new SimpleStringProperty(storedSettings.get("MANUAL_CODE", "")); + pdfInputDirectory = new SimpleObjectProperty<>(Paths.get(storedSettings.get("PDF_INPUT_DIRECTORY", ""))); + pdfTargetDirectory = new SimpleObjectProperty<>(Paths.get(storedSettings.get("PDF_TARGET_DIRECTORY", ""))); + searchAtPage = new SimpleIntegerProperty(storedSettings.getInt("SEARCH_AT_PAGE", 1)); + withFileRenaming = new SimpleBooleanProperty(storedSettings.getBoolean("WITH_FILE_RENAMING", false)); + useFileAttribute = new SimpleBooleanProperty(storedSettings.getBoolean("USE_FILE_ATTRIBUTE", true)); + writeFileAttribute = new SimpleBooleanProperty(storedSettings.getBoolean("WRITE_FILE_ATTRIBUTE", true)); + openLogFile = new SimpleBooleanProperty(storedSettings.getBoolean("OPEN_LOG_FILE", false)); } /** - * Gets image size setting (in px). + * Gets the setting for image size (px) for the creation of new GIFs with QR codes. * - * @return image size + * @return image size (px) */ - public final int getImageSize() { - return imageSize.get(); + public final int getQrcodeImageSize() { + return qrcodeImageSize.get(); } /** - * Sets the image size setting (in px). + * Sets the setting for image size (px) for the creation of new GIFs with QR codes. * - * @param size image size + * @param size image size (px) * @throws IllegalArgumentException if size was negative or zero */ - public final void setImageSize(int size) { + public final void setQrcodeImageSize(int size) { if (size < 1) { throw new IllegalArgumentException("Size is negative or zero."); } - this.imageSize.set(size); - storedSettings.putInt("LAST_IMAGE_SIZE", size); + this.qrcodeImageSize.set(size); + storedSettings.putInt("QRCODE_IMAGE_SIZE", size); } /** - * Gets the input file path setting. The path may be invalid and the file may not exist. + * Gets the input file path setting where a text file with requested QR codes can be found. This does not check the + * * validity of the path. * * @return input file path */ - public final Path getInputFile() { - return inputFile.get(); + public final Path getCodesInputFile() { + return codesInputFile.get(); } /** @@ -87,29 +88,30 @@ public final Path getInputFile() { * * @param file input file path */ - public final void setInputFile(Path file) { - inputFile.set(file); - storedSettings.put("LAST_INPUT_FILE", file.toAbsolutePath().toString()); + public final void setCodesInputFile(Path file) { + codesInputFile.set(file); + storedSettings.put("CODES_INPUT_FILE", file.toAbsolutePath().toString()); } /** - * Gets the output directory setting. The path may be invalid and the directory may not exist. + * Gets the setting for the output directory where the GIFs with QR codes will be saved. This does not check the validity of the + * path. * * @return output directory path */ - public final Path getOutputDirectory() { - return outputDir.get(); + public final Path getQrcodeImageOutputDirectory() { + return qrcodeImageOutputDirectory.get(); } /** - * Sets the output directory path setting, where QR images will be stored. This does not check the validity of the + * Sets the setting for the output directory where the GIFs with QR codes will be saved. This does not check the validity of the * path. * - * @param directory directory path setting + * @param directory output directory path */ - public final void setOutputDirectory(Path directory) { - outputDir.set(directory); - storedSettings.put("LAST_OUTPUT_DIR", directory.toAbsolutePath().toString()); + public final void setQrcodeImageOutputDirectory(Path directory) { + qrcodeImageOutputDirectory.set(directory); + storedSettings.put("QRCODE_IMAGE_OUTPUT_DIR", directory.toAbsolutePath().toString()); } /** @@ -117,8 +119,8 @@ public final void setOutputDirectory(Path directory) { * * @return whether to add annotation */ - public final boolean getWithAnnotation() { - return withAnnotation.get(); + public final boolean getQrcodeImageWithAnnotation() { + return qrcodeImageWithAnnotation.get(); } /** @@ -126,28 +128,28 @@ public final boolean getWithAnnotation() { * * @param withAnnotation whether to add annotation */ - public final void setWithAnnotation(boolean withAnnotation) { - this.withAnnotation.set(withAnnotation); - storedSettings.putBoolean("LAST_WITH_ANNOTATION", withAnnotation); + public final void setQrcodeImageWithAnnotation(boolean withAnnotation) { + this.qrcodeImageWithAnnotation.set(withAnnotation); + storedSettings.putBoolean("QRCODE_IMAGE_WITH_ANNOTATION", withAnnotation); } /** - * Gets the PDF path. The path may not be valid. + * Gets the path to the PDF that will be manually tagged with a custom file attribute. This does not check the path for validity. * * @return PDF path */ - public final Path getPDFPath() { - return pdfPath.get(); + public final Path getManualPdf() { + return manualPdf.get(); } /** - * Sets the PDF path. This does not check the path for validity. + * Sets the path to the PDF that will be manually tagged with a custom file attribute. This does not check the path for validity. * * @param file PDF path */ - public final void setPDFPath(Path file) { - pdfPath.set(file); - storedSettings.put("LAST_PDF_PATH", file.toAbsolutePath().toString()); + public final void setManualPdf(Path file) { + manualPdf.set(file); + storedSettings.put("MANUAL_PDF", file.toAbsolutePath().toString()); } /** @@ -155,8 +157,8 @@ public final void setPDFPath(Path file) { * * @return code */ - public final String getCode() { - return code.get(); + public final String getManualCode() { + return manualCode.get(); } /** @@ -165,46 +167,46 @@ public final String getCode() { * @param code the code * @throws IllegalArgumentException if the provided code had invalid characters */ - public final void setCode(String code) { + public final void setManualCode(String code) { if (!QrPdf.isValidQRCode(code)) { throw new IllegalArgumentException("Invalid characters in code."); } - this.code.set(code); - storedSettings.put("LAST_CODE", code); + this.manualCode.set(code); + storedSettings.put("MANUAL_CODE", code); } /** - * Gets the input directory path setting. The path may be invalid and the directory may not exist. + * Gets the input directory path for scanning and/or renaming of PDFs. This does not check the path for validity. * * @return input directory path */ public final Path getInputDirectory() { - return inputDir.get(); + return pdfInputDirectory.get(); } /** - * Sets the input directory path. This does not check the path for validity. + * Sets the input directory path for scanning and/or renaming of PDFs. This does not check the path for validity. * - * @param path input directory path + * @param directory input directory path */ - public final void setInputDirectory(Path path) { - this.inputDir.set(path); - storedSettings.put("LAST_INPUT_DIR", path.toAbsolutePath().toString()); + public final void setInputDirectory(Path directory) { + this.pdfInputDirectory.set(directory); + storedSettings.put("PDF_INPUT_DIRECTORY", directory.toAbsolutePath().toString()); } /** - * Gets the page number where the QR code should be, according to the user. + * Gets the page number where the QR code should be searched for, according to the user. * * @return page number */ public final int getQRPage() { - return qrPage.get(); + return searchAtPage.get(); } /** - * Sets the page number where the QR code should be, according to the user. + * Sets the page number where the QR code should be searched for, according to the user. * * @param page the page number * @throws IllegalArgumentException if the page number is negative or zero @@ -213,46 +215,46 @@ public final void setQRPage(int page) { if (page < 1) { throw new IllegalArgumentException("Page is negative or zero."); } - this.qrPage.set(page); - storedSettings.putInt("LAST_QR_PAGE", page); + this.searchAtPage.set(page); + storedSettings.putInt("SEARCH_AT_PAGE", page); } /** - * Gets the target directory path setting. The path may be invalid and the directory may not exist. + * Gets the target directory path for renamed PDFs. This does not check the path for validity. * * @return target directory path */ public final Path getTargetDirectory() { - return targetDir.get(); + return pdfTargetDirectory.get(); } /** - * Sets the target directory path. This does not check the path for validity. + * Sets the target directory path for renamed PDFs. This does not check the path for validity. * - * @param path target directory path + * @param directory target directory path */ - public final void setTargetDirectory(Path path) { - this.targetDir.set(path); - storedSettings.put("LAST_TARGET_DIR", path.toAbsolutePath().toString()); + public final void setTargetDirectory(Path directory) { + this.pdfTargetDirectory.set(directory); + storedSettings.put("PDF_TARGET_DIRECTORY", directory.toAbsolutePath().toString()); } /** - * Gets whether the custom file attributes should be used to detect the QR code. + * Gets whether the custom file attributes should be used to detect a (QR) code. * * @return whether to use the custom file attributes */ - public final boolean getUseFileAttributes() { - return useFileAttributes.getValue(); + public final boolean getUseFileAttribute() { + return useFileAttribute.getValue(); } /** - * Sets whether the custom file attributes should be used to detect the QR code. + * Sets whether the custom file attributes should be used to detect a (QR) code. * - * @param useFileAttributes whether to use the custom file attributes + * @param useFileAttribute whether to use the custom file attributes */ - public final void setUseFileAttributes(boolean useFileAttributes) { - this.useFileAttributes.set(useFileAttributes); - storedSettings.putBoolean("LAST_USE_FILE_ATTRIBUTES", useFileAttributes); + public final void setUseFileAttribute(boolean useFileAttribute) { + this.useFileAttribute.set(useFileAttribute); + storedSettings.putBoolean("USE_FILE_ATTRIBUTE", useFileAttribute); } /** @@ -260,18 +262,18 @@ public final void setUseFileAttributes(boolean useFileAttributes) { * * @return whether to rename */ - public final boolean getWithRenaming() { - return withRenaming.getValue(); + public final boolean getWithFileRenaming() { + return withFileRenaming.getValue(); } /** * Sets whether the PDF files should be renamed according to the found QR code. * - * @param withRenaming whether to rename + * @param withFileRenaming whether to rename */ - public final void setWithRenaming(boolean withRenaming) { - this.withRenaming.set(withRenaming); - storedSettings.putBoolean("LAST_WITH_RENAMING", withRenaming); + public final void setWithFileRenaming(boolean withFileRenaming) { + this.withFileRenaming.set(withFileRenaming); + storedSettings.putBoolean("WITH_FILE_RENAMING", withFileRenaming); } /** @@ -279,22 +281,22 @@ public final void setWithRenaming(boolean withRenaming) { * * @return whether to write the custom file attributes */ - public final boolean getWriteFileAttributes() { - return writeFileAttributes.getValue(); + public final boolean getWriteFileAttribute() { + return writeFileAttribute.getValue(); } /** * Sets whether the custom file attributes should be written when a QR code was detected. * - * @param writeFileAttributes whether to write the custom file attributes + * @param writeFileAttribute whether to write the custom file attributes */ - public final void setWriteFileAttributes(boolean writeFileAttributes) { - this.writeFileAttributes.set(writeFileAttributes); - storedSettings.putBoolean("LAST_WRITE_FILE_ATTRIBUTES", writeFileAttributes); + public final void setWriteFileAttribute(boolean writeFileAttribute) { + this.writeFileAttribute.set(writeFileAttribute); + storedSettings.putBoolean("WRITE_FILE_ATTRIBUTE", writeFileAttribute); } /** - * Gets whether the CSV log file should be opened externally at the end. + * Gets whether the CSV log file should be opened externally at the end of scanning and/or renaming. * * @return whether to open the file */ @@ -303,12 +305,12 @@ public final boolean getOpenLogFile() { } /** - * Sets whether to open the CSV log file after all operations. + * Sets whether to open the CSV log file at the end of scanning and/or renaming. * * @param openLogFile whether to open the file */ public final void setOpenLogFile(boolean openLogFile) { this.openLogFile.set(openLogFile); - storedSettings.putBoolean("LAST_OPEN_LOG_FILE", openLogFile); + storedSettings.putBoolean("OPEN_LOG_FILE", openLogFile); } } From c4f86019ed88f3adbbe6aa3da5e774cbf14c9d91 Mon Sep 17 00:00:00 2001 From: LS31 Date: Thu, 28 May 2020 00:38:07 +0200 Subject: [PATCH 04/10] Renaming and refactoring for clarity. --- src/main/java/nl/ls31/qrscan/MainApp.java | 10 +++--- ...oller.java => CreateImagesController.java} | 6 ++-- ...oller.java => ManualTagPdfController.java} | 8 ++--- .../qrscan/controller/RootController.java | 26 ++++++--------- ...ontroller.java => ScanPdfsController.java} | 16 ++++----- ...{CreateTask.java => CreateImagesTask.java} | 9 +++-- .../nl/ls31/qrscan/core/CsvLogWriter.java | 8 ++--- .../QrPdf.java => core/PdfScanner.java} | 10 +++--- ...mageWriter.java => QrcodeImageWriter.java} | 2 +- .../{RenameTask.java => RenamePdfsTask.java} | 33 ++++++++++--------- .../core/{ScanTask.java => ScanPdfsTask.java} | 33 +++++++++---------- .../nl/ls31/qrscan/model/AppSettings.java | 3 +- .../{SingleResult.java => PdfScanResult.java} | 12 ++++--- .../nl/ls31/qrscan/view/ResultsDialog.java | 20 +++++------ ...{CreateView.fxml => CreateImagesView.fxml} | 2 +- ...nualTagView.fxml => ManualTagPdfView.fxml} | 2 +- .../fxml/{ScanView.fxml => ScanPdfsView.fxml} | 2 +- 17 files changed, 100 insertions(+), 102 deletions(-) rename src/main/java/nl/ls31/qrscan/controller/{CreateController.java => CreateImagesController.java} (95%) rename src/main/java/nl/ls31/qrscan/controller/{ManualTagController.java => ManualTagPdfController.java} (95%) rename src/main/java/nl/ls31/qrscan/controller/{ScanController.java => ScanPdfsController.java} (92%) rename src/main/java/nl/ls31/qrscan/core/{CreateTask.java => CreateImagesTask.java} (94%) rename src/main/java/nl/ls31/qrscan/{model/QrPdf.java => core/PdfScanner.java} (98%) rename src/main/java/nl/ls31/qrscan/core/{QrImageWriter.java => QrcodeImageWriter.java} (99%) rename src/main/java/nl/ls31/qrscan/core/{RenameTask.java => RenamePdfsTask.java} (80%) rename src/main/java/nl/ls31/qrscan/core/{ScanTask.java => ScanPdfsTask.java} (81%) rename src/main/java/nl/ls31/qrscan/model/{SingleResult.java => PdfScanResult.java} (91%) rename src/main/resources/fxml/{CreateView.fxml => CreateImagesView.fxml} (98%) rename src/main/resources/fxml/{ManualTagView.fxml => ManualTagPdfView.fxml} (98%) rename src/main/resources/fxml/{ScanView.fxml => ScanPdfsView.fxml} (98%) diff --git a/src/main/java/nl/ls31/qrscan/MainApp.java b/src/main/java/nl/ls31/qrscan/MainApp.java index 90a266a..0adba2d 100644 --- a/src/main/java/nl/ls31/qrscan/MainApp.java +++ b/src/main/java/nl/ls31/qrscan/MainApp.java @@ -7,7 +7,7 @@ import javafx.scene.layout.BorderPane; import javafx.stage.Stage; import nl.ls31.qrscan.controller.RootController; -import nl.ls31.qrscan.controller.ScanController; +import nl.ls31.qrscan.controller.ScanPdfsController; import nl.ls31.qrscan.model.AppSettings; import org.tinylog.Logger; @@ -67,7 +67,7 @@ public void start(Stage primaryStage) { // Load layouts from FXML file. FXMLLoader loader = new FXMLLoader(MainApp.class.getResource("/fxml/RootLayout.fxml")); - FXMLLoader scanViewLoader = new FXMLLoader(MainApp.class.getResource("/fxml/ScanView.fxml")); + FXMLLoader scanViewLoader = new FXMLLoader(MainApp.class.getResource("/fxml/ScanPdfsView.fxml")); try { rootLayout = loader.load(); } catch (IOException e) { @@ -85,8 +85,8 @@ public void start(Stage primaryStage) { } catch (IOException e) { Logger.error(e, "Scan layout not found."); } - ScanController scanController = scanViewLoader.getController(); - scanController.setMainApp(this); - scanController.updateControlsByModel(); + ScanPdfsController scanPdfsController = scanViewLoader.getController(); + scanPdfsController.setMainApp(this); + scanPdfsController.updateControlsByModel(); } } \ No newline at end of file diff --git a/src/main/java/nl/ls31/qrscan/controller/CreateController.java b/src/main/java/nl/ls31/qrscan/controller/CreateImagesController.java similarity index 95% rename from src/main/java/nl/ls31/qrscan/controller/CreateController.java rename to src/main/java/nl/ls31/qrscan/controller/CreateImagesController.java index 9418499..b4f90ef 100644 --- a/src/main/java/nl/ls31/qrscan/controller/CreateController.java +++ b/src/main/java/nl/ls31/qrscan/controller/CreateImagesController.java @@ -8,7 +8,7 @@ import javafx.stage.FileChooser; import javafx.stage.Stage; import nl.ls31.qrscan.MainApp; -import nl.ls31.qrscan.core.CreateTask; +import nl.ls31.qrscan.core.CreateImagesTask; import nl.ls31.qrscan.view.ProgressDialog; import java.io.File; @@ -20,7 +20,7 @@ * * @author Lars Steggink */ -public class CreateController { +public class CreateImagesController { private MainApp mainApp; @FXML @@ -106,7 +106,7 @@ private void handleCreateButton() { mainApp.getAppSettings().setQrcodeImageSize(sizeSpinner.getValue()); int size = mainApp.getAppSettings().getQrcodeImageSize(); - Task> createTask = new CreateTask(inputFile, outputDir, size, withAnnotation); + Task> createTask = new CreateImagesTask(inputFile, outputDir, size, withAnnotation); ProgressDialog pForm = new ProgressDialog("Creating files...", createTask.progressProperty()); pForm.show(); diff --git a/src/main/java/nl/ls31/qrscan/controller/ManualTagController.java b/src/main/java/nl/ls31/qrscan/controller/ManualTagPdfController.java similarity index 95% rename from src/main/java/nl/ls31/qrscan/controller/ManualTagController.java rename to src/main/java/nl/ls31/qrscan/controller/ManualTagPdfController.java index 9602fb7..d537a44 100644 --- a/src/main/java/nl/ls31/qrscan/controller/ManualTagController.java +++ b/src/main/java/nl/ls31/qrscan/controller/ManualTagPdfController.java @@ -10,8 +10,8 @@ import javafx.stage.FileChooser.ExtensionFilter; import javafx.stage.Stage; import nl.ls31.qrscan.MainApp; +import nl.ls31.qrscan.core.PdfScanner; import nl.ls31.qrscan.model.AppSettings; -import nl.ls31.qrscan.model.QrPdf; import org.tinylog.Logger; import java.io.File; @@ -23,7 +23,7 @@ * * @author Lars Steggink */ -public class ManualTagController { +public class ManualTagPdfController { private MainApp mainApp; @FXML @@ -41,7 +41,7 @@ public class ManualTagController { @FXML private void handleCodeFieldEdit() { String userInput = codeField.getText(); - if (QrPdf.isValidQRCode(userInput)) { + if (PdfScanner.isValidQRCode(userInput)) { codeField.setStyle("-fx-border-color: green; -fx-border-width: 2px ;"); } else { codeField.setStyle("-fx-border-color: red; -fx-border-width: 2px ;"); @@ -95,7 +95,7 @@ public void setMainApp(MainApp mainApp) { */ private void tagFile() { AppSettings settings = mainApp.getAppSettings(); - QrPdf pdf = new QrPdf(settings.getManualPdf()); + PdfScanner pdf = new PdfScanner(settings.getManualPdf()); try { pdf.setQRCodeFileAttribute(settings.getManualCode()); String message = "Successfully tagged " + settings.getManualPdf().getFileName().toString() + " with code " diff --git a/src/main/java/nl/ls31/qrscan/controller/RootController.java b/src/main/java/nl/ls31/qrscan/controller/RootController.java index 089a643..c68dae1 100644 --- a/src/main/java/nl/ls31/qrscan/controller/RootController.java +++ b/src/main/java/nl/ls31/qrscan/controller/RootController.java @@ -20,15 +20,9 @@ */ public class RootController { - @FXML - private MenuItem exitItem; private MainApp mainApp; @FXML - private MenuItem aboutItem; - @FXML - private MenuItem createItem; - @FXML - private MenuItem manualTagItem; + private MenuItem exitItem, manualTagItem, createItem, aboutItem; /** * Sets a call back reference to the main application. @@ -54,7 +48,7 @@ public void handleExitItem() { public void handleAboutItem() { Alert alert = new Alert(AlertType.INFORMATION); alert.setTitle("About QRScan"); - alert.setHeaderText("QRScan version 2.1.0"); + alert.setHeaderText("QRScan version 2.2.0"); alert.setContentText("A big thanks to the following frameworks: " + "PDFBox by The Apache Software Foundation (Apache license v2.0), " + "Java Advanced Imaging Image I/O Tools API (BSD licence), " @@ -70,14 +64,14 @@ public void handleCreateItem() { try { Stage stage = new Stage(); stage.initModality(Modality.APPLICATION_MODAL); - FXMLLoader createViewLoader = new FXMLLoader(MainApp.class.getResource("/fxml/CreateView.fxml")); + FXMLLoader createViewLoader = new FXMLLoader(MainApp.class.getResource("/fxml/CreateImagesView.fxml")); AnchorPane createView = createViewLoader.load(); stage.setScene(new Scene(createView)); // Give the controllers access to the main app. - CreateController createController = createViewLoader.getController(); - createController.setMainApp(mainApp); - createController.updateControlsByModel(); + CreateImagesController createImagesController = createViewLoader.getController(); + createImagesController.setMainApp(mainApp); + createImagesController.updateControlsByModel(); stage.show(); } catch (IOException e) { e.printStackTrace(); @@ -92,14 +86,14 @@ public void handleManualTagItem() { try { Stage stage = new Stage(); stage.initModality(Modality.APPLICATION_MODAL); - FXMLLoader manualTagViewLoader = new FXMLLoader(MainApp.class.getResource("/fxml/ManualTagView.fxml")); + FXMLLoader manualTagViewLoader = new FXMLLoader(MainApp.class.getResource("/fxml/ManualTagPdfView.fxml")); AnchorPane manualTagView = manualTagViewLoader.load(); stage.setScene(new Scene(manualTagView)); // Give the controllers access to the main app. - ManualTagController manualTagController = manualTagViewLoader.getController(); - manualTagController.setMainApp(mainApp); - manualTagController.updateControlsByModel(); + ManualTagPdfController manualTagPdfController = manualTagViewLoader.getController(); + manualTagPdfController.setMainApp(mainApp); + manualTagPdfController.updateControlsByModel(); stage.show(); } catch (IOException e) { e.printStackTrace(); diff --git a/src/main/java/nl/ls31/qrscan/controller/ScanController.java b/src/main/java/nl/ls31/qrscan/controller/ScanPdfsController.java similarity index 92% rename from src/main/java/nl/ls31/qrscan/controller/ScanController.java rename to src/main/java/nl/ls31/qrscan/controller/ScanPdfsController.java index 373eb04..a069c81 100644 --- a/src/main/java/nl/ls31/qrscan/controller/ScanController.java +++ b/src/main/java/nl/ls31/qrscan/controller/ScanPdfsController.java @@ -5,10 +5,10 @@ import javafx.scene.control.*; import javafx.stage.DirectoryChooser; import nl.ls31.qrscan.MainApp; -import nl.ls31.qrscan.core.RenameTask; -import nl.ls31.qrscan.core.ScanTask; +import nl.ls31.qrscan.core.RenamePdfsTask; +import nl.ls31.qrscan.core.ScanPdfsTask; import nl.ls31.qrscan.model.AppSettings; -import nl.ls31.qrscan.model.SingleResult; +import nl.ls31.qrscan.model.PdfScanResult; import nl.ls31.qrscan.view.ProgressDialog; import nl.ls31.qrscan.view.ResultsDialog; @@ -21,7 +21,7 @@ * * @author Lars Steggink */ -public class ScanController { +public class ScanPdfsController { private MainApp mainApp; @FXML @@ -165,12 +165,12 @@ private void handleScanButton() { boolean writeFileAttributes = appSettings.getWriteFileAttribute(); boolean openLogFile = appSettings.getOpenLogFile(); - Task> task; + Task> task; if (appSettings.getWithFileRenaming()) { Path targetDir = appSettings.getTargetDirectory(); - task = new RenameTask(inputDir, targetDir, qrPage, useFileAttributes, writeFileAttributes, openLogFile); + task = new RenamePdfsTask(inputDir, targetDir, qrPage, useFileAttributes, writeFileAttributes, openLogFile); } else { - task = new ScanTask(inputDir, qrPage, useFileAttributes, writeFileAttributes, openLogFile); + task = new ScanPdfsTask(inputDir, qrPage, useFileAttributes, writeFileAttributes, openLogFile); } ProgressDialog pDialog = new ProgressDialog("Processing...", task.progressProperty()); @@ -182,7 +182,7 @@ private void handleScanButton() { scanButton.setDisable(false); ResultsDialog rDialog = new ResultsDialog( task.getValue(), - task instanceof RenameTask, + task instanceof RenamePdfsTask, task.getMessage()); rDialog.show(); // TODO Move code to create CSV log file here. diff --git a/src/main/java/nl/ls31/qrscan/core/CreateTask.java b/src/main/java/nl/ls31/qrscan/core/CreateImagesTask.java similarity index 94% rename from src/main/java/nl/ls31/qrscan/core/CreateTask.java rename to src/main/java/nl/ls31/qrscan/core/CreateImagesTask.java index 5fdcea2..1d935fb 100644 --- a/src/main/java/nl/ls31/qrscan/core/CreateTask.java +++ b/src/main/java/nl/ls31/qrscan/core/CreateImagesTask.java @@ -2,7 +2,6 @@ import com.google.zxing.WriterException; import javafx.concurrent.Task; -import nl.ls31.qrscan.model.QrPdf; import org.tinylog.Logger; import java.io.IOException; @@ -23,7 +22,7 @@ * * @author Lars Steggink */ -public class CreateTask extends Task> { +public class CreateImagesTask extends Task> { final static private String LSEP = System.lineSeparator(); private final Path inputFile; @@ -40,7 +39,7 @@ public class CreateTask extends Task> { * annotation is requested. * @param withText whether the code should be placed as regular text below the QR code */ - public CreateTask(Path inputFile, Path outputDir, int size, boolean withText) { + public CreateImagesTask(Path inputFile, Path outputDir, int size, boolean withText) { this.inputFile = inputFile; this.outputDir = outputDir; this.size = size; @@ -80,7 +79,7 @@ private List createImages(Set codeList) { List imageList = new ArrayList<>(); for (String code : codeList) { updateProgress(++current, allCodes); - if (!QrPdf.isValidQRCode(code)) { + if (!PdfScanner.isValidQRCode(code)) { Logger.warn("Skipped code " + code + " with illegal characters. "); illegal++; continue; @@ -151,7 +150,7 @@ private Set readQRCodesFromFile(Path codeFile) { private Path createImage(String code, Path outputDir) throws WriterException, IOException { Path imagePath = outputDir.resolve(code + ".gif"); - QrImageWriter.writeGIF(imagePath, code, size, withText); + QrcodeImageWriter.writeGIF(imagePath, code, size, withText); return imagePath; } } diff --git a/src/main/java/nl/ls31/qrscan/core/CsvLogWriter.java b/src/main/java/nl/ls31/qrscan/core/CsvLogWriter.java index bb4dde8..a7fe603 100644 --- a/src/main/java/nl/ls31/qrscan/core/CsvLogWriter.java +++ b/src/main/java/nl/ls31/qrscan/core/CsvLogWriter.java @@ -1,6 +1,6 @@ package nl.ls31.qrscan.core; -import nl.ls31.qrscan.model.SingleResult; +import nl.ls31.qrscan.model.PdfScanResult; import java.io.BufferedWriter; import java.io.IOException; @@ -28,7 +28,7 @@ public class CsvLogWriter { * @param logFilePath path where the CSV file should be created * @throws IOException if unable to save the log file */ - public static void writeLogFile(List results, Path logFilePath) throws IOException { + public static void writeLogFile(List results, Path logFilePath) throws IOException { String logContent = createLogContent(results); try (BufferedWriter logOut = Files.newBufferedWriter(logFilePath)) { logOut.write(logContent); @@ -41,14 +41,14 @@ public static void writeLogFile(List results, Path logFilePath) th * @param results results of scanning and renaming * @return log contents */ - private static String createLogContent(List results) { + private static String createLogContent(List results) { StringBuilder csvBuffer = new StringBuilder(); // CSV header csvBuffer.append("InputPath" + SEP + "RenamedPath" + SEP + "FileCreated" + SEP + "PageCount" + SEP + "QRCodeFound" + SEP + "QRCodePage" + SEP + "QRcode").append(LSEP); // CSV content: one line for every result - for (SingleResult result : results) { + for (PdfScanResult result : results) { csvBuffer.append(QUOTE).append(result.getInputFilePath().toAbsolutePath().toString()).append(QUOTE).append(SEP); if (result.isFileRenamed()) { csvBuffer.append(QUOTE).append(result.getOutputFilePath().toAbsolutePath().toString()).append(QUOTE).append(SEP); diff --git a/src/main/java/nl/ls31/qrscan/model/QrPdf.java b/src/main/java/nl/ls31/qrscan/core/PdfScanner.java similarity index 98% rename from src/main/java/nl/ls31/qrscan/model/QrPdf.java rename to src/main/java/nl/ls31/qrscan/core/PdfScanner.java index 27d4530..75f5908 100644 --- a/src/main/java/nl/ls31/qrscan/model/QrPdf.java +++ b/src/main/java/nl/ls31/qrscan/core/PdfScanner.java @@ -1,4 +1,4 @@ -package nl.ls31.qrscan.model; +package nl.ls31.qrscan.core; import com.google.zxing.*; import com.google.zxing.client.j2se.BufferedImageLuminanceSource; @@ -26,7 +26,7 @@ * * @author Lars Steggink */ -public class QrPdf { +public class PdfScanner { /** * This custom file attribute is used to add the QR code to the PDF file meta data. */ @@ -39,7 +39,7 @@ public class QrPdf { * * @param docPath Path of the document. */ - public QrPdf(Path docPath) { + public PdfScanner(Path docPath) { this.docPath = docPath; this.qrCodeMap = new HashMap<>(); } @@ -197,7 +197,7 @@ public String getQRCodeFileAttribute() throws IOException { view.read(FILE_ATTRIBUTE, buf); buf.flip(); String value = Charset.defaultCharset().decode(buf).toString(); - if (QrPdf.isValidQRCode(value)) { + if (PdfScanner.isValidQRCode(value)) { return value; } else { throw new IOException("Invalid QR code in file attribute."); @@ -212,7 +212,7 @@ public String getQRCodeFileAttribute() throws IOException { * @throws IllegalArgumentException if code contain illegal characters */ public void setQRCodeFileAttribute(String code) throws IOException, IllegalArgumentException { - if (!QrPdf.isValidQRCode(code)) { + if (!PdfScanner.isValidQRCode(code)) { throw new IllegalArgumentException("Illegal characters in QR code."); } else { UserDefinedFileAttributeView view = Files.getFileAttributeView(docPath, UserDefinedFileAttributeView.class); diff --git a/src/main/java/nl/ls31/qrscan/core/QrImageWriter.java b/src/main/java/nl/ls31/qrscan/core/QrcodeImageWriter.java similarity index 99% rename from src/main/java/nl/ls31/qrscan/core/QrImageWriter.java rename to src/main/java/nl/ls31/qrscan/core/QrcodeImageWriter.java index fd2a7d1..a19a64a 100644 --- a/src/main/java/nl/ls31/qrscan/core/QrImageWriter.java +++ b/src/main/java/nl/ls31/qrscan/core/QrcodeImageWriter.java @@ -22,7 +22,7 @@ * * @author Lars Steggink */ -public class QrImageWriter { +public class QrcodeImageWriter { /** * Write an image file containing a specified QR code and (optionally) a small annotation underneath. diff --git a/src/main/java/nl/ls31/qrscan/core/RenameTask.java b/src/main/java/nl/ls31/qrscan/core/RenamePdfsTask.java similarity index 80% rename from src/main/java/nl/ls31/qrscan/core/RenameTask.java rename to src/main/java/nl/ls31/qrscan/core/RenamePdfsTask.java index f9cf67a..8f996eb 100644 --- a/src/main/java/nl/ls31/qrscan/core/RenameTask.java +++ b/src/main/java/nl/ls31/qrscan/core/RenamePdfsTask.java @@ -1,7 +1,6 @@ package nl.ls31.qrscan.core; -import nl.ls31.qrscan.model.QrPdf; -import nl.ls31.qrscan.model.SingleResult; +import nl.ls31.qrscan.model.PdfScanResult; import org.tinylog.Logger; import java.io.IOException; @@ -10,7 +9,7 @@ import java.util.List; /** - * This task performs the thing mentioned in ScanTask. However, after all PDFs are scanned for QR codes, the PDFs are + * This task performs the thing mentioned in ScanPdfsTask. However, after all PDFs are scanned for QR codes, the PDFs are * then moved to the output directory and renamed. * *

@@ -34,14 +33,14 @@ * * @author Lars Steggink */ -public class RenameTask extends ScanTask { +public class RenamePdfsTask extends ScanPdfsTask { final static private String LSEP = System.lineSeparator(); private final Path outputDir; /** - * This task performs the thing mentioned in ScanTask. However, after all PDFs are scanned for QR codes, the PDFs - * are then moved to the output directory and renamed. + * This task performs the thing mentioned in ScanPdfsTask. However, after all PDFs are scanned for QR codes, the + * PDFs are then moved to the output directory and renamed. * * @param inputDir input directory with PDF files * @param outputDir main output directory for renamed PDF files @@ -51,12 +50,14 @@ public class RenameTask extends ScanTask { * scanning * @param openLogFile whether to open the CSV log file at the end */ - public RenameTask(Path inputDir, Path outputDir, int qrCodePage, boolean useFileAttributes, - boolean writeFileAttributes, boolean openLogFile) { + public RenamePdfsTask(Path inputDir, Path outputDir, int qrCodePage, boolean useFileAttributes, + boolean writeFileAttributes, boolean openLogFile) { super(inputDir, qrCodePage, useFileAttributes, writeFileAttributes, openLogFile); this.outputDir = outputDir; } + // TODO extract PdfFileRenamer (putting the logic of renaming and creating subdirs outside of this task) + /** * Iterates over every file, scans for QR codes, then renames. * @@ -67,12 +68,12 @@ public RenameTask(Path inputDir, Path outputDir, int qrCodePage, boolean useFile * @return list of results */ @Override - protected List call() { - List pdfs = findInputFiles(inputDir); - List scanResults = scanInputFiles(pdfs); + protected List call() { + List pdfs = findInputFiles(inputDir); + List scanResults = scanInputFiles(pdfs); try { - List results = renameScanResults(scanResults); - logResults(results, outputDir); + List results = renameScanResults(scanResults); + logResults(results, outputDir); // TODO put this outside of task return results; } catch (IOException e) { Logger.error("!Unable to create or use output path."); @@ -87,7 +88,7 @@ protected List call() { * @return chosen path * @throws IOException if unable to create sub directory */ - private Path findTargetPath(SingleResult scanResult) throws IOException { + private Path findTargetPath(PdfScanResult scanResult) throws IOException { String qr = scanResult.getQrCode(); // Create sub directory within main output directory. @@ -116,7 +117,7 @@ private Path findTargetPath(SingleResult scanResult) throws IOException { * @return updated scan results, including the old and new file path * @throws IOException if unable to create or use output directory */ - private List renameScanResults(List scanResults) throws IOException { + private List renameScanResults(List scanResults) throws IOException { int fileCount = scanResults.size(); int success = 0; int failed = 0; @@ -132,7 +133,7 @@ private List renameScanResults(List scanResults) thr } // Iterate over every scanned file. - for (SingleResult scanResult : scanResults) { + for (PdfScanResult scanResult : scanResults) { current++; updateProgress(current, fileCount); diff --git a/src/main/java/nl/ls31/qrscan/core/ScanTask.java b/src/main/java/nl/ls31/qrscan/core/ScanPdfsTask.java similarity index 81% rename from src/main/java/nl/ls31/qrscan/core/ScanTask.java rename to src/main/java/nl/ls31/qrscan/core/ScanPdfsTask.java index 85e3191..a274714 100644 --- a/src/main/java/nl/ls31/qrscan/core/ScanTask.java +++ b/src/main/java/nl/ls31/qrscan/core/ScanPdfsTask.java @@ -2,8 +2,7 @@ import com.google.zxing.NotFoundException; import javafx.concurrent.Task; -import nl.ls31.qrscan.model.QrPdf; -import nl.ls31.qrscan.model.SingleResult; +import nl.ls31.qrscan.model.PdfScanResult; import org.tinylog.Logger; import java.awt.*; @@ -27,7 +26,7 @@ * * @author Lars Steggink */ -public class ScanTask extends Task> { +public class ScanPdfsTask extends Task> { final static private String LSEP = System.lineSeparator(); protected final Path inputDir; private final int qrCodePage; @@ -43,7 +42,7 @@ public class ScanTask extends Task> { * scanning * @param openLogFile whether to open the CSV log file at the end. */ - public ScanTask(Path inputDir, int qrCodePage, boolean useFileAttributes, boolean writeFileAttributes, boolean openLogFile) { + public ScanPdfsTask(Path inputDir, int qrCodePage, boolean useFileAttributes, boolean writeFileAttributes, boolean openLogFile) { this.inputDir = inputDir; this.qrCodePage = qrCodePage; this.useFileAttributes = useFileAttributes; @@ -55,9 +54,9 @@ public ScanTask(Path inputDir, int qrCodePage, boolean useFileAttributes, boolea * Iterates over every PDF file and tries to find the QR code. */ @Override - protected List call() { - List pdfs = findInputFiles(inputDir); - List results = scanInputFiles(pdfs); + protected List call() { + List pdfs = findInputFiles(inputDir); + List results = scanInputFiles(pdfs); logResults(results, inputDir); return results; } @@ -70,7 +69,7 @@ protected List call() { * @param results Results from scanning. * @param dir Directory to save CSV file into. */ - protected void logResults(List results, Path dir) { + protected void logResults(List results, Path dir) { // Create a time stamp for the log file name, then log in that file. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); String timestamp = sdf.format(Calendar.getInstance().getTime()); @@ -92,15 +91,15 @@ protected void logResults(List results, Path dir) { * @param inputDir Path to directory. * @return List of PDF files (no guarantees regarding available QR codes). */ - protected List findInputFiles(Path inputDir) { - List allFiles = new ArrayList<>(); + protected List findInputFiles(Path inputDir) { + List allFiles = new ArrayList<>(); SimpleFileVisitor pdfFileVisitor = new SimpleFileVisitor<>() { @Override public FileVisitResult visitFile(Path filePath, BasicFileAttributes attrs) { // Convert path to file if (filePath.toString().toLowerCase().endsWith(".pdf")) { - allFiles.add(new QrPdf(filePath)); + allFiles.add(new PdfScanner(filePath)); } return FileVisitResult.CONTINUE; } @@ -120,7 +119,7 @@ public FileVisitResult visitFile(Path filePath, BasicFileAttributes attrs) { * @param inputFiles List of files to scan for QR codes. * @return Results from scanning the input files. */ - protected List scanInputFiles(List inputFiles) { + protected List scanInputFiles(List inputFiles) { int fileCount = inputFiles.size(); int success = 0; int failed = 0; @@ -129,23 +128,23 @@ protected List scanInputFiles(List inputFiles) { + " Scanning page: " + qrCodePage + LSEP + " Number of files: " + fileCount); // Start the loop through all files. - List results = new ArrayList<>(); - for (QrPdf pdf : inputFiles) { + List results = new ArrayList<>(); + for (PdfScanner pdf : inputFiles) { updateProgress(++current, fileCount); Logger.info("Now scanning file " + pdf.getPath().getFileName() + "."); try { String qrCode = pdf.getQRCode(qrCodePage, useFileAttributes, writeFileAttributes); Logger.info("Found QR code " + qrCode + " in " + pdf.getPath().getFileName() + "."); - results.add(new SingleResult(pdf, SingleResult.ResultStatus.QR_CODE_FOUND, qrCodePage, qrCode)); + results.add(new PdfScanResult(pdf, PdfScanResult.ResultStatus.QR_CODE_FOUND, qrCodePage, qrCode)); success++; } catch (IOException e) { Logger.warn(e, "!Unable to access " + pdf.getPath().getFileName() + " or page not found."); - results.add(new SingleResult(pdf, SingleResult.ResultStatus.NO_FILE_ACCESS, qrCodePage, "")); + results.add(new PdfScanResult(pdf, PdfScanResult.ResultStatus.NO_FILE_ACCESS, qrCodePage, "")); failed++; } catch (NotFoundException e) { Logger.warn(e, "!Unable to find QR code at specified page in " + pdf.getPath().getFileName() + "."); - results.add(new SingleResult(pdf, SingleResult.ResultStatus.NO_QR_CODE, qrCodePage, "")); + results.add(new PdfScanResult(pdf, PdfScanResult.ResultStatus.NO_QR_CODE, qrCodePage, "")); failed++; } } diff --git a/src/main/java/nl/ls31/qrscan/model/AppSettings.java b/src/main/java/nl/ls31/qrscan/model/AppSettings.java index e9aa6ac..179e3b6 100644 --- a/src/main/java/nl/ls31/qrscan/model/AppSettings.java +++ b/src/main/java/nl/ls31/qrscan/model/AppSettings.java @@ -4,6 +4,7 @@ import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleStringProperty; +import nl.ls31.qrscan.core.PdfScanner; import java.nio.file.Path; import java.nio.file.Paths; @@ -168,7 +169,7 @@ public final String getManualCode() { * @throws IllegalArgumentException if the provided code had invalid characters */ public final void setManualCode(String code) { - if (!QrPdf.isValidQRCode(code)) { + if (!PdfScanner.isValidQRCode(code)) { throw new IllegalArgumentException("Invalid characters in code."); } diff --git a/src/main/java/nl/ls31/qrscan/model/SingleResult.java b/src/main/java/nl/ls31/qrscan/model/PdfScanResult.java similarity index 91% rename from src/main/java/nl/ls31/qrscan/model/SingleResult.java rename to src/main/java/nl/ls31/qrscan/model/PdfScanResult.java index 9fbb537..4718909 100644 --- a/src/main/java/nl/ls31/qrscan/model/SingleResult.java +++ b/src/main/java/nl/ls31/qrscan/model/PdfScanResult.java @@ -3,19 +3,23 @@ import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleStringProperty; +import nl.ls31.qrscan.core.PdfScanner; import java.io.IOException; import java.nio.file.Path; /** - * In a SingleResult, meta data about QR-PDFs is stored: i.e. the file name (and, after renaming the old and new file + * In a PdfScanResult, meta data about QR-PDFs is stored: i.e. the file name (and, after renaming the old and new file * name), number of pages in the PDF, if a QR code was found, what it was and on which page it was found. *

- * Note: the QrPdf itself is not stored in the result. + * Note: the PdfScanner itself is not stored in the result. * * @author Lars Steggink */ -public class SingleResult { +public class PdfScanResult { + + // TODO: remove 'actions' from this class, make it more passive. + // TODO: extract a PdfRenameResult as a subclass of this one. private final SimpleObjectProperty resultStatus; private final int qrCodePage; @@ -33,7 +37,7 @@ public class SingleResult { * @param qrCodePage the page that was scanned * @param qrCode the QR code, if found, otherwise "" */ - public SingleResult(QrPdf pdf, ResultStatus resultStatus, int qrCodePage, String qrCode) { + public PdfScanResult(PdfScanner pdf, ResultStatus resultStatus, int qrCodePage, String qrCode) { this.inputFilePath = new SimpleObjectProperty<>(pdf.getPath()); this.outputFilePath = inputFilePath; this.isRenamed = new SimpleBooleanProperty(false); diff --git a/src/main/java/nl/ls31/qrscan/view/ResultsDialog.java b/src/main/java/nl/ls31/qrscan/view/ResultsDialog.java index 99b5a19..9056375 100644 --- a/src/main/java/nl/ls31/qrscan/view/ResultsDialog.java +++ b/src/main/java/nl/ls31/qrscan/view/ResultsDialog.java @@ -12,21 +12,21 @@ import javafx.stage.Modality; import javafx.stage.Stage; import javafx.stage.StageStyle; -import nl.ls31.qrscan.model.SingleResult; +import nl.ls31.qrscan.model.PdfScanResult; import java.util.List; /** - * A dialog window with the results of a ScanTask or RenameTask. + * A dialog window with the results of a ScanPdfsTask or RenamePdfsTask. */ public class ResultsDialog { private final Stage dialogStage; /** - * A dialog window with the results of a ScanTask or RenameTask. + * A dialog window with the results of a ScanPdfsTask or RenamePdfsTask. */ - public ResultsDialog(List results, boolean showRenamedColumn, String summary) { - ObservableList resultList = FXCollections.observableArrayList(results); + public ResultsDialog(List results, boolean showRenamedColumn, String summary) { + ObservableList resultList = FXCollections.observableArrayList(results); dialogStage = new Stage(); dialogStage.initStyle(StageStyle.DECORATED); @@ -37,25 +37,25 @@ public ResultsDialog(List results, boolean showRenamedColumn, Stri dialogStage.setTitle("Result overview"); final Label label = new Label(summary); - TableView table = new TableView<>(); + TableView table = new TableView<>(); - TableColumn inputPathCol = new TableColumn<>("File path"); + TableColumn inputPathCol = new TableColumn<>("File path"); inputPathCol.setMinWidth(400); inputPathCol.setCellValueFactory(new PropertyValueFactory<>("inputFilePath")); inputPathCol.setSortType(TableColumn.SortType.DESCENDING); - TableColumn renamedPathCol = new TableColumn<>("Renamed file path"); + TableColumn renamedPathCol = new TableColumn<>("Renamed file path"); renamedPathCol.setVisible(showRenamedColumn); renamedPathCol.setMinWidth(400); renamedPathCol.setCellValueFactory(new PropertyValueFactory<>("renamedFilePath")); renamedPathCol.setSortType(TableColumn.SortType.DESCENDING); - TableColumn qrCodeStatusCol = new TableColumn<>("QR code status"); + TableColumn qrCodeStatusCol = new TableColumn<>("QR code status"); qrCodeStatusCol.setMinWidth(40); qrCodeStatusCol.setCellValueFactory(new PropertyValueFactory<>("qrCodeStatus")); renamedPathCol.setSortType(TableColumn.SortType.DESCENDING); - TableColumn qrCodeCol = new TableColumn<>("QR code"); + TableColumn qrCodeCol = new TableColumn<>("QR code"); qrCodeCol.setMinWidth(60); qrCodeCol.setCellValueFactory(new PropertyValueFactory<>("qrCode")); renamedPathCol.setSortType(TableColumn.SortType.DESCENDING); diff --git a/src/main/resources/fxml/CreateView.fxml b/src/main/resources/fxml/CreateImagesView.fxml similarity index 98% rename from src/main/resources/fxml/CreateView.fxml rename to src/main/resources/fxml/CreateImagesView.fxml index c22f3c2..7b6943c 100644 --- a/src/main/resources/fxml/CreateView.fxml +++ b/src/main/resources/fxml/CreateImagesView.fxml @@ -6,7 +6,7 @@ + xmlns="http://javafx.com/javafx/11.0.1" fx:controller="nl.ls31.qrscan.controller.CreateImagesController">

diff --git a/src/main/resources/fxml/ManualTagView.fxml b/src/main/resources/fxml/ManualTagPdfView.fxml similarity index 98% rename from src/main/resources/fxml/ManualTagView.fxml rename to src/main/resources/fxml/ManualTagPdfView.fxml index af01396..ddf9db1 100644 --- a/src/main/resources/fxml/ManualTagView.fxml +++ b/src/main/resources/fxml/ManualTagPdfView.fxml @@ -6,7 +6,7 @@ + xmlns="http://javafx.com/javafx/11.0.1" fx:controller="nl.ls31.qrscan.controller.ManualTagPdfController">
diff --git a/src/main/resources/fxml/ScanView.fxml b/src/main/resources/fxml/ScanPdfsView.fxml similarity index 98% rename from src/main/resources/fxml/ScanView.fxml rename to src/main/resources/fxml/ScanPdfsView.fxml index ae4aaf2..463061a 100644 --- a/src/main/resources/fxml/ScanView.fxml +++ b/src/main/resources/fxml/ScanPdfsView.fxml @@ -7,7 +7,7 @@ + fx:controller="nl.ls31.qrscan.controller.ScanPdfsController">
From 6302e069836d95081105e51e6d1efc4db6123d7c Mon Sep 17 00:00:00 2001 From: LS31 Date: Sat, 17 Oct 2020 12:25:52 +0200 Subject: [PATCH 05/10] Version upgrades for dependencies. Switched to twelvemonkeys imageio implementation (which had updates in 2020). --- pom.xml | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 924cb9e..fefbc78 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ UTF-8 14 - 14.0.1 + 16-ea+2 @@ -25,10 +25,15 @@ javafx-fxml ${javafx.version} - + + + com.twelvemonkeys.imageio + imageio-jpeg + 3.6 com.github.jai-imageio @@ -38,12 +43,12 @@ com.google.zxing core - 3.4.0 + 3.4.1 com.google.zxing javase - 3.4.0 + 3.4.1 org.apache.pdfbox @@ -55,32 +60,32 @@ org.apache.pdfbox pdfbox - 2.0.19 + 2.0.21 org.apache.pdfbox xmpbox - 2.0.19 + 2.0.21 org.apache.pdfbox pdfbox-tools - 2.0.19 + 2.0.21 org.apache.pdfbox fontbox - 2.0.18 + 2.0.21 org.tinylog tinylog-api - 2.1.2 + 2.2.0-RC1 org.tinylog tinylog-impl - 2.1.2 + 2.2.0-RC1 @@ -94,6 +99,7 @@ ${maven.compiler.release} + org.apache.maven.plugins maven-assembly-plugin @@ -119,10 +125,29 @@ + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + + shade + + + + + + + + + + org.openjfx javafx-maven-plugin - 0.0.4 + 0.0.5 nl.ls31.qrscan.Launcher ${maven.compiler.release} From 02243621823f31b0313c62a73338af527864401a Mon Sep 17 00:00:00 2001 From: LS31 Date: Sat, 19 Jun 2021 12:21:09 +0200 Subject: [PATCH 06/10] Version upgrades for dependencies. Switched to twelvemonkeys imageio implementation (which had updates in 2020). --- .gitignore | 1 + pom.xml | 34 +++++++++++++--------------------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 79f14cb..870d458 100644 --- a/.gitignore +++ b/.gitignore @@ -72,3 +72,4 @@ fabric.properties /target/ /.idea/ +/dependency-reduced-pom.xml diff --git a/pom.xml b/pom.xml index dd19745..7b1034c 100644 --- a/pom.xml +++ b/pom.xml @@ -5,40 +5,34 @@ nl.ls31 qrscan 2.2.0-SNAPSHOT - QRScan + qrscan + jar https://github.com/LS31/qrscan UTF-8 - 14 - 16-ea+2 org.openjfx javafx-controls - ${javafx.version} + 16 org.openjfx javafx-fxml - ${javafx.version} + 16 - com.twelvemonkeys.imageio imageio-jpeg - 3.6 + 3.7.0 com.github.jai-imageio jai-imageio-jpeg2000 - 1.3.0 + 1.4.0 com.google.zxing @@ -53,8 +47,6 @@ org.apache.pdfbox jbig2-imageio - 3.0.3 @@ -65,7 +57,7 @@ org.apache.pdfbox xmpbox - 2.0.21 + 2.0.24 org.apache.pdfbox @@ -75,17 +67,17 @@ org.apache.pdfbox fontbox - 2.0.21 + 2.0.24 org.tinylog tinylog-api - 2.2.0-RC1 + 2.3.2 org.tinylog tinylog-impl - 2.2.0-RC1 + 2.3.2 @@ -96,7 +88,7 @@ maven-compiler-plugin 3.8.1 - ${maven.compiler.release} + 14 @@ -147,10 +139,10 @@ org.openjfx javafx-maven-plugin - 0.0.5 + 0.0.6 nl.ls31.qrscan.Launcher - ${maven.compiler.release} + 14 From dc095932f5150435b4d014d148b75f1bd8a5ecf0 Mon Sep 17 00:00:00 2001 From: LS31 Date: Sat, 19 Jun 2021 12:35:43 +0200 Subject: [PATCH 07/10] Updated acknowledgement --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 927c340..ed08791 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,9 @@ Good QR code recognition has been attained with documents that were scanned at a The [provided executable JAR](https://github.com/LS31/qrscan/releases) is ready to use. The current version runs with Java 14. You need to have a recent Java Virtual Machine ([Java Runtime Environment](https://java.com/en/download/)) installed to execute the JAR file. On Windows, simply double-click the JAR file to execute. # Acknowledgements -A big thanks to the following projects: [PDFBox by The Apache Software Foundation](https://pdfbox.apache.org/), [Java Advanced Imaging Image I/O Tools API](https://github.com/jai-imageio/jai-imageio-jpeg2000), and the [ZXing project](https://github.com/zxing). +A big thanks to the following projects: [PDFBox by The Apache Software Foundation](https://pdfbox.apache.org/) +, [Java Advanced Imaging Image I/O Tools API](https://github.com/jai-imageio/jai-imageio-jpeg2000) +, [TwelveMonkeys ImageIO](https://haraldk.github.io/TwelveMonkeys/), and the [ZXing project](https://github.com/zxing). # Release history * **1.0.0** @@ -33,3 +35,5 @@ A big thanks to the following projects: [PDFBox by The Apache Software Foundatio * Updated logging (and simplified for end user). * Updated to JDK/JRE 14. * Updated versions of all dependencies. +* **2.1.2** + * Updated versions of dependencies. \ No newline at end of file From 0bd5ad510ae6273237d51056091e7f1608cacc81 Mon Sep 17 00:00:00 2001 From: LS31 Date: Sat, 19 Jun 2021 13:09:02 +0200 Subject: [PATCH 08/10] Size spinner now editable. --- src/main/resources/fxml/CreateImagesView.fxml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/fxml/CreateImagesView.fxml b/src/main/resources/fxml/CreateImagesView.fxml index 7b6943c..70d81f3 100644 --- a/src/main/resources/fxml/CreateImagesView.fxml +++ b/src/main/resources/fxml/CreateImagesView.fxml @@ -43,8 +43,8 @@