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