Merge branch 'development' of
[Mograsim.git] / LogicUI / src / era / mi / gui / examples / Playground.java
1 package era.mi.gui.examples;
2
3 import era.mi.gui.LogicUIStandalone;
4 import era.mi.gui.model.ViewModel;
5 import era.mi.gui.model.components.GUIAndGate;
6 import era.mi.gui.model.components.GUIManualSwitch;
7 import era.mi.gui.model.components.GUINotGate;
8 import era.mi.gui.model.components.GUIOrGate;
9 import era.mi.gui.model.wires.GUIWire;
10 import era.mi.gui.model.wires.WireCrossPoint;
11 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
12
13 public class Playground
14 {
15         public static void main(String[] args)
16         {
17                 ViewModel model = new ViewModel();
18                 createRSLatchExample(model);
19                 LogicUIStandalone ui = new LogicUIStandalone(model);
20                 ui.run();
21         }
22
23         private static void createRSLatchExample(ViewModel model)
24         {
25                 GUIManualSwitch rIn = new GUIManualSwitch(model);
26                 rIn.moveTo(100, 100);
27                 GUIManualSwitch sIn = new GUIManualSwitch(model);
28                 sIn.moveTo(100, 200);
29
30                 GUIOrGate or1 = new GUIOrGate(model, 1);
31                 or1.moveTo(160, 102.5);
32                 new GUIWire(model, rIn.getOutputPin(), or1.getInputPins().get(0));
33
34                 GUIOrGate or2 = new GUIOrGate(model, 1);
35                 or2.moveTo(160, 192.5);
36                 new GUIWire(model, sIn.getOutputPin(), or2.getInputPins().get(1));
37
38                 GUINotGate not1 = new GUINotGate(model, 1);
39                 not1.moveTo(200, 107.5);
40                 new GUIWire(model, or1.getOutputPin(), not1.getInputPins().get(0));
41
42                 GUINotGate not2 = new GUINotGate(model, 1);
43                 not2.moveTo(200, 197.5);
44                 new GUIWire(model, or2.getOutputPin(), not2.getInputPins().get(0));
45
46                 WireCrossPoint p1 = new WireCrossPoint(model, 1);
47                 p1.moveTo(250, 112.5);
48                 new GUIWire(model, not1.getOutputPin(), p1.getPin());
49                 new GUIWire(model, p1.getPin(), or2.getInputPins().get(0), new Point(250, 130), new Point(140, 185), new Point(140, 197.5));
50
51                 WireCrossPoint p2 = new WireCrossPoint(model, 1);
52                 p2.moveTo(250, 202.5);
53                 new GUIWire(model, not2.getOutputPin(), p2.getPin());
54                 new GUIWire(model, p2.getPin(), or1.getInputPins().get(1), new Point(250, 185), new Point(140, 130), new Point(140, 117.5));
55
56                 WireCrossPoint o1 = new WireCrossPoint(model, 1);
57                 o1.moveTo(270, 112.5);
58                 new GUIWire(model, p1.getPin(), o1.getPin());
59
60                 WireCrossPoint o2 = new WireCrossPoint(model, 1);
61                 o2.moveTo(270, 202.5);
62                 new GUIWire(model, p2.getPin(), o2.getPin());
63         }
64
65         @SuppressWarnings("unused")
66         private static void createBasicExample(ViewModel model)
67         {
68                 GUIAndGate andGate = new GUIAndGate(model, 1);
69                 andGate.moveTo(10, 10);
70                 GUINotGate notGate = new GUINotGate(model, 1);
71                 notGate.moveTo(10, 40);
72
73                 WireCrossPoint wcp1 = new WireCrossPoint(model, 1);
74                 wcp1.moveTo(150, 10);
75
76                 new GUIWire(model, andGate.getOutputPin(), notGate.getInputPins().get(0), new Point(60, 50));
77                 new GUIWire(model, notGate.getOutputPin(), wcp1.getPin());
78
79                 GUIManualSwitch sw1 = new GUIManualSwitch(model);
80                 sw1.moveTo(-20, 0);
81                 GUIManualSwitch sw2 = new GUIManualSwitch(model);
82                 sw2.moveTo(-20, 50);
83
84                 new GUIWire(model, sw1.getOutputPin(), andGate.getInputPins().get(0));
85                 new GUIWire(model, sw2.getOutputPin(), andGate.getInputPins().get(1));
86         }
87 }