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