Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions jsignpdf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>jbig2-imageio</artifactId>
</dependency>
<dependency>
<groupId>com.github.kwart.jsign</groupId>
<artifactId>jsign-jpedal</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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%");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -947,6 +958,7 @@ private void onFileClose() {

@FXML
private void onFileExit() {
saveViewStateToConfig();
stage.close();
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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).
*/
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<jsign.pkcs11.version>1.1.0</jsign.pkcs11.version>
<jsign.jpedal.version>4.92.13</jsign.jpedal.version>
<pdfbox.version>3.0.7</pdfbox.version>
<jbig2-imageio.version>3.0.2</jbig2-imageio.version>
<commons-io.version>2.22.0</commons-io.version>
<commons-cli.version>1.11.0</commons-cli.version>
<commons-lang3.version>3.20.0</commons-lang3.version>
Expand Down Expand Up @@ -111,6 +112,11 @@
<artifactId>pdfbox</artifactId>
<version>${pdfbox.version}</version>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>jbig2-imageio</artifactId>
<version>${jbig2-imageio.version}</version>
</dependency>
<dependency>
<groupId>com.github.kwart.jsign</groupId>
<artifactId>jsign-jpedal</artifactId>
Expand Down