X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model.editor%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Feditor%2Fhandles%2FWireHandle.java;h=839c2b5b733532991232ced408242bfc03513222;hb=8bed58cd47f4e53a0a83e066d38864aa6875502f;hp=a5e97d4c8fc3dc503dde1e27d9ddc76c6b88f1c3;hpb=878d036669f4aa9d0c332ced43da3a08b94655e9;p=Mograsim.git diff --git a/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/WireHandle.java b/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/WireHandle.java index a5e97d4c..839c2b5b 100644 --- a/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/WireHandle.java +++ b/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/WireHandle.java @@ -9,20 +9,23 @@ import net.haspamelodica.swt.helper.gcs.GeneralGC; import net.haspamelodica.swt.helper.swtobjectwrappers.Point; import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; import net.mograsim.logic.model.editor.states.EditorState; -import net.mograsim.logic.model.model.wires.GUIWire; -import net.mograsim.logic.model.model.wires.GUIWire.PathChangedListener; +import net.mograsim.logic.model.model.LogicModelModifiable; +import net.mograsim.logic.model.model.wires.ModelWire; -public class WireHandle extends Handle implements PathChangedListener +public class WireHandle extends Handle { private boolean selected = false; private final static double WIDTH = 2.0; private final static double WIDTH_SQUARED = WIDTH * WIDTH; - public final GUIWire parent; + private final LogicModelModifiable model; + public final ModelWire parent; - public WireHandle(GUIWire parent) + public WireHandle(LogicModelModifiable model, ModelWire parent) { + super(5); + this.model = model; this.parent = parent; - parent.addPathChangedListener(this); + parent.addPathChangedListener(c -> updateBounds()); updateBounds(); } @@ -30,7 +33,7 @@ public class WireHandle extends Handle implements PathChangedListener void destroy() { super.destroy(); - parent.removePathChangedListener(this); + parent.removePathChangedListener(c -> updateBounds()); } public void updateBounds() @@ -68,7 +71,9 @@ public class WireHandle extends Handle implements PathChangedListener @Override public void reqDelete() { - parent.destroy(); + // this wire could already be removed implicitly when removing a selection containing both wires and components + if (model.getWireByName(parent.name) != null) + model.destroyWire(parent); } @Override @@ -101,7 +106,7 @@ public class WireHandle extends Handle implements PathChangedListener } - private static Optional click(GUIWire w, double x, double y) + private static Optional click(ModelWire w, double x, double y) { Rectangle modifiedBounds = w.getBounds(); modifiedBounds.x -= WIDTH; @@ -153,10 +158,4 @@ public class WireHandle extends Handle implements PathChangedListener { return HandleType.WIRE; } - - @Override - public void pathChanged(GUIWire wire, int diff) - { - updateBounds(); - } }