From f4e2d015a9d307a6091971448364409fae553dd8 Mon Sep 17 00:00:00 2001 From: tkellner Date: Wed, 31 Oct 2012 16:36:44 +0000 Subject: Allow setting signature position with keyboard git-svn-id: https://svn.iaik.tugraz.at/svn/egiz/prj/current/12PDF-OVER-4.0@12716 3a0b52a2-8410-0410-bc02-ff6273a87459 --- .../gui/composites/PositioningComposite.java | 36 ++++++++++++++++++++-- .../pdfover/gui/composites/SignaturePanel.java | 9 ++++++ 2 files changed, 43 insertions(+), 2 deletions(-) (limited to 'trunk/pdf-over-gui/src/main') diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java index 33506f00..9d96fb94 100644 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java +++ b/trunk/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/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 b2f5270f..c9c223b8 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 @@ -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