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.SubmodelComponentParams;
13 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIfulladder;
14 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIhalfadder;
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");
30 setInputPins("Input pin #0");
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 = (SimpleRectangularSubmodelComponent) GUICustomComponentCreator.create(model,
82 GUIManualSwitch swA = new GUIManualSwitch(model);
84 GUIManualSwitch swB = new GUIManualSwitch(model);
86 GUIManualSwitch swC = new GUIManualSwitch(model);
90 GUIBitDisplay bdY = new GUIBitDisplay(model);
92 GUIBitDisplay bdZ = new GUIBitDisplay(model);
95 new GUIWire(model, swA.getOutputPin(), adder.getPin("A"));
96 new GUIWire(model, swB.getOutputPin(), adder.getPin("B"));
97 new GUIWire(model, swC.getOutputPin(), adder.getPin("C"));
99 new GUIWire(model, adder.getPin("Y"), bdY.getInputPin());
100 new GUIWire(model, adder.getPin("Z"), bdZ.getInputPin());
102 SubmodelComponent adder2 = GUICustomComponentCreator.create(model, pC, "");
104 swA = new GUIManualSwitch(model);
106 swB = new GUIManualSwitch(model);
108 swC = new GUIManualSwitch(model);
111 adder2.moveTo(30, 80);
112 bdY = new GUIBitDisplay(model);
114 bdZ = new GUIBitDisplay(model);
117 new GUIWire(model, swA.getOutputPin(), adder.getPin("A"));
118 new GUIWire(model, swB.getOutputPin(), adder.getPin("B"));
119 new GUIWire(model, swC.getOutputPin(), adder.getPin("C"));
121 new GUIWire(model, adder.getPin("Y"), bdY.getInputPin());
122 new GUIWire(model, adder.getPin("Z"), bdZ.getInputPin());