From: Fabian Stemmler Date: Fri, 27 Sep 2019 19:15:18 +0000 (+0200) Subject: Non-default values are now highlighted in the InstructionTable X-Git-Url: https://mograsim.net/gitweb/?p=Mograsim.git;a=commitdiff_plain;h=6b01ce390c1bb33d133902479645abfcc293704f Non-default values are now highlighted in the InstructionTable --- diff --git a/plugins/net.mograsim.plugin.core/OSGI-INF/l10n/bundle.properties b/plugins/net.mograsim.plugin.core/OSGI-INF/l10n/bundle.properties index 9faa5eec..6a98b02f 100644 --- a/plugins/net.mograsim.plugin.core/OSGI-INF/l10n/bundle.properties +++ b/plugins/net.mograsim.plugin.core/OSGI-INF/l10n/bundle.properties @@ -15,6 +15,8 @@ command.label = Convert to Mograsim Project extension.name.1 = XML Problem decorator.label = Resource Decorator themeElementCategory.label = Mograsim +themeElementCategory.label.0 = Simulation +themeElementCategory.label.1 = Microinstructions colorDefinition.label = Simulation Background colorDefinition.description = The Background of the Simulation Visualisation colorDefinition.label.0 = Simulation Foreground Color @@ -28,11 +30,12 @@ colorDefinition.label.7 = Simulation Color X colorDefinition.label.8 = Simulation Color Z colorDefinition.label.9 = Simulation Color 0 colorDefinition.label.10 = Simulation text color +colorDefinition.label.11 = Modified Cell Background Color +colorDefinition.label.12 = Modified Cell Foreground Color fontDefinition.label = Assembler Operation Style view.name.0 = Simulation View view.name.1 = Memory wizards.newWizards.category = Mograsim wizards.newWizards.mpm.name = Microprogram Memory wizards.newWizards.mpm.desc = Creates a default new Microprogram Memory -themeElementCategory.label.0 = Simulation Bundle-Vendor.0 = Mograsim Team \ No newline at end of file diff --git a/plugins/net.mograsim.plugin.core/plugin.xml b/plugins/net.mograsim.plugin.core/plugin.xml index c48d9c43..e431d6e3 100644 --- a/plugins/net.mograsim.plugin.core/plugin.xml +++ b/plugins/net.mograsim.plugin.core/plugin.xml @@ -206,6 +206,11 @@ label="%themeElementCategory.label.0" parentId="net.mograsim.plugin.mograsim"> + + + + + + diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/editors/SimulationViewEditor.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/editors/SimulationViewEditor.java index 6b17dcf0..d40bc77b 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/editors/SimulationViewEditor.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/editors/SimulationViewEditor.java @@ -298,7 +298,7 @@ public class SimulationViewEditor extends EditorPart private void addInstructionPreviewControlWidgets(Composite parent) { - instPreview = new InstructionTable(parent, new DisplaySettings()); + instPreview = new InstructionTable(parent, new DisplaySettings(), getSite().getWorkbenchWindow().getWorkbench().getThemeManager()); instPreview.getTableViewer().getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); instPreview.setContentProvider(new ActiveInstructionPreviewContentProvider(instPreview.getTableViewer())); } diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/ColorProvider.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/ColorProvider.java new file mode 100644 index 00000000..6aee0bd7 --- /dev/null +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/ColorProvider.java @@ -0,0 +1,61 @@ +package net.mograsim.plugin.tables.mi; + +import org.eclipse.jface.resource.ColorRegistry; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.swt.graphics.Color; +import org.eclipse.ui.themes.IThemeManager; + +public class ColorProvider +{ + private final TableViewer viewer; + private final IThemeManager themeManager; + private ColorRegistry cRegistry; + + private final static String modifBackground = "net.mograsim.plugin.modified_cell_bg_color", + modifForeground = "net.mograsim.plugin.modified_cell_fg_color"; + private final IPropertyChangeListener updateListener; + + public ColorProvider(TableViewer viewer, IThemeManager themeManager) + { + this.viewer = viewer; + this.themeManager = themeManager; + this.cRegistry = themeManager.getCurrentTheme().getColorRegistry(); + updateListener = e -> + { + switch (e.getProperty()) + { + case IThemeManager.CHANGE_CURRENT_THEME: + cRegistry = themeManager.getCurrentTheme().getColorRegistry(); + //$FALL-THROUGH$ + case modifBackground: + case modifForeground: + viewer.refresh(); + break; + default: + break; + } + }; + themeManager.addPropertyChangeListener(updateListener); + } + + public Color getBackground(Object element, int index) + { + InstructionTableRow row = (InstructionTableRow) element; + + return row.data.getCell(row.address).getParameter(index).isDefault() ? viewer.getTable().getBackground() + : cRegistry.get(modifBackground); + } + + public Color getForeground(Object element, int index) + { + InstructionTableRow row = (InstructionTableRow) element; + return row.data.getCell(row.address).getParameter(index).isDefault() ? viewer.getTable().getForeground() + : cRegistry.get(modifForeground); + } + + public void dispose() + { + themeManager.removePropertyChangeListener(updateListener); + } +} diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTable.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTable.java index afa7f40a..11e57baa 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTable.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTable.java @@ -17,6 +17,7 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.ui.themes.IThemeManager; import net.mograsim.machine.mi.MicroInstructionDefinition; import net.mograsim.machine.mi.MicroInstructionMemory; @@ -28,17 +29,19 @@ import net.mograsim.plugin.tables.LazyTableViewer; public class InstructionTable { - protected DisplaySettings displaySettings; - protected LazyTableViewer viewer; + protected final DisplaySettings displaySettings; + protected final LazyTableViewer viewer; private TableViewerColumn[] columns = new TableViewerColumn[0]; private MicroInstructionDefinition miDef; private MicroInstructionMemory memory; private InstructionTableContentProvider provider; + private final ColorProvider cProv; - public InstructionTable(Composite parent, DisplaySettings displaySettings) + public InstructionTable(Composite parent, DisplaySettings displaySettings, IThemeManager themeManager) { viewer = new LazyTableViewer(parent, SWT.FULL_SELECTION | SWT.BORDER | SWT.VIRTUAL); this.displaySettings = displaySettings; + this.cProv = new ColorProvider(viewer, themeManager); Table table = viewer.getTable(); table.setHeaderVisible(true); @@ -157,15 +160,15 @@ public class InstructionTable { case BOOLEAN_IMMEDIATE: support = new BooleanEditingSupport(viewer, miDef, index); - provider = new ParameterLabelProvider(index); + provider = new ParameterLabelProvider(cProv, index); break; case INTEGER_IMMEDIATE: support = new IntegerEditingSupport(viewer, miDef, index, displaySettings, this.provider); - provider = new IntegerColumnLabelProvider(displaySettings, index); + provider = new IntegerColumnLabelProvider(displaySettings, cProv, index); break; case MNEMONIC: support = new MnemonicEditingSupport(viewer, miDef, index, this.provider); - provider = new ParameterLabelProvider(index); + provider = new ParameterLabelProvider(cProv, index); break; default: throw new IllegalStateException( @@ -230,4 +233,10 @@ public class InstructionTable { Display.getDefault().asyncExec(() -> viewer.refresh()); } + + public void dispose() + { + cProv.dispose(); + viewer.getTable().dispose(); + } } 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 235e3e53..0158c7bb 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 @@ -51,8 +51,7 @@ public class InstructionView extends EditorPart implements MemoryCellModifiedLis new RadixSelector(parent, displaySettings); addActivationButton(parent); - - table = new InstructionTable(parent, displaySettings); + table = new InstructionTable(parent, displaySettings, getSite().getWorkbenchWindow().getWorkbench().getThemeManager()); table.setContentProvider(provider); table.bindMicroInstructionMemory(memory); @@ -240,4 +239,11 @@ public class InstructionView extends EditorPart implements MemoryCellModifiedLis { highlight((int) (address - memory.getDefinition().getMinimalAddress())); } + + @Override + public void dispose() + { + table.dispose(); + super.dispose(); + } } diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerColumnLabelProvider.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerColumnLabelProvider.java index a2d50877..0c29bcff 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerColumnLabelProvider.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerColumnLabelProvider.java @@ -2,17 +2,21 @@ package net.mograsim.plugin.tables.mi; import java.math.BigInteger; +import org.eclipse.swt.graphics.Color; + import net.mograsim.machine.mi.parameters.IntegerImmediate; import net.mograsim.plugin.tables.DisplaySettings; import net.mograsim.plugin.tables.NumberColumnLabelProvider; public class IntegerColumnLabelProvider extends NumberColumnLabelProvider { - private int index; + private final int index; + private final ColorProvider cProv; - public IntegerColumnLabelProvider(DisplaySettings displaySettings, int index) + public IntegerColumnLabelProvider(DisplaySettings displaySettings, ColorProvider cProv, int index) { super(displaySettings); + this.cProv = cProv; this.index = index; } @@ -30,4 +34,15 @@ public class IntegerColumnLabelProvider extends NumberColumnLabelProvider .getExpectedBits(); } + @Override + public Color getBackground(Object element) + { + return cProv.getBackground(element, index); + } + + @Override + public Color getForeground(Object element) + { + return cProv.getForeground(element, index); + } } diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/ParameterLabelProvider.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/ParameterLabelProvider.java index 46e3ea7b..1c10940a 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/ParameterLabelProvider.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/ParameterLabelProvider.java @@ -1,15 +1,18 @@ package net.mograsim.plugin.tables.mi; import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.swt.graphics.Color; public class ParameterLabelProvider extends ColumnLabelProvider { private final int index; + private final ColorProvider cProv; - public ParameterLabelProvider(int index) + public ParameterLabelProvider(ColorProvider cProv, int index) { super(); this.index = index; + this.cProv = cProv; } @Override @@ -18,4 +21,16 @@ public class ParameterLabelProvider extends ColumnLabelProvider InstructionTableRow row = (InstructionTableRow) element; return row.data.getCell(row.address).getParameter(index).toString(); } + + @Override + public Color getBackground(Object element) + { + return cProv.getBackground(element, index); + } + + @Override + public Color getForeground(Object element) + { + return cProv.getForeground(element, index); + } }