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
<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
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)
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:
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()
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;
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)
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);
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];
cProv.dispose();
viewer.getTable().dispose();
}
+
+ public void highlight(int row)
+ {
+ highlighter.highlight(row);
+ }
}
private MicroInstructionMemory memory;
private InstructionTable table;
private MachineContext context;
- private RowHighlighter highlighter;
@SuppressWarnings("unused")
@Override
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)
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;
{
return cProv.getForeground(element, index);
}
+
+ @Override
+ public Font getFont(Object element)
+ {
+ return cProv.getFont(element, index);
+ }
}
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
public class ParameterLabelProvider extends ColumnLabelProvider
{
{
return cProv.getForeground(element, index);
}
+
+ @Override
+ public Font getFont(Object element)
+ {
+ return cProv.getFont(element, index);
+ }
}
package net.mograsim.plugin.tables.mi;
+import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.swt.widgets.Display;
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)
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;
}
}