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