GUIComponents now have names
[Mograsim.git] / net.mograsim.logic.ui.am2900 / src / net / mograsim / logic / ui / model / components / mi / nandbased / am2901 / GUIAm2901.java
index b589e67..d396148 100644 (file)
@@ -2,26 +2,29 @@ package net.mograsim.logic.ui.model.components.mi.nandbased.am2901;
 
 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.mi.nandbased.GUIand;
 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIdlatch4;
 import net.mograsim.logic.ui.model.components.mi.nandbased.GUImux1_4;
 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIor4;
 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIram4;
 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIsel3_4;
+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 GUIAm2901 extends SimpleRectangularSubmodelComponent
 {
-       private GUIram4 ram;
-       private GUIAm2901QReg qreg;
-
        public GUIAm2901(ViewModelModifiable model)
        {
-               super(model, 1, "GUIAm2901");
+               this(model, null);
+       }
+
+       public GUIAm2901(ViewModelModifiable model, String name)
+       {
+               super(model, 1, "GUIAm2901", name);
                setSubmodelScale(.1);
                setInputPins("I8", "I7", "I6", "I5", "I4", "I3", "I2", "I1", "I0", "C", "Cn", "D1", "D2", "D3", "D4", "A0", "A1", "A2", "A3", "B0",
                                "B1", "B2", "B3", "IRAMn", "IRAMn+3", "IQn", "IQn+3");
@@ -79,12 +82,12 @@ public class GUIAm2901 extends SimpleRectangularSubmodelComponent
                GUIAm2901ALUInclSourceDecodeInclFunctionDecode alu = new GUIAm2901ALUInclSourceDecodeInclFunctionDecode(submodelModifiable);
                GUIor4 Fneq0 = new GUIor4(submodelModifiable);
                GUINandGate notFneq0 = new GUINandGate(submodelModifiable, 1);
-               ram = new GUIram4(submodelModifiable);
+               GUIram4 ram = new GUIram4(submodelModifiable);
                GUIdlatch4 QAlatch = new GUIdlatch4(submodelModifiable);
                GUIdlatch4 QBlatch = new GUIdlatch4(submodelModifiable);
                GUIsel3_4 ramDsel = new GUIsel3_4(submodelModifiable);
                GUIsel3_4 qregDsel = new GUIsel3_4(submodelModifiable);
-               qreg = new GUIAm2901QReg(submodelModifiable);
+               GUIAm2901QReg qreg = new GUIAm2901QReg(submodelModifiable);
 
                WireCrossPoint cpC1 = new WireCrossPoint(submodelModifiable, 1);
                WireCrossPoint cpC2 = new WireCrossPoint(submodelModifiable, 1);
@@ -342,54 +345,13 @@ public class GUIAm2901 extends SimpleRectangularSubmodelComponent
                new GUIWire(submodelModifiable, cpFneq0, notFneq0.getPin("A"), new Point(315, 445));
                new GUIWire(submodelModifiable, cpFneq0, notFneq0.getPin("B"), new Point(315, 455));
                new GUIWire(submodelModifiable, notFneq0.getPin("Y"), Feq0, new Point[0]);
-       }
 
-       @Override
-       public void setHighLevelState(String stateID, Object newState)
-       {
-               switch (stateID)
-               {
-               default:
-                       int indexOfDot = stateID.indexOf('.');
-                       if (indexOfDot != -1)
-                       {
-                               switch (stateID.substring(0, indexOfDot))
-                               {
-                               case "regs":
-                                       ram.setHighLevelState(stateID.substring(indexOfDot + 1), newState);
-                                       break;
-                               case "qreg":
-                                       qreg.setHighLevelState(stateID.substring(indexOfDot + 1), newState);
-                                       break;
-                               default:
-                                       super.setHighLevelState(stateID, newState);
-                                       break;
-                               }
-                       } else
-                               super.setHighLevelState(stateID, newState);
-               }
+               addHighLevelStateSubcomponentID("regs", ram);
+               addHighLevelStateSubcomponentID("qreg", qreg);
        }
 
-       @Override
-       public Object getHighLevelState(String stateID)
+       static
        {
-               switch (stateID)
-               {
-               default:
-                       int indexOfDot = stateID.indexOf('.');
-                       if (indexOfDot != -1)
-                       {
-                               switch (stateID.substring(0, indexOfDot))
-                               {
-                               case "regs":
-                                       return ram.getHighLevelState(stateID.substring(indexOfDot + 1));
-                               case "qreg":
-                                       return qreg.getHighLevelState(stateID.substring(indexOfDot + 1));
-                               default:
-                                       return super.getHighLevelState(stateID);
-                               }
-                       }
-                       return super.getHighLevelState(stateID);
-               }
+               IndirectGUIComponentCreator.setComponentSupplier(GUIAm2901.class.getCanonicalName(), (m, p, n) -> new GUIAm2901(m, n));
        }
 }
\ No newline at end of file