From: Fabian Stemmler Date: Wed, 4 Sep 2019 19:24:22 +0000 (+0200) Subject: The instruction editor can now display integers in bases 2, 8, 10 and 16 X-Git-Url: https://mograsim.net/gitweb/?p=Mograsim.git;a=commitdiff_plain;h=1e6eee9a46051c1e3f841b9675d3337ba3b72ac7 The instruction editor can now display integers in bases 2, 8, 10 and 16 --- diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/DisplaySettings.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/DisplaySettings.java new file mode 100644 index 00000000..dde6b015 --- /dev/null +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/DisplaySettings.java @@ -0,0 +1,49 @@ +package net.mograsim.plugin.tables; + +import java.util.HashSet; +import java.util.Set; + +import net.mograsim.plugin.asm.AsmNumberUtil.NumberType; + +public class DisplaySettings +{ + private NumberType dataNumberType; + private final Set observers; + + public DisplaySettings() + { + this(NumberType.HEXADECIMAL); + } + + public DisplaySettings(NumberType dataNumberType) + { + this.dataNumberType = dataNumberType; + observers = new HashSet<>(); + } + + public NumberType getDataNumberType() + { + return dataNumberType; + } + + public void setDataNumberType(NumberType dataNumberType) + { + this.dataNumberType = dataNumberType; + notifyObservers(); + } + + void notifyObservers() + { + observers.forEach(r -> r.run()); + } + + public void addObserver(Runnable ob) + { + observers.add(ob); + } + + public void removeObserver(Runnable ob) + { + observers.remove(ob); + } +} \ No newline at end of file diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/NumberCellEditingSupport.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/NumberCellEditingSupport.java index 7bba426d..a1d81072 100644 --- a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/NumberCellEditingSupport.java +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/NumberCellEditingSupport.java @@ -8,7 +8,6 @@ import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TextCellEditor; import net.mograsim.plugin.asm.AsmNumberUtil; -import net.mograsim.plugin.tables.memory.DisplaySettings; public abstract class NumberCellEditingSupport extends EditingSupport { diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/NumberColumnLabelProvider.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/NumberColumnLabelProvider.java index 35f032ac..6ee2c2b4 100644 --- a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/NumberColumnLabelProvider.java +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/NumberColumnLabelProvider.java @@ -5,7 +5,6 @@ import java.math.BigInteger; import org.eclipse.jface.viewers.ColumnLabelProvider; import net.mograsim.plugin.asm.AsmNumberUtil; -import net.mograsim.plugin.tables.memory.DisplaySettings; public abstract class NumberColumnLabelProvider extends ColumnLabelProvider { diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/RadixSelector.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/RadixSelector.java new file mode 100644 index 00000000..b72df0e9 --- /dev/null +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/RadixSelector.java @@ -0,0 +1,67 @@ +package net.mograsim.plugin.tables; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +import net.mograsim.plugin.asm.AsmNumberUtil.NumberType; + +public class RadixSelector +{ + private final Composite parent; + private final DisplaySettings target; + private Label label; + private Combo combo; + + public RadixSelector(Composite parent, DisplaySettings target) + { + this.parent = parent; + this.target = target; + setupRadixSelector(); + } + + private void setupRadixSelector() + { + label = new Label(parent, SWT.NONE); + label.setText("Radix: "); + combo = new Combo(parent, SWT.READ_ONLY); + + String entries[] = new String[] { "Binary", "Octal", "Decimal", "Hexadecimal" }; + NumberType corTypes[] = new NumberType[] { NumberType.BINARY, NumberType.OCTAL, NumberType.DECIMAL, NumberType.HEXADECIMAL }; + combo.setItems(entries); + combo.select(3); + combo.addSelectionListener(new SelectionListener() + { + @Override + public void widgetSelected(SelectionEvent e) + { + int index = combo.getSelectionIndex(); + if (index == -1) + target.setDataNumberType(NumberType.HEXADECIMAL); + else + { + target.setDataNumberType(corTypes[index]); + } + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) + { + widgetSelected(e); + } + }); + } + + public Label getLabel() + { + return label; + } + + public Combo getCombo() + { + return combo; + } +} diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/memory/DisplaySettings.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/memory/DisplaySettings.java deleted file mode 100644 index 8816a526..00000000 --- a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/memory/DisplaySettings.java +++ /dev/null @@ -1,23 +0,0 @@ -package net.mograsim.plugin.tables.memory; - -import net.mograsim.plugin.asm.AsmNumberUtil.NumberType; - -public class DisplaySettings -{ - private NumberType dataNumberType; - - public DisplaySettings(NumberType dataNumberType) - { - this.dataNumberType = dataNumberType; - } - - public NumberType getDataNumberType() - { - return dataNumberType; - } - - public void setDataNumberType(NumberType dataNumberType) - { - this.dataNumberType = dataNumberType; - } -} \ No newline at end of file diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/memory/MemoryCellEditingSupport.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/memory/MemoryCellEditingSupport.java index 94f1821e..46eefcd9 100644 --- a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/memory/MemoryCellEditingSupport.java +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/memory/MemoryCellEditingSupport.java @@ -4,6 +4,7 @@ import java.math.BigInteger; import org.eclipse.jface.viewers.TableViewer; +import net.mograsim.plugin.tables.DisplaySettings; import net.mograsim.plugin.tables.NumberCellEditingSupport; public class MemoryCellEditingSupport extends NumberCellEditingSupport diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/memory/MemoryView.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/memory/MemoryView.java index 98983a66..7488ee90 100644 --- a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/memory/MemoryView.java +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/memory/MemoryView.java @@ -6,12 +6,9 @@ import org.eclipse.jface.viewers.ColumnLabelProvider; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.events.VerifyListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Table; @@ -23,8 +20,9 @@ import net.mograsim.machine.MainMemory; import net.mograsim.machine.MainMemoryDefinition; import net.mograsim.machine.standard.memory.WordAddressableMemory; import net.mograsim.plugin.asm.AsmNumberUtil; -import net.mograsim.plugin.asm.AsmNumberUtil.NumberType; +import net.mograsim.plugin.tables.DisplaySettings; import net.mograsim.plugin.tables.NumberColumnLabelProvider; +import net.mograsim.plugin.tables.RadixSelector; public class MemoryView extends ViewPart { @@ -33,11 +31,12 @@ public class MemoryView extends ViewPart private DisplaySettings displaySettings; private String addressFormat; + @SuppressWarnings("unused") @Override public void createPartControl(Composite parent) { provider = new MemoryTableContentProvider(); - displaySettings = new DisplaySettings(NumberType.HEXADECIMAL); + displaySettings = new DisplaySettings(); GridLayout layout = new GridLayout(6, false); parent.setLayout(layout); @@ -55,7 +54,7 @@ public class MemoryView extends ViewPart provider.setLowerBound(AsmNumberUtil.valueOf(fromText.getText()).longValue()); viewer.refresh(); } - catch (@SuppressWarnings("unused") NumberFormatException ex) + catch (NumberFormatException ex) { // Nothing to do here } @@ -74,47 +73,15 @@ public class MemoryView extends ViewPart provider.setAmount(AsmNumberUtil.valueOf(amountText.getText()).intValue()); viewer.refresh(); } - catch (@SuppressWarnings("unused") NumberFormatException ex) + catch (NumberFormatException ex) { // Nothing to do here } }); - - setupRadixSelector(parent); - + new RadixSelector(parent, displaySettings); createViewer(parent); - } - - private void setupRadixSelector(Composite parent) - { - Label radixLabel = new Label(parent, SWT.NONE); - radixLabel.setText("Radix: "); - Combo selectRadix = new Combo(parent, SWT.READ_ONLY); - - String entries[] = new String[] { "Binary", "Octal", "Decimal", "Hexadecimal" }; - NumberType corTypes[] = new NumberType[] { NumberType.BINARY, NumberType.OCTAL, NumberType.DECIMAL, NumberType.HEXADECIMAL }; - selectRadix.setItems(entries); - selectRadix.addSelectionListener(new SelectionListener() - { - @Override - public void widgetSelected(SelectionEvent e) - { - int index = selectRadix.getSelectionIndex(); - if (index == -1) - displaySettings.setDataNumberType(NumberType.HEXADECIMAL); - else - { - displaySettings.setDataNumberType(corTypes[index]); - } - viewer.refresh(); - } - @Override - public void widgetDefaultSelected(SelectionEvent e) - { - widgetSelected(e); - } - }); + displaySettings.addObserver(() -> viewer.refresh()); } private void createViewer(Composite parent) diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java index 846d9abf..ee1f5da0 100644 --- a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java @@ -3,6 +3,7 @@ package net.mograsim.plugin.tables.mi; import java.io.File; import java.io.IOException; +import org.eclipse.jface.viewers.ColumnLabelProvider; import org.eclipse.jface.viewers.EditingSupport; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; @@ -21,7 +22,8 @@ import net.mograsim.machine.mi.MicroprogramMemoryParseException; import net.mograsim.machine.mi.MicroprogramMemoryParser; import net.mograsim.machine.mi.parameters.ParameterClassification; import net.mograsim.plugin.asm.AsmNumberUtil.NumberType; -import net.mograsim.plugin.tables.memory.DisplaySettings; +import net.mograsim.plugin.tables.DisplaySettings; +import net.mograsim.plugin.tables.RadixSelector; import net.mograsim.plugin.util.DropDownMenu; import net.mograsim.plugin.util.DropDownMenu.DropDownEntry; @@ -32,13 +34,19 @@ public class InstructionView extends ViewPart private TableViewerColumn[] columns = new TableViewerColumn[0]; private MicroInstructionDefinition miDef; private MicroprogramMemory memory; + private DisplaySettings displaySettings; + @SuppressWarnings("unused") @Override public void createPartControl(Composite parent) { InstructionTableContentProvider provider = new InstructionTableContentProvider(); - GridLayout layout = new GridLayout(1, false); + GridLayout layout = new GridLayout(3, false); setupMenuButtons(parent); + + displaySettings = new DisplaySettings(); + new RadixSelector(parent, displaySettings); + parent.setLayout(layout); viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER | SWT.VIRTUAL); Table table = viewer.getTable(); @@ -47,7 +55,11 @@ public class InstructionView extends ViewPart viewer.setUseHashlookup(true); viewer.setContentProvider(provider); - viewer.getTable().setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH)); + GridData viewerData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH); + viewerData.horizontalSpan = 3; + viewer.getTable().setLayoutData(viewerData); + + displaySettings.addObserver(() -> viewer.refresh()); } @SuppressWarnings("unused") @@ -114,27 +126,36 @@ public class InstructionView extends ViewPart int bounds = 20 + 20 * classes[i].getExpectedBits(); TableViewerColumn col = createTableViewerColumn(name, bounds); - col.setLabelProvider(new ParameterLabelProvider(i)); - col.setEditingSupport(createEditingSupport(miDef, i)); + createEditingAndLabel(col, miDef, i); } } - private EditingSupport createEditingSupport(MicroInstructionDefinition miDef, int index) + private void createEditingAndLabel(TableViewerColumn col, MicroInstructionDefinition miDef, int index) { ParameterClassification parameterClassification = miDef.getParameterClassifications()[index]; + EditingSupport support; + ColumnLabelProvider provider; switch (parameterClassification.getExpectedType()) { case BOOLEAN_IMMEDIATE: - return new BooleanEditingSupport(viewer, miDef, index); + support = new BooleanEditingSupport(viewer, miDef, index); + provider = new ParameterLabelProvider(index); + break; case INTEGER_IMMEDIATE: - return new IntegerEditingSupport(viewer, miDef, index, new DisplaySettings(NumberType.DECIMAL)); + support = new IntegerEditingSupport(viewer, miDef, index, new DisplaySettings(NumberType.DECIMAL)); + provider = new IntegerColumnLabelProvider(displaySettings, index); + break; case MNEMONIC: - return new MnemonicEditingSupport(viewer, miDef, index); + support = new MnemonicEditingSupport(viewer, miDef, index); + provider = new ParameterLabelProvider(index); + break; default: throw new IllegalStateException( "Unable to create EditingSupport for unknown ParameterType " + parameterClassification.getExpectedType()); } + col.setEditingSupport(support); + col.setLabelProvider(provider); } private TableViewerColumn createTableViewerColumn(String title, int bound) diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerColumnLabelProvider.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerColumnLabelProvider.java new file mode 100644 index 00000000..4455f4a0 --- /dev/null +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerColumnLabelProvider.java @@ -0,0 +1,26 @@ +package net.mograsim.plugin.tables.mi; + +import java.math.BigInteger; + +import net.mograsim.machine.mi.MicroInstruction; +import net.mograsim.machine.mi.parameters.IntegerImmediate; +import net.mograsim.plugin.tables.DisplaySettings; +import net.mograsim.plugin.tables.NumberColumnLabelProvider; + +public class IntegerColumnLabelProvider extends NumberColumnLabelProvider +{ + private int index; + + public IntegerColumnLabelProvider(DisplaySettings displaySettings, int index) + { + super(displaySettings); + this.index = index; + } + + @Override + public BigInteger getAsBigInteger(Object element) + { + return ((IntegerImmediate) ((MicroInstruction) element).getParameter(index)).getValueAsBigInteger(); + } + +} diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerEditingSupport.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerEditingSupport.java index 43d6041e..db86ab07 100644 --- a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerEditingSupport.java +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerEditingSupport.java @@ -8,8 +8,8 @@ import net.mograsim.machine.mi.MicroInstruction; import net.mograsim.machine.mi.MicroInstructionDefinition; import net.mograsim.machine.mi.parameters.IntegerClassification; import net.mograsim.machine.mi.parameters.IntegerImmediate; +import net.mograsim.plugin.tables.DisplaySettings; import net.mograsim.plugin.tables.NumberCellEditingSupport; -import net.mograsim.plugin.tables.memory.DisplaySettings; public class IntegerEditingSupport extends NumberCellEditingSupport {