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