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
public class LogicUIStandalone\r
{\r
private ViewModel model;\r
+ private Timeline timeline;\r
\r
private final Display display;\r
private final Shell shell;\r
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
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
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();
}