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 3079b50..1df22be 100644 (file)
@@ -8,6 +8,9 @@ import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
 
 import era.mi.gui.model.ViewModel;
+import era.mi.gui.modeladapter.LogicModelParameters;
+import era.mi.gui.modeladapter.ViewLogicModelAdapter;
+import era.mi.logic.timeline.Timeline;
 import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasOverlay;
 import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput;
 
@@ -19,6 +22,7 @@ import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInpu
 public class LogicUIStandalone
 {
        private ViewModel model;
+       private Timeline timeline;
 
        private final Display display;
        private final Shell shell;
@@ -37,6 +41,12 @@ public class LogicUIStandalone
                userInput.buttonZoom = 2;
                userInput.enableUserInput();
                new ZoomableCanvasOverlay(ui, null).enableScale();
+
+               // TODO don't do this here
+               LogicModelParameters params = new LogicModelParameters();
+               params.gateProcessTime = 50;
+               params.wireTravelTime = 10;
+               timeline = ViewLogicModelAdapter.convert(model, params);
        }
 
        public LogicUICanvas getLogicUICanvas()
@@ -50,33 +60,33 @@ 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
-//                             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();
-//             });
+               Thread simulationThread = new Thread(() ->
+               {
+                       while (running.get())
+                       {
+                               // always execute to keep timeline from "hanging behind" for too long
+                               timeline.executeUpTo(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();
+               });
 
                shell.open();
                while (!shell.isDisposed())
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();
        }