]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteLink.java
27986a03fa59af21c9ffee36981c0fe6714773b9
[simantics/platform.git] / bundles / org.simantics.diagram.connection / src / org / simantics / diagram / connection / RouteLink.java
1 /*******************************************************************************\r
2  * Copyright (c) 2011 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.diagram.connection;\r
13 \r
14 import gnu.trove.map.hash.THashMap;\r
15 \r
16 import java.io.Serializable;\r
17 \r
18 public class RouteLink extends RoutePoint implements Serializable {\r
19 \r
20     private static final long serialVersionUID = 1446230300676765986L;\r
21 \r
22     RouteLine a;\r
23     RouteLine b;\r
24 \r
25     /**\r
26      * Default constructor for copy-method\r
27      */\r
28     private RouteLink() {\r
29     }\r
30     \r
31     RouteLink(RouteLine a, RouteLine b) {\r
32         this.a = a;\r
33         this.b = b;\r
34         a.addPoint(this);\r
35         b.addPoint(this);\r
36     }\r
37     \r
38     void removeFromOther(RouteLine other) {\r
39         if(a == other)\r
40             b.points.remove(this);\r
41         else\r
42             a.points.remove(this);\r
43     }\r
44 \r
45     public RouteLine getA() {\r
46         return a;\r
47     }\r
48     \r
49     public RouteLine getB() {\r
50         return b;\r
51     }\r
52 \r
53     public void setA(RouteLine rl) {\r
54         this.a = rl;\r
55         rl.addPoint(this);\r
56         if(b.isTransient())\r
57             b.terminal.line = rl;\r
58     }\r
59     \r
60     public void setB(RouteLine rl) {\r
61         this.b = rl;\r
62         rl.addPoint(this);\r
63         if(a.isTransient())\r
64             a.terminal.line = rl;\r
65     }\r
66 \r
67     public RouteLine getOther(RouteLine line) {\r
68         if(a == line)\r
69             return b;\r
70         else\r
71             return a;\r
72     }\r
73 \r
74     public void replace(RouteLine rl1, RouteLine rl2) {\r
75         if(a == rl1)\r
76             setA(rl2);\r
77         else if(b == rl1)\r
78             setB(rl2);\r
79     }\r
80 \r
81         @Override\r
82         RouteLink copy(THashMap<Object, Object> map) {\r
83                 RouteLink copy = (RouteLink)map.get(this);\r
84                 if(copy == null) {\r
85                         copy = new RouteLink();\r
86                         map.put(this, copy);\r
87                         copy.a = a.copy(map);\r
88                         copy.b = b.copy(map);                   \r
89                         copy.x = x;\r
90                         copy.y = y;\r
91                 }\r
92                 return copy;\r
93         }\r
94     \r
95 }\r