X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Feditors%2FMemoryEditor.java;h=b367f3a4aadcce123949c3317f517234490a2c30;hb=d55dc585ecd9f8bfd800ba7a034ab1e6b6bba2b3;hp=507adae920d02de816a733923f4f4c717228886a;hpb=9719314d2cb5e435e61e730939d2cd1a92f9a924;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 507adae9..b367f3a4 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 @@ -7,6 +7,7 @@ import java.math.BigInteger; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.SafeRunnable; import org.eclipse.jface.viewers.TableViewerColumn; import org.eclipse.swt.SWT; @@ -23,6 +24,8 @@ import org.eclipse.ui.IEditorSite; import org.eclipse.ui.IFileEditorInput; import org.eclipse.ui.PartInitException; import org.eclipse.ui.part.EditorPart; +import org.eclipse.ui.themes.ITheme; +import org.eclipse.ui.themes.IThemeManager; import net.mograsim.machine.MainMemory; import net.mograsim.machine.MainMemoryDefinition; @@ -56,6 +59,9 @@ public class MemoryEditor extends EditorPart private final MemoryCellModifiedListener memListener; + private final static String font = "net.mograsim.plugin.memory.table_font"; + private IPropertyChangeListener fontChangeListener; + public MemoryEditor() { memListener = this::cellModified; @@ -105,19 +111,21 @@ public class MemoryEditor extends EditorPart Text amountText = new Text(parent, SWT.BORDER); amountText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); amountText.addVerifyListener(vl); - amountText.setText("0"); amountText.addModifyListener(e -> { try { - provider.setAmount(AsmNumberUtil.valueOf(amountText.getText()).intValue()); - viewer.refresh(); + if (provider != null) + provider.setAmount(AsmNumberUtil.valueOf(amountText.getText()).intValue()); + if (viewer != null) + viewer.refresh(); } catch (NumberFormatException x) { // Nothing to do here } }); + amountText.setText("100");// do this after registering the ModifyListener new RadixSelector(parent, displaySettings); addActivationButton(parent); @@ -139,12 +147,29 @@ public class MemoryEditor extends EditorPart table.setLinesVisible(true); viewer.setUseHashlookup(true); viewer.setContentProvider(provider); - getSite().setSelectionProvider(viewer);// TODO what does this? + getSite().setSelectionProvider(viewer);// TODO what does this do? viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 7, 1)); + + IThemeManager themeManager = getSite().getWorkbenchWindow().getWorkbench().getThemeManager(); + themeManager.addPropertyChangeListener(fontChangeListener = (e) -> + { + if (IThemeManager.CHANGE_CURRENT_THEME.equals(e.getProperty()) || font.equals(e.getProperty())) + { + updateFont(themeManager.getCurrentTheme()); + viewer.refresh(); + } + }); + updateFont(themeManager.getCurrentTheme()); + if (memory != null) viewer.setInput(memory); } + private void updateFont(ITheme theme) + { + viewer.getTable().setFont(theme.getFontRegistry().get(font)); + } + private void createColumns() { TableViewerColumn addrCol = createTableViewerColumn("Address", 100); @@ -274,6 +299,7 @@ public class MemoryEditor extends EditorPart @Override public void dispose() { + getSite().getWorkbenchWindow().getWorkbench().getThemeManager().removePropertyChangeListener(fontChangeListener); if (memory != null) memory.deregisterCellModifiedListener(memListener); super.dispose();