A GUIWire now can trigger a redraw
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Wed, 15 May 2019 22:55:01 +0000 (00:55 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Wed, 15 May 2019 22:55:01 +0000 (00:55 +0200)
LogicUI/src/era/mi/examples/gui/LogicUI.java
LogicUI/src/era/mi/wires/gui/GUIWire.java

index 5c77574..82528d1 100644 (file)
@@ -100,7 +100,7 @@ public class LogicUI
        }\r
        private void addWire(BasicGUIComponent component1, int component1ConnectionIndex, BasicGUIComponent component2, int component2ConnectionIndex, Point... path)\r
        {\r
-               wires.add(new GUIWire(component1, component1ConnectionIndex, componentPositions.get(component1), component2, component2ConnectionIndex, componentPositions.get(component2), path));\r
+               wires.add(new GUIWire(canvas::redrawThreadsafe, component1, component1ConnectionIndex, componentPositions.get(component1), component2, component2ConnectionIndex, componentPositions.get(component2), path));\r
        }\r
        private void drawComponent(GeneralGC gc, BasicGUIComponent component)\r
        {\r
index 7cfa796..1de3e9e 100644 (file)
@@ -12,7 +12,7 @@ public class GUIWire
        private final WireArray wa;\r
        private final double[]  path;\r
 \r
-       public GUIWire(BasicGUIComponent component1, int component1ConnectionIndex, Point component1Pos, BasicGUIComponent component2, int component2ConnectionIndex, Point component2Pos, Point... path)\r
+       public GUIWire(Runnable redraw, BasicGUIComponent component1, int component1ConnectionIndex, Point component1Pos, BasicGUIComponent component2, int component2ConnectionIndex, Point component2Pos, Point... path)\r
        {\r
                this.wa = component1.getConnectedWireArray(component1ConnectionIndex);\r
                if(!Objects.equals(wa, component2.getConnectedWireArray(component2ConnectionIndex)))\r
@@ -29,6 +29,8 @@ public class GUIWire
                Point component2ConnectionPoint = component2.getWireArrayConnectionPoint(component2ConnectionIndex);\r
                this.path[this.path.length - 2] = component2Pos.x + component2ConnectionPoint.x;\r
                this.path[this.path.length - 1] = component2Pos.y + component2ConnectionPoint.y;\r
+\r
+               wa.addObserver((initiator, oldValues) -> redraw.run());\r
        }\r
 \r
        public void render(GeneralGC gc)\r