From: Fabian Stemmler Date: Sat, 28 Sep 2019 22:48:43 +0000 (+0200) Subject: Made highlighted/modified cells bold; New default modified cell color X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=a4ef021616f9bf3b6a7778c7b5b6a22d5a7d1c20;p=Mograsim.git Made highlighted/modified cells bold; New default modified cell color --- diff --git a/plugins/net.mograsim.plugin.core/OSGI-INF/l10n/bundle.properties b/plugins/net.mograsim.plugin.core/OSGI-INF/l10n/bundle.properties index 6a98b02f..2c6f94c2 100644 --- a/plugins/net.mograsim.plugin.core/OSGI-INF/l10n/bundle.properties +++ b/plugins/net.mograsim.plugin.core/OSGI-INF/l10n/bundle.properties @@ -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 diff --git a/plugins/net.mograsim.plugin.core/plugin.xml b/plugins/net.mograsim.plugin.core/plugin.xml index e431d6e3..4f85d4a5 100644 --- a/plugins/net.mograsim.plugin.core/plugin.xml +++ b/plugins/net.mograsim.plugin.core/plugin.xml @@ -209,7 +209,8 @@ + label="%themeElementCategory.label.1" + parentId="net.mograsim.plugin.mograsim"> + value="COLOR_GREEN"> + value="COLOR_BLACK"> + + + + + + { 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() diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTable.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTable.java index 11e57baa..7b17f240 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTable.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTable.java @@ -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); + } } diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java index 7a692c94..fe03d940 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java @@ -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) diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerColumnLabelProvider.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerColumnLabelProvider.java index 0c29bcff..648eb85d 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerColumnLabelProvider.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerColumnLabelProvider.java @@ -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); + } } diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/ParameterLabelProvider.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/ParameterLabelProvider.java index 1c10940a..07ae3aeb 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/ParameterLabelProvider.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/ParameterLabelProvider.java @@ -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); + } } diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/RowHighlighter.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/RowHighlighter.java index 18e01084..17b2cd22 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/RowHighlighter.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/RowHighlighter.java @@ -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; } }