GUIWire now supports moving pins
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Tue, 28 May 2019 09:51:33 +0000 (11:51 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Tue, 28 May 2019 09:51:33 +0000 (11:51 +0200)
LogicUI/src/era/mi/gui/model/wires/GUIWire.java

index 1121335..c4cb2f1 100644 (file)
@@ -27,16 +27,27 @@ public class GUIWire
                        this.path[dstI + 0] = path[srcI].x;
                        this.path[dstI + 1] = path[srcI].y;
                }
-               // TODO support moving pins
-               Point pos;
-               pos = pin1.getPos();
+
+               pin1.addPinMovedListener(p -> pin1Moved());
+               pin2.addPinMovedListener(p -> pin2Moved());
+               pin1Moved();
+               pin2Moved();
+
+               model.wireCreated(this);
+       }
+
+       private void pin1Moved()
+       {
+               Point pos = pin1.getPos();
                this.path[0] = pos.x;
                this.path[1] = pos.y;
-               pos = pin2.getPos();
+       }
+
+       private void pin2Moved()
+       {
+               Point pos = pin2.getPos();
                this.path[this.path.length - 2] = pos.x;
                this.path[this.path.length - 1] = pos.y;
-
-               model.wireCreated(this);
        }
 
        public void destroy()