X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Ftables%2Fmi%2FColorProvider.java;h=fe545fc6837a7f183468c74ee9d63d09460871f8;hb=a4ef021616f9bf3b6a7778c7b5b6a22d5a7d1c20;hp=6aee0bd7c5cae3fd10a326f98dfa83c51efcb879;hpb=ae2d1ae853d5232df4337e4b2c417a9d57e11aa7;p=Mograsim.git 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 index 6aee0bd7..fe545fc6 100644 --- 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 @@ -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()