X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Feditors%2FMemoryEditor.java;h=0186780eb7eb279ee6270ccfa199a7f6a2bfe290;hb=f098cd47d06be0cc654532a5fad0e5e89f0ef93c;hp=c1268fec3572fd8ac77fb1a31e67c6cf90f5d042;hpb=a5e96c79d684392d7fdcf149736c2d95200e6fda;p=Mograsim.git diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/editors/MemoryEditor.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/editors/MemoryEditor.java index c1268fec..0186780e 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/editors/MemoryEditor.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/editors/MemoryEditor.java @@ -20,6 +20,7 @@ import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.ScrollBar; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.Text; @@ -79,8 +80,7 @@ public class MemoryEditor extends EditorPart provider = new MemoryTableContentProvider(); displaySettings = new DisplaySettings(); - parent.setLayout(new GridLayout(7, false)); - + parent.setLayout(new GridLayout(8, false)); createHeader(parent); createViewer(parent); @@ -90,58 +90,41 @@ public class MemoryEditor extends EditorPart @SuppressWarnings("unused") // RadixSelector and exceptions private void createHeader(Composite parent) { - Label fromLabel = new Label(parent, SWT.NONE); - fromLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); - fromLabel.setText("Address: "); - - Text fromText = new Text(parent, SWT.BORDER); - fromText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + Text gotoText = new Text(parent, SWT.BORDER); + gotoText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); NumberVerifyListener vl = new NumberVerifyListener(); - fromText.addVerifyListener(vl); - fromText.setText("0"); - fromText.addModifyListener(e -> + gotoText.addVerifyListener(vl); + gotoText.setText("0"); + + Runnable gotoAction = () -> { try { - provider.setLowerBound(AsmNumberUtil.valueOf(fromText.getText()).longValue()); - viewer.refresh(); + loadAround((int) (AsmNumberUtil.valueOf(gotoText.getText()).longValue() - provider.getLowerBound())); + viewer.getTable().deselectAll(); } catch (NumberFormatException x) { // Nothing to do here } + }; + + gotoText.addTraverseListener((e) -> + { + if (e.detail == SWT.TRAVERSE_RETURN) + gotoAction.run(); }); - Label amountLabel = new Label(parent, SWT.NONE); - amountLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); - amountLabel.setText("Number of cells: "); - Text amountText = new Text(parent, SWT.BORDER); - amountText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - amountText.addVerifyListener(vl); - amountText.addModifyListener(e -> + + Button gotoButton = new Button(parent, SWT.PUSH); + gotoButton.setText("Go to"); + gotoButton.addListener(SWT.Selection, e -> { - try - { - if (provider != null) - provider.setAmount(AsmNumberUtil.valueOf(amountText.getText()).intValue()); - if (viewer != null) - viewer.refresh(); - } - catch (NumberFormatException x) - { - // Nothing to do here - } + gotoAction.run(); }); - amountText.setText("100");// do this after registering the ModifyListener - new RadixSelector(parent, displaySettings); - addActivationButton(parent); - } + new Label(parent, SWT.NONE).setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - private void addActivationButton(Composite parent) - { - Button activationButton = new Button(parent, SWT.PUSH); - activationButton.setText("Set Active"); - activationButton.addListener(SWT.Selection, e -> context.getActiveMachine().ifPresent(m -> m.getMainMemory().bind(memory))); + new RadixSelector(parent, displaySettings); } private void createViewer(Composite parent) @@ -154,8 +137,20 @@ public class MemoryEditor extends EditorPart table.setLinesVisible(true); viewer.setUseHashlookup(true); viewer.setContentProvider(provider); - getSite().setSelectionProvider(viewer);// TODO what does this do? - viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 7, 1)); + getSite().setSelectionProvider(viewer); + viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 8, 1)); + + // TODO: Also support keyboard inputs for flexible scrolling + ScrollBar vBar = table.getVerticalBar(); + vBar.addListener(SWT.Selection, (e) -> + { + int sel; + if ((sel = vBar.getSelection()) < vBar.getMinimum() + vBar.getThumb() * 2 || sel > vBar.getMaximum() - vBar.getThumb() * 2) + { + loadAround(table.getTopIndex()); + table.deselectAll(); + } + }); IThemeManager themeManager = getSite().getWorkbenchWindow().getWorkbench().getThemeManager(); themeManager.addPropertyChangeListener(fontChangeListener = (e) -> @@ -179,6 +174,27 @@ public class MemoryEditor extends EditorPart fontDependent.forEach(c -> c.setFont(newFont)); } + private void loadAround(int row) + { + long prevLb = provider.getLowerBound(); + long address = prevLb + row; + long actualLb = Long.max(address - MemoryTableContentProvider.MAX_VISIBLE_ROWS / 2, memory.getDefinition().getMinimalAddress()); + + long prevHb = provider.getUpperBound(); + // +- 1 row is not really important + long actualHb = Long.min(address + MemoryTableContentProvider.MAX_VISIBLE_ROWS / 2, memory.getDefinition().getMaximalAddress()); + + if (actualLb != prevLb || actualHb != prevHb) + { + Table table = viewer.getTable(); + provider.setBounds(actualLb, actualHb); + int rowIndex = (int) (address - actualLb); + if (rowIndex >= 0 && rowIndex < table.getItemCount()) + table.showItem(table.getItem(rowIndex)); + viewer.refresh(); + } + } + private void createColumns() { TableViewerColumn addrCol = createTableViewerColumn("Address", 100); @@ -223,7 +239,6 @@ public class MemoryEditor extends EditorPart { IFileEditorInput fileInput = (IFileEditorInput) input; context = ProjectMachineContext.getMachineContextOf(fileInput.getFile().getProject()); - context.activateMachine(); setPartName(fileInput.getName()); try