1 package era.mi.gui.examples;
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.Simulation;
10 import era.mi.logic.wires.Wire;
11 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
13 public class RSLatchGUIExample
15 private static final int WIRE_DELAY = 10;
16 private static final int OR_DELAY = 50;
17 private static final int NOT_DELAY = 50;
19 public static void main(String[] args)
21 LogicUIStandalone ui = new LogicUIStandalone();
22 addComponentsAndWires(ui.getLogicUICanvas());
26 public static void addComponentsAndWires(LogicUICanvas ui)
28 Simulation.TIMELINE.reset();
29 Wire r = new Wire(1, WIRE_DELAY);
30 Wire s = new Wire(1, WIRE_DELAY);
31 Wire t2 = new Wire(1, WIRE_DELAY);
32 Wire t1 = new Wire(1, WIRE_DELAY);
33 Wire q = new Wire(1, WIRE_DELAY);
34 Wire nq = new Wire(1, WIRE_DELAY);
36 GUIManualSwitch rIn = ui.addComponent(new GUIManualSwitch(r.createReadWriteEnd()), 100, 100);
37 GUIManualSwitch sIn = ui.addComponent(new GUIManualSwitch(s.createReadWriteEnd()), 100, 200);
38 GUIOrGate or1 = ui.addComponent(new GUIOrGate(OR_DELAY, t1.createReadWriteEnd(), r.createReadOnlyEnd(), nq.createReadOnlyEnd()), 160, 102.5);
39 GUIOrGate or2 = ui.addComponent(new GUIOrGate(OR_DELAY, t2.createReadWriteEnd(), q.createReadOnlyEnd(), s.createReadOnlyEnd()), 160, 192.5);
40 GUINotGate not1 = ui.addComponent(new GUINotGate(NOT_DELAY, t1.createReadOnlyEnd(), q.createReadWriteEnd()), 200, 107.5);
41 GUINotGate not2 = ui.addComponent(new GUINotGate(NOT_DELAY, t2.createReadOnlyEnd(), nq.createReadWriteEnd()), 200, 197.5);
43 WireConnectionPoint p1 = ui.addComponent(new WireConnectionPoint(q, 3), 250, 112.5);
44 WireConnectionPoint p2 = ui.addComponent(new WireConnectionPoint(nq, 3), 250, 202.5);
45 WireConnectionPoint o1 = ui.addComponent(new WireConnectionPoint(q, 1), 270, 112.5);
46 WireConnectionPoint o2 = ui.addComponent(new WireConnectionPoint(nq, 1), 270, 202.5);
48 ui.addWire(rIn, 0, or1, 0);
49 ui.addWire(sIn, 0, or2, 1);
50 ui.addWire(or1, 2, not1, 0);
51 ui.addWire(or2, 2, not2, 0);
52 ui.addWire(not1, 1, p1, 0);
53 ui.addWire(not2, 1, p2, 0);
54 ui.addWire(p1, 1, or2, 0, new Point(250, 130), new Point(140, 185), new Point(140, 197.5));
55 ui.addWire(p2, 1, or1, 1, new Point(250, 185), new Point(140, 130), new Point(140, 117.5));
56 ui.addWire(p1, 2, o1, 0);
57 ui.addWire(p2, 2, o2, 0);