import net.mograsim.machine.Memory.MemoryCellModifiedListener;
import net.mograsim.machine.mi.AssignableMicroInstructionMemory;
import net.mograsim.plugin.nature.MachineContext;
+import net.mograsim.plugin.nature.MachineContext.ActiveMachineListener;
import net.mograsim.plugin.nature.ProjectMachineContext;
import net.mograsim.plugin.tables.DisplaySettings;
import net.mograsim.plugin.tables.mi.ActiveInstructionPreviewContentProvider;
private InstructionTable instPreview;
private Label noMachineLabel;
- private MemoryCellModifiedListener currentRegisteredCellListener;
- private LogicObserver currentClockObserver;
+ private ActiveMachineListener activeMNachineListener;
+ private MemoryCellModifiedListener memCellListener;
+ private LogicObserver clockObserver;
+
+ public SimulationViewEditor()
+ {
+ activeMNachineListener = m -> recreateContextDependentControls();
+ memCellListener = a -> instPreview.refresh();
+ clockObserver = o ->
+ {
+ if (((CoreClock) o).isOn())
+ {
+ exec.pauseLiveExecution();
+ if (!pauseButton.isDisposed())
+ Display.getDefault().asyncExec(() ->
+ {
+ if (!pauseButton.isDisposed())
+ pauseButton.setSelection(false);
+ setPauseText(pauseButton, false);
+ });
+ }
+ };
+ }
@Override
public void createPartControl(Composite parent)
double offX;
double offY;
double zoom;
- if (exec != null)
- exec.stopLiveExecution();
- if (machine != null)
- {
- machine.getMicroInstructionMemory().deregisterCellModifiedListener(currentRegisteredCellListener);
- machine.getClock().deregisterObserver(currentClockObserver);
- }
+ stopExecAndDeregisterContextDependentListeners();
if (canvas != null)
{
offX = canvas.getOffX();
AssignableMicroInstructionMemory mIMemory = machine.getMicroInstructionMemory();
instPreview.bindMicroInstructionMemory(mIMemory);
- currentRegisteredCellListener = a -> instPreview.refresh();
- mIMemory.registerCellModifiedListener(currentRegisteredCellListener);
+ mIMemory.registerCellModifiedListener(memCellListener);
canvasParent.layout();
}
}
+ private void stopExecAndDeregisterContextDependentListeners()
+ {
+ if (exec != null)
+ exec.stopLiveExecution();
+ if (machine != null)
+ {
+ machine.getMicroInstructionMemory().deregisterCellModifiedListener(memCellListener);
+ machine.getClock().deregisterObserver(clockObserver);
+ }
+ }
+
private void addSimulationControlWidgets(Composite parent)
{
Composite c = new Composite(parent, SWT.NONE);
sbseButton = new Button(c, SWT.CHECK);
pauseButton = new Button(c, SWT.TOGGLE);
- currentClockObserver = o ->
- {
- if (((CoreClock) o).isOn())
- {
- exec.pauseLiveExecution();
- if (!pauseButton.isDisposed())
- Display.getDefault().asyncExec(() ->
- {
- if (!pauseButton.isDisposed())
- pauseButton.setSelection(false);
- setPauseText(pauseButton, false);
- });
- }
- };
sbseButton.setText("Step by step execution");
sbseButton.addListener(SWT.Selection, e ->
{
CoreClock cl = machine.getClock();
if (sbseButton.getSelection())
- cl.registerObserver(currentClockObserver);
+ cl.registerObserver(clockObserver);
else
- cl.deregisterObserver(currentClockObserver);
+ cl.deregisterObserver(clockObserver);
});
sbseButton.setSelection(false);
IFileEditorInput fileInput = (IFileEditorInput) input;
context = ProjectMachineContext.getMachineContextOf(fileInput.getFile().getProject());
context.activateMachine();
- context.addActiveMachineListener(m -> recreateContextDependentControls());
+ context.addActiveMachineListener(activeMNachineListener);
recreateContextDependentControls();
setPartName(fileInput.getName());
@Override
public void dispose()
{
- exec.stopLiveExecution();
+ stopExecAndDeregisterContextDependentListeners();
+ context.removeActiveMachineListener(activeMNachineListener);
super.dispose();
}
}
\ No newline at end of file