summaryrefslogtreecommitdiff
path: root/pdf-over-gui/src
diff options
context:
space:
mode:
authortkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7>2013-04-10 19:04:53 +0000
committertkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7>2013-04-10 19:04:53 +0000
commitbf11c220be14bab318134e9f61eb697a9a72005b (patch)
tree523f8d29a4e8512de3befaadf6d9760fe67b98aa /pdf-over-gui/src
parentf1f26b60f22e8efe0b13f6afde916dab597d7737 (diff)
downloadmocca-bf11c220be14bab318134e9f61eb697a9a72005b.tar.gz
mocca-bf11c220be14bab318134e9f61eb697a9a72005b.tar.bz2
mocca-bf11c220be14bab318134e9f61eb697a9a72005b.zip
Allow dragging the signature
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@118 174cde9d-5d70-4d2a-aa98-46368bc2aaf7
Diffstat (limited to 'pdf-over-gui/src')
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java21
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SignaturePanel.java37
2 files changed, 46 insertions, 12 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 716e1388..0470aeef 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
@@ -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/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 4c83e57f..6eb014d6 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
@@ -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