1 package net.mograsim.plugin;
3 import org.eclipse.swt.SWT;
4 import org.eclipse.swt.widgets.Composite;
5 import org.eclipse.ui.themes.ITheme;
6 import org.eclipse.ui.themes.IThemePreview;
8 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
9 import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput;
10 import net.mograsim.logic.core.timeline.Timeline;
11 import net.mograsim.logic.ui.LogicExecuter;
12 import net.mograsim.logic.ui.LogicUICanvas;
13 import net.mograsim.logic.ui.model.ViewModelModifiable;
14 import net.mograsim.logic.ui.model.components.GUIManualSwitch;
15 import net.mograsim.logic.ui.model.components.GUINotGate;
16 import net.mograsim.logic.ui.model.components.GUIOrGate;
17 import net.mograsim.logic.ui.model.wires.GUIWire;
18 import net.mograsim.logic.ui.model.wires.WireCrossPoint;
19 import net.mograsim.logic.ui.modeladapter.LogicModelParameters;
20 import net.mograsim.logic.ui.modeladapter.ViewLogicModelAdapter;
22 public class SimulationPreview implements IThemePreview
25 private LogicUICanvas ui;
26 private LogicExecuter exec;
29 @SuppressWarnings("unused")
30 public void createControl(Composite parent, ITheme currentTheme)
32 ViewModelModifiable model = new ViewModelModifiable();
33 LogicModelParameters params = new LogicModelParameters();
34 params.gateProcessTime = 50;
35 params.wireTravelTime = 10;
37 GUIManualSwitch rIn = new GUIManualSwitch(model);
39 GUIManualSwitch sIn = new GUIManualSwitch(model);
42 GUIOrGate or1 = new GUIOrGate(model, 1);
44 new GUIWire(model, rIn.getOutputPin(), or1.getPin("A"));
46 GUIOrGate or2 = new GUIOrGate(model, 1);
48 new GUIWire(model, sIn.getOutputPin(), or2.getPin("B"));
50 GUINotGate not1 = new GUINotGate(model, 1);
51 not1.moveTo(110, 17.5);
52 new GUIWire(model, or1.getPin("Y"), not1.getPin("A"));
54 GUINotGate not2 = new GUINotGate(model, 1);
55 not2.moveTo(110, 67.5);
56 new GUIWire(model, or2.getPin("Y"), not2.getPin("A"));
58 WireCrossPoint p1 = new WireCrossPoint(model, 1);
59 p1.moveCenterTo(140, 22.5);
60 new GUIWire(model, not1.getPin("Y"), p1);
61 new GUIWire(model, p1, or2.getPin("A"), new Point(140, 35), new Point(50, 60), new Point(50, 67.5));
63 WireCrossPoint p2 = new WireCrossPoint(model, 1);
64 p2.moveCenterTo(140, 72.5);
65 new GUIWire(model, not2.getPin("Y"), p2);
66 new GUIWire(model, p2, or1.getPin("B"), new Point(140, 60), new Point(50, 35), new Point(50, 27.5));
68 WireCrossPoint o1 = new WireCrossPoint(model, 1);
69 o1.moveCenterTo(150, 22.5);
70 new GUIWire(model, p1, o1);
72 WireCrossPoint o2 = new WireCrossPoint(model, 1);
73 o2.moveCenterTo(150, 72.5);
74 new GUIWire(model, p2, o2);
76 Timeline t = ViewLogicModelAdapter.convert(model, params);
77 exec = new LogicExecuter(t);
81 ui = new LogicUICanvas(parent, SWT.NONE, model);
82 ZoomableCanvasUserInput userInput = new ZoomableCanvasUserInput(ui);
83 userInput.buttonDrag = 3;
84 userInput.buttonZoom = 2;
85 userInput.enableUserInput();
87 currentTheme.getColorRegistry().addListener(e -> update(currentTheme));
89 ui.zoomSteps(12, 10, 10);
90 exec.startLiveExecution();
93 private void update(ITheme currentTheme)
95 ui.setBackground(currentTheme.getColorRegistry().get("net.mograsim.plugin.sim_backgound"));
96 ui.setForeground(currentTheme.getColorRegistry().get("net.mograsim.plugin.sim_text_color"));
100 public void dispose()
102 exec.stopLiveExecution();