1 | package de.ugoe.cs.eventbench.swt;
|
---|
2 |
|
---|
3 | import org.eclipse.swt.SWT;
|
---|
4 | import org.eclipse.swt.custom.StyleRange;
|
---|
5 | import org.eclipse.swt.custom.StyledText;
|
---|
6 |
|
---|
7 | import de.ugoe.cs.util.StringTools;
|
---|
8 | import de.ugoe.cs.util.console.Console;
|
---|
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;
|
---|
13 |
|
---|
14 | public class SWTConsole implements IOutputListener, IErrorListener, ITraceListener, ICommandListener {
|
---|
15 |
|
---|
16 | StyledText output;
|
---|
17 |
|
---|
18 | public SWTConsole(StyledText styledText) {
|
---|
19 | Console.getInstance().registerOutputListener(this);
|
---|
20 | Console.getInstance().registerErrorListener(this);
|
---|
21 | Console.getInstance().registerTraceListener(this);
|
---|
22 | Console.getInstance().registerCommandListener(this);
|
---|
23 | this.output = styledText;
|
---|
24 | }
|
---|
25 |
|
---|
26 | @Override
|
---|
27 | public void outputMsg(String newMessage) {
|
---|
28 | output.append(newMessage);
|
---|
29 | }
|
---|
30 |
|
---|
31 | @Override
|
---|
32 | public void errorMsg(String errMessage) {
|
---|
33 | appendColored(errMessage, SWT.COLOR_RED);
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Override
|
---|
37 | public void traceMsg(String traceMessage) {
|
---|
38 | appendColored(traceMessage, SWT.COLOR_BLUE);
|
---|
39 | }
|
---|
40 |
|
---|
41 | @Override
|
---|
42 | public void commandNotification(String command) {
|
---|
43 | output.append("> " + command + StringTools.ENDLINE);
|
---|
44 | }
|
---|
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 | }
|
---|
54 | }
|
---|