1 package era.mi.gui.examples;
\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.GUIOrGateOld;
\r
8 import era.mi.gui.wires.WireConnectionPoint;
\r
9 import era.mi.logic.timeline.Timeline;
\r
10 import era.mi.logic.wires.Wire;
\r
11 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
\r
13 public class RSLatchGUIExample
\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
19 public static void main(String[] args)
\r
21 Timeline t = new Timeline(11);
\r
22 t.setTimeFunction(() -> System.currentTimeMillis()); // real time simulation
\r
23 LogicUIStandalone ui = new LogicUIStandalone(t);
\r
24 addComponentsAndWires(ui.getLogicUICanvas(), t);
\r
28 public static void addComponentsAndWires(LogicUICanvas ui, Timeline t)
\r
30 Wire r = new Wire(t, 1, WIRE_DELAY);
\r
31 Wire s = new Wire(t, 1, WIRE_DELAY);
\r
32 Wire t2 = new Wire(t, 1, WIRE_DELAY);
\r
33 Wire t1 = new Wire(t, 1, WIRE_DELAY);
\r
34 Wire q = new Wire(t, 1, WIRE_DELAY);
\r
35 Wire nq = new Wire(t, 1, WIRE_DELAY);
\r
37 GUIManualSwitch rIn = ui.addComponent(new GUIManualSwitch(t, r.createReadWriteEnd()), 100, 100);
\r
38 GUIManualSwitch sIn = ui.addComponent(new GUIManualSwitch(t, s.createReadWriteEnd()), 100, 200);
\r
39 GUIOrGateOld or1 = ui.addComponent(new GUIOrGateOld(t, OR_DELAY, t1.createReadWriteEnd(), r.createReadOnlyEnd(), nq.createReadOnlyEnd()),
\r
41 GUIOrGateOld or2 = ui.addComponent(new GUIOrGateOld(t, OR_DELAY, t2.createReadWriteEnd(), q.createReadOnlyEnd(), s.createReadOnlyEnd()),
\r
43 GUINotGate not1 = ui.addComponent(new GUINotGate(t, NOT_DELAY, t1.createReadOnlyEnd(), q.createReadWriteEnd()), 200, 107.5);
\r
44 GUINotGate not2 = ui.addComponent(new GUINotGate(t, NOT_DELAY, t2.createReadOnlyEnd(), nq.createReadWriteEnd()), 200, 197.5);
\r
46 WireConnectionPoint p1 = ui.addComponent(new WireConnectionPoint(q, 3), 250, 112.5);
\r
47 WireConnectionPoint p2 = ui.addComponent(new WireConnectionPoint(nq, 3), 250, 202.5);
\r
48 WireConnectionPoint o1 = ui.addComponent(new WireConnectionPoint(q, 1), 270, 112.5);
\r
49 WireConnectionPoint o2 = ui.addComponent(new WireConnectionPoint(nq, 1), 270, 202.5);
\r
51 ui.addWire(rIn, 0, or1, 0);
\r
52 ui.addWire(sIn, 0, or2, 1);
\r
53 ui.addWire(or1, 2, not1, 0);
\r
54 ui.addWire(or2, 2, not2, 0);
\r
55 ui.addWire(not1, 1, p1, 0);
\r
56 ui.addWire(not2, 1, p2, 0);
\r
57 ui.addWire(p1, 1, or2, 0, new Point(250, 130), new Point(140, 185), new Point(140, 197.5));
\r
58 ui.addWire(p2, 1, or1, 1, new Point(250, 185), new Point(140, 130), new Point(140, 117.5));
\r
59 ui.addWire(p1, 2, o1, 0);
\r
60 ui.addWire(p2, 2, o2, 0);
\r