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.Button;
7 import org.eclipse.swt.widgets.Display;
8 import org.eclipse.swt.widgets.Label;
9 import org.eclipse.swt.widgets.MessageBox;
10 import org.eclipse.swt.widgets.Shell;
11 import org.eclipse.swt.widgets.Text;
13 public class DialogManager
17 public DialogManager(Shell parent)
22 public void openWarningDialog(String title, String message)
24 MessageBox b = new MessageBox(parent, SWT.ICON_WARNING | SWT.OK);
26 b.setMessage(message);
30 public static class InteractiveDialog
32 private String[] finalInput;
33 private final Display display;
34 private final Shell shell;
35 private final Button b1, b2;
36 private Text[] textFields;
37 private InteractiveDialog.InteractiveDialogState state;
39 public InteractiveDialog(String title, String acceptLabel, String cancelLabel, String... inputs)
41 display = Display.getDefault();
42 shell = new Shell(SWT.CLOSE | SWT.TITLE | SWT.MIN | SWT.ON_TOP | SWT.APPLICATION_MODAL);
43 shell.setMinimumSize(500, 150);
45 GridLayout layout = new GridLayout();
46 layout.numColumns = 2;
47 shell.setLayout(layout);
49 this.textFields = new Text[inputs.length];
50 for (int i = 0; i < inputs.length; i++)
52 Label textFieldName = new Label(shell, SWT.NONE);
53 textFieldName.setText(inputs[i].concat(":"));
54 GridData g = new GridData();
55 g.grabExcessHorizontalSpace = true;
56 g.horizontalAlignment = SWT.FILL;
57 Text newTextField = new Text(shell, SWT.BORDER);
58 newTextField.setLayoutData(g);
59 textFields[i] = newTextField;
61 b1 = new Button(shell, SWT.PUSH);
62 b1.addListener(SWT.Selection, e ->
64 state = InteractiveDialogState.ACCEPTED;
68 b1.setText(acceptLabel);
69 b2 = new Button(shell, SWT.PUSH);
70 b2.addListener(SWT.Selection, e ->
72 state = InteractiveDialogState.CANCELLED;
76 b2.setText(cancelLabel);
78 state = InteractiveDialogState.ACTIVE;
83 public String getText()
88 public String getText(int index)
90 if (!shell.isDisposed())
91 return textFields[index].getText();
93 return finalInput[index];
99 while (!shell.isDisposed())
100 if (!display.readAndDispatch())
104 public void dispose()
109 public InteractiveDialog.InteractiveDialogState getState()
114 private void buildFinalInput()
116 finalInput = new String[textFields.length];
117 for (int i = 0; i < textFields.length; i++)
118 finalInput[i] = textFields[i].getText();
121 public static enum InteractiveDialogState
123 ACTIVE, ACCEPTED, CANCELLED;
127 public static void openAddPinDialog(Editor editor, double x, double y)