GUIComponents now have names
[Mograsim.git] / net.mograsim.logic.ui.am2900 / src / net / mograsim / logic / ui / model / components / mi / nandbased / GUIdlatch.java
index 009e6f0..e0a6038 100644 (file)
@@ -2,11 +2,12 @@ package net.mograsim.logic.ui.model.components.mi.nandbased;
 
 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
 import net.mograsim.logic.ui.model.ViewModelModifiable;
-import net.mograsim.logic.ui.model.components.GUINandGate;
-import net.mograsim.logic.ui.model.components.SimpleRectangularSubmodelComponent;
+import net.mograsim.logic.ui.model.components.atomic.GUINandGate;
+import net.mograsim.logic.ui.model.components.submodels.SimpleRectangularSubmodelComponent;
 import net.mograsim.logic.ui.model.wires.GUIWire;
 import net.mograsim.logic.ui.model.wires.Pin;
 import net.mograsim.logic.ui.model.wires.WireCrossPoint;
+import net.mograsim.logic.ui.serializing.IndirectGUIComponentCreator;
 
 public class GUIdlatch extends SimpleRectangularSubmodelComponent
 {
@@ -14,7 +15,12 @@ public class GUIdlatch extends SimpleRectangularSubmodelComponent
 
        public GUIdlatch(ViewModelModifiable model)
        {
-               super(model, 1, "GUIdlatch");
+               this(model, null);
+       }
+
+       public GUIdlatch(ViewModelModifiable model, String name)
+       {
+               super(model, 1, "GUIdlatch", name);
                setSubmodelScale(.4);
                setInputPins("D", "E");
                setOutputPins("Q", "_Q");
@@ -52,10 +58,12 @@ public class GUIdlatch extends SimpleRectangularSubmodelComponent
                new GUIWire(submodelModifiable, nand2.getPin("Y"), _rsLatch.getPin("_R"), new Point(40, 37.5), new Point(40, 22.5));
                new GUIWire(submodelModifiable, _rsLatch.getPin("Q"), Q, new Point[0]);
                new GUIWire(submodelModifiable, _rsLatch.getPin("_Q"), _Q);
+
+               addAtomicHighLevelStateID("q");
        }
 
        @Override
-       public void setHighLevelState(String stateID, Object newState)
+       public void setAtomicHighLevelState(String stateID, Object newState)
        {
                switch (stateID)
                {
@@ -63,20 +71,26 @@ public class GUIdlatch extends SimpleRectangularSubmodelComponent
                        _rsLatch.setHighLevelState("q", newState);
                        break;
                default:
-                       super.setHighLevelState(stateID, newState);
-                       break;
+                       // should not happen because we tell SubmodelComponent to only allow these state IDs.
+                       throw new IllegalStateException("Illegal atomic state ID: " + stateID);
                }
        }
 
        @Override
-       public Object getHighLevelState(String stateID)
+       public Object getAtomicHighLevelState(String stateID)
        {
                switch (stateID)
                {
                case "q":
                        return _rsLatch.getHighLevelState("q");
                default:
-                       return super.getHighLevelState(stateID);
+                       // should not happen because we tell SubmodelComponent to only allow these state IDs.
+                       throw new IllegalStateException("Illegal atomic state ID: " + stateID);
                }
        }
+
+       static
+       {
+               IndirectGUIComponentCreator.setComponentSupplier(GUIdlatch.class.getCanonicalName(), (m, p, n) -> new GUIdlatch(m, n));
+       }
 }
\ No newline at end of file