X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=LogicUI%2Fsrc%2Fera%2Fmi%2Fgui%2FLogicUIStandalone.java;fp=LogicUI%2Fsrc%2Fera%2Fmi%2Fgui%2FLogicUIStandalone.java;h=8bbfb1c50e3c147c2c910e58c0e8a91d0e913ad7;hb=50082bc2126d3f408acbdf4103bb4fdf29ac1d4f;hp=db498ace49e235ab036bb9ebd961f29e00160fb3;hpb=a37db10f5372ec09624b2ad9b60587e498991cbd;p=Mograsim.git diff --git a/LogicUI/src/era/mi/gui/LogicUIStandalone.java b/LogicUI/src/era/mi/gui/LogicUIStandalone.java index db498ace..8bbfb1c5 100644 --- a/LogicUI/src/era/mi/gui/LogicUIStandalone.java +++ b/LogicUI/src/era/mi/gui/LogicUIStandalone.java @@ -7,7 +7,7 @@ import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; -import era.mi.logic.timeline.Timeline; +import era.mi.gui.model.ViewModel; import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasOverlay; import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput; @@ -18,18 +18,19 @@ import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInpu */ public class LogicUIStandalone { + private ViewModel model; + private final Display display; private final Shell shell; private final LogicUICanvas ui; - private Timeline timeline; - public LogicUIStandalone(Timeline timeline) + public LogicUIStandalone(ViewModel model) { - this.timeline = timeline; + this.model = model; display = new Display(); shell = new Shell(display); shell.setLayout(new FillLayout()); - ui = new LogicUICanvas(shell, SWT.NONE); + ui = new LogicUICanvas(shell, SWT.NONE, model); ZoomableCanvasUserInput userInput = new ZoomableCanvasUserInput(ui); userInput.buttonDrag = 3; @@ -49,39 +50,40 @@ public class LogicUIStandalone public void run() { AtomicBoolean running = new AtomicBoolean(true); - Thread simulationThread = new Thread(() -> - { - while (running.get()) - { - // always execute to keep timeline from "hanging behind" for too long - timeline.executeUntil(timeline.laterThan(System.currentTimeMillis()), System.currentTimeMillis() + 10); - long sleepTime; - if (timeline.hasNext()) - sleepTime = 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(); - timeline.addEventAddedListener(event -> - { - if (event.getTiming() <= System.currentTimeMillis()) - simulationThread.interrupt(); - }); +// Thread simulationThread = new Thread(() -> +// { +// while (running.get()) +// { +// // always execute to keep timeline from "hanging behind" for too long +// timeline.executeUntil(timeline.laterThan(System.currentTimeMillis()), System.currentTimeMillis() + 10); +// model.timeline.executeUpTo(System.currentTimeMillis(), System.currentTimeMillis() + 10); +// long sleepTime; +// if (model.timeline.hasNext()) +// sleepTime = model.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(); +// model.timeline.addEventAddedListener(event -> +// { +// if (event.getTiming() <= System.currentTimeMillis()) +// simulationThread.interrupt(); +// }); shell.open(); while (!shell.isDisposed()) if (!display.readAndDispatch()) display.sleep(); running.set(false); - simulationThread.interrupt(); +// simulationThread.interrupt(); } } \ No newline at end of file