]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/participant/CanvasGrab.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / participant / CanvasGrab.java
diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/CanvasGrab.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/CanvasGrab.java
new file mode 100644 (file)
index 0000000..7ca15a8
--- /dev/null
@@ -0,0 +1,63 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.g2d.participant;\r
+\r
+import java.awt.geom.Point2D;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;\r
+import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency;\r
+\r
+/**\r
+ * Participant that enables grabbing of canvas.\r
+ * \r
+ * @See {@link HandPainter} Paints grabbing of canvas\r
+ * @author Toni Kalajainen\r
+ */\r
+public class CanvasGrab extends AbstractCanvasParticipant {\r
+\r
+       @Dependency TransformUtil util;\r
+       \r
+    public Map<Integer, PointerInfo> grabInfo = new HashMap<Integer, PointerInfo>();\r
+    \r
+    public PointerInfo grabCanvas(int id, Point2D pos)\r
+    {          \r
+       PointerInfo result = new PointerInfo(pos, id);\r
+        result.currentPos = pos;        \r
+        grabInfo.put(id, result);        \r
+       return result;\r
+    }\r
+    \r
+    public void releaseCanvas(int id)\r
+    {\r
+       grabInfo.remove(id);\r
+    }\r
+       \r
+    /** Info of pointers with left button down */\r
+    public static final class PointerInfo {\r
+        public final int mouseId;\r
+        // Anchoring position in control coordinates \r
+        public Point2D anchorPos;\r
+        public Point2D currentPos;\r
+        public PointerInfo(Point2D anchorPos, int mouseId) {\r
+            this.anchorPos = anchorPos;\r
+            this.mouseId = mouseId;\r
+        }       \r
+    }\r
+    \r
+    public Map<Integer, PointerInfo> getGrabInfo()\r
+    {\r
+       return grabInfo;\r
+    }\r
+       \r
+}\r