Instruction Table Editing Support now uses the correct font
authorFabian Stemmler <stemmler@in.tum.de>
Mon, 30 Sep 2019 13:42:05 +0000 (15:42 +0200)
committerFabian Stemmler <stemmler@in.tum.de>
Mon, 30 Sep 2019 13:42:05 +0000 (15:42 +0200)
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/ColorProvider.java [deleted file]
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/FontAndColorHelper.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/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

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
deleted file mode 100644 (file)
index 0a1dc0c..0000000
+++ /dev/null
@@ -1,122 +0,0 @@
-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.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.themes.ITheme;
-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 Font boldItalic;
-
-       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)
-       {
-               this.viewer = viewer;
-               this.themeManager = themeManager;
-               themeChanged(themeManager.getCurrentTheme());
-               updateListener = e ->
-               {
-                       switch (e.getProperty())
-                       {
-                       case IThemeManager.CHANGE_CURRENT_THEME:
-                               themeChanged(themeManager.getCurrentTheme());
-                               //$FALL-THROUGH$
-                       case font:
-                       case colorModifBackground:
-                       case colorModifForeground:
-                               viewer.refresh();
-                               break;
-                       default:
-                               break;
-                       }
-               };
-               themeManager.addPropertyChangeListener(updateListener);
-       }
-
-       private void themeChanged(ITheme theme)
-       {
-               cRegistry = theme.getColorRegistry();
-               fRegistry = theme.getFontRegistry();
-               boldItalic = fRegistry.getDescriptor(font).setStyle(SWT.BOLD | SWT.ITALIC).createFont(Display.getDefault());
-       }
-
-       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);
-       }
-
-       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 Font getFont(Object element, int column)
-       {
-               InstructionTableRow row = (InstructionTableRow) element;
-               boolean modified = !isDefault(row, column), highlighted = isHighlighted(row);
-               if (modified && highlighted)
-                       return boldItalic;
-               if (modified)
-                       return fRegistry.getItalic(font);
-               if (highlighted)
-                       return fRegistry.getBold(font);
-               return 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()
-       {
-               themeManager.removePropertyChangeListener(updateListener);
-       }
-}
diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/FontAndColorHelper.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/FontAndColorHelper.java
new file mode 100644 (file)
index 0000000..90d53dc
--- /dev/null
@@ -0,0 +1,123 @@
+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.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.themes.ITheme;
+import org.eclipse.ui.themes.IThemeManager;
+
+import net.mograsim.machine.mi.MicroInstructionMemory;
+
+public class FontAndColorHelper
+{
+       private final TableViewer viewer;
+       private final IThemeManager themeManager;
+       private long highlightedAddress = -1;
+       private ColorRegistry cRegistry;
+       private FontRegistry fRegistry;
+       private Font boldItalic;
+
+       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 FontAndColorHelper(TableViewer viewer, IThemeManager themeManager)
+       {
+               this.viewer = viewer;
+               this.themeManager = themeManager;
+               themeChanged(themeManager.getCurrentTheme());
+               updateListener = e ->
+               {
+                       switch (e.getProperty())
+                       {
+                       case IThemeManager.CHANGE_CURRENT_THEME:
+                               themeChanged(themeManager.getCurrentTheme());
+                               //$FALL-THROUGH$
+                       case font:
+                       case colorModifBackground:
+                       case colorModifForeground:
+                               viewer.refresh();
+                               break;
+                       default:
+                               break;
+                       }
+               };
+               themeManager.addPropertyChangeListener(updateListener);
+       }
+
+       private void themeChanged(ITheme theme)
+       {
+               cRegistry = theme.getColorRegistry();
+               fRegistry = theme.getFontRegistry();
+               boldItalic = fRegistry.getDescriptor(font).setStyle(SWT.BOLD | SWT.ITALIC).createFont(Display.getDefault());
+               viewer.getTable().setFont(fRegistry.get(font));
+       }
+
+       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);
+       }
+
+       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 Font getFont(Object element, int column)
+       {
+               InstructionTableRow row = (InstructionTableRow) element;
+               boolean modified = !isDefault(row, column), highlighted = isHighlighted(row);
+               if (modified && highlighted)
+                       return boldItalic;
+               if (modified)
+                       return fRegistry.getItalic(font);
+               if (highlighted)
+                       return fRegistry.getBold(font);
+               return 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()
+       {
+               themeManager.removePropertyChangeListener(updateListener);
+       }
+}
index a806bd2..6ffc93e 100644 (file)
@@ -38,13 +38,13 @@ public class InstructionTable
        private MicroInstructionMemory memory;
        private InstructionTableContentProvider provider;
        private final RowHighlighter highlighter;
-       private final ColorProvider cProv;
+       private final FontAndColorHelper cProv;
 
        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);
+               this.cProv = new FontAndColorHelper(viewer, themeManager);
                this.highlighter = new RowHighlighter(viewer, cProv);
 
                Table table = viewer.getTable();
index 648eb85..699f022 100644 (file)
@@ -12,9 +12,9 @@ import net.mograsim.plugin.tables.NumberColumnLabelProvider;
 public class IntegerColumnLabelProvider extends NumberColumnLabelProvider
 {
        private final int index;
-       private final ColorProvider cProv;
+       private final FontAndColorHelper cProv;
 
-       public IntegerColumnLabelProvider(DisplaySettings displaySettings, ColorProvider cProv, int index)
+       public IntegerColumnLabelProvider(DisplaySettings displaySettings, FontAndColorHelper cProv, int index)
        {
                super(displaySettings);
                this.cProv = cProv;
index 07ae3ae..310e47d 100644 (file)
@@ -7,9 +7,9 @@ import org.eclipse.swt.graphics.Font;
 public class ParameterLabelProvider extends ColumnLabelProvider
 {
        private final int index;
-       private final ColorProvider cProv;
+       private final FontAndColorHelper cProv;
 
-       public ParameterLabelProvider(ColorProvider cProv, int index)
+       public ParameterLabelProvider(FontAndColorHelper cProv, int index)
        {
                super();
                this.index = index;
index 03cb37c..e7435a2 100644 (file)
@@ -11,10 +11,10 @@ public class RowHighlighter
 {
        private int highlighted = -1;
        private LazyTableViewer viewer;
-       private ColorProvider cProv;
+       private FontAndColorHelper cProv;
        private SingleSWTRequest requester = new SingleSWTRequest();
 
-       public RowHighlighter(LazyTableViewer viewer, ColorProvider cProv)
+       public RowHighlighter(LazyTableViewer viewer, FontAndColorHelper cProv)
        {
                this.viewer = viewer;
                this.cProv = cProv;