49182d6680142e13c325123807ae9c7155168890
[Mograsim.git] / net.mograsim.logic.model / src / net / mograsim / logic / model / LogicUIStandaloneGUI.java
1 package net.mograsim.logic.model;
2
3 import org.eclipse.swt.SWT;
4 import org.eclipse.swt.layout.FillLayout;
5 import org.eclipse.swt.widgets.Display;
6 import org.eclipse.swt.widgets.Shell;
7
8 import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasOverlay;
9 import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput;
10 import net.mograsim.logic.model.model.LogicModel;
11
12 /**
13  * Standalone simulation visualizer graphical user interface.
14  * 
15  * @author Daniel Kirschten
16  */
17 public class LogicUIStandaloneGUI implements Runnable
18 {
19         private final Display display;
20         private final Shell shell;
21         private final LogicUICanvas ui;
22
23         public LogicUIStandaloneGUI(LogicModel model)
24         {
25                 display = new Display();
26                 shell = new Shell(display);
27                 shell.setLayout(new FillLayout());
28                 ui = new LogicUICanvas(shell, SWT.NONE, model);
29
30                 ZoomableCanvasUserInput userInput = new ZoomableCanvasUserInput(ui);
31                 userInput.buttonDrag = 3;
32                 userInput.buttonZoom = 2;
33                 userInput.enableUserInput();
34                 new ZoomableCanvasOverlay(ui, null).enableScale();
35         }
36
37         public LogicUICanvas getLogicUICanvas()
38         {
39                 return ui;
40         }
41
42         /**
43          * Opens the UI shell. Returns when the shell is closed.
44          */
45         @Override
46         public void run()
47         {
48                 shell.open();
49                 while (!shell.isDisposed())
50                         if (!display.readAndDispatch())
51                                 display.sleep();
52         }
53 }