5e6bb6664545f8884e4c978fd8a189ad9f959882
[Mograsim.git] / LogicUI / src / era / mi / gui / examples / Playground.java
1 package era.mi.gui.examples;
2
3 import org.eclipse.swt.SWT;
4
5 import era.mi.gui.LogicUIStandalone;
6 import era.mi.gui.model.ViewModel;
7 import era.mi.gui.model.components.GUIAndGate;
8 import era.mi.gui.model.components.GUIManualSwitch;
9 import era.mi.gui.model.components.GUINotGate;
10 import era.mi.gui.model.wires.GUIWire;
11 import era.mi.gui.model.wires.WireCrossPoint;
12 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
13
14 public class Playground
15 {
16         public static void main(String[] args)
17         {
18                 ViewModel model = new ViewModel();
19                 GUIAndGate andGate = new GUIAndGate(model, 1);
20                 andGate.moveTo(10, 10);
21                 GUINotGate notGate = new GUINotGate(model, 1);
22                 notGate.moveTo(10, 40);
23
24                 WireCrossPoint wcp1 = new WireCrossPoint(model, 1);
25                 wcp1.moveTo(150, 10);
26
27                 new GUIWire(model, andGate.getOutputPin(), notGate.getInputPins().get(0), new Point(60, 50));
28                 new GUIWire(model, notGate.getOutputPin(), wcp1.getPin());
29
30                 GUIManualSwitch sw1 = new GUIManualSwitch(model);
31                 sw1.moveTo(-20, 0);
32                 GUIManualSwitch sw2 = new GUIManualSwitch(model);
33                 sw2.moveTo(-20, 50);
34
35                 new GUIWire(model, sw1.getOutputPin(), andGate.getInputPins().get(0));
36                 new GUIWire(model, sw2.getOutputPin(), andGate.getInputPins().get(1));
37
38                 LogicUIStandalone ui = new LogicUIStandalone(model);
39
40                 ui.getLogicUICanvas().addListener(SWT.KeyDown, e -> notGate.moveTo(100, 10));
41                 ui.run();
42         }
43
44         public static void addComponentsAndWires(LogicUIStandalone ui, ViewModel model)
45         {
46                 GUIAndGate andGate = new GUIAndGate(model, 1);
47                 andGate.moveTo(10, 10);
48                 GUINotGate notGate = new GUINotGate(model, 1);
49                 notGate.moveTo(10, 40);
50
51                 new GUIWire(model, andGate.getPins().get(0), notGate.getPins().get(1), new Point(20, 50));
52
53                 ui.getLogicUICanvas().addListener(SWT.KeyDown, e -> notGate.moveTo(150, 10));
54         }
55 }