From 097a32997c8cad126e63814478f07d34c25570b0 Mon Sep 17 00:00:00 2001 From: tkellner Date: Wed, 31 Oct 2012 16:36:42 +0000 Subject: Restrict signature to page dimensions on change git-svn-id: https://svn.iaik.tugraz.at/svn/egiz/prj/current/12PDF-OVER-4.0@12711 3a0b52a2-8410-0410-bc02-ff6273a87459 --- .../pdfover/gui/composites/SignaturePanel.java | 29 +++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'trunk/pdf-over-gui') diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SignaturePanel.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SignaturePanel.java index cb23d055..e4060af5 100644 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SignaturePanel.java +++ b/trunk/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