1 package net.mograsim.plugin.views;
3 import javax.inject.Inject;
5 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
6 import org.eclipse.swt.SWT;
7 import org.eclipse.swt.layout.GridData;
8 import org.eclipse.swt.layout.GridLayout;
9 import org.eclipse.swt.widgets.Button;
10 import org.eclipse.swt.widgets.Composite;
11 import org.eclipse.swt.widgets.Label;
12 import org.eclipse.swt.widgets.Slider;
13 import org.eclipse.ui.PlatformUI;
14 import org.eclipse.ui.part.ViewPart;
16 import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput;
17 import net.mograsim.logic.model.LogicExecuter;
18 import net.mograsim.logic.model.LogicUICanvas;
19 import net.mograsim.machine.Machine;
20 import net.mograsim.machine.mi.AssignableMicroInstructionMemory;
21 import net.mograsim.plugin.EclipsePreferences;
22 import net.mograsim.plugin.MachineContext;
23 import net.mograsim.plugin.MograsimActivator;
24 import net.mograsim.plugin.tables.DisplaySettings;
25 import net.mograsim.plugin.tables.mi.ActiveInstructionPreviewContentProvider;
26 import net.mograsim.plugin.tables.mi.InstructionTable;
27 import net.mograsim.preferences.Preferences;
29 public class LogicUIPart extends ViewPart
34 private LogicExecuter exec;
35 private LogicUICanvas ui;
41 exec.stopLiveExecution();
45 public void createPartControl(Composite parent)
48 Preferences.setPreferences(new EclipsePreferences(PlatformUI.getWorkbench().getThemeManager().getCurrentTheme(),
49 MograsimActivator.instance().getPreferenceStore()));
51 Machine m = MachineContext.getInstance().getMachine();
54 GridLayout layout = new GridLayout(1, true);
55 parent.setLayout(layout);
57 addSimulationControlWidgets(parent);
59 ui = new LogicUICanvas(parent, SWT.NONE, m.getModel());
60 ui.addTransformListener((x, y, z) -> part.setDirty(z < 1));
61 ZoomableCanvasUserInput userInput = new ZoomableCanvasUserInput(ui);
62 userInput.buttonDrag = 3;
63 userInput.buttonZoom = 2;
64 userInput.enableUserInput();
66 GridData uiData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
67 ui.setLayoutData(uiData);
69 // initialize Instruction preview
70 InstructionTable instPreview = new InstructionTable(parent, new DisplaySettings());
71 instPreview.setContentProvider(new ActiveInstructionPreviewContentProvider(instPreview.getTableViewer()));
72 AssignableMicroInstructionMemory mIMemory = m.getMicroInstructionMemory();
73 instPreview.bindMicroInstructionMemory(mIMemory);
74 mIMemory.registerCellModifiedListener(a -> instPreview.refresh());
75 mIMemory.registerMemoryReassignedListener(n -> instPreview.refresh());
77 GridData previewData = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL);
78 instPreview.getTableViewer().getTable().setLayoutData(previewData);
80 // initialize executer
81 exec = new LogicExecuter(m.getTimeline());
84 exec.startLiveExecution();
87 private void addSimulationControlWidgets(Composite parent)
89 Composite c = new Composite(parent, SWT.NONE);
90 c.setLayout(new GridLayout(4, false));
91 Button pauseButton = new Button(c, SWT.TOGGLE);
92 pauseButton.setText("Running");
94 pauseButton.addListener(SWT.Selection, e ->
96 if (!pauseButton.getSelection())
98 pauseButton.setText("Running");
99 exec.unpauseLiveExecution();
102 pauseButton.setText("Paused");
103 exec.pauseLiveExecution();
107 Label speedLabel = new Label(c, SWT.NONE);
108 speedLabel.setText("Simulation Speed: ");
110 Slider slider = new Slider(c, SWT.NONE);
111 slider.setMinimum(1);
112 slider.setMaximum(100 + slider.getThumb());
113 slider.setIncrement(1);
115 Label speedPercentageLabel = new Label(c, SWT.NONE);
116 speedPercentageLabel.setText("100%");
118 slider.addListener(SWT.Selection, e ->
120 int selection = slider.getSelection();
121 speedPercentageLabel.setText(selection + "%");
123 exec.setSpeedPercentage(slider.getSelection());
125 slider.setSelection(100);
127 c.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL));
133 public void setFocus()