X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Ftables%2Fmi%2FInstructionView.java;h=93a7632755e36b390d2dac5c6c406c3f399d560f;hb=0eb525202d3c871a2a20f789af1728248f3cff11;hp=7a692c9495a66d2cf1cfb47b5eda0a019cd40389;hpb=ae2d1ae853d5232df4337e4b2c417a9d57e11aa7;p=Mograsim.git diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java index 7a692c94..93a76327 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java @@ -17,25 +17,54 @@ import org.eclipse.ui.IFileEditorInput; import org.eclipse.ui.PartInitException; import org.eclipse.ui.part.EditorPart; +import net.mograsim.machine.Machine.ActiveMicroInstructionChangedListener; import net.mograsim.machine.Memory.MemoryCellModifiedListener; import net.mograsim.machine.mi.AssignableMicroInstructionMemory.MIMemoryReassignedListener; import net.mograsim.machine.mi.MicroInstructionMemory; -import net.mograsim.machine.mi.MicroInstructionMemory.ActiveMicroInstructionChangedListener; import net.mograsim.machine.mi.MicroInstructionMemoryParseException; import net.mograsim.machine.mi.MicroInstructionMemoryParser; 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.RadixSelector; -public class InstructionView extends EditorPart implements MemoryCellModifiedListener, ActiveMicroInstructionChangedListener +public class InstructionView extends EditorPart { private InstructionTableContentProvider provider; private boolean dirty = false; private MicroInstructionMemory memory; private InstructionTable table; private MachineContext context; - private RowHighlighter highlighter; + + // Listeners + private MemoryCellModifiedListener cellModifiedListener = address -> + { + setDirty(true); + table.refresh(); + }; + + private ActiveMicroInstructionChangedListener instChangeListener = (oldAddress, newAddress) -> + { + highlight((int) (newAddress - memory.getDefinition().getMinimalAddress())); + }; + + private MIMemoryReassignedListener reassignedListener = newAssignee -> + { + // clear highlighting if the memory is reassigned + if (newAssignee != memory) + highlight(-1); + }; + + private ActiveMachineListener activeMachineListener = (oldMachine, newMachine) -> + { + // clear highlighting if the active machine changes + if (newMachine.isEmpty() || !newMachine.equals(oldMachine)) + { + highlight(-1); + oldMachine.ifPresent(m -> m.getMicroInstructionMemory().deregisterMemoryReassignedListener(reassignedListener)); + } + }; @SuppressWarnings("unused") @Override @@ -56,12 +85,11 @@ public class InstructionView extends EditorPart implements MemoryCellModifiedLis GridData viewerData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH); viewerData.horizontalSpan = 3; table.getTableViewer().getTable().setLayoutData(viewerData); - highlighter = new RowHighlighter(table.getTableViewer()); } - public void highlight(int index) + public void highlight(int row) { - highlighter.highlight(index); + table.highlight(row); } private void addActivationButton(Composite parent) @@ -70,23 +98,10 @@ public class InstructionView extends EditorPart implements MemoryCellModifiedLis activationButton.setText("Set Active"); activationButton.addListener(SWT.Selection, e -> context.getActiveMachine().ifPresent(m -> { - // clear highlighting if the memory is reassigned - MIMemoryReassignedListener memReassignedListener = n -> - { - if (n != memory) - highlight(-1); - }; - m.getMicroInstructionMemory().registerMemoryReassignedListener(memReassignedListener); - // clear highlighting if the active machine changes - context.addActiveMachineListener(n -> - { - if (n.isEmpty() || n.get() != m) - { - highlight(-1); - m.getMicroInstructionMemory().deregisterMemoryReassignedListener(memReassignedListener); - } - }); + m.getMicroInstructionMemory().registerMemoryReassignedListener(reassignedListener); + context.addActiveMachineListener(activeMachineListener); m.getMicroInstructionMemory().bind(memory); + m.addActiveMicroInstructionChangedListener(instChangeListener); })); } @@ -94,14 +109,12 @@ public class InstructionView extends EditorPart implements MemoryCellModifiedLis { if (this.memory != null) { - this.memory.deregisterCellModifiedListener(this); - this.memory.deregisterActiveMicroInstructionChangedListener(this); + this.memory.deregisterCellModifiedListener(cellModifiedListener); } this.memory = memory; if (memory != null) { - this.memory.registerCellModifiedListener(this); - this.memory.registerActiveMicroInstructionChangedListener(this); + this.memory.registerCellModifiedListener(cellModifiedListener); } if (table != null) table.bindMicroInstructionMemory(memory); @@ -208,29 +221,22 @@ public class InstructionView extends EditorPart implements MemoryCellModifiedLis return false; } - @Override - public void update(long address) - { - setDirty(true); - table.refresh(); - } - private void setDirty(boolean value) { dirty = value; firePropertyChange(PROP_DIRTY); } - @Override - public void activeMicroInstructionChanged(long address) - { - highlight((int) (address - memory.getDefinition().getMinimalAddress())); - } - @Override public void dispose() { - table.dispose(); + memory.deregisterCellModifiedListener(cellModifiedListener); + context.getActiveMachine().ifPresent(m -> + { + m.removeActiveMicroInstructionChangedListener(instChangeListener); + m.getMicroInstructionMemory().deregisterMemoryReassignedListener(reassignedListener); + }); + context.removeActiveMachineListener(activeMachineListener); super.dispose(); } }