dc6091f667d9a8700cfbb3a9a71c6485d381692e
[Mograsim.git] / LogicUI / src / era / mi / gui / examples / 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.GUIOrGate;
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                 LogicUIStandalone ui = new LogicUIStandalone(t);
23                 addComponentsAndWires(ui.getLogicUICanvas(), t);
24                 ui.run();
25         }
26
27         public static void addComponentsAndWires(LogicUICanvas ui, Timeline t)
28         {
29                 Wire r = new Wire(t, 1, WIRE_DELAY);
30                 Wire s = new Wire(t, 1, WIRE_DELAY);
31                 Wire t2 = new Wire(t, 1, WIRE_DELAY);
32                 Wire t1 = new Wire(t, 1, WIRE_DELAY);
33                 Wire q = new Wire(t, 1, WIRE_DELAY);
34                 Wire nq = new Wire(t, 1, WIRE_DELAY);
35
36                 GUIManualSwitch rIn = ui.addComponent(new GUIManualSwitch(t, r.createReadWriteEnd()), 100, 100);
37                 GUIManualSwitch sIn = ui.addComponent(new GUIManualSwitch(t, s.createReadWriteEnd()), 100, 200);
38                 GUIOrGate or1 = ui.addComponent(new GUIOrGate(t, OR_DELAY, t1.createReadWriteEnd(), r.createReadOnlyEnd(), nq.createReadOnlyEnd()),
39                                 160, 102.5);
40                 GUIOrGate or2 = ui.addComponent(new GUIOrGate(t, OR_DELAY, t2.createReadWriteEnd(), q.createReadOnlyEnd(), s.createReadOnlyEnd()),
41                                 160, 192.5);
42                 GUINotGate not1 = ui.addComponent(new GUINotGate(t, NOT_DELAY, t1.createReadOnlyEnd(), q.createReadWriteEnd()), 200, 107.5);
43                 GUINotGate not2 = ui.addComponent(new GUINotGate(t, NOT_DELAY, t2.createReadOnlyEnd(), nq.createReadWriteEnd()), 200, 197.5);
44
45                 WireConnectionPoint p1 = ui.addComponent(new WireConnectionPoint(q, 3), 250, 112.5);
46                 WireConnectionPoint p2 = ui.addComponent(new WireConnectionPoint(nq, 3), 250, 202.5);
47                 WireConnectionPoint o1 = ui.addComponent(new WireConnectionPoint(q, 1), 270, 112.5);
48                 WireConnectionPoint o2 = ui.addComponent(new WireConnectionPoint(nq, 1), 270, 202.5);
49
50                 ui.addWire(rIn, 0, or1, 0);
51                 ui.addWire(sIn, 0, or2, 1);
52                 ui.addWire(or1, 2, not1, 0);
53                 ui.addWire(or2, 2, not2, 0);
54                 ui.addWire(not1, 1, p1, 0);
55                 ui.addWire(not2, 1, p2, 0);
56                 ui.addWire(p1, 1, or2, 0, new Point(250, 130), new Point(140, 185), new Point(140, 197.5));
57                 ui.addWire(p2, 1, or1, 1, new Point(250, 185), new Point(140, 130), new Point(140, 117.5));
58                 ui.addWire(p1, 2, o1, 0);
59                 ui.addWire(p2, 2, o2, 0);
60         }
61 }