From 7959f310ed60567201e37f1dc2eb1dc370763cff Mon Sep 17 00:00:00 2001 From: Fabian Stemmler Date: Sun, 25 Aug 2019 17:30:07 +0200 Subject: [PATCH] Added Memory View to the plugin --- .../OSGI-INF/l10n/bundle_de.properties | 1 + net.mograsim.plugin.core/META-INF/MANIFEST.MF | 3 +- .../OSGI-INF/l10n/bundle.properties | 1 + net.mograsim.plugin.core/plugin.xml | 7 + .../memory/MemoryCellEditingSupport.java | 61 +++++ .../memory/MemoryTableContentProvider.java | 57 +++++ .../plugin/memory/MemoryTableRow.java | 20 ++ .../mograsim/plugin/memory/MemoryView.java | 208 ++++++++++++++++++ .../memory/NumberCellEditorValidator.java | 17 ++ .../plugin/memory/NumberVerifyListener.java | 26 +++ 10 files changed, 400 insertions(+), 1 deletion(-) create mode 100644 net.mograsim.plugin.core/src/net/mograsim/plugin/memory/MemoryCellEditingSupport.java create mode 100644 net.mograsim.plugin.core/src/net/mograsim/plugin/memory/MemoryTableContentProvider.java create mode 100644 net.mograsim.plugin.core/src/net/mograsim/plugin/memory/MemoryTableRow.java create mode 100644 net.mograsim.plugin.core/src/net/mograsim/plugin/memory/MemoryView.java create mode 100644 net.mograsim.plugin.core/src/net/mograsim/plugin/memory/NumberCellEditorValidator.java create mode 100644 net.mograsim.plugin.core/src/net/mograsim/plugin/memory/NumberVerifyListener.java diff --git a/net.mograsim.plugin.core.nl_de/OSGI-INF/l10n/bundle_de.properties b/net.mograsim.plugin.core.nl_de/OSGI-INF/l10n/bundle_de.properties index ef3435f0..6297d7d7 100644 --- a/net.mograsim.plugin.core.nl_de/OSGI-INF/l10n/bundle_de.properties +++ b/net.mograsim.plugin.core.nl_de/OSGI-INF/l10n/bundle_de.properties @@ -29,4 +29,5 @@ colorDefinition.label.9 = Simulation Farbe 0 colorDefinition.label.10 = Simulation Textfarbe fontDefinition.label = Assembler Operation Textstil view.name.0 = Simulation View +view.name.1 = Speicher themeElementCategory.label.0 = Simulation \ No newline at end of file diff --git a/net.mograsim.plugin.core/META-INF/MANIFEST.MF b/net.mograsim.plugin.core/META-INF/MANIFEST.MF index fa50b3b2..02cb0fa8 100644 --- a/net.mograsim.plugin.core/META-INF/MANIFEST.MF +++ b/net.mograsim.plugin.core/META-INF/MANIFEST.MF @@ -22,7 +22,8 @@ Require-Bundle: org.eclipse.core.runtime, net.mograsim.logic.model;bundle-version="0.1.0";visibility:=reexport, net.mograsim.logic.model.am2900;bundle-version="0.1.0";visibility:=reexport, javax.annotation;bundle-version="1.0.0", - net.mograsim.preferences;bundle-version="0.1.0" + net.mograsim.preferences;bundle-version="0.1.0", + net.mograsim.machine Bundle-RequiredExecutionEnvironment: JavaSE-11 Automatic-Module-Name: net.mograsim.plugin.core Bundle-Vendor: %Bundle-Vendor.0 diff --git a/net.mograsim.plugin.core/OSGI-INF/l10n/bundle.properties b/net.mograsim.plugin.core/OSGI-INF/l10n/bundle.properties index d9cb1957..87fc3eef 100644 --- a/net.mograsim.plugin.core/OSGI-INF/l10n/bundle.properties +++ b/net.mograsim.plugin.core/OSGI-INF/l10n/bundle.properties @@ -29,5 +29,6 @@ colorDefinition.label.9 = Simulation Color 0 colorDefinition.label.10 = Simulation text color fontDefinition.label = Assembler Operation Style view.name.0 = Simulation View +view.name.1 = Memory themeElementCategory.label.0 = Simulation Bundle-Vendor.0 = Mograsim Team \ No newline at end of file diff --git a/net.mograsim.plugin.core/plugin.xml b/net.mograsim.plugin.core/plugin.xml index 47d83d27..5932f6d2 100644 --- a/net.mograsim.plugin.core/plugin.xml +++ b/net.mograsim.plugin.core/plugin.xml @@ -88,6 +88,13 @@ name="%view.name.0" restorable="true"> + + + { + try + { + provider.setLowerBound(AsmNumberUtil.valueOf(fromText.getText()).longValue()); + viewer.refresh(); + } + catch (@SuppressWarnings("unused") NumberFormatException ex) + { + // Nothing to do here + } +// fromText.setText(AsmNumberUtil.toString(BigInteger.valueOf(provider.getLowerBound()), NumberType.HEXADECIMAL)); + }); + + Label amountLabel = new Label(parent, SWT.NONE); + amountLabel.setText("Number of cells: "); + Text amountText = new Text(parent, SWT.BORDER | SWT.SEARCH); + amountText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL)); + amountText.addVerifyListener(vl); + amountText.setText("0"); + amountText.addModifyListener(e -> + { + try + { + provider.setAmount(AsmNumberUtil.valueOf(amountText.getText()).intValue()); + viewer.refresh(); + } + catch (@SuppressWarnings("unused") NumberFormatException ex) + { + // Nothing to do here + } +// amountText.setText(Integer.toString(provider.getAmount())); + }); + + setupRadixSelector(parent); + + 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); + } + }); + } + + private void createViewer(Composite parent) + { + viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); + createColumns(); + Table table = viewer.getTable(); + table.setHeaderVisible(true); + table.setLinesVisible(true); + viewer.setContentProvider(provider); + setMemoryBinding(new WordAddressableMemory(new DefaultMainMemoryDefinition(8, 8, 8L, 256L))); + getSite().setSelectionProvider(viewer); + + GridData gd = new GridData(); + gd.verticalAlignment = GridData.FILL; + gd.horizontalSpan = 6; + gd.grabExcessHorizontalSpace = true; + gd.grabExcessVerticalSpace = true; + gd.horizontalAlignment = GridData.FILL; + viewer.getControl().setLayoutData(gd); + } + + private void createColumns() + { + String[] titles = { "Address", "Data" }; + int[] bounds = { 100, 100 }; + + TableViewerColumn col = createTableViewerColumn(titles[0], bounds[0]); + col.setLabelProvider(new ColumnLabelProvider() + { + @Override + public String getText(Object element) + { + MemoryTableRow row = (MemoryTableRow) element; + return String.format(addressFormat, row.address);// TODO: make the string length dependent on memory address length + } + }); + + col = createTableViewerColumn(titles[1], bounds[1]); + col.setLabelProvider(new ColumnLabelProvider() + { + @Override + public String getText(Object element) + { + MemoryTableRow row = (MemoryTableRow) element; + return AsmNumberUtil.toString(row.getMemory().getCellAsBigInteger(row.address), displaySettings.getDataNumberType()); + } + }); + col.setEditingSupport(new MemoryCellEditingSupport(viewer, displaySettings)); + } + + private TableViewerColumn createTableViewerColumn(String title, int bound) + { + TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE); + TableColumn column = viewerColumn.getColumn(); + column.setText(title); + column.setWidth(bound); + column.setResizable(true); + column.setMoveable(false); + return viewerColumn; + } + + @Override + public void setFocus() + { + viewer.getControl().setFocus(); + } + + public void setMemoryBinding(MainMemory m) + { + int hexAddressLength = Long.toUnsignedString(m.getDefinition().getMaximalAddress(), 16).length(); + addressFormat = "0x%0" + hexAddressLength + "X"; + viewer.setInput(m); + } + + public static class DisplaySettings + { + private AsmNumberUtil.NumberType dataNumberType; + + public AsmNumberUtil.NumberType getDataNumberType() + { + return dataNumberType; + } + + public void setDataNumberType(AsmNumberUtil.NumberType dataNumberType) + { + this.dataNumberType = dataNumberType; + } + } +} diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/memory/NumberCellEditorValidator.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/memory/NumberCellEditorValidator.java new file mode 100644 index 00000000..236eaa06 --- /dev/null +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/memory/NumberCellEditorValidator.java @@ -0,0 +1,17 @@ +package net.mograsim.plugin.memory; + +import org.eclipse.jface.viewers.ICellEditorValidator; + +import net.mograsim.plugin.asm.AsmNumberUtil; + +public class NumberCellEditorValidator implements ICellEditorValidator +{ + + @Override + public String isValid(Object value) + { + return AsmNumberUtil.NumberType.NONE.equals(AsmNumberUtil.getType((String) value)) ? (String) value + "is not a valid number" + : null; + } + +} diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/memory/NumberVerifyListener.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/memory/NumberVerifyListener.java new file mode 100644 index 00000000..4e5d11c8 --- /dev/null +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/memory/NumberVerifyListener.java @@ -0,0 +1,26 @@ +package net.mograsim.plugin.memory; + +import org.eclipse.swt.events.VerifyEvent; +import org.eclipse.swt.events.VerifyListener; +import org.eclipse.swt.widgets.Text; + +import net.mograsim.plugin.asm.AsmNumberUtil; +import net.mograsim.plugin.asm.AsmNumberUtil.NumberType; + +public class NumberVerifyListener implements VerifyListener +{ + + @Override + public void verifyText(VerifyEvent e) + { + String text = computeModifiedText(e); + e.doit = !NumberType.NONE.equals(AsmNumberUtil.prefixOfType(text)); + } + + private static String computeModifiedText(VerifyEvent e) + { + String modifiedText = ((Text) e.getSource()).getText(); + modifiedText = modifiedText.substring(0, e.start).concat(e.text).concat(modifiedText.substring(e.end)); + return modifiedText; + } +} -- 2.17.1