From 5f8f05cd27d2b7663e32093c3e9c542b1af9224b Mon Sep 17 00:00:00 2001 From: Fabian Stemmler Date: Tue, 1 Oct 2019 17:27:02 +0200 Subject: [PATCH] MemoryEditor Font can now be configured --- .../OSGI-INF/l10n/bundle.properties | 2 ++ plugins/net.mograsim.plugin.core/plugin.xml | 32 +++++++++++++------ .../mograsim/plugin/editors/MemoryEditor.java | 26 ++++++++++++++- .../plugin/tables/mi/FontAndColorHelper.java | 10 +++--- 4 files changed, 54 insertions(+), 16 deletions(-) diff --git a/plugins/net.mograsim.plugin.core/OSGI-INF/l10n/bundle.properties b/plugins/net.mograsim.plugin.core/OSGI-INF/l10n/bundle.properties index 2c6f94c2..8bec7721 100644 --- a/plugins/net.mograsim.plugin.core/OSGI-INF/l10n/bundle.properties +++ b/plugins/net.mograsim.plugin.core/OSGI-INF/l10n/bundle.properties @@ -17,6 +17,7 @@ decorator.label = Resource Decorator themeElementCategory.label = Mograsim themeElementCategory.label.0 = Simulation themeElementCategory.label.1 = Microinstructions +themeElementCategory.label.2 = Memory colorDefinition.label = Simulation Background colorDefinition.description = The Background of the Simulation Visualisation colorDefinition.label.0 = Simulation Foreground Color @@ -36,6 +37,7 @@ colorDefinition.label.13 = Highlighted Cell Background Color colorDefinition.label.14 = Highlighted Cell Foreground Color fontDefinition.label = Assembler Operation Style fontDefinition.label.0 = Table Font +fontDefinition.label.1 = Table Font view.name.0 = Simulation View view.name.1 = Memory wizards.newWizards.category = Mograsim diff --git a/plugins/net.mograsim.plugin.core/plugin.xml b/plugins/net.mograsim.plugin.core/plugin.xml index 9060a60b..8e00c1f6 100644 --- a/plugins/net.mograsim.plugin.core/plugin.xml +++ b/plugins/net.mograsim.plugin.core/plugin.xml @@ -213,6 +213,12 @@ label="%themeElementCategory.label.1" parentId="net.mograsim.plugin.mograsim"> + + - - + + + + 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..028a1b5b 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; @@ -139,12 +145,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 +297,7 @@ public class MemoryEditor extends EditorPart @Override public void dispose() { + getSite().getWorkbenchWindow().getWorkbench().getThemeManager().removePropertyChangeListener(fontChangeListener); if (memory != null) memory.deregisterCellModifiedListener(memListener); super.dispose(); diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/FontAndColorHelper.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/FontAndColorHelper.java index befbac8c..1aabce63 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/FontAndColorHelper.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/FontAndColorHelper.java @@ -23,11 +23,11 @@ public class FontAndColorHelper private Font boldItalic, bold, italic, normal; private Color modifBackground, modifForeground, highlightBackground, highlightForeground; - 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", - colorHighlightForeground = "net.mograsim.plugin.highlighted_cell_fg_color", - colorHighlightBackground = "net.mograsim.plugin.highlighted_cell_bg_color"; + private final static String font = "net.mograsim.plugin.mi.table_font", + colorModifBackground = "net.mograsim.plugin.mi.modified_cell_bg_color", + colorModifForeground = "net.mograsim.plugin.mi.modified_cell_fg_color", + colorHighlightForeground = "net.mograsim.plugin.mi.highlighted_cell_fg_color", + colorHighlightBackground = "net.mograsim.plugin.mi.highlighted_cell_bg_color"; private final IPropertyChangeListener updateListener; public FontAndColorHelper(TableViewer viewer, IThemeManager themeManager) -- 2.17.1