diff --git a/jsignpdf/pom.xml b/jsignpdf/pom.xml index f162a52b..ff719d5a 100644 --- a/jsignpdf/pom.xml +++ b/jsignpdf/pom.xml @@ -159,6 +159,10 @@ org.apache.pdfbox pdfbox + + org.apache.pdfbox + jbig2-imageio + com.github.kwart.jsign jsign-jpedal diff --git a/jsignpdf/src/main/java/net/sf/jsignpdf/fx/view/MainWindowController.java b/jsignpdf/src/main/java/net/sf/jsignpdf/fx/view/MainWindowController.java index ae3a14d2..35c7a2c9 100644 --- a/jsignpdf/src/main/java/net/sf/jsignpdf/fx/view/MainWindowController.java +++ b/jsignpdf/src/main/java/net/sf/jsignpdf/fx/view/MainWindowController.java @@ -69,12 +69,13 @@ import net.sf.jsignpdf.fx.preset.PresetValidation; import net.sf.jsignpdf.fx.util.RecentFilesManager; import net.sf.jsignpdf.fx.viewmodel.DocumentViewModel; -import net.sf.jsignpdf.utils.PropertyStoreFactory; import net.sf.jsignpdf.fx.viewmodel.SignaturePlacementViewModel; import net.sf.jsignpdf.fx.viewmodel.SigningOptionsViewModel; import net.sf.jsignpdf.fx.viewmodel.VisibleSignatureCoordinator; import net.sf.jsignpdf.types.PadesLevel; import net.sf.jsignpdf.types.PageInfo; +import net.sf.jsignpdf.utils.PropertyProvider; +import net.sf.jsignpdf.utils.PropertyStoreFactory; import static net.sf.jsignpdf.Constants.LOGGER; import static net.sf.jsignpdf.Constants.RES; @@ -84,7 +85,12 @@ */ public class MainWindowController { + private static final String KEY_LAST_OPEN_DIR = "last.open.dir"; + private static final String KEY_LAST_ZOOM = "last.zoom"; + private Stage stage; + private File lastOpenDir; + private double lastZoomLevel = 1.0; private BasicSignerOptions options; private final DocumentViewModel documentVM = new DocumentViewModel(); private final SigningOptionsViewModel signingVM = new SigningOptionsViewModel(); @@ -319,6 +325,7 @@ private void initialize() { progressBar.setVisible(false); updateStatus(RES.get("jfx.gui.status.ready")); + loadPersistedViewState(); cmbZoom.getItems().addAll("50%", "75%", "100%", "125%", "150%", "200%"); cmbZoom.setValue("100%"); @@ -351,8 +358,9 @@ private void initialize() { } }); - // Zoom level changes update combo + // Zoom level changes update combo and remember the last zoom (persisted on document open / exit) documentVM.zoomLevelProperty().addListener((obs, oldVal, newVal) -> { + lastZoomLevel = newVal.doubleValue(); String formatted = Math.round(newVal.doubleValue() * 100) + "%"; if (!formatted.equals(cmbZoom.getValue())) { cmbZoom.setValue(formatted); @@ -931,10 +939,13 @@ private void handleKeyPress(KeyEvent event) { @FXML private void onFileOpen() { - File file = new NativeFileChooser() + NativeFileChooser fc = new NativeFileChooser() .setTitle(RES.get("jfx.gui.dialog.openPdf.title")) - .addFilter(ExtensionFilter.of("PDF Files", "*.pdf")) - .showOpenDialog(stage); + .addFilter(ExtensionFilter.of("PDF Files", "*.pdf")); + if (lastOpenDir != null) { + fc.setInitialDirectory(lastOpenDir); + } + File file = fc.showOpenDialog(stage); if (file != null) { openDocument(file); } @@ -947,6 +958,7 @@ private void onFileClose() { @FXML private void onFileExit() { + saveViewStateToConfig(); stage.close(); } @@ -1184,6 +1196,8 @@ private void onDragDropped(DragEvent event) { // --- Document handling --- private void openDocument(File file) { + lastOpenDir = file.getParentFile(); + saveViewStateToConfig(); try { if (options == null) { options = new BasicSignerOptions(); @@ -1218,13 +1232,13 @@ private void openDocument(File file) { documentVM.setDocumentFile(file); documentVM.setPageCount(pages); - documentVM.setZoomLevel(1.0); + documentVM.setZoomLevel(lastZoomLevel); lblDropHint.setVisible(false); setDocumentControlsDisabled(false); lblPageCount.setText("/ " + pages); txtPageNumber.setText("1"); - cmbZoom.setValue("100%"); + cmbZoom.setValue(Math.round(lastZoomLevel * 100) + "%"); stage.setTitle("JSignPdf " + Constants.VERSION + " - " + file.getName()); LOGGER.info("Opened document: " + file.getAbsolutePath()); @@ -1342,6 +1356,38 @@ private void closeDocument() { stage.setTitle("JSignPdf " + Constants.VERSION); } + private void loadPersistedViewState() { + try { + PropertyProvider cfg = PropertyStoreFactory.getInstance().mainConfig(); + String dir = cfg.getProperty(KEY_LAST_OPEN_DIR); + if (dir != null && !dir.isEmpty()) { + File f = new File(dir); + if (f.isDirectory()) { + lastOpenDir = f; + } + } + String zoom = cfg.getProperty(KEY_LAST_ZOOM); + if (zoom != null) { + lastZoomLevel = Double.parseDouble(zoom); + } + } catch (Exception e) { + LOGGER.log(Level.FINE, "Could not load persisted view state", e); + } + } + + private void saveViewStateToConfig() { + try { + PropertyProvider cfg = PropertyStoreFactory.getInstance().mainConfig(); + if (lastOpenDir != null) { + cfg.setProperty(KEY_LAST_OPEN_DIR, lastOpenDir.getAbsolutePath()); + } + cfg.setProperty(KEY_LAST_ZOOM, String.valueOf(lastZoomLevel)); + cfg.save(); + } catch (Exception e) { + LOGGER.log(Level.FINE, "Could not persist view state", e); + } + } + /** * Returns the document view model (used by other controllers). */ diff --git a/pom.xml b/pom.xml index c5baea59..f5846724 100644 --- a/pom.xml +++ b/pom.xml @@ -28,6 +28,7 @@ 1.1.0 4.92.13 3.0.7 + 3.0.2 2.22.0 1.11.0 3.20.0 @@ -111,6 +112,11 @@ pdfbox ${pdfbox.version} + + org.apache.pdfbox + jbig2-imageio + ${jbig2-imageio.version} + com.github.kwart.jsign jsign-jpedal