From 11e2aef0171915b9c789b6f1b68ba41eef7e3d92 Mon Sep 17 00:00:00 2001 From: Fabian Stemmler Date: Mon, 30 Sep 2019 23:24:58 +0200 Subject: [PATCH] Fixed a bug: colors/fonts did not update properly in InstructionTable --- .../plugin/tables/mi/FontAndColorHelper.java | 72 +++++++++++++++---- 1 file changed, 58 insertions(+), 14 deletions(-) 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 index 90d53dcf..befbac8c 100644 --- 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 @@ -20,13 +20,14 @@ public class FontAndColorHelper private long highlightedAddress = -1; private ColorRegistry cRegistry; private FontRegistry fRegistry; - private Font boldItalic; + private Font boldItalic, bold, italic, normal; + private Color modifBackground, modifForeground, highlightBackground, highlightForeground; 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"; + colorHighlightForeground = "net.mograsim.plugin.highlighted_cell_fg_color", + colorHighlightBackground = "net.mograsim.plugin.highlighted_cell_bg_color"; private final IPropertyChangeListener updateListener; public FontAndColorHelper(TableViewer viewer, IThemeManager themeManager) @@ -40,15 +41,26 @@ public class FontAndColorHelper { case IThemeManager.CHANGE_CURRENT_THEME: themeChanged(themeManager.getCurrentTheme()); - //$FALL-THROUGH$ + break; case font: + fontChanged(); + break; case colorModifBackground: + colorModifBackgroundChanged(); + break; case colorModifForeground: - viewer.refresh(); + colorModifForegroundChanged(); break; - default: + case colorHighlightBackground: + colorHighlightBackgroundChanged(); + break; + case colorHighlightForeground: + colorHighlightForegroundChanged(); break; + default: + return; } + viewer.refresh(); }; themeManager.addPropertyChangeListener(updateListener); } @@ -57,8 +69,40 @@ public class FontAndColorHelper { cRegistry = theme.getColorRegistry(); fRegistry = theme.getFontRegistry(); + fontChanged(); + colorHighlightBackgroundChanged(); + colorHighlightForegroundChanged(); + colorModifBackgroundChanged(); + colorModifForegroundChanged(); + } + + private void fontChanged() + { boldItalic = fRegistry.getDescriptor(font).setStyle(SWT.BOLD | SWT.ITALIC).createFont(Display.getDefault()); - viewer.getTable().setFont(fRegistry.get(font)); + bold = fRegistry.getBold(font); + italic = fRegistry.getItalic(font); + normal = fRegistry.get(font); + viewer.getTable().setFont(normal); + } + + private void colorModifBackgroundChanged() + { + modifBackground = cRegistry.get(colorModifBackground); + } + + private void colorModifForegroundChanged() + { + modifForeground = cRegistry.get(colorModifForeground); + } + + private void colorHighlightBackgroundChanged() + { + highlightBackground = cRegistry.get(colorHighlightBackground); + } + + private void colorHighlightForegroundChanged() + { + highlightForeground = cRegistry.get(colorHighlightForeground); } public Color getBackground(Object element, int column) @@ -67,10 +111,10 @@ public class FontAndColorHelper if (isDefault(row, column)) { if (isHighlighted(row)) - return cRegistry.get(colorHighlightedBackground); + return highlightBackground; return viewer.getTable().getBackground(); } - return cRegistry.get(colorModifBackground); + return modifBackground; } public Color getForeground(Object element, int column) @@ -79,10 +123,10 @@ public class FontAndColorHelper if (isDefault(row, column)) { if (isHighlighted(row)) - return cRegistry.get(colorHighlightedForeground); + return highlightForeground; return viewer.getTable().getForeground(); } - return cRegistry.get(colorModifForeground); + return modifForeground; } public Font getFont(Object element, int column) @@ -92,10 +136,10 @@ public class FontAndColorHelper if (modified && highlighted) return boldItalic; if (modified) - return fRegistry.getItalic(font); + return italic; if (highlighted) - return fRegistry.getBold(font); - return fRegistry.get(font); + return bold; + return normal; } private static boolean isDefault(InstructionTableRow row, int column) -- 2.17.1