Made highlighted/modified cells bold; New default modified cell color
authorFabian Stemmler <stemmler@in.tum.de>
Sat, 28 Sep 2019 22:48:43 +0000 (00:48 +0200)
committerFabian Stemmler <stemmler@in.tum.de>
Sat, 28 Sep 2019 22:48:43 +0000 (00:48 +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/tables/mi/ColorProvider.java
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
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/RowHighlighter.java

index 6a98b02..2c6f94c 100644 (file)
@@ -32,7 +32,10 @@ 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
+colorDefinition.label.13 = Highlighted Cell Background Color
+colorDefinition.label.14 = Highlighted Cell Foreground Color
 fontDefinition.label = Assembler Operation Style
+fontDefinition.label.0 = Table Font
 view.name.0 = Simulation View
 view.name.1 = Memory
 wizards.newWizards.category = Mograsim
index e431d6e..4f85d4a 100644 (file)
       <themeElementCategory
             class="net.mograsim.plugin.SimulationPreview"
             id="net.mograsim.plugin.mi"
-            label="%themeElementCategory.label.1">
+            label="%themeElementCategory.label.1"
+            parentId="net.mograsim.plugin.mograsim">
       </themeElementCategory>
       <colorDefinition
             categoryId="net.mograsim.logic.model"
             id="net.mograsim.plugin.modified_cell_bg_color"
             isEditable="true"
             label="%colorDefinition.label.11"
-            value="COLOR_BLUE">
+            value="COLOR_GREEN">
       </colorDefinition>
       <colorDefinition
             categoryId="net.mograsim.plugin.mi"
             id="net.mograsim.plugin.modified_cell_fg_color"
             isEditable="true"
             label="%colorDefinition.label.12"
-            value="COLOR_WHITE">
+            value="COLOR_BLACK">
+      </colorDefinition>
+      <fontDefinition
+            categoryId="net.mograsim.plugin.mi"
+            id="net.mograsim.plugin.table_font"
+            isEditable="true"
+            label="%fontDefinition.label.0">
+      </fontDefinition>
+      <colorDefinition
+            categoryId="net.mograsim.plugin.mi"
+            id="net.mograsim.plugin.highlighted_cell_bg_color"
+            isEditable="true"
+            label="%colorDefinition.label.13"
+            value="COLOR_YELLOW">
+      </colorDefinition>
+      <colorDefinition
+            categoryId="net.mograsim.plugin.mi"
+            id="net.mograsim.plugin.highlighted_cell_fg_color"
+            isEditable="true"
+            label="%colorDefinition.label.14"
+            value="COLOR_BLACK">
       </colorDefinition>
    </extension>
    <extension
index 6aee0bd..fe545fc 100644 (file)
@@ -1,19 +1,28 @@
 package net.mograsim.plugin.tables.mi;
 
 import org.eclipse.jface.resource.ColorRegistry;
+import org.eclipse.jface.resource.FontRegistry;
 import org.eclipse.jface.util.IPropertyChangeListener;
 import org.eclipse.jface.viewers.TableViewer;
 import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
 import org.eclipse.ui.themes.IThemeManager;
 
+import net.mograsim.machine.mi.MicroInstructionMemory;
+
 public class ColorProvider
 {
        private final TableViewer viewer;
        private final IThemeManager themeManager;
+       private long highlightedAddress = -1;
        private ColorRegistry cRegistry;
+       private FontRegistry fRegistry;
 
-       private final static String modifBackground = "net.mograsim.plugin.modified_cell_bg_color",
-                       modifForeground = "net.mograsim.plugin.modified_cell_fg_color";
+       private final static String font = "net.mograsim.plugin.table_font",
+                       colorModifBackground = "net.mograsim.plugin.modified_cell_bg_color",
+                       colorModifForeground = "net.mograsim.plugin.modified_cell_fg_color",
+                       colorHighlightedForeground = "net.mograsim.plugin.highlighted_cell_fg_color",
+                       colorHighlightedBackground = "net.mograsim.plugin.highlighted_cell_bg_color";
        private final IPropertyChangeListener updateListener;
 
        public ColorProvider(TableViewer viewer, IThemeManager themeManager)
@@ -21,15 +30,18 @@ public class ColorProvider
                this.viewer = viewer;
                this.themeManager = themeManager;
                this.cRegistry = themeManager.getCurrentTheme().getColorRegistry();
+               this.fRegistry = themeManager.getCurrentTheme().getFontRegistry();
                updateListener = e ->
                {
                        switch (e.getProperty())
                        {
                        case IThemeManager.CHANGE_CURRENT_THEME:
                                cRegistry = themeManager.getCurrentTheme().getColorRegistry();
+                               fRegistry = themeManager.getCurrentTheme().getFontRegistry();
                                //$FALL-THROUGH$
-                       case modifBackground:
-                       case modifForeground:
+                       case font:
+                       case colorModifBackground:
+                       case colorModifForeground:
                                viewer.refresh();
                                break;
                        default:
@@ -39,19 +51,52 @@ public class ColorProvider
                themeManager.addPropertyChangeListener(updateListener);
        }
 
-       public Color getBackground(Object element, int index)
+       public Color getBackground(Object element, int column)
        {
                InstructionTableRow row = (InstructionTableRow) element;
+               if (isDefault(row, column))
+               {
+                       if (isHighlighted(row))
+                               return cRegistry.get(colorHighlightedBackground);
+                       return viewer.getTable().getBackground();
+               }
+               return cRegistry.get(colorModifBackground);
+       }
 
-               return row.data.getCell(row.address).getParameter(index).isDefault() ? viewer.getTable().getBackground()
-                               : cRegistry.get(modifBackground);
+       public Color getForeground(Object element, int column)
+       {
+               InstructionTableRow row = (InstructionTableRow) element;
+               if (isDefault(row, column))
+               {
+                       if (isHighlighted(row))
+                               return cRegistry.get(colorHighlightedForeground);
+                       return viewer.getTable().getForeground();
+               }
+               return cRegistry.get(colorModifForeground);
        }
 
-       public Color getForeground(Object element, int index)
+       public Font getFont(Object element, int column)
        {
                InstructionTableRow row = (InstructionTableRow) element;
-               return row.data.getCell(row.address).getParameter(index).isDefault() ? viewer.getTable().getForeground()
-                               : cRegistry.get(modifForeground);
+               return !isDefault(row, column) || isHighlighted(row) ? fRegistry.getBold(font) : fRegistry.get(font);
+       }
+
+       private static boolean isDefault(InstructionTableRow row, int column)
+       {
+               return column == -1 ? true : row.data.getCell(row.address).getParameter(column).isDefault();
+       }
+
+       private boolean isHighlighted(InstructionTableRow row)
+       {
+               return highlightedAddress == row.address;
+       }
+
+       /**
+        * @param index Index of the row to highlight; An negative index means no row is highlighted
+        */
+       public void highlight(long row)
+       {
+               highlightedAddress = row + ((MicroInstructionMemory) viewer.getInput()).getDefinition().getMinimalAddress();
        }
 
        public void dispose()
index 11e57ba..7b17f24 100644 (file)
@@ -12,6 +12,8 @@ import org.eclipse.jface.viewers.TableViewerColumn;
 import org.eclipse.jface.viewers.TableViewerEditor;
 import org.eclipse.jface.viewers.TableViewerFocusCellManager;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
@@ -35,6 +37,7 @@ public class InstructionTable
        private MicroInstructionDefinition miDef;
        private MicroInstructionMemory memory;
        private InstructionTableContentProvider provider;
+       private final RowHighlighter highlighter;
        private final ColorProvider cProv;
 
        public InstructionTable(Composite parent, DisplaySettings displaySettings, IThemeManager themeManager)
@@ -42,6 +45,7 @@ public class InstructionTable
                viewer = new LazyTableViewer(parent, SWT.FULL_SELECTION | SWT.BORDER | SWT.VIRTUAL);
                this.displaySettings = displaySettings;
                this.cProv = new ColorProvider(viewer, themeManager);
+               this.highlighter = new RowHighlighter(viewer, cProv);
 
                Table table = viewer.getTable();
                table.setHeaderVisible(true);
@@ -87,7 +91,26 @@ public class InstructionTable
 
                TableViewerColumn col = createTableViewerColumn("Address");
                columns[0] = col;
-               col.setLabelProvider(new AddressLabelProvider());
+               col.setLabelProvider(new AddressLabelProvider()
+               {
+                       @Override
+                       public Color getBackground(Object element)
+                       {
+                               return cProv.getBackground(element, -1);
+                       }
+
+                       @Override
+                       public Color getForeground(Object element)
+                       {
+                               return cProv.getForeground(element, -1);
+                       }
+
+                       @Override
+                       public Font getFont(Object element)
+                       {
+                               return cProv.getFont(element, -1);
+                       }
+               });
 
                String[] columnTitles = new String[size];
 
@@ -239,4 +262,9 @@ public class InstructionTable
                cProv.dispose();
                viewer.getTable().dispose();
        }
+
+       public void highlight(int row)
+       {
+               highlighter.highlight(row);
+       }
 }
index 7a692c9..fe03d94 100644 (file)
@@ -35,7 +35,6 @@ public class InstructionView extends EditorPart implements MemoryCellModifiedLis
        private MicroInstructionMemory memory;
        private InstructionTable table;
        private MachineContext context;
-       private RowHighlighter highlighter;
 
        @SuppressWarnings("unused")
        @Override
@@ -56,12 +55,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)
index 0c29bcf..648eb85 100644 (file)
@@ -3,6 +3,7 @@ package net.mograsim.plugin.tables.mi;
 import java.math.BigInteger;
 
 import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
 
 import net.mograsim.machine.mi.parameters.IntegerImmediate;
 import net.mograsim.plugin.tables.DisplaySettings;
