1 package net.mograsim.logic.ui.examples;
3 import java.io.IOException;
4 import java.util.HashMap;
6 import net.mograsim.logic.ui.SimpleLogicUIStandalone;
7 import net.mograsim.logic.ui.model.ViewModelModifiable;
8 import net.mograsim.logic.ui.model.components.GUIBitDisplay;
9 import net.mograsim.logic.ui.model.components.GUIComponentCreator;
10 import net.mograsim.logic.ui.model.components.GUICustomComponentCreator;
11 import net.mograsim.logic.ui.model.components.GUIManualSwitch;
12 import net.mograsim.logic.ui.model.components.SimpleRectangularSubmodelComponent;
13 import net.mograsim.logic.ui.model.components.SubmodelComponent;
14 import net.mograsim.logic.ui.model.components.SubmodelComponentParams;
15 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIfulladder;
16 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIhalfadder;
17 import net.mograsim.logic.ui.model.wires.GUIWire;
19 public class JsonExample
21 public static void main(String[] args)
23 SimpleLogicUIStandalone.executeVisualisation(JsonExample::mappingTest);
26 public static void mappingTest(ViewModelModifiable model)
28 GUIComponentCreator.create(model, "GUIAm2901", new HashMap<String, Object>());
31 private static class TestComponent extends SimpleRectangularSubmodelComponent
33 protected TestComponent(ViewModelModifiable model)
35 super(model, 1, "Test");
37 setInputPins("Input pin #0");
38 GUICustomComponentCreator.create(submodelModifiable, "HalfAdder.json");
42 // Execute only after HalfAdder.json has been created
43 public static void refJsonFromJsonTest(ViewModelModifiable model)
45 TestComponent t = new TestComponent(model);
46 t.calculateParams().writeJson("Test.json");
47 SubmodelComponent c = GUICustomComponentCreator.create(model, "Test.json");
51 public static void createHalfAdderExample(ViewModelModifiable model)
53 GUIhalfadder tmp = new GUIhalfadder(model);
55 SubmodelComponentParams p = tmp.calculateParams();
58 p.writeJson("HalfAdder.json");
59 p = SubmodelComponentParams.readJson("HalfAdder.json");
66 GUICustomComponentCreator.create(model, p);
69 @SuppressWarnings("unused") // for GUIWires being created
70 public static void createFromJsonExample(ViewModelModifiable model)
72 SimpleRectangularSubmodelComponent tmp = new GUIfulladder(model);
73 SubmodelComponentParams pC = tmp.calculateParams();
74 tmp.moveTo(1000, 100);
77 pC.writeJson("FullAdder.json");
78 pC = SubmodelComponentParams.readJson("FullAdder.json");
85 SimpleRectangularSubmodelComponent adder = (SimpleRectangularSubmodelComponent) GUICustomComponentCreator.create(model,
88 GUIManualSwitch swA = new GUIManualSwitch(model);
90 GUIManualSwitch swB = new GUIManualSwitch(model);
92 GUIManualSwitch swC = new GUIManualSwitch(model);
96 GUIBitDisplay bdY = new GUIBitDisplay(model);
98 GUIBitDisplay bdZ = new GUIBitDisplay(model);
101 new GUIWire(model, swA.getOutputPin(), adder.getPin("A"));
102 new GUIWire(model, swB.getOutputPin(), adder.getPin("B"));
103 new GUIWire(model, swC.getOutputPin(), adder.getPin("C"));
105 new GUIWire(model, adder.getPin("Y"), bdY.getInputPin());
106 new GUIWire(model, adder.getPin("Z"), bdZ.getInputPin());
108 SubmodelComponent adder2 = GUICustomComponentCreator.create(model, pC);
110 swA = new GUIManualSwitch(model);
112 swB = new GUIManualSwitch(model);
114 swC = new GUIManualSwitch(model);
117 adder2.moveTo(30, 80);
118 bdY = new GUIBitDisplay(model);
120 bdZ = new GUIBitDisplay(model);
123 new GUIWire(model, swA.getOutputPin(), adder2.getPin("A"));
124 new GUIWire(model, swB.getOutputPin(), adder2.getPin("B"));
125 new GUIWire(model, swC.getOutputPin(), adder2.getPin("C"));
127 new GUIWire(model, adder2.getPin("Y"), bdY.getInputPin());
128 new GUIWire(model, adder2.getPin("Z"), bdZ.getInputPin());