Non-default values are now highlighted in the InstructionTable
authorFabian Stemmler <stemmler@in.tum.de>
Fri, 27 Sep 2019 19:15:18 +0000 (21:15 +0200)
committerFabian Stemmler <stemmler@in.tum.de>
Fri, 27 Sep 2019 19:18:05 +0000 (21:18 +0200)
plugins/net.mograsim.plugin.core/OSGI-INF/l10n/bundle.properties
plugins/net.mograsim.plugin.core/plugin.xml
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/editors/SimulationViewEditor.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/ColorProvider.java [new file with mode: 0644]
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTable.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerColumnLabelProvider.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/ParameterLabelProvider.java

index 9faa5ee..6a98b02 100644 (file)
@@ -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
index c48d9c4..e431d6e 100644 (file)
             label="%themeElementCategory.label.0"
             parentId="net.mograsim.plugin.mograsim">
       </themeElementCategory>
+      <themeElementCategory
+            class="net.mograsim.plugin.SimulationPreview"
+            id="net.mograsim.plugin.mi"
+            label="%themeElementCategory.label.1">
+      </themeElementCategory>
       <colorDefinition
             categoryId="net.mograsim.logic.model"
             id="net.mograsim.logic.model.color.background"
             isEditable="true"
             label="%fontDefinition.label">
       </fontDefinition>
+      <colorDefinition
+            categoryId="net.mograsim.plugin.mi"
+            id="net.mograsim.plugin.modified_cell_bg_color"
+            isEditable="true"
+            label="%colorDefinition.label.11"
+            value="COLOR_BLUE">
+      </colorDefinition>
+      <colorDefinition
+            categoryId="net.mograsim.plugin.mi"
+            id="net.mograsim.plugin.modified_cell_fg_color"
+            isEditable="true"
+            label="%colorDefinition.label.12"
+            value="COLOR_WHITE">
+      </colorDefinition>
    </extension>
    <extension
          point="org.eclipse.ui.preferencePages">
index 6b17dcf..d40bc77 100644 (file)
@@ -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 (file)
index 0000000..6aee0bd
--- /dev/null
@@ -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);
+       }
+}
index afa7f40..11e57ba 100644 (file)
@@ -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();
+       }
 }
index 235e3e5..0158c7b 100644 (file)
@@ -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();
+       }
 }
index a2d5087..0c29bcf 100644 (file)
@@ -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);
+       }
 }
index 46e3ea7..1c10940 100644 (file)
@@ -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);
+       }
 }