source: trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/swt/SWTConsole.java @ 359

Last change on this file since 359 was 238, checked in by sherbold, 13 years ago
  • beautification of SWT console output; trace messages are now displayed in blue, errors in red
  • Property svn:mime-type set to text/plain
File size: 1.6 KB
Line 
1package de.ugoe.cs.eventbench.swt;
2
3import org.eclipse.swt.SWT;
4import org.eclipse.swt.custom.StyleRange;
5import org.eclipse.swt.custom.StyledText;
6
7import de.ugoe.cs.util.StringTools;
8import de.ugoe.cs.util.console.Console;
9import de.ugoe.cs.util.console.listener.ICommandListener;
10import de.ugoe.cs.util.console.listener.IErrorListener;
11import de.ugoe.cs.util.console.listener.IOutputListener;
12import de.ugoe.cs.util.console.listener.ITraceListener;
13
14public 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}
Note: See TracBrowser for help on using the repository browser.