1 package net.mograsim.logic.model.editor;
3 import org.eclipse.swt.SWT;
4 import org.eclipse.swt.layout.GridData;
5 import org.eclipse.swt.layout.GridLayout;
6 import org.eclipse.swt.widgets.Display;
7 import org.eclipse.swt.widgets.List;
8 import org.eclipse.swt.widgets.Shell;
10 import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasOverlay;
11 import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput;
12 import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator;
14 public class EditorGUI
16 final Display display;
18 public final EditorCanvas logicCanvas;
19 private final List addList;
21 public EditorGUI(Editor editor)
23 display = Display.getDefault();
24 shell = new Shell(display);
27 GridLayout layout = new GridLayout();
28 shell.setLayout(layout);
29 layout.numColumns = 2;
31 GridData d = new GridData();
32 d.grabExcessVerticalSpace = true;
33 d.verticalAlignment = SWT.FILL;
34 addList = new List(shell, SWT.FILL);
35 addList.setLayoutData(d);
39 d.grabExcessHorizontalSpace = true;
40 d.horizontalAlignment = SWT.FILL;
41 d.grabExcessVerticalSpace = true;
42 d.verticalAlignment = SWT.FILL;
44 logicCanvas = new EditorCanvas(shell, SWT.TRAIL, editor);
45 logicCanvas.setLayoutData(d);
48 new EditorUserInput(editor, this);
49 ZoomableCanvasUserInput userInput = new ZoomableCanvasUserInput(logicCanvas);
50 userInput.buttonDrag = 3;
51 userInput.buttonZoom = 2;
52 userInput.enableUserInput();
53 new ZoomableCanvasOverlay(logicCanvas, null).enableScale();
56 public void refreshAddList()
58 addList.setItems(IndirectGUIComponentCreator.getStandardComponentIDs().toArray(String[]::new));
62 public String getAddListSelected()
64 String[] selection = addList.getSelection();
65 if(selection.length == 0)
66 throw new IllegalStateException("Selection in the Add Component List may never be empty!");
73 while (!shell.isDisposed())
74 if (!display.readAndDispatch())