package de.tutorials;
import java.io.PrintStream;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
/**
* <p>
* TODO Description of the type
* </p>
* @author Thomas.Darimont
*/
public class SystemOutRedictionExample {
/**
* <p>
* TODO Description of method
* </p>
* @param args
*/
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.setSize(320, 240);
final Text text = new Text(shell, SWT.V_SCROLL | SWT.H_SCROLL);
text.setEditable(false);
shell.setText("SystemErrRedictionExample");
shell.open();
final PrintStream backupSystemOutStream = System.out;
System.setOut(new PrintStream(backupSystemOutStream) {
public void print(final String s) {
display.asyncExec(new Runnable() {
public void run() {
text.append(s);
text.append("\n");
}
});
super.print("aaaa: " + s);
}
});
new Thread() {
{
setDaemon(true);
}
public void run() {
while (true) {
System.out.println(System.currentTimeMillis() + ": xxx");
new Exception().printStackTrace(System.out);
try {
Thread.sleep(2000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}.start();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
}