X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=SampleERCP%2Fsrc%2Fsampleercp%2Fparts%2FLogicUIPart.java;fp=SampleERCP%2Fsrc%2Fsampleercp%2Fparts%2FLogicUIPart.java;h=7ed8377e0419d822ebb57f9a93100c443a90cc8f;hb=15c8eb1395228603c0eb9ef8c8209eea1d879701;hp=0000000000000000000000000000000000000000;hpb=cc6fcf9796595ef27188e468e776bc55506decf9;p=Mograsim.git diff --git a/SampleERCP/src/sampleercp/parts/LogicUIPart.java b/SampleERCP/src/sampleercp/parts/LogicUIPart.java new file mode 100644 index 00000000..7ed8377e --- /dev/null +++ b/SampleERCP/src/sampleercp/parts/LogicUIPart.java @@ -0,0 +1,54 @@ +package sampleercp.parts; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; + +import era.mi.gui.LogicUICanvas; +import era.mi.gui.examples.RSLatchGUIExample; +import era.mi.logic.Simulation; +import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput; + +public class LogicUIPart +{ + @Inject + private MPart part; + + @PostConstruct + public void create(Composite parent) + { + LogicUICanvas ui = new LogicUICanvas(parent, SWT.NONE); + RSLatchGUIExample.addComponentsAndWires(ui); + ui.addTransformListener((x, y, z) -> part.setDirty(z < 1)); + ZoomableCanvasUserInput userInput = new ZoomableCanvasUserInput(ui); + userInput.buttonDrag = 3; + userInput.buttonZoom = 2; + userInput.enableUserInput(); + Thread simulationThread = new Thread(() -> + { + // TODO find a better condition + while (!ui.isDisposed()) + { + // always execute to keep timeline from "hanging behind" for too long + Simulation.TIMELINE.executeUpTo(System.currentTimeMillis(), System.currentTimeMillis() + 10); + long sleepTime; + if (Simulation.TIMELINE.hasNext()) + sleepTime = Simulation.TIMELINE.nextEventTime() - System.currentTimeMillis(); + else + sleepTime = 10; + try + { + if (sleepTime > 0) + Thread.sleep(sleepTime); + } + catch (InterruptedException e) + { + } // it is normal execution flow to be interrupted + } + }); + simulationThread.start(); + } +} \ No newline at end of file