From f1f26b60f22e8efe0b13f6afde916dab597d7737 Mon Sep 17 00:00:00 2001 From: tkellner Date: Wed, 10 Apr 2013 19:04:48 +0000 Subject: Display signature placeholder git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@117 174cde9d-5d70-4d2a-aa98-46368bc2aaf7 --- .../gui/composites/PositioningComposite.java | 11 +++++- .../pdfover/gui/composites/SignaturePanel.java | 43 +++++++++++++++------- .../gui/workflow/states/PositioningState.java | 4 ++ 3 files changed, 44 insertions(+), 14 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 922e278b..716e1388 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 @@ -35,7 +35,6 @@ import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.ScrollBar; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -217,4 +216,14 @@ public class PositioningComposite extends StateComposite { public SignaturePosition getPosition() { return this.position; } + + /** + * Set the signature placeholder image + * @param placeholder signature placeholder + */ + public void setPlaceholder(Image placeholder) { + if (this.viewer == null) + return; + this.viewer.setSignaturePlaceholder(placeholder); + } } 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 1c6a6e9c..4c83e57f 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 @@ -49,23 +49,25 @@ public class SignaturePanel extends JPanel { private static final long serialVersionUID = 1L; /** The PDF file being displayed */ - private PDFFile pdf; + private PDFFile pdf = null; /** The image of the rendered PDF page being displayed */ - Image currentImage; + Image currentImage = null; /** The current PDFPage that was rendered into currentImage */ - private PDFPage currentPage; + private PDFPage currentPage = null; /** The current transform from screen to page space */ - AffineTransform currentXform; + AffineTransform currentXform = null; /** The horizontal offset of the image from the left edge of the panel */ - int offx; + int offx = 0; /** The vertical offset of the image from the top of the panel */ - int offy; + int offy = 0; /** The size of the image */ - private Dimension prevSize; + private Dimension prevSize = null; /** The position of the signature, in document space */ - Point2D sigPagePos; + Point2D sigPagePos = null; /** The position of the signature, in screen space */ - Point2D sigScreenPos; + Point2D sigScreenPos = null; + /** The signature placeholder image */ + private Image sigPlaceholder = null; /** * Create a new PagePanel, with a default size of 800 by 600 pixels. @@ -73,8 +75,7 @@ public class SignaturePanel extends JPanel { */ public SignaturePanel(PDFFile pdf) { super(new BorderLayout()); - this.pdf = pdf; - this.sigPagePos = null; + setDocument(pdf); setPreferredSize(new Dimension(800, 600)); setFocusable(true); addMouseListener(this.mouseListener); @@ -92,6 +93,15 @@ public class SignaturePanel extends JPanel { showPage(pdf.getNumPages()); } + /** + * Set the signature placeholder image + * @param placeholder signature placeholder + */ + public void setSignaturePlaceholder(Image placeholder) + { + this.sigPlaceholder = placeholder; + } + /** * Change the currently displayed page * @param page the number of the page to display @@ -204,12 +214,19 @@ public class SignaturePanel extends JPanel { if ((imwid == sz.width && imhgt <= sz.height) || (imhgt == sz.height && imwid <= sz.width)) { + // draw document g.drawImage(this.currentImage, this.offx, this.offy, this); - g.setColor(Color.red); + // draw signature int sigx = (int) (this.offx + this.sigScreenPos.getX()); int sigy = (int) (this.offy + this.sigScreenPos.getY()); - g.drawRect(sigx - 10, sigy - 10, 20, 20); + if (this.sigPlaceholder == null) { + g.setColor(Color.red); + g.drawRect(sigx - 10, sigy - 10, 20, 20); + } + else { + g.drawImage(this.sigPlaceholder, sigx, sigy, null); + } } else { // the image is bogus. try again, or give up. diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java index e08a0f69..39ce2b08 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java @@ -56,7 +56,11 @@ public class PositioningState extends State { this.positionComposite = this.stateMachine.getGUIProvider().createComposite(PositioningComposite.class, SWT.RESIZE, this); log.debug("Displaying " + this.stateMachine.getStatus().getDocument()); + SignatureParameter param = this.stateMachine.getPDFSigner().getPDFSigner().newParameter(); + Emblem emblem = new FileNameEmblem(this.stateMachine.getConfigProvider().getDefaultEmblem()); + param.setEmblem(emblem); this.positionComposite.displayDocument(this.stateMachine.getStatus().getDocument()); + this.positionComposite.setPlaceholder(param.getPlaceholder()); } return this.positionComposite; -- cgit v1.2.3