Renamed mograsim to net.mograsim
[Mograsim.git] / LogicUI / src / net / mograsim / logic / ui / LogicUIStandaloneGUI.java
1 package net.mograsim.logic.ui;
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.ui.model.ViewModel;
11 import net.mograsim.logic.ui.modeladapter.LogicModelParameters;
12
13 /**
14  * Standalone simulation visualizer graphical user interface.
15  * 
16  * @author Daniel Kirschten
17  */
18 public class LogicUIStandaloneGUI
19 {
20         private final Display display;
21         private final Shell shell;
22         private final LogicUICanvas ui;
23
24         public LogicUIStandaloneGUI(ViewModel model)
25         {
26                 display = new Display();
27                 shell = new Shell(display);
28                 shell.setLayout(new FillLayout());
29                 ui = new LogicUICanvas(shell, SWT.NONE, model);
30
31                 ZoomableCanvasUserInput userInput = new ZoomableCanvasUserInput(ui);
32                 userInput.buttonDrag = 3;
33                 userInput.buttonZoom = 2;
34                 userInput.enableUserInput();
35                 new ZoomableCanvasOverlay(ui, null).enableScale();
36
37                 // TODO don't do this here
38                 LogicModelParameters params = new LogicModelParameters();
39                 params.gateProcessTime = 50;
40                 params.wireTravelTime = 10;
41 //              timeline = ViewLogicModelAdapter.convert(model, params);
42         }
43
44         public LogicUICanvas getLogicUICanvas()
45         {
46                 return ui;
47         }
48
49         /**
50          * Opens the UI shell. Returns when the shell is closed.
51          */
52         public void run()
53         {
54                 shell.open();
55                 while (!shell.isDisposed())
56                         if (!display.readAndDispatch())
57                                 display.sleep();
58         }
59 }