@@ -45,4 +46,10 @@ public class IntegerColumnLabelProvider extends NumberColumnLabelProvider
        {
                return cProv.getForeground(element, index);
        }
+
+       @Override
+       public Font getFont(Object element)
+       {
+               return cProv.getFont(element, index);
+       }
 }
index 1c10940..07ae3ae 100644 (file)
@@ -2,6 +2,7 @@ package net.mograsim.plugin.tables.mi;
 
 import org.eclipse.jface.viewers.ColumnLabelProvider;
 import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
 
 public class ParameterLabelProvider extends ColumnLabelProvider
 {
@@ -33,4 +34,10 @@ public class ParameterLabelProvider extends ColumnLabelProvider
        {
                return cProv.getForeground(element, index);
        }
+
+       @Override
+       public Font getFont(Object element)
+       {
+               return cProv.getFont(element, index);
+       }
 }
index 18e0108..17b2cd2 100644 (file)
@@ -1,5 +1,6 @@
 package net.mograsim.plugin.tables.mi;
 
+import java.util.Optional;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.eclipse.swt.widgets.Display;
@@ -9,13 +10,15 @@ import net.mograsim.plugin.tables.LazyTableViewer;
 
 public class RowHighlighter
 {
-       private int highlighted, toHighlight;
+       private int highlighted = -1, toHighlight;
        private LazyTableViewer viewer;
        private AtomicBoolean waiting = new AtomicBoolean();
+       private ColorProvider cProv;
 
-       public RowHighlighter(LazyTableViewer viewer)
+       public RowHighlighter(LazyTableViewer viewer, ColorProvider cProv)
        {
                this.viewer = viewer;
+               this.cProv = cProv;
        }
 
        public void highlight(int row)
@@ -41,14 +44,16 @@ public class RowHighlighter
 
        private void innerHighlight(int row)
        {
-               viewer.highlightRow(highlighted, false);
-               highlighted = row;
+               Table table = viewer.getTable();
+               cProv.highlight(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));
+                       Optional.of(table.getItem(row).getData()).ifPresent(d -> viewer.update(d, null));
                }
+               if (highlighted != -1)
+                       Optional.of(table.getItem(highlighted).getData()).ifPresent(d -> viewer.update(d, null));
+               highlighted = row;
        }
 }