1 /*******************************************************************************
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.scenegraph.g2d.nodes.connection;
14 import gnu.trove.map.hash.THashMap;
16 import org.simantics.diagram.connection.RouteGraph;
17 import org.simantics.diagram.connection.RouteLine;
18 import org.simantics.diagram.connection.RouteTerminal;
21 * @author Tuukka Lehtonen
23 public class RemoveLineAction {
27 RouteTerminal terminal;
29 public RemoveLineAction(RouteGraph rg, RouteGraph rgc, RouteTerminal terminal) {
32 this.terminal = terminal;
35 public RouteGraph getOriginalRouteGraph() {
39 public RouteGraph getRouteGraph() {
45 * @param l the route line to remove
48 * @return the performed action or <code>null</code> if no action to perform
50 public static RemoveLineAction perform(RouteGraph rg, RouteLine line, double x, double y) {
51 // Can't remove segments from connections that have only two terminals.
52 if (rg.isSimpleConnection() || rg.getTerminals().size() <= 2)
55 THashMap<Object, Object> map = new THashMap<Object, Object>();
56 RouteGraph rgc = rg.copy(map);
57 RouteLine lc = (RouteLine) map.get(line);
59 RouteTerminal terminal = lc.getTerminal();
63 rgc.disconnect(terminal);
66 return new RemoveLineAction(rg, rgc, terminal);