From 7c499c09c039d1a875d8f4463a0c2816337c8e6d Mon Sep 17 00:00:00 2001 From: tkellner Date: Wed, 10 Apr 2013 19:05:33 +0000 Subject: Restrict signature to page dimensions on change git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@125 174cde9d-5d70-4d2a-aa98-46368bc2aaf7 --- .../pdfover/gui/composites/SignaturePanel.java | 29 +++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'pdf-over-gui/src/main') 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 cb23d055..e4060af5 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 @@ -207,6 +207,8 @@ public class SignaturePanel extends JPanel { clamp((int) ((pageSize.getHeight() / 4) * 3), 0, this.currentImage.getHeight(null) - this.sigScreenHeight)); this.sigPagePos = this.currentXform.transform(this.sigScreenPos, this.sigPagePos); } + else + updateSigPos((int) this.sigScreenPos.getX(), (int) this.sigScreenPos.getY()); this.prevSize = pageSize; @@ -312,15 +314,9 @@ public class SignaturePanel extends JPanel { private int dragYOffset = 0; private void updateSigPos(int sigx, int sigy) { - if (SignaturePanel.this.currentImage == null) - return; - sigx -= SignaturePanel.this.offX; - sigx = clamp(sigx, 0, SignaturePanel.this.currentImage.getWidth(null) - SignaturePanel.this.sigScreenWidth); - sigy -= SignaturePanel.this.offY; - sigy = clamp(sigy, 0, SignaturePanel.this.currentImage.getHeight(null) - SignaturePanel.this.sigScreenHeight); - SignaturePanel.this.sigScreenPos = new Point2D.Double(sigx, sigy); - SignaturePanel.this.sigPagePos = SignaturePanel.this.currentXform.transform(SignaturePanel.this.sigScreenPos, SignaturePanel.this.sigPagePos); - repaint(); + SignaturePanel.this.updateSigPos( + sigx - SignaturePanel.this.offX, + sigy - SignaturePanel.this.offY); } /** Handles a mousePressed event */ @@ -378,6 +374,21 @@ public class SignaturePanel extends JPanel { return (sig.contains(pos)); } + /** + * Update the signature placeholder position + * @param sigx X position on the document (screen coordinates) + * @param sigy Y position on the document (screen coordinates) + */ + void updateSigPos(int sigx, int sigy) { + if (this.currentImage == null) + return; + sigx = clamp(sigx, 0, this.currentImage.getWidth(null) - this.sigScreenWidth); + sigy = clamp(sigy, 0, this.currentImage.getHeight(null) - this.sigScreenHeight); + this.sigScreenPos = new Point2D.Double(sigx, sigy); + this.sigPagePos = this.currentXform.transform(this.sigScreenPos, this.sigPagePos); + repaint(); + } + /** * Clamp x to be within [min-max] * @param x int to clamp -- cgit v1.2.3