From: Fabian Stemmler Date: Sat, 28 Sep 2019 12:41:27 +0000 (+0200) Subject: Fixed issue with row highlighting X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=ae2d1ae853d5232df4337e4b2c417a9d57e11aa7;p=Mograsim.git Fixed issue with row highlighting Too many highlight requests were being sent to the SWT Eventqueue when running the simulation at a faster speed. Now there can be at most one such request at the same time. --- 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 0158c7bb..7a692c94 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 @@ -11,7 +11,6 @@ import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorSite; import org.eclipse.ui.IFileEditorInput; @@ -27,17 +26,16 @@ import net.mograsim.machine.mi.MicroInstructionMemoryParser; import net.mograsim.plugin.nature.MachineContext; import net.mograsim.plugin.nature.ProjectMachineContext; import net.mograsim.plugin.tables.DisplaySettings; -import net.mograsim.plugin.tables.LazyTableViewer; import net.mograsim.plugin.tables.RadixSelector; public class InstructionView extends EditorPart implements MemoryCellModifiedListener, ActiveMicroInstructionChangedListener { private InstructionTableContentProvider provider; - private int highlighted = 0; private boolean dirty = false; private MicroInstructionMemory memory; private InstructionTable table; private MachineContext context; + private RowHighlighter highlighter; @SuppressWarnings("unused") @Override @@ -58,23 +56,12 @@ 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) { - Display.getDefault().asyncExec(() -> - { - LazyTableViewer viewer = table.getTableViewer(); - viewer.highlightRow(highlighted, false); - highlighted = index; - if (index != -1) - { - viewer.highlightRow(index, true); - viewer.getTable() - .showItem(viewer.getTable().getItem(Math.min((int) memory.getDefinition().getMaximalAddress(), index + 2))); - viewer.getTable().showItem(viewer.getTable().getItem(index)); - } - }); + highlighter.highlight(index); } private void addActivationButton(Composite parent) diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/RowHighlighter.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/RowHighlighter.java new file mode 100644 index 00000000..18e01084 --- /dev/null +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/RowHighlighter.java @@ -0,0 +1,54 @@ +package net.mograsim.plugin.tables.mi; + +import java.util.concurrent.atomic.AtomicBoolean; + +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Table; + +import net.mograsim.plugin.tables.LazyTableViewer; + +public class RowHighlighter +{ + private int highlighted, toHighlight; + private LazyTableViewer viewer; + private AtomicBoolean waiting = new AtomicBoolean(); + + public RowHighlighter(LazyTableViewer viewer) + { + this.viewer = viewer; + } + + public void highlight(int row) + { + synchronized (waiting) + { + toHighlight = row; + if (!waiting.get()) + { + waiting.set(true); + Display.getDefault().asyncExec(() -> + { + synchronized (waiting) + { + waiting.set(false); + if (!viewer.getTable().isDisposed()) + innerHighlight(toHighlight); + } + }); + } + } + } + + private void innerHighlight(int row) + { + viewer.highlightRow(highlighted, false); + highlighted = row; + if (row != -1) + { + viewer.highlightRow(row, true); + Table table = viewer.getTable(); + table.showItem(table.getItem(Math.min(table.getItemCount(), row + 2))); + table.showItem(table.getItem(row)); + } + } +}