X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model.editor%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Feditor%2Fhandles%2FHandleManager.java;h=c5e06a54cc7bb2d634903a9a647fafcb02b140dc;hb=cc6e329dc014542eb743833ef865b9d59047abbb;hp=91b0e3b07630d2ce32903a04edcab2b835a5ff3a;hpb=9e9a77976efe36de6ae82e74a013cd07a17dd352;p=Mograsim.git diff --git a/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/HandleManager.java b/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/HandleManager.java index 91b0e3b0..c5e06a54 100644 --- a/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/HandleManager.java +++ b/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/HandleManager.java @@ -8,6 +8,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; import java.util.stream.Collectors; @@ -114,8 +115,13 @@ public class HandleManager private void registerWire(GUIWire wire) { - wire.addPathChangedListener((w, diff) -> + Point[] path = wire.getPath(); + AtomicInteger oldLength = new AtomicInteger(path == null ? 0 : path.length); + wire.addPathChangedListener(w -> { + Point[] newPath = w.getPath(); + int newLength = newPath == null ? 0 : newPath.length; + int diff = oldLength.getAndSet(newLength) - newLength; if(diff != 0) { if(diff > 0) @@ -134,9 +140,9 @@ public class HandleManager pointHandlesPerWire.get(w).forEach(h -> h.updatePos()); }); addWireHandle(wire); - if (wire.getPath() == null) + if (path == null) return; - for (int i = 0; i < wire.getPath().length; i++) + for (int i = 0; i < path.length; i++) { addWirePointHandle(wire); }