Actually use adapter. Somehow this introduced a rendering bug...
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Wed, 29 May 2019 14:57:34 +0000 (16:57 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Wed, 29 May 2019 14:57:34 +0000 (16:57 +0200)
LogicUI/src/era/mi/gui/LogicUIStandalone.java
LogicUI/src/era/mi/gui/examples/Playground.java

index 3e29a6e..a7f4a45 100644 (file)
@@ -8,6 +8,9 @@ import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;\r
 \r
 import era.mi.gui.model.ViewModel;\r
+import era.mi.gui.modeladapter.LogicModelParameters;\r
+import era.mi.gui.modeladapter.ViewLogicModelAdapter;\r
+import era.mi.logic.timeline.Timeline;\r
 import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasOverlay;\r
 import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput;\r
 \r
@@ -19,6 +22,7 @@ import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInpu
 public class LogicUIStandalone\r
 {\r
        private ViewModel model;\r
+       private Timeline timeline;\r
 \r
        private final Display display;\r
        private final Shell shell;\r
@@ -37,6 +41,12 @@ public class LogicUIStandalone
                userInput.buttonZoom = 2;\r
                userInput.enableUserInput();\r
                new ZoomableCanvasOverlay(ui, null).enableScale();\r
+\r
+               // TODO don't do this here\r
+               LogicModelParameters params = new LogicModelParameters();\r
+               params.gateProcessTime = 50;\r
+               params.wireTravelTime = 10;\r
+               timeline = ViewLogicModelAdapter.convert(model, params);\r
        }\r
 \r
        public LogicUICanvas getLogicUICanvas()\r
@@ -50,33 +60,33 @@ 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
-//                             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
+               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
 \r
                shell.open();\r
                while (!shell.isDisposed())\r
index 372381a..cf9f1e0 100644 (file)
@@ -11,15 +11,19 @@ import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
 
 public class Playground
 {
-       private static final int WIRE_DELAY = 10;
-       private static final int OR_DELAY = 50;
-       private static final int NOT_DELAY = 50;
-
        public static void main(String[] args)
        {
                ViewModel model = new ViewModel();
+               GUIAndGate andGate = new GUIAndGate(model, 1);
+               andGate.moveTo(10, 10);
+               GUINotGate notGate = new GUINotGate(model, 1);
+               notGate.moveTo(10, 40);
+
+               new GUIWire(model, andGate.getPins().get(0), notGate.getPins().get(1), new Point(20, 50));
+
                LogicUIStandalone ui = new LogicUIStandalone(model);
-               addComponentsAndWires(ui, model);
+
+               ui.getLogicUICanvas().addListener(SWT.KeyDown, e -> notGate.moveTo(150, 10));
                ui.run();
        }