[188] | 1 | package de.ugoe.cs.eventbench.swt;
|
---|
| 2 |
|
---|
[238] | 3 | import org.eclipse.swt.SWT;
|
---|
| 4 | import org.eclipse.swt.custom.StyleRange;
|
---|
| 5 | import org.eclipse.swt.custom.StyledText;
|
---|
[188] | 6 |
|
---|
[192] | 7 | import de.ugoe.cs.util.StringTools;
|
---|
[188] | 8 | import de.ugoe.cs.util.console.Console;
|
---|
[200] | 9 | import de.ugoe.cs.util.console.listener.ICommandListener;
|
---|
| 10 | import de.ugoe.cs.util.console.listener.IErrorListener;
|
---|
| 11 | import de.ugoe.cs.util.console.listener.IOutputListener;
|
---|
| 12 | import de.ugoe.cs.util.console.listener.ITraceListener;
|
---|
[188] | 13 |
|
---|
[200] | 14 | public class SWTConsole implements IOutputListener, IErrorListener, ITraceListener, ICommandListener {
|
---|
[188] | 15 |
|
---|
[238] | 16 | StyledText output;
|
---|
[188] | 17 |
|
---|
[238] | 18 | public SWTConsole(StyledText styledText) {
|
---|
[200] | 19 | Console.getInstance().registerOutputListener(this);
|
---|
| 20 | Console.getInstance().registerErrorListener(this);
|
---|
| 21 | Console.getInstance().registerTraceListener(this);
|
---|
| 22 | Console.getInstance().registerCommandListener(this);
|
---|
[238] | 23 | this.output = styledText;
|
---|
[188] | 24 | }
|
---|
| 25 |
|
---|
| 26 | @Override
|
---|
[202] | 27 | public void outputMsg(String newMessage) {
|
---|
[188] | 28 | output.append(newMessage);
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | @Override
|
---|
[202] | 32 | public void errorMsg(String errMessage) {
|
---|
[238] | 33 | appendColored(errMessage, SWT.COLOR_RED);
|
---|
[188] | 34 | }
|
---|
| 35 |
|
---|
| 36 | @Override
|
---|
[202] | 37 | public void traceMsg(String traceMessage) {
|
---|
[238] | 38 | appendColored(traceMessage, SWT.COLOR_BLUE);
|
---|
[188] | 39 | }
|
---|
| 40 |
|
---|
| 41 | @Override
|
---|
| 42 | public void commandNotification(String command) {
|
---|
[192] | 43 | output.append("> " + command + StringTools.ENDLINE);
|
---|
[188] | 44 | }
|
---|
[238] | 45 |
|
---|
| 46 | private void appendColored(String str, int id) {
|
---|
| 47 | StyleRange styleRange = new StyleRange();
|
---|
| 48 | styleRange.start = output.getText().length();
|
---|
| 49 | styleRange.length = str.length();
|
---|
| 50 | styleRange.foreground = output.getDisplay().getSystemColor(id);
|
---|
| 51 | output.append(str);
|
---|
| 52 | output.setStyleRange(styleRange);
|
---|
| 53 | }
|
---|
[188] | 54 | }
|
---|