Fixed a bug in Am2900; created dlatch8/80; relayouted some components
[Mograsim.git] / net.mograsim.logic.model.editor / src / net / mograsim / logic / model / editor / handles / WireHandle.java
index a5e97d4..839c2b5 100644 (file)
@@ -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<WireClickData> click(GUIWire w, double x, double y)
+       private static Optional<WireClickData> 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();
-       }
 }