]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/MoveImpl.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / element / handler / impl / MoveImpl.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.element.handler.impl;
13
14 import java.awt.geom.AffineTransform;
15 import java.awt.geom.Point2D;
16
17 import org.simantics.g2d.element.ElementHints;
18 import org.simantics.g2d.element.IElement;
19 import org.simantics.g2d.element.handler.Move;
20
21 /**
22  * This implementation of Move transforms element variable ElementHints.KEY_TRANSFORM. 
23  * 
24  * @author Toni Kalajainen
25  */
26 public class MoveImpl implements Move {
27
28     private static final long serialVersionUID = 1395438821342445141L;
29
30     public static final MoveImpl HANDLER = new MoveImpl(); 
31
32     @Override
33     public Point2D getPosition(IElement e) {
34         AffineTransform at = e.getHint(ElementHints.KEY_TRANSFORM);
35         Point2D p = new Point2D.Double(
36                 at.getTranslateX(),
37                 at.getTranslateY());
38         return p;
39     }
40
41     @Override
42     public void moveTo(IElement e, double x, double y) {                
43         AffineTransform origAt = e.getHint(ElementHints.KEY_TRANSFORM);
44         double oldX = origAt.getTranslateX();
45         double oldY = origAt.getTranslateY();
46         AffineTransform move = new AffineTransform();
47         move.setToTranslation(x-oldX, y-oldY);
48         AffineTransform at2 = new AffineTransform(origAt);
49         at2.preConcatenate(move);
50         e.setHint(ElementHints.KEY_TRANSFORM, at2);
51     }
52
53
54 }