]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.g2d.participant;\r
13 \r
14 import java.awt.geom.Point2D;\r
15 import java.util.HashMap;\r
16 import java.util.Map;\r
17 \r
18 import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;\r
19 import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency;\r
20 \r
21 /**\r
22  * Participant that enables grabbing of canvas.\r
23  * \r
24  * @See {@link HandPainter} Paints grabbing of canvas\r
25  * @author Toni Kalajainen\r
26  */\r
27 public class CanvasGrab extends AbstractCanvasParticipant {\r
28 \r
29         @Dependency TransformUtil util;\r
30         \r
31     public Map<Integer, PointerInfo> grabInfo = new HashMap<Integer, PointerInfo>();\r
32     \r
33     public PointerInfo grabCanvas(int id, Point2D pos)\r
34     {           \r
35         PointerInfo result = new PointerInfo(pos, id);\r
36         result.currentPos = pos;        \r
37         grabInfo.put(id, result);        \r
38         return result;\r
39     }\r
40     \r
41     public void releaseCanvas(int id)\r
42     {\r
43         grabInfo.remove(id);\r
44     }\r
45         \r
46     /** Info of pointers with left button down */\r
47     public static final class PointerInfo {\r
48         public final int mouseId;\r
49         // Anchoring position in control coordinates \r
50         public Point2D anchorPos;\r
51         public Point2D currentPos;\r
52         public PointerInfo(Point2D anchorPos, int mouseId) {\r
53             this.anchorPos = anchorPos;\r
54             this.mouseId = mouseId;\r
55         }       \r
56     }\r
57     \r
58     public Map<Integer, PointerInfo> getGrabInfo()\r
59     {\r
60         return grabInfo;\r
61     }\r
62         \r
63 }\r