diff options
author | tkellner <tkellner@3a0b52a2-8410-0410-bc02-ff6273a87459> | 2012-10-31 16:36:39 +0000 |
---|---|---|
committer | tkellner <tkellner@3a0b52a2-8410-0410-bc02-ff6273a87459> | 2012-10-31 16:36:39 +0000 |
commit | 5919ca54190dcc4eb00e9a0bb2feef4a2b9caf3b (patch) | |
tree | 2bfc652e1b2cc548a036c6f32015d7f7f8be3f65 /trunk | |
parent | b2a5eec09446851751037c5b57f2576b54ef1f2b (diff) | |
download | pdf-over-5919ca54190dcc4eb00e9a0bb2feef4a2b9caf3b.tar.gz pdf-over-5919ca54190dcc4eb00e9a0bb2feef4a2b9caf3b.tar.bz2 pdf-over-5919ca54190dcc4eb00e9a0bb2feef4a2b9caf3b.zip |
Allow dragging the signature
git-svn-id: https://svn.iaik.tugraz.at/svn/egiz/prj/current/12PDF-OVER-4.0@12704 3a0b52a2-8410-0410-bc02-ff6273a87459
Diffstat (limited to 'trunk')
-rw-r--r-- | trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java | 21 | ||||
-rw-r--r-- | trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SignaturePanel.java | 37 |
2 files changed, 46 insertions, 12 deletions
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 716e1388..0470aeef 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 @@ -95,6 +95,17 @@ public class PositioningComposite extends StateComposite { } /** + * Set the signature placeholder image + * Must be called _after_ displayDocument + * @param placeholder signature placeholder + */ + public void setPlaceholder(Image placeholder) { + if (this.viewer == null) + return; + this.viewer.setSignaturePlaceholder(placeholder); + } + + /** * Create the composite. * @param parent * @param style @@ -216,14 +227,4 @@ 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/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 4c83e57f..6eb014d6 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 @@ -26,6 +26,8 @@ import java.awt.event.MouseEvent; import java.awt.geom.AffineTransform; import java.awt.geom.NoninvertibleTransformException; import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; +import java.awt.geom.Point2D.Double; import javax.swing.JPanel; @@ -258,6 +260,8 @@ public class SignaturePanel extends JPanel { private MouseAdapter mouseListener = new MouseAdapter() { private boolean doDrag = false; + private int dragXOffset = 0; + private int dragYOffset = 0; private void updateSigPos(int sigx, int sigy) { if (SignaturePanel.this.currentImage == null) @@ -276,8 +280,20 @@ public class SignaturePanel extends JPanel { public void mousePressed(MouseEvent evt) { if (evt.getButton() == MouseEvent.BUTTON1) { - updateSigPos(evt.getX(), evt.getY()); this.doDrag = true; + if (isOnSignature(evt.getX(), evt.getY())) { + this.dragXOffset = (int) + (SignaturePanel.this.sigScreenPos.getX() - + (evt.getX() - SignaturePanel.this.offx)); + this.dragYOffset = (int) + (SignaturePanel.this.sigScreenPos.getY() - + (evt.getY() - SignaturePanel.this.offy)); + } + else { + this.dragXOffset = 0; + this.dragYOffset = 0; + } + updateSigPos(evt.getX() + this.dragXOffset, evt.getY() + this.dragYOffset); } } @@ -293,11 +309,28 @@ public class SignaturePanel extends JPanel { @Override public void mouseDragged(MouseEvent evt) { if (this.doDrag) - updateSigPos(evt.getX(), evt.getY()); + updateSigPos(evt.getX() + this.dragXOffset, evt.getY() + this.dragYOffset); } }; /** + * Check whether given point is on signature placeholder + * @param x x coordinate + * @param y y coordinate + * @return true if given point is on signature placeholder + */ + boolean isOnSignature(int x, int y) + { + Rectangle2D sig = new Rectangle2D.Double( + this.sigScreenPos.getX() + this.offx, + this.sigScreenPos.getY() + this.offy, + this.sigPlaceholder.getWidth(null), + this.sigPlaceholder.getHeight(null)); + Point2D pos = new Point2D.Double(x, y); + return (sig.contains(pos)); + } + + /** * Clamp x to be within [min-max] * @param x int to clamp * @param min minimum value |