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