The final restructured version for automatic build using maven tycho
[Mograsim.git] / plugins / net.mograsim.logic.model / src / net / mograsim / logic / model / LogicUIStandaloneGUI.java
diff --git a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/LogicUIStandaloneGUI.java b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/LogicUIStandaloneGUI.java
new file mode 100644 (file)
index 0000000..49182d6
--- /dev/null
@@ -0,0 +1,53 @@
+package net.mograsim.logic.model;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasOverlay;
+import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput;
+import net.mograsim.logic.model.model.LogicModel;
+
+/**
+ * Standalone simulation visualizer graphical user interface.
+ * 
+ * @author Daniel Kirschten
+ */
+public class LogicUIStandaloneGUI implements Runnable
+{
+       private final Display display;
+       private final Shell shell;
+       private final LogicUICanvas ui;
+
+       public LogicUIStandaloneGUI(LogicModel model)
+       {
+               display = new Display();
+               shell = new Shell(display);
+               shell.setLayout(new FillLayout());
+               ui = new LogicUICanvas(shell, SWT.NONE, model);
+
+               ZoomableCanvasUserInput userInput = new ZoomableCanvasUserInput(ui);
+               userInput.buttonDrag = 3;
+               userInput.buttonZoom = 2;
+               userInput.enableUserInput();
+               new ZoomableCanvasOverlay(ui, null).enableScale();
+       }
+
+       public LogicUICanvas getLogicUICanvas()
+       {
+               return ui;
+       }
+
+       /**
+        * Opens the UI shell. Returns when the shell is closed.
+        */
+       @Override
+       public void run()
+       {
+               shell.open();
+               while (!shell.isDisposed())
+                       if (!display.readAndDispatch())
+                               display.sleep();
+       }
+}
\ No newline at end of file