summaryrefslogtreecommitdiff
path: root/pdf-over-gui/src/main/java/at
diff options
context:
space:
mode:
authorJakob Heher <jakob.heher@iaik.tugraz.at>2022-11-03 15:01:23 +0100
committerJakob Heher <jakob.heher@iaik.tugraz.at>2022-11-03 15:01:23 +0100
commitd0ba2d54ed60c67fb2ca91f1eb534d800e3d7e6c (patch)
tree3b8dec28497eb8dd6c080c3dd21b30415a35489c /pdf-over-gui/src/main/java/at
parent1835bf6f84516b74bbd6334dda56a9f3953c5590 (diff)
downloadpdf-over-d0ba2d54ed60c67fb2ca91f1eb534d800e3d7e6c.tar.gz
pdf-over-d0ba2d54ed60c67fb2ca91f1eb534d800e3d7e6c.tar.bz2
pdf-over-d0ba2d54ed60c67fb2ca91f1eb534d800e3d7e6c.zip
fix UX race condition in positioningpanel
cf. #129
Diffstat (limited to 'pdf-over-gui/src/main/java/at')
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java11
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SignaturePanel.java4
2 files changed, 11 insertions, 4 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java
index 85b950a6..5be8a4c7 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java
@@ -26,6 +26,7 @@ import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
+import java.awt.geom.Point2D;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.eclipse.swt.SWT;
@@ -123,6 +124,8 @@ public class PositioningComposite extends StateComposite {
requestFocus();
}
+ @Override public void onDisplay() { if (this.viewer.getSigPagePos() == null) this.btnSign.setEnabled(false); }
+
/**
* Set the PDF Document to display
*
@@ -132,6 +135,7 @@ public class PositioningComposite extends StateComposite {
public void displayDocument(final PDDocument document) {
EventQueue.invokeLater(() -> {
this.viewer.setDocument(document);
+ getDisplay().asyncExec(() -> this.btnSign.setEnabled(true));
});
if (document != null)
@@ -333,9 +337,12 @@ public class PositioningComposite extends StateComposite {
if (this.currentPage == 0) {
this.position = new SignaturePosition();
} else {
+ Point2D pos = this.viewer.getSigPagePos();
+ if (pos == null) return;
+
this.position = new SignaturePosition(
- this.viewer.getSigPageX(),
- this.viewer.getSigPageY(),
+ pos.getX(),
+ pos.getY(),
this.currentPage);
}
PositioningComposite.this.state.updateStateMachine();
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SignaturePanel.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SignaturePanel.java
index 72811050..6f4064bc 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SignaturePanel.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SignaturePanel.java
@@ -29,6 +29,7 @@ import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
+import javax.annotation.CheckForNull;
import javax.swing.JPanel;
import org.apache.pdfbox.pdmodel.PDDocument;
@@ -110,8 +111,7 @@ public class SignaturePanel extends JPanel {
private int offY = 0;
/** The position of the top-left corner of the signature, in absolute page space */
private Point2D sigPagePos = null;
- public double getSigPageX() { return this.sigPagePos.getX(); }
- public double getSigPageY() { return this.sigPagePos.getY(); }
+ public @CheckForNull Point2D getSigPagePos() { return this.sigPagePos; }
/** The signature placeholder image */
private Image sigPlaceholder = null;
/** Width of the signature placeholder in page space */