3 import java.util.concurrent.atomic.AtomicBoolean;
5 import org.eclipse.swt.SWT;
6 import org.eclipse.swt.layout.FillLayout;
7 import org.eclipse.swt.widgets.Display;
8 import org.eclipse.swt.widgets.Shell;
10 import era.mi.gui.model.ViewModel;
11 import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasOverlay;
12 import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput;
15 * Standalone simulation visualizer.
17 * @author Daniel Kirschten
19 public class LogicUIStandalone
21 private ViewModel model;
23 private final Display display;
24 private final Shell shell;
25 private final LogicUICanvas ui;
27 public LogicUIStandalone(ViewModel model)
30 display = new Display();
31 shell = new Shell(display);
32 shell.setLayout(new FillLayout());
33 ui = new LogicUICanvas(shell, SWT.NONE, model);
35 ZoomableCanvasUserInput userInput = new ZoomableCanvasUserInput(ui);
36 userInput.buttonDrag = 3;
37 userInput.buttonZoom = 2;
38 userInput.enableUserInput();
39 new ZoomableCanvasOverlay(ui, null).enableScale();
42 public LogicUICanvas getLogicUICanvas()
48 * Start the simulation timeline, and open the UI shell. Returns when the shell is closed.
52 AtomicBoolean running = new AtomicBoolean(true);
53 // Thread simulationThread = new Thread(() ->
55 // while (running.get())
57 // // always execute to keep timeline from "hanging behind" for too long
58 // model.timeline.executeUpTo(System.currentTimeMillis(), System.currentTimeMillis() + 10);
60 // if (model.timeline.hasNext())
61 // sleepTime = model.timeline.nextEventTime() - System.currentTimeMillis();
67 // Thread.sleep(sleepTime);
69 // catch (InterruptedException e)
71 // } // it is normal execution flow to be interrupted
74 // simulationThread.start();
75 // model.timeline.addEventAddedListener(event ->
77 // if (event.getTiming() <= System.currentTimeMillis())
78 // simulationThread.interrupt();
82 while (!shell.isDisposed())
83 if (!display.readAndDispatch())
86 // simulationThread.interrupt();