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