X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fmodel%2Fwires%2FGUIWire.java;h=c8f6217ccd72fe20b11b260a7b9e14ea60e9e2b7;hb=ed9c53e1fac04d87ccfd5ab701e2381f18863bab;hp=f59355ce53060ac95cfea7a4b6fa5986eeac48e6;hpb=a86976434d00dce2652d93256cc12b6e3a0f324a;p=Mograsim.git diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/GUIWire.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/GUIWire.java index f59355ce..c8f6217c 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/GUIWire.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/GUIWire.java @@ -61,7 +61,6 @@ public class GUIWire */ private double[] effectivePath; - private final List redrawListeners; private final List> pathChangedListeners; /** @@ -244,10 +243,9 @@ public class GUIWire this.path = path == null ? null : Arrays.copyOf(path, path.length); this.bounds = new Rectangle(0, 0, -1, -1); - redrawListeners = new ArrayList<>(); pathChangedListeners = new ArrayList<>(); - logicObs = (i) -> callRedrawListeners(); + logicObs = (i) -> model.requestRedraw(); pin1.addPinMovedListener(p -> pinMoved()); pin2.addPinMovedListener(p -> pinMoved()); @@ -298,7 +296,7 @@ public class GUIWire private void pinMoved() { recalculateEffectivePath(); - callRedrawListeners(); + model.requestRedraw(); } // "graphical" operations @@ -392,7 +390,7 @@ public class GUIWire this.path = deepPathCopy(path); recalculateEffectivePath(); callPathChangedListeners(); - callRedrawListeners(); + model.requestRedraw(); } public Point getPathPoint(int index) @@ -405,7 +403,7 @@ public class GUIWire path[index] = pointCopy(p); recalculateEffectivePath(); callPathChangedListeners(); - callRedrawListeners(); + model.requestRedraw(); } public void insertPathPoint(Point p, int index) @@ -421,6 +419,8 @@ public class GUIWire System.arraycopy(oldPath, index, path, index + 1, oldPath.length - index); path[index] = pointCopy(p); } + recalculateEffectivePath(); + callPathChangedListeners(); } public void removePathPoint(int index) @@ -435,6 +435,8 @@ public class GUIWire if (index < oldPath.length - 1) System.arraycopy(oldPath, index + 1, path, index, oldPath.length - index - 1); } + recalculateEffectivePath(); + callPathChangedListeners(); } public double[] getEffectivePath() @@ -510,13 +512,10 @@ public class GUIWire // listeners // @formatter:off - public void addRedrawListener (Runnable listener) {redrawListeners .add (listener);} public void addPathChangedListener (Consumer listener) {pathChangedListeners.add (listener);} - public void removeRedrawListener (Runnable listener) {redrawListeners .remove(listener);} public void removePathChangedListener(Consumer listener) {pathChangedListeners.remove(listener);} - private void callRedrawListeners () {redrawListeners .forEach(l -> l.run ( ));} private void callPathChangedListeners() {pathChangedListeners.forEach(l -> l.accept(this));} // @formatter:on