55a96a51a7ec905c69c2c72a6f06af70af8d8284
[Mograsim.git] / plugins / 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 import net.mograsim.preferences.Preferences;
12
13 /**
14  * Standalone simulation visualizer graphical user interface.
15  * 
16  * @author Daniel Kirschten
17  */
18 public class LogicUIStandaloneGUI implements Runnable
19 {
20         private final Display display;
21         private final Shell shell;
22         private final LogicUICanvas ui;
23
24         public LogicUIStandaloneGUI(LogicModel 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 = Preferences.current().getInt("net.mograsim.logic.model.button.drag");
33                 userInput.buttonZoom = Preferences.current().getInt("net.mograsim.logic.model.button.zoom");
34                 userInput.enableUserInput();
35                 new ZoomableCanvasOverlay(ui, null).enableScale();
36         }
37
38         public LogicUICanvas getLogicUICanvas()
39         {
40                 return ui;
41         }
42
43         /**
44          * Opens the UI shell. Returns when the shell is closed.
45          */
46         @Override
47         public void run()
48         {
49                 shell.open();
50                 while (!shell.isDisposed())
51                         if (!display.readAndDispatch())
52                                 display.sleep();
53         }
54 }