From 6ed8fd2ff36fae464b9e74795385c2eb57ee649d Mon Sep 17 00:00:00 2001 From: tkellner Date: Wed, 10 Apr 2013 19:06:11 +0000 Subject: Allow setting signature position with keyboard git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@130 174cde9d-5d70-4d2a-aa98-46368bc2aaf7 --- .../gui/composites/PositioningComposite.java | 36 ++++++++++++++++++++-- .../pdfover/gui/composites/SignaturePanel.java | 9 ++++++ 2 files changed, 43 insertions(+), 2 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 33506f00..9d96fb94 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 @@ -45,8 +45,7 @@ import at.asit.pdfover.signator.SignaturePosition; import com.sun.pdfview.PDFFile; /** - * - * + * Composite which allows to position the signature on a preview of the document */ public class PositioningComposite extends StateComposite { /** @@ -55,6 +54,9 @@ public class PositioningComposite extends StateComposite { static final Logger log = LoggerFactory .getLogger(PositioningComposite.class); + /** How far to displace the signature with the arrow keys */ + private static final int SIGNATURE_KEYBOARD_POSITIONING_OFFSET = 15; + private SignaturePanel viewer = null; private PDFFile pdf = null; @@ -139,6 +141,8 @@ public class PositioningComposite extends StateComposite { @Override public void keyPressed(KeyEvent e) { int newPage = PositioningComposite.this.currentPage; + int sigXOffset = 0; + int sigYOffset = 0; switch (e.keyCode) { @@ -164,10 +168,29 @@ public class PositioningComposite extends StateComposite { case SWT.KEYPAD_CR: PositioningComposite.this.setFinalPosition(); break; + + case SWT.ARROW_LEFT: + sigXOffset -= SIGNATURE_KEYBOARD_POSITIONING_OFFSET; + break; + + case SWT.ARROW_RIGHT: + sigXOffset += SIGNATURE_KEYBOARD_POSITIONING_OFFSET; + break; + + case SWT.ARROW_UP: + sigYOffset -= SIGNATURE_KEYBOARD_POSITIONING_OFFSET; + break; + + case SWT.ARROW_DOWN: + sigYOffset += SIGNATURE_KEYBOARD_POSITIONING_OFFSET; + break; } if (newPage != PositioningComposite.this.currentPage) showPage(newPage); + + if (sigXOffset != 0 || sigYOffset != 0) + PositioningComposite.this.translateSignaturePosition(sigXOffset, sigYOffset); } }; @@ -223,6 +246,15 @@ public class PositioningComposite extends StateComposite { this.layout(true, true); } + /** + * Translate the signature placeholder position + * @param sigXOffset signature placeholder horizontal position offset + * @param sigYOffset signature placeholder vertical position offset + */ + public void translateSignaturePosition(int sigXOffset, int sigYOffset) { + PositioningComposite.this.viewer.translateSignaturePosition(sigXOffset, sigYOffset); + } + /** * Set the signature position and continue to the next state * @param position the signature position 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 b2f5270f..c9c223b8 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 @@ -135,6 +135,15 @@ public class SignaturePanel extends JPanel { showPage(this.pdf.getPage(page)); } + /** + * Translate the signature placeholder position + * @param sigXOffset signature placeholder horizontal position offset + * @param sigYOffset signature placeholder vertical position offset + */ + public void translateSignaturePosition(int sigXOffset, int sigYOffset) { + updateSigPos((int) this.sigScreenPos.getX() + sigXOffset, (int) this.sigScreenPos.getY() + sigYOffset); + } + /** * Get the current horizontal position of the signature * @return signature x coordinate -- cgit v1.2.3