Merge branch 'development' of
[Mograsim.git] / LogicUI / oldsrc / RSLatchGUIExample.java
1 package era.mi.gui.examples;
2
3 import era.mi.gui.LogicUICanvas;
4 import era.mi.gui.LogicUIStandalone;
5 import era.mi.gui.components.GUIManualSwitch;
6 import era.mi.gui.components.GUINotGate;
7 import era.mi.gui.components.GUIOrGateOld;
8 import era.mi.gui.wires.WireConnectionPoint;
9 import era.mi.logic.timeline.Timeline;
10 import era.mi.logic.wires.Wire;
11 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
12
13 public class RSLatchGUIExample
14 {
15         private static final int WIRE_DELAY = 10;
16         private static final int OR_DELAY = 50;
17         private static final int NOT_DELAY = 50;
18
19         public static void main(String[] args)
20         {
21                 Timeline t = new Timeline(11);
22                 t.setTimeFunction(() -> System.currentTimeMillis()); // real time simulation
23                 LogicUIStandalone ui = new LogicUIStandalone(t);
24                 addComponentsAndWires(ui.getLogicUICanvas(), t);
25                 ui.run();
26         }
27
28         public static void addComponentsAndWires(LogicUICanvas ui, Timeline t)
29         {
30                 Wire r = new Wire(t, 1, WIRE_DELAY);
31                 Wire s = new Wire(t, 1, WIRE_DELAY);
32                 Wire t2 = new Wire(t, 1, WIRE_DELAY);
33                 Wire t1 = new Wire(t, 1, WIRE_DELAY);
34                 Wire q = new Wire(t, 1, WIRE_DELAY);
35                 Wire nq = new Wire(t, 1, WIRE_DELAY);
36
37                 GUIManualSwitch rIn = ui.addComponent(new GUIManualSwitch(t, r.createReadWriteEnd()), 100, 100);
38                 GUIManualSwitch sIn = ui.addComponent(new GUIManualSwitch(t, s.createReadWriteEnd()), 100, 200);
39                 GUIOrGateOld or1 = ui.addComponent(new GUIOrGateOld(t, OR_DELAY, t1.createReadWriteEnd(), r.createReadOnlyEnd(), nq.createReadOnlyEnd()),
40                                 160, 102.5);
41                 GUIOrGateOld or2 = ui.addComponent(new GUIOrGateOld(t, OR_DELAY, t2.createReadWriteEnd(), q.createReadOnlyEnd(), s.createReadOnlyEnd()),
42                                 160, 192.5);
43                 GUINotGate not1 = ui.addComponent(new GUINotGate(t, NOT_DELAY, t1.createReadOnlyEnd(), q.createReadWriteEnd()), 200, 107.5);
44                 GUINotGate not2 = ui.addComponent(new GUINotGate(t, NOT_DELAY, t2.createReadOnlyEnd(), nq.createReadWriteEnd()), 200, 197.5);
45
46                 WireConnectionPoint p1 = ui.addComponent(new WireConnectionPoint(q, 3), 250, 112.5);
47                 WireConnectionPoint p2 = ui.addComponent(new WireConnectionPoint(nq, 3), 250, 202.5);
48                 WireConnectionPoint o1 = ui.addComponent(new WireConnectionPoint(q, 1), 270, 112.5);
49                 WireConnectionPoint o2 = ui.addComponent(new WireConnectionPoint(nq, 1), 270, 202.5);
50
51                 ui.addWire(rIn, 0, or1, 0);
52                 ui.addWire(sIn, 0, or2, 1);
53                 ui.addWire(or1, 2, not1, 0);
54                 ui.addWire(or2, 2, not2, 0);
55                 ui.addWire(not1, 1, p1, 0);
56                 ui.addWire(not2, 1, p2, 0);
57                 ui.addWire(p1, 1, or2, 0, new Point(250, 130), new Point(140, 185), new Point(140, 197.5));
58                 ui.addWire(p2, 1, or1, 1, new Point(250, 185), new Point(140, 130), new Point(140, 117.5));
59                 ui.addWire(p1, 2, o1, 0);
60                 ui.addWire(p2, 2, o2, 0);
61         }
62 }