1 package net.mograsim.logic.ui.examples;
3 import java.io.IOException;
5 import net.mograsim.logic.ui.SimpleLogicUIStandalone;
6 import net.mograsim.logic.ui.model.ViewModelModifiable;
7 import net.mograsim.logic.ui.model.components.GUIBitDisplay;
8 import net.mograsim.logic.ui.model.components.GUICustomComponentCreator;
9 import net.mograsim.logic.ui.model.components.GUIManualSwitch;
10 import net.mograsim.logic.ui.model.components.SimpleRectangularSubmodelComponent;
11 import net.mograsim.logic.ui.model.components.SubmodelComponent;
12 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIfulladder;
13 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIhalfadder;
14 import net.mograsim.logic.ui.model.components.params.SubmodelComponentParams;
15 import net.mograsim.logic.ui.model.wires.GUIWire;
17 public class JsonExample
19 public static void main(String[] args)
21 SimpleLogicUIStandalone.executeVisualisation(JsonExample::refJsonFromJsonTest);
24 private static class TestComponent extends SimpleRectangularSubmodelComponent
26 protected TestComponent(ViewModelModifiable model)
28 super(model, 1, "Test");
31 GUICustomComponentCreator.create(submodelModifiable, "HalfAdder.json");
35 // Execute only after HalfAdder.json has been created
36 public static void refJsonFromJsonTest(ViewModelModifiable model)
38 TestComponent t = new TestComponent(model);
39 t.calculateParams().writeJson("Test.json");
40 SubmodelComponent c = GUICustomComponentCreator.create(model, "Test.json");
45 public static void createHalfAdderExample(ViewModelModifiable model)
47 GUIhalfadder tmp = new GUIhalfadder(model);
49 SubmodelComponentParams p = tmp.calculateParams();
52 p.writeJson("HalfAdder.json");
53 p = SubmodelComponentParams.readJson("HalfAdder.json");
60 GUICustomComponentCreator.create(model, p, "");
63 @SuppressWarnings("unused") // for GUIWires being created
64 public static void createFromJsonExample(ViewModelModifiable model)
66 SimpleRectangularSubmodelComponent tmp = new GUIfulladder(model);
67 SubmodelComponentParams pC = tmp.calculateParams();
68 tmp.moveTo(1000, 100);
71 pC.writeJson("FullAdder.json");
72 pC = SubmodelComponentParams.readJson("FullAdder.json");
79 SimpleRectangularSubmodelComponent adder = new GUIfulladder(model);
81 GUIManualSwitch swA = new GUIManualSwitch(model);
83 GUIManualSwitch swB = new GUIManualSwitch(model);
85 GUIManualSwitch swC = new GUIManualSwitch(model);
89 GUIBitDisplay bdY = new GUIBitDisplay(model);
91 GUIBitDisplay bdZ = new GUIBitDisplay(model);
94 new GUIWire(model, swA.getOutputPin(), adder.getInputPins().get(0));
95 new GUIWire(model, swB.getOutputPin(), adder.getInputPins().get(1));
96 new GUIWire(model, swC.getOutputPin(), adder.getInputPins().get(2));
98 new GUIWire(model, adder.getOutputPins().get(0), bdY.getInputPin());
99 new GUIWire(model, adder.getOutputPins().get(1), bdZ.getInputPin());
101 SubmodelComponent adder2 = GUICustomComponentCreator.create(model, pC, "");
103 swA = new GUIManualSwitch(model);
105 swB = new GUIManualSwitch(model);
107 swC = new GUIManualSwitch(model);
110 adder2.moveTo(30, 80);
111 bdY = new GUIBitDisplay(model);
113 bdZ = new GUIBitDisplay(model);
116 new GUIWire(model, swA.getOutputPin(), adder2.getPins().get(0));
117 new GUIWire(model, swB.getOutputPin(), adder2.getPins().get(1));
118 new GUIWire(model, swC.getOutputPin(), adder2.getPins().get(2));
120 new GUIWire(model, adder2.getPins().get(3), bdY.getInputPin());
121 new GUIWire(model, adder2.getPins().get(4), bdZ.getInputPin());