X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2FSimulationPreview.java;h=5fcc1688f6587580de828e45c7f662a98d5c5d8a;hb=8bed58cd47f4e53a0a83e066d38864aa6875502f;hp=9426f2c956a241dcebd8d6452fe775c04f94b67c;hpb=1852c81ce3a63e6847fc5404f91607b553fcd882;p=Mograsim.git 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 9426f2c9..5fcc1688 100644 --- a/net.mograsim.plugin.core/src/net/mograsim/plugin/SimulationPreview.java +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/SimulationPreview.java @@ -6,99 +6,98 @@ 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; +import net.mograsim.logic.model.LogicExecuter; +import net.mograsim.logic.model.LogicUICanvas; +import net.mograsim.logic.model.model.LogicModelModifiable; +import net.mograsim.logic.model.model.components.atomic.ModelManualSwitch; +import net.mograsim.logic.model.model.components.atomic.ModelNotGate; +import net.mograsim.logic.model.model.components.atomic.ModelOrGate; +import net.mograsim.logic.model.model.wires.ModelWire; +import net.mograsim.logic.model.model.wires.ModelWireCrossPoint; +import net.mograsim.logic.model.modeladapter.CoreModelParameters; +import net.mograsim.logic.model.modeladapter.LogicCoreAdapter; +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) { - ViewModelModifiable model = new ViewModelModifiable(); - LogicModelParameters params = new LogicModelParameters(); + 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); + + LogicModelModifiable model = new LogicModelModifiable(); + CoreModelParameters params = new CoreModelParameters(); params.gateProcessTime = 50; params.wireTravelTime = 10; - GUIManualSwitch rIn = new GUIManualSwitch(model); + ModelManualSwitch rIn = new ModelManualSwitch(model, 1); rIn.moveTo(10, 10); - GUIManualSwitch sIn = new GUIManualSwitch(model); + ModelManualSwitch sIn = new ModelManualSwitch(model, 1); sIn.moveTo(10, 70); - GUIOrGate or1 = new GUIOrGate(model, 1); + ModelOrGate or1 = new ModelOrGate(model, 1); or1.moveTo(70, 12.5); - new GUIWire(model, rIn.getOutputPin(), or1.getPin("A")); + new ModelWire(model, rIn.getOutputPin(), or1.getPin("A")); - GUIOrGate or2 = new GUIOrGate(model, 1); + ModelOrGate or2 = new ModelOrGate(model, 1); or2.moveTo(70, 62.5); - new GUIWire(model, sIn.getOutputPin(), or2.getPin("B")); + new ModelWire(model, sIn.getOutputPin(), or2.getPin("B")); - GUINotGate not1 = new GUINotGate(model, 1); + ModelNotGate not1 = new ModelNotGate(model, 1); not1.moveTo(110, 17.5); - new GUIWire(model, or1.getPin("Y"), not1.getPin("A")); + new ModelWire(model, or1.getPin("Y"), not1.getPin("A")); - GUINotGate not2 = new GUINotGate(model, 1); + ModelNotGate not2 = new ModelNotGate(model, 1); not2.moveTo(110, 67.5); - new GUIWire(model, or2.getPin("Y"), not2.getPin("A")); + new ModelWire(model, or2.getPin("Y"), not2.getPin("A")); - WireCrossPoint p1 = new WireCrossPoint(model, 1); + ModelWireCrossPoint p1 = new ModelWireCrossPoint(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)); + new ModelWire(model, not1.getPin("Y"), p1); + new ModelWire(model, p1, or2.getPin("A"), new Point(140, 35), new Point(50, 60), new Point(50, 67.5)); - WireCrossPoint p2 = new WireCrossPoint(model, 1); + ModelWireCrossPoint p2 = new ModelWireCrossPoint(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)); + new ModelWire(model, not2.getPin("Y"), p2); + new ModelWire(model, p2, or1.getPin("B"), new Point(140, 60), new Point(50, 35), new Point(50, 27.5)); - WireCrossPoint o1 = new WireCrossPoint(model, 1); + ModelWireCrossPoint o1 = new ModelWireCrossPoint(model, 1); o1.moveCenterTo(150, 22.5); - new GUIWire(model, p1, o1); + new ModelWire(model, p1, o1); - WireCrossPoint o2 = new WireCrossPoint(model, 1); + ModelWireCrossPoint o2 = new ModelWireCrossPoint(model, 1); o2.moveCenterTo(150, 72.5); - new GUIWire(model, p2, o2); + new ModelWire(model, p2, o2); - Timeline t = ViewLogicModelAdapter.convert(model, params); + Timeline t = LogicCoreAdapter.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); + + ui.zoom(3.5, 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")); + currentTheme.addPropertyChangeListener(e -> ui.redraw()); } @Override public void dispose() { exec.stopLiveExecution(); + if (Preferences.current() == currentThemePreferences) + Preferences.setPreferences(oldPreferences); } }