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