]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/TranslateElement.java
Fixed the order of parameters in the transformation
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / synchronization / graph / TranslateElement.java
index 39401ef283963d48ab7c9b63e9405120c7efb811..f7a1ad185429f8d17b495ed560a6392566a0add7 100644 (file)
-/*******************************************************************************\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.diagram.synchronization.graph;\r
-\r
-import java.awt.geom.AffineTransform;\r
-import java.awt.geom.Point2D;\r
-\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.CommentMetadata;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.diagram.synchronization.ModificationAdapter;\r
-import org.simantics.g2d.element.ElementHints;\r
-import org.simantics.g2d.element.IElement;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class TranslateElement extends ModificationAdapter {\r
-\r
-    Resource element;\r
-    Point2D  absolutePosition;\r
-    Point2D  offset;\r
-\r
-    public static TranslateElement absolute(Resource element, double x, double y) {\r
-        return new TranslateElement(element, new Point2D.Double(x, y), null);\r
-    }\r
-\r
-    public static TranslateElement absolute(Resource element, Point2D absolutePosition) {\r
-        return new TranslateElement(element, absolutePosition, null);\r
-    }\r
-\r
-    public static TranslateElement offset(Resource element, double x, double y) {\r
-        return new TranslateElement(element, null, new Point2D.Double(x, y));\r
-    }\r
-\r
-    public static TranslateElement offset(Resource element, Point2D offset) {\r
-        return new TranslateElement(element, null, offset);\r
-    }\r
-\r
-    /**\r
-     * @param element the element to translate, must contain a {@link Resource}\r
-     *        type {@link ElementHints#KEY_OBJECT} hint\r
-     * @param absolutePosition <code>null</code> to not define an absolute\r
-     *        position to set, otherwise this position will override the\r
-     *        original translation of the element\r
-     * @param offset an offset to apply to the element's position. If\r
-     *        {@link #absolutePosition} is null, only an offset will be applied\r
-     */\r
-    public TranslateElement(IElement element, Point2D absolutePosition, Point2D offset) {\r
-        this((Resource) element.getHint(ElementHints.KEY_OBJECT), absolutePosition, offset);\r
-    }\r
-\r
-    /**\r
-     * @param element the element to translate\r
-     * @param absolutePosition <code>null</code> to not define an absolute\r
-     *        position to set, otherwise this position will override the\r
-     *        original translation of the element\r
-     * @param offset an offset to apply to the element's position. If\r
-     *        {@link #absolutePosition} is null, only an offset will be applied\r
-     */\r
-    public TranslateElement(Resource element, Point2D absolutePosition, Point2D offset) {\r
-        super(LOW_PRIORITY);\r
-        this.element = element;\r
-        this.absolutePosition = absolutePosition;\r
-        this.offset = offset;\r
-    }\r
-\r
-    @Override\r
-    public void perform(WriteGraph graph) throws DatabaseException {\r
-        if (absolutePosition == null && offset == null)\r
-            return;\r
-\r
-        AffineTransform at = DiagramGraphUtil.getTransform(graph, element);\r
-\r
-        double x = at.getTranslateX();\r
-        double y = at.getTranslateY();\r
-        if (absolutePosition != null) {\r
-            x = absolutePosition.getX();\r
-            y = absolutePosition.getY();\r
-        }\r
-        if (offset != null) {\r
-            x += offset.getX();\r
-            y += offset.getY();\r
-        }\r
-\r
-        boolean changed = !(x == at.getTranslateX() && y == at.getTranslateY());\r
-        if (!changed)\r
-            return;\r
-\r
-        at.setTransform(at.getScaleX(), at.getShearX(), at.getShearY(), at.getScaleY(), x, y);\r
-\r
-        DiagramGraphUtil.setTransform(graph, element, at);\r
-        CommentMetadata cm = graph.getMetadata(CommentMetadata.class);\r
-        graph.addMetadata(cm.add("Translated " + element));\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.diagram.synchronization.graph;
+
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
+
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.CommentMetadata;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.diagram.synchronization.ModificationAdapter;
+import org.simantics.g2d.element.ElementHints;
+import org.simantics.g2d.element.IElement;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class TranslateElement extends ModificationAdapter {
+
+    Resource element;
+    Point2D  absolutePosition;
+    Point2D  offset;
+
+    public static TranslateElement absolute(Resource element, double x, double y) {
+        return new TranslateElement(element, new Point2D.Double(x, y), null);
+    }
+
+    public static TranslateElement absolute(Resource element, Point2D absolutePosition) {
+        return new TranslateElement(element, absolutePosition, null);
+    }
+
+    public static TranslateElement offset(Resource element, double x, double y) {
+        return new TranslateElement(element, null, new Point2D.Double(x, y));
+    }
+
+    public static TranslateElement offset(Resource element, Point2D offset) {
+        return new TranslateElement(element, null, offset);
+    }
+
+    /**
+     * @param element the element to translate, must contain a {@link Resource}
+     *        type {@link ElementHints#KEY_OBJECT} hint
+     * @param absolutePosition <code>null</code> to not define an absolute
+     *        position to set, otherwise this position will override the
+     *        original translation of the element
+     * @param offset an offset to apply to the element's position. If
+     *        {@link #absolutePosition} is null, only an offset will be applied
+     */
+    public TranslateElement(IElement element, Point2D absolutePosition, Point2D offset) {
+        this((Resource) element.getHint(ElementHints.KEY_OBJECT), absolutePosition, offset);
+    }
+
+    /**
+     * @param element the element to translate
+     * @param absolutePosition <code>null</code> to not define an absolute
+     *        position to set, otherwise this position will override the
+     *        original translation of the element
+     * @param offset an offset to apply to the element's position. If
+     *        {@link #absolutePosition} is null, only an offset will be applied
+     */
+    public TranslateElement(Resource element, Point2D absolutePosition, Point2D offset) {
+        super(LOW_PRIORITY);
+        this.element = element;
+        this.absolutePosition = absolutePosition;
+        this.offset = offset;
+    }
+
+    @Override
+    public void perform(WriteGraph graph) throws DatabaseException {
+        if (absolutePosition == null && offset == null)
+            return;
+
+        AffineTransform at = DiagramGraphUtil.getTransform(graph, element);
+
+        double x = at.getTranslateX();
+        double y = at.getTranslateY();
+        if (absolutePosition != null) {
+            x = absolutePosition.getX();
+            y = absolutePosition.getY();
+        }
+        if (offset != null) {
+            x += offset.getX();
+            y += offset.getY();
+        }
+
+        boolean changed = !(x == at.getTranslateX() && y == at.getTranslateY());
+        if (!changed)
+            return;
+
+        at.setTransform(at.getScaleX(), at.getShearY(), at.getShearX(), at.getScaleY(), x, y);
+
+        DiagramGraphUtil.setTransform(graph, element, at);
+        CommentMetadata cm = graph.getMetadata(CommentMetadata.class);
+        graph.addMetadata(cm.add("Translated " + element));
+    }
+
+}