final Shell shell = new Shell(d, SWT.TITLE | SWT.CLOSE | SWT.RESIZE);
shell.setText("AgentWise Demo Control Centerâ„¢");
shell.setLayout(new RowLayout(SWT.VERTICAL));
final Monitor primary = d.getPrimaryMonitor();
shell.setLocation(primary.getClientArea().x, primary.getClientArea().y);
shell
.setSize(primary.getClientArea().width, primary.getClientArea().height);
final Composite controlsComposite = new Composite(shell, SWT.NONE);
controlsComposite.setLayout(new RowLayout(SWT.HORIZONTAL));
final Label timeLabel = new Label(controlsComposite, SWT.NONE);
timeLabel.setText("End simulation time (in hours): ");
final Text timeText = new Text(controlsComposite, SWT.NONE);
timeText.setText("6.0");
timeText.setLayoutData(new RowData(40, SWT.DEFAULT));
timeText.addListener(SWT.Verify, new Listener() {
@Override
public void handleEvent(Event e) {
final String string = e.text;
final char[] chars = new char[string.length()];
string.getChars(0, chars.length, chars, 0);
for (int i = 0; i < chars.length; i++) {
if (!('0' <= chars[i] && chars[i] <= '9') && chars[i] != '.') {
e.doit = false;
return;
}
}
for (final DemoRunner dr : demoRunners) {
dr.setTime(Double.parseDouble(e.text));
}
}
});
final List<Button> monitorCheckBoxes = newArrayList();
for (int i = 0; i < d.getMonitors().length; i++) {
final Monitor m = d.getMonitors()[i];
final Button b = new Button(controlsComposite, SWT.CHECK);
b.setData(m);
final boolean isPrimary = m.equals(d.getPrimaryMonitor());
b.setText(i + " " + m.getBounds().width + "x" + m.getBounds().height
+ (isPrimary ? " PRIMARY" : ""));
b.setSelection(!isPrimary);
monitorCheckBoxes.add(b);
}
final List<Button> demoCheckBoxes = newArrayList();
for (final DemoType dt : DemoType.values()) {
final Button b = new Button(controlsComposite, SWT.CHECK);
demoCheckBoxes.add(b);
b.setText(dt.name());
b.setData(dt);
b.setSelection(true);
}
final Button runButton = new Button(shell, SWT.TOGGLE);
runButton.setSize(300, 100);
runButton.setText("Start demo");
final Font f = runButton.getFont();
final FontData[] fontData = f.getFontData();
for (int i = 0; i < fontData.length; i++) {
fontData[i].setHeight(60);
}
final Font newFont = new Font(d, fontData);
runButton.setFont(newFont);
final Composite panelComposite = new Composite(shell, SWT.NONE);
// panelComposite.setLayout(new RowLayout(SWT.HORIZONTAL));
final List<DemoRunnerControlPanel> panels = newArrayList();
runButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
// clear old runners
for (final DemoRunner dr : demoRunners) {
dr.setRunning(false);
}
demoRunners.clear();
// close old shells
for (final Shell s : d.getShells()) {
if (s != shell) {
s.close();
}
}
for (final DemoRunnerControlPanel panel : panels) {
panel.remove();
}
panels.clear();
controlsComposite.setEnabled(!((Button) e.widget).getSelection());
for (final Control c : controlsComposite.getChildren()) {
c.setEnabled(!((Button) e.widget).getSelection());
}
if (((Button) e.widget).getSelection()) {
runButton.setText("Stop demo");
} else {
runButton.setText("Start demo");
}
if (((Button) e.widget).getSelection()) {
int index = 0;
final List<DemoType> types = newArrayList();
for (final Button b : demoCheckBoxes) {
if (b.getSelection()) {
types.add((DemoType) b.getData());
}
}
final ImmutableList<DemoType> demoTypes = ImmutableList.copyOf(types);
for (final Button b : monitorCheckBoxes) {
if (b.getSelection()) {
final Monitor m = (Monitor) b.getData();
final DemoRunner dr = new DemoRunner(d, demoTypes, index);
index++;
dr.setTime(Double.parseDouble(timeText.getText()));