--- /dev/null
+/*******************************************************************************\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.scenegraph.g2d.nodes.connection;\r
+\r
+import gnu.trove.map.hash.THashMap;\r
+\r
+import org.simantics.diagram.connection.RouteGraph;\r
+import org.simantics.diagram.connection.RouteLine;\r
+import org.simantics.diagram.connection.RouteTerminal;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class RemoveLineAction {\r
+\r
+ RouteGraph rg;\r
+ RouteGraph rgc;\r
+ RouteTerminal terminal;\r
+\r
+ public RemoveLineAction(RouteGraph rg, RouteGraph rgc, RouteTerminal terminal) {\r
+ this.rg = rg;\r
+ this.rgc = rgc;\r
+ this.terminal = terminal;\r
+ }\r
+\r
+ public RouteGraph getOriginalRouteGraph() {\r
+ return rg;\r
+ }\r
+\r
+ public RouteGraph getRouteGraph() {\r
+ return rgc;\r
+ }\r
+\r
+ /**\r
+ * @param rg\r
+ * @param l the route line to remove\r
+ * @param x\r
+ * @param y\r
+ * @return the performed action or <code>null</code> if no action to perform\r
+ */\r
+ public static RemoveLineAction perform(RouteGraph rg, RouteLine line, double x, double y) {\r
+ // Can't remove segments from connections that have only two terminals.\r
+ if (rg.isSimpleConnection() || rg.getTerminals().size() <= 2)\r
+ return null;\r
+\r
+ THashMap<Object, Object> map = new THashMap<Object, Object>();\r
+ RouteGraph rgc = rg.copy(map);\r
+ RouteLine lc = (RouteLine) map.get(line);\r
+\r
+ RouteTerminal terminal = lc.getTerminal();\r
+ if (terminal == null)\r
+ return null;\r
+\r
+ rgc.disconnect(terminal);\r
+ rgc.remove(terminal);\r
+\r
+ return new RemoveLineAction(rg, rgc, terminal);\r
+ }\r
+\r
+}\r