From: Daniel Kirschten Date: Tue, 25 Jun 2019 08:45:53 +0000 (+0200) Subject: Now using preference system in plugin.core X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=a6d67c4b85c65b7eed47ad6124e3ea365cef296c;p=Mograsim.git Now using preference system in plugin.core --- diff --git a/net.mograsim.plugin.core/.settings/org.eclipse.jdt.ui.prefs b/net.mograsim.plugin.core/.settings/org.eclipse.jdt.ui.prefs index 737e3a56..2615e7b9 100644 --- a/net.mograsim.plugin.core/.settings/org.eclipse.jdt.ui.prefs +++ b/net.mograsim.plugin.core/.settings/org.eclipse.jdt.ui.prefs @@ -1,6 +1,6 @@ eclipse.preferences.version=1 editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true -formatter_profile=_Eclipse ajusted old +formatter_profile=_MoGraSim formatter_settings_version=16 sp_cleanup.add_default_serial_version_id=true sp_cleanup.add_generated_serial_version_id=false diff --git a/net.mograsim.plugin.core/META-INF/MANIFEST.MF b/net.mograsim.plugin.core/META-INF/MANIFEST.MF index 8ef1a712..7e65cf9e 100644 --- a/net.mograsim.plugin.core/META-INF/MANIFEST.MF +++ b/net.mograsim.plugin.core/META-INF/MANIFEST.MF @@ -21,7 +21,8 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.ui.themes;bundle-version="1.2.400", net.mograsim.logic.ui;bundle-version="0.1.0";visibility:=reexport, net.mograsim.logic.ui.am2900;bundle-version="0.1.0";visibility:=reexport, - javax.annotation;bundle-version="1.0.0" + javax.annotation;bundle-version="1.0.0", + net.mograsim.preferences;bundle-version="0.1.0" Bundle-RequiredExecutionEnvironment: JavaSE-11 Automatic-Module-Name: net.mograsim.plugin.core Bundle-Vendor: Mograsim Team diff --git a/net.mograsim.plugin.core/plugin.xml b/net.mograsim.plugin.core/plugin.xml index 7dc987ca..16c36890 100644 --- a/net.mograsim.plugin.core/plugin.xml +++ b/net.mograsim.plugin.core/plugin.xml @@ -221,54 +221,95 @@ + + + label="%colorDefinition.label" + value="COLOR_WHITE"> %colorDefinition.description + label="%colorDefinition.label.0" + value="COLOR_BLACK"> + + + + + + + + + + + label="%colorDefinition.label.1" + value="COLOR_GREEN"> + label="%colorDefinition.label.2" + value="COLOR_BLUE"> + label="%colorDefinition.label.3" + value="COLOR_RED"> + label="%colorDefinition.label.4" + value="COLOR_MAGENTA"> update(currentTheme)); - - ui.zoomSteps(12, 10, 10); - exec.startLiveExecution(); - } - - private void update(ITheme currentTheme) - { - ui.setBackground(currentTheme.getColorRegistry().get("net.mograsim.plugin.sim_backgound")); - ui.setForeground(currentTheme.getColorRegistry().get("net.mograsim.plugin.sim_text_color")); - } - - @Override - public void dispose() - { - exec.stopLiveExecution(); - } -} diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/SimulationPreview.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/SimulationPreview.java new file mode 100644 index 00000000..9426f2c9 --- /dev/null +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/SimulationPreview.java @@ -0,0 +1,104 @@ +package net.mograsim.plugin; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.themes.ITheme; +import org.eclipse.ui.themes.IThemePreview; + +import net.haspamelodica.swt.helper.swtobjectwrappers.Point; +import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput; +import net.mograsim.logic.core.timeline.Timeline; +import net.mograsim.logic.ui.LogicExecuter; +import net.mograsim.logic.ui.LogicUICanvas; +import net.mograsim.logic.ui.model.ViewModelModifiable; +import net.mograsim.logic.ui.model.components.GUIManualSwitch; +import net.mograsim.logic.ui.model.components.GUINotGate; +import net.mograsim.logic.ui.model.components.GUIOrGate; +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; + +public class SimulationPreview implements IThemePreview +{ + + private LogicUICanvas ui; + private LogicExecuter exec; + + @Override + @SuppressWarnings("unused") + public void createControl(Composite parent, ITheme currentTheme) + { + ViewModelModifiable model = new ViewModelModifiable(); + LogicModelParameters params = new LogicModelParameters(); + params.gateProcessTime = 50; + params.wireTravelTime = 10; + + GUIManualSwitch rIn = new GUIManualSwitch(model); + rIn.moveTo(10, 10); + GUIManualSwitch sIn = new GUIManualSwitch(model); + sIn.moveTo(10, 70); + + GUIOrGate or1 = new GUIOrGate(model, 1); + or1.moveTo(70, 12.5); + new GUIWire(model, rIn.getOutputPin(), or1.getPin("A")); + + GUIOrGate or2 = new GUIOrGate(model, 1); + or2.moveTo(70, 62.5); + new GUIWire(model, sIn.getOutputPin(), or2.getPin("B")); + + GUINotGate not1 = new GUINotGate(model, 1); + not1.moveTo(110, 17.5); + new GUIWire(model, or1.getPin("Y"), not1.getPin("A")); + + GUINotGate not2 = new GUINotGate(model, 1); + not2.moveTo(110, 67.5); + new GUIWire(model, or2.getPin("Y"), not2.getPin("A")); + + WireCrossPoint p1 = new WireCrossPoint(model, 1); + p1.moveCenterTo(140, 22.5); + new GUIWire(model, not1.getPin("Y"), p1); + new GUIWire(model, p1, or2.getPin("A"), new Point(140, 35), new Point(50, 60), new Point(50, 67.5)); + + WireCrossPoint p2 = new WireCrossPoint(model, 1); + p2.moveCenterTo(140, 72.5); + new GUIWire(model, not2.getPin("Y"), p2); + new GUIWire(model, p2, or1.getPin("B"), new Point(140, 60), new Point(50, 35), new Point(50, 27.5)); + + WireCrossPoint o1 = new WireCrossPoint(model, 1); + o1.moveCenterTo(150, 22.5); + new GUIWire(model, p1, o1); + + WireCrossPoint o2 = new WireCrossPoint(model, 1); + o2.moveCenterTo(150, 72.5); + new GUIWire(model, p2, o2); + + Timeline t = ViewLogicModelAdapter.convert(model, params); + exec = new LogicExecuter(t); + + rIn.clicked(0, 0); + + ui = new LogicUICanvas(parent, SWT.NONE, model); + ZoomableCanvasUserInput userInput = new ZoomableCanvasUserInput(ui); + userInput.buttonDrag = 3; + userInput.buttonZoom = 2; + userInput.enableUserInput(); + update(currentTheme); + currentTheme.getColorRegistry().addListener(e -> update(currentTheme)); + + ui.zoomSteps(12, 10, 10); + exec.startLiveExecution(); + } + + private void update(ITheme currentTheme) + { + ui.setBackground(currentTheme.getColorRegistry().get("net.mograsim.plugin.sim_backgound")); + ui.setForeground(currentTheme.getColorRegistry().get("net.mograsim.plugin.sim_text_color")); + } + + @Override + public void dispose() + { + exec.stopLiveExecution(); + } +} 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 aab85c8c..61e0b384 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,11 +2,17 @@ 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 org.eclipse.ui.themes.ITheme; import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput; @@ -21,6 +27,9 @@ 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.preferences.ColorDefinition.BuiltInColor; +import net.mograsim.preferences.Preferences; public class LogicUIPart extends ViewPart { @@ -40,6 +49,33 @@ public class LogicUIPart extends ViewPart @Override 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 new ColorDefinition(BuiltInColor.COLOR_BLACK); + } + 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(); + } + }); + // setup view model ViewModelModifiable viewModel = new ViewModelModifiable(); createTestbench(viewModel);