Implemented the RS-Latch-Example
[Mograsim.git] / LogicUI / src / era / mi / wires / gui / GUIWire.java
1 package era.mi.wires.gui;\r
2 \r
3 import java.util.Objects;\r
4 \r
5 import era.mi.components.gui.BasicGUIComponent;\r
6 import era.mi.logic.wires.WireArray;\r
7 import net.haspamelodica.swt.helper.gcs.GeneralGC;\r
8 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;\r
9 \r
10 public class GUIWire\r
11 {\r
12         private final WireArray wa;\r
13         private final double[]  path;\r
14 \r
15         public GUIWire(BasicGUIComponent component1, int component1ConnectionIndex, Point component1Pos, BasicGUIComponent component2, int component2ConnectionIndex, Point component2Pos, Point... path)\r
16         {\r
17                 this.wa = component1.getConnectedWireArray(component1ConnectionIndex);\r
18                 if(!Objects.equals(wa, component2.getConnectedWireArray(component2ConnectionIndex)))\r
19                         throw new IllegalArgumentException("Given connection points are not connected!");\r
20                 this.path = new double[path.length * 2 + 4];\r
21                 Point component1ConnectionPoint = component1.getWireArrayConnectionPoint(component1ConnectionIndex);\r
22                 this.path[0] = component1Pos.x + component1ConnectionPoint.x;\r
23                 this.path[1] = component1Pos.y + component1ConnectionPoint.y;\r
24                 for(int srcI = 0, dstI = 2; srcI < path.length; srcI ++, dstI += 2)\r
25                 {\r
26                         this.path[dstI + 0] = path[srcI].x;\r
27                         this.path[dstI + 1] = path[srcI].y;\r
28                 }\r
29                 Point component2ConnectionPoint = component2.getWireArrayConnectionPoint(component2ConnectionIndex);\r
30                 this.path[this.path.length - 2] = component2Pos.x + component2ConnectionPoint.x;\r
31                 this.path[this.path.length - 1] = component2Pos.y + component2ConnectionPoint.y;\r
32         }\r
33 \r
34         public void render(GeneralGC gc)\r
35         {\r
36                 gc.drawPolyline(path);\r
37         }\r
38 }