final Shell shell = new Shell(Display.getCurrent(), SWT.ON_TOP
| SWT.SHELL_TRIM | SWT.TOOL | SWT.CLOSE);
GridLayout layout = new GridLayout();
layout.numColumns = 4;
GridData gd;
shell.setLayout(layout);
shell.setText("Debug for " + dlData.getDownloadObject().getName());
final Text txtFP = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL);
gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 4;
txtFP.setLayoutData(gd);
final Button btnAutoRefresh = new Button(shell, SWT.CHECK);
btnAutoRefresh.setText("Auto-Refresh");
btnAutoRefresh.setLayoutData(new GridData());
final Button btnRefresh = new Button(shell, SWT.NONE);
btnRefresh.setLayoutData(new GridData());
btnRefresh.setText("Refresh");
final Button btnToClip = new Button(shell, SWT.NONE);
btnToClip.setLayoutData(new GridData());
btnToClip.setText("To Clipboard");
btnToClip.addListener(SWT.MouseUp, new Listener() {
public void handleEvent(Event event) {
new Clipboard(Display.getCurrent()).setContents(
new Object[] { txtFP.getText() },
new Transfer[] { TextTransfer.getInstance() });
}
});
final Label lbl = new Label(shell, SWT.NONE);
gd = new GridData(GridData.FILL_HORIZONTAL);
lbl.setLayoutData(gd);
final TimerTask task = new TimerTask() {
String lastText = "";
public String formatString() {
return "FP:\n" + dlData.sExplainFP + "\n" + "SR:" + dlData.sExplainSR
+ "\n" + "TRACE:\n" + dlData.sTrace;
}
public void setText(final String s) {
lastText = s;
txtFP.setText(s);
}
public void run() {
if (shell.isDisposed())
return;
shell.getDisplay().syncExec(new Runnable() {
public void run() {
if (shell.isDisposed()) {
return;
}
String s = formatString();
if (s.compareTo(lastText) != 0) {
if (lastText.length() == 0 || btnAutoRefresh.getSelection()
|| btnRefresh.getData("Pressing") != null)
setText(s);
else
lbl.setText("Information is outdated. Press refresh.");
} else {
lbl.setText("");
}
}
});
}
};
btnAutoRefresh.addListener(SWT.MouseUp, new Listener() {
public void handleEvent(Event event) {
if (btnAutoRefresh.getSelection())
lbl.setText("");
task.run();
}
});
btnRefresh.addListener(SWT.MouseUp, new Listener() {
public void handleEvent(Event event) {
btnRefresh.setData("Pressing", "1");
task.run();
btnRefresh.setData("Pressing", null);
}
});
shell.addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_ESCAPE) {
shell.dispose();
}
}
});
shell.setSize(550, 350);
shell.open();
Timer timer = new Timer(true);
timer.schedule(task, 0, 2000);