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

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