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