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 GUIdff extends SimpleRectangularSubmodelComponent
{
+ private GUI_rsLatch _rsLatch;
+
public GUIdff(ViewModelModifiable model)
{
- super(model, 1, "GUIdff");
+ this(model, null);
+ }
+
+ public GUIdff(ViewModelModifiable model, String name)
+ {
+ super(model, 1, "GUIdff", name);
setSubmodelScale(.2);
setInputPins("C", "D");
setOutputPins("Q", "_Q");
GUI_rsLatch _rsLatch1 = new GUI_rsLatch(submodelModifiable);
GUInand3 nand3 = new GUInand3(submodelModifiable);
GUINandGate nand2 = new GUINandGate(submodelModifiable, 1);
- GUI_rsLatch _rsLatch2 = new GUI_rsLatch(submodelModifiable);
+ GUI_rsLatch _rsLatch2 = this._rsLatch = new GUI_rsLatch(submodelModifiable);
WireCrossPoint cp1 = new WireCrossPoint(submodelModifiable, 1);
WireCrossPoint cp2 = new WireCrossPoint(submodelModifiable, 1);
new GUIWire(submodelModifiable, cp4, nand2.getPin("A"), new Point(100, 65));
new GUIWire(submodelModifiable, _rsLatch2.getPin("Q"), Q);
new GUIWire(submodelModifiable, _rsLatch2.getPin("_Q"), _Q);
+
+ addAtomicHighLevelStateID("q");
+ }
+
+ @Override
+ public void setAtomicHighLevelState(String stateID, Object newState)
+ {
+ switch (stateID)
+ {
+ case "q":
+ _rsLatch.setHighLevelState("q", newState);
+ break;
+ default:
+ // should not happen because we tell SubmodelComponent to only allow these state IDs.
+ throw new IllegalStateException("Illegal atomic state ID: " + stateID);
+ }
+ }
+
+ @Override
+ public Object getAtomicHighLevelState(String stateID)
+ {
+ switch (stateID)
+ {
+ case "q":
+ return _rsLatch.getHighLevelState("q");
+ default:
+ // should not happen because we tell SubmodelComponent to only allow these state IDs.
+ throw new IllegalStateException("Illegal atomic state ID: " + stateID);
+ }
+ }
+
+ static
+ {
+ IndirectGUIComponentCreator.setComponentSupplier(GUIdff.class.getCanonicalName(), (m, p, n) -> new GUIdff(m, n));
}
}
\ No newline at end of file