]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/actions/MoveAction.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.diagram.connection / src / org / simantics / diagram / connection / actions / MoveAction.java
index 2f469f65f7a68f01c311989adee1ce9910a923aa..dbe862e0361d2206d23999fef14cbd5aaf1fc0a6 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
- * 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.connection.actions;\r
-\r
-import gnu.trove.map.hash.THashMap;\r
-\r
-import java.awt.Graphics2D;\r
-\r
-import org.simantics.diagram.connection.RouteGraph;\r
-import org.simantics.diagram.connection.RouteLine;\r
-import org.simantics.diagram.connection.RouteLink;\r
-import org.simantics.diagram.connection.RouteTerminal;\r
-import org.simantics.diagram.connection.rendering.IRouteGraphRenderer;\r
-\r
-public class MoveAction implements IAction {\r
-\r
-    protected RouteGraph rg;\r
-    protected Object target;\r
-    protected RouteGraph movedRg;\r
-\r
-    public MoveAction(RouteGraph rg, Object target) {\r
-        this.rg = rg;\r
-        this.target = target;\r
-    }\r
-\r
-    @Override\r
-    public void render(Graphics2D g, IRouteGraphRenderer renderer, double x, double y) {\r
-        THashMap<Object, Object> map = new THashMap<Object, Object>();\r
-        movedRg = rg.copy(map);\r
-        move(movedRg, map.get(target), x, y);\r
-        renderer.render(g, movedRg);\r
-    }\r
-\r
-    public RouteGraph getRouteGraph() {\r
-        return movedRg == null ? rg : movedRg;\r
-    }\r
-\r
-    public Object getTarget() {\r
-        return target;\r
-    }\r
-\r
-    public void finish(double x, double y) {\r
-        move(rg, target, x, y);\r
-        movedRg = null;\r
-    }\r
-\r
-    protected void move(RouteGraph rg, Object target, double x, double y) {\r
-        moveTarget(rg, target, x, y);\r
-    }\r
-\r
-    private static void moveTarget(RouteGraph rg, Object target, double x, double y) {\r
-        if(target instanceof RouteLine) {\r
-            RouteLine line = (RouteLine)target;\r
-            rg.setLocation(line, x, y);\r
-        }\r
-        else if(target instanceof RouteTerminal) {\r
-            RouteTerminal terminal = (RouteTerminal)target;\r
-            rg.setLocation(terminal, x, y);\r
-        }\r
-        else if(target instanceof RouteLink) {\r
-            RouteLink link = (RouteLink)target;\r
-            RouteLine a = link.getA();\r
-            RouteLine b = link.getB();\r
-            rg.setLocation(a, x, y);\r
-            rg.setLocation(b, x, y);\r
-        }\r
-    }\r
-\r
-    public static MoveAction create(RouteGraph rg, double x, double y) {\r
-        return create(rg, x, y, TOLERANCE);\r
-    }\r
-\r
-    public static MoveAction create(RouteGraph rg, double x, double y, double tolerance) {\r
-        Object target = rg.pick(x, y, tolerance);\r
-        if(target == null)\r
-            return null;\r
-        else\r
-            return new MoveAction(rg, target);\r
-    }\r
-\r
-    public static MoveAction create(RouteGraph rg, double x, double y, double tolerance, TargetFilter filter) {\r
-        Object target = rg.pick(x, y, tolerance);\r
-        if (target != null && (filter == null || filter.accept(target)))\r
-            return new MoveAction(rg, target);\r
-        return null;\r
-    }\r
-\r
-    public static interface TargetFilter {\r
-        boolean accept(Object target);\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2011 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.connection.actions;
+
+import gnu.trove.map.hash.THashMap;
+
+import java.awt.Graphics2D;
+
+import org.simantics.diagram.connection.RouteGraph;
+import org.simantics.diagram.connection.RouteLine;
+import org.simantics.diagram.connection.RouteLink;
+import org.simantics.diagram.connection.RouteTerminal;
+import org.simantics.diagram.connection.rendering.IRouteGraphRenderer;
+
+public class MoveAction implements IAction {
+
+    protected RouteGraph rg;
+    protected Object target;
+    protected RouteGraph movedRg;
+
+    public MoveAction(RouteGraph rg, Object target) {
+        this.rg = rg;
+        this.target = target;
+    }
+
+    @Override
+    public void render(Graphics2D g, IRouteGraphRenderer renderer, double x, double y) {
+        THashMap<Object, Object> map = new THashMap<Object, Object>();
+        movedRg = rg.copy(map);
+        move(movedRg, map.get(target), x, y);
+        renderer.render(g, movedRg);
+    }
+
+    public RouteGraph getRouteGraph() {
+        return movedRg == null ? rg : movedRg;
+    }
+
+    public Object getTarget() {
+        return target;
+    }
+
+    public void finish(double x, double y) {
+        move(rg, target, x, y);
+        movedRg = null;
+    }
+
+    protected void move(RouteGraph rg, Object target, double x, double y) {
+        moveTarget(rg, target, x, y);
+    }
+
+    private static void moveTarget(RouteGraph rg, Object target, double x, double y) {
+        if(target instanceof RouteLine) {
+            RouteLine line = (RouteLine)target;
+            rg.setLocation(line, x, y);
+        }
+        else if(target instanceof RouteTerminal) {
+            RouteTerminal terminal = (RouteTerminal)target;
+            rg.setLocation(terminal, x, y);
+        }
+        else if(target instanceof RouteLink) {
+            RouteLink link = (RouteLink)target;
+            RouteLine a = link.getA();
+            RouteLine b = link.getB();
+            rg.setLocation(a, x, y);
+            rg.setLocation(b, x, y);
+        }
+    }
+
+    public static MoveAction create(RouteGraph rg, double x, double y) {
+        return create(rg, x, y, TOLERANCE);
+    }
+
+    public static MoveAction create(RouteGraph rg, double x, double y, double tolerance) {
+        Object target = rg.pick(x, y, tolerance);
+        if(target == null)
+            return null;
+        else
+            return new MoveAction(rg, target);
+    }
+
+    public static MoveAction create(RouteGraph rg, double x, double y, double tolerance, TargetFilter filter) {
+        Object target = rg.pick(x, y, tolerance);
+        if (target != null && (filter == null || filter.accept(target)))
+            return new MoveAction(rg, target);
+        return null;
+    }
+
+    public static interface TargetFilter {
+        boolean accept(Object target);
+    }
+
+}