GUIComponents now have names
[Mograsim.git] / net.mograsim.logic.ui.am2900 / src / net / mograsim / logic / ui / model / components / mi / nandbased / GUI_rsLatch.java
index a7f8025..4ae8bd3 100644 (file)
@@ -4,11 +4,12 @@ import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
 import net.mograsim.logic.core.types.Bit;
 import net.mograsim.logic.core.types.BitVector;
 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 GUI_rsLatch extends SimpleRectangularSubmodelComponent
 {
@@ -16,7 +17,12 @@ public class GUI_rsLatch extends SimpleRectangularSubmodelComponent
 
        public GUI_rsLatch(ViewModelModifiable model)
        {
-               super(model, 1, "_rsLatch");
+               this(model, null);
+       }
+
+       public GUI_rsLatch(ViewModelModifiable model, String name)
+       {
+               super(model, 1, "_rsLatch", name);
                setSubmodelScale(.4);
                setInputPins("_S", "_R");
                setOutputPins("Q", "_Q");
@@ -50,10 +56,12 @@ public class GUI_rsLatch extends SimpleRectangularSubmodelComponent
                new GUIWire(submodelModifiable, cp2, nand1.getPin("B"), new Point(65, 42.5), new Point(5, 42.5), new Point(5, 22.5));
                wireQ = new GUIWire(submodelModifiable, cp1, Q, new Point(35, 17.5), new Point(35, 7.5), new Point(65, 7.5), new Point(65, 12.5));
                wire_Q = new GUIWire(submodelModifiable, cp2, _Q, new Point[0]);
+
+               addAtomicHighLevelStateID("q");
        }
 
        @Override
-       public void setHighLevelState(String stateID, Object newState)
+       public void setAtomicHighLevelState(String stateID, Object newState)
        {
                switch (stateID)
                {
@@ -74,22 +82,28 @@ public class GUI_rsLatch extends SimpleRectangularSubmodelComponent
                        }
                        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":
                        if (wireQ.hasLogicModelBinding())
-                               return wireQ.getWireValues().getBit(0).join(wire_Q.getWireValues().getBit(0).not());
+                               return wireQ.getWireValues().getBit(0);
                        return null;
                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(GUI_rsLatch.class.getCanonicalName(), (m, p, n) -> new GUI_rsLatch(m, n));
+       }
 }
\ No newline at end of file