Started restructuring LogicUI
[Mograsim.git] / LogicUI / src / era / mi / gui / LogicUIStandalone.java
index c50af4a..638ecf4 100644 (file)
@@ -7,7 +7,7 @@ import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.widgets.Display;\r
 import org.eclipse.swt.widgets.Shell;\r
 \r
-import era.mi.logic.timeline.Timeline;\r
+import era.mi.gui.model.ViewModel;\r
 import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasOverlay;\r
 import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput;\r
 \r
@@ -18,14 +18,15 @@ import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInpu
  */\r
 public class LogicUIStandalone\r
 {\r
+       private ViewModel model;\r
+\r
        private final Display display;\r
        private final Shell shell;\r
        private final LogicUICanvas ui;\r
-       private Timeline timeline;\r
 \r
-       public LogicUIStandalone(Timeline timeline)\r
+       public LogicUIStandalone(ViewModel model)\r
        {\r
-               this.timeline = timeline;\r
+               this.model = model;\r
                display = new Display();\r
                shell = new Shell(display);\r
                shell.setLayout(new FillLayout());\r
@@ -49,39 +50,39 @@ public class LogicUIStandalone
        public void run()\r
        {\r
                AtomicBoolean running = new AtomicBoolean(true);\r
-               Thread simulationThread = new Thread(() ->\r
-               {\r
-                       while (running.get())\r
-                       {\r
-                               // always execute to keep timeline from "hanging behind" for too long\r
-                               timeline.executeUpTo(System.currentTimeMillis(), System.currentTimeMillis() + 10);\r
-                               long sleepTime;\r
-                               if (timeline.hasNext())\r
-                                       sleepTime = timeline.nextEventTime() - System.currentTimeMillis();\r
-                               else\r
-                                       sleepTime = 10;\r
-                               try\r
-                               {\r
-                                       if (sleepTime > 0)\r
-                                               Thread.sleep(sleepTime);\r
-                               }\r
-                               catch (InterruptedException e)\r
-                               {\r
-                               } // it is normal execution flow to be interrupted\r
-                       }\r
-               });\r
-               simulationThread.start();\r
-               timeline.addEventAddedListener(event ->\r
-               {\r
-                       if (event.getTiming() <= System.currentTimeMillis())\r
-                               simulationThread.interrupt();\r
-               });\r
+//             Thread simulationThread = new Thread(() ->\r
+//             {\r
+//                     while (running.get())\r
+//                     {\r
+//                             // always execute to keep timeline from "hanging behind" for too long\r
+//                             model.timeline.executeUpTo(System.currentTimeMillis(), System.currentTimeMillis() + 10);\r
+//                             long sleepTime;\r
+//                             if (model.timeline.hasNext())\r
+//                                     sleepTime = model.timeline.nextEventTime() - System.currentTimeMillis();\r
+//                             else\r
+//                                     sleepTime = 10;\r
+//                             try\r
+//                             {\r
+//                                     if (sleepTime > 0)\r
+//                                             Thread.sleep(sleepTime);\r
+//                             }\r
+//                             catch (InterruptedException e)\r
+//                             {\r
+//                             } // it is normal execution flow to be interrupted\r
+//                     }\r
+//             });\r
+//             simulationThread.start();\r
+//             model.timeline.addEventAddedListener(event ->\r
+//             {\r
+//                     if (event.getTiming() <= System.currentTimeMillis())\r
+//                             simulationThread.interrupt();\r
+//             });\r
 \r
                shell.open();\r
                while (!shell.isDisposed())\r
                        if (!display.readAndDispatch())\r
                                display.sleep();\r
                running.set(false);\r
-               simulationThread.interrupt();\r
+//             simulationThread.interrupt();\r
        }\r
 }
\ No newline at end of file