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