From: Daniel Kirschten Date: Tue, 25 Jun 2019 09:47:16 +0000 (+0200) Subject: The user no longer has to click on "Apply" to see changes in the preview X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=a2815c569225ca01628436d32a82abeea12359c5;p=Mograsim.git The user no longer has to click on "Apply" to see changes in the preview --- diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/SimulationPreview.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/SimulationPreview.java index 381a2bc6..b8488d50 100644 --- a/net.mograsim.plugin.core/src/net/mograsim/plugin/SimulationPreview.java +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/SimulationPreview.java @@ -17,17 +17,25 @@ import net.mograsim.logic.ui.model.wires.GUIWire; import net.mograsim.logic.ui.model.wires.WireCrossPoint; import net.mograsim.logic.ui.modeladapter.LogicModelParameters; import net.mograsim.logic.ui.modeladapter.ViewLogicModelAdapter; +import net.mograsim.preferences.Preferences; public class SimulationPreview implements IThemePreview { - private LogicUICanvas ui; private LogicExecuter exec; + private Preferences oldPreferences; + private Preferences currentThemePreferences; @Override @SuppressWarnings("unused") public void createControl(Composite parent, ITheme currentTheme) { + oldPreferences = Preferences.current(); + + currentThemePreferences = new ThemePreferences(currentTheme); + // TODO this will change the global preferences; so if another LogicUICanvas redraws, it will use the "new" colors too. + Preferences.setPreferences(currentThemePreferences); + ViewModelModifiable model = new ViewModelModifiable(); LogicModelParameters params = new LogicModelParameters(); params.gateProcessTime = 50; @@ -81,11 +89,15 @@ public class SimulationPreview implements IThemePreview ui.zoom(3.5, 10, 10); exec.startLiveExecution(); + + currentTheme.addPropertyChangeListener(e -> ui.redraw()); } @Override public void dispose() { exec.stopLiveExecution(); + if (Preferences.current() == currentThemePreferences) + Preferences.setPreferences(oldPreferences); } } diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/ThemePreferences.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/ThemePreferences.java new file mode 100644 index 00000000..b4bc0aca --- /dev/null +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/ThemePreferences.java @@ -0,0 +1,45 @@ +package net.mograsim.plugin; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.resource.ColorRegistry; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.ui.statushandlers.StatusManager; +import org.eclipse.ui.themes.ITheme; + +import net.mograsim.preferences.ColorDefinition; +import net.mograsim.preferences.Preferences; + +public class ThemePreferences extends Preferences +{ + private final ITheme theme; + + public ThemePreferences(ITheme theme) + { + this.theme = theme; + } + + @Override + public ColorDefinition getColorDefinition(String name) + { + RGB rgb = getColorRegistry().getRGB(name); + if (rgb == null) + { + StatusManager.getManager().handle(new Status(IStatus.ERROR, "net.mograsim.plugin.core", "No color for name " + name)); + return null; + } + return new ColorDefinition(rgb.red, rgb.green, rgb.blue); + } + + @Override + public Color getColor(String name) + { + return getColorRegistry().get(name); + } + + private ColorRegistry getColorRegistry() + { + return theme.getColorRegistry(); + } +} \ No newline at end of file diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/views/LogicUIPart.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/views/LogicUIPart.java index d40f5a35..1ae8066e 100644 --- a/net.mograsim.plugin.core/src/net/mograsim/plugin/views/LogicUIPart.java +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/views/LogicUIPart.java @@ -2,17 +2,11 @@ package net.mograsim.plugin.views; import javax.inject.Inject; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; import org.eclipse.e4.ui.model.application.ui.basic.MPart; -import org.eclipse.jface.resource.ColorRegistry; import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.ViewPart; -import org.eclipse.ui.statushandlers.StatusManager; import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput; import net.mograsim.logic.core.timeline.Timeline; @@ -26,7 +20,7 @@ import net.mograsim.logic.ui.model.components.mi.nandbased.am2901.GUIAm2901; import net.mograsim.logic.ui.model.wires.GUIWire; import net.mograsim.logic.ui.modeladapter.LogicModelParameters; import net.mograsim.logic.ui.modeladapter.ViewLogicModelAdapter; -import net.mograsim.preferences.ColorDefinition; +import net.mograsim.plugin.ThemePreferences; import net.mograsim.preferences.Preferences; public class LogicUIPart extends ViewPart @@ -48,31 +42,7 @@ public class LogicUIPart extends ViewPart public void createPartControl(Composite parent) { // set preferences - Preferences.setPreferences(new Preferences() - { - @Override - public ColorDefinition getColorDefinition(String name) - { - RGB rgb = getColorRegistry().getRGB(name); - if (rgb == null) - { - StatusManager.getManager().handle(new Status(IStatus.ERROR, "net.mograsim.plugin.core", "No color for name " + name)); - return null; - } - return new ColorDefinition(rgb.red, rgb.green, rgb.blue); - } - - @Override - public Color getColor(String name) - { - return getColorRegistry().get(name); - } - - private ColorRegistry getColorRegistry() - { - return PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry(); - } - }); + Preferences.setPreferences(new ThemePreferences(PlatformUI.getWorkbench().getThemeManager().getCurrentTheme())); // setup view model ViewModelModifiable viewModel = new ViewModelModifiable();