- Timestamp:
- 08/28/12 16:42:22 (12 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/java-utils-test/src/test/java/de/ugoe/cs/util/console/TextConsoleTest.java
r670 r674 71 71 public void testTraceMsg_1() throws Exception { 72 72 TextConsole fixture = new TextConsole(); 73 fixture.setDebug(true);74 73 String traceMessage = "test"; 75 74 Level traceLevel = Level.WARNING; … … 83 82 @Test 84 83 public void testTraceMsg_2() throws Exception { 85 TextConsole fixture = new TextConsole(); 86 fixture.setDebug(true); 84 TextConsole fixture = new TextConsole(Level.INFO); 87 85 String traceMessage = "test"; 88 86 Level traceLevel = Level.INFO; … … 96 94 @Test 97 95 public void testTraceMsg_3() throws Exception { 98 TextConsole fixture = new TextConsole(); 99 fixture.setDebug(false); 96 TextConsole fixture = new TextConsole(Level.WARNING); 100 97 String traceMessage = "[INFO] test"; 101 98 Level traceLevel = Level.INFO; -
trunk/java-utils/src/main/java/de/ugoe/cs/util/console/TextConsole.java
r633 r674 21 21 public class TextConsole implements IOutputListener, IErrorListener, 22 22 ITraceListener, IExceptionListener { 23 23 24 24 /** 25 * <p> 26 * In the debug mode, trace messages will be printed. 27 * </p> 25 * <p>Defines the trace level used by this console.</p> 28 26 */ 29 private boolean debugMode = true; 27 private Level traceLevel; 28 29 /** 30 * <p> 31 * Creates a new text console and automatically registers it as observer. The trace level is {@link Level#WARNING}. 32 * </p> 33 */ 34 public TextConsole() { 35 this(Level.WARNING); 36 } 30 37 31 38 /** … … 33 40 * Creates a new text console and automatically registers it as observer. 34 41 * </p> 42 * @param traceLevel trace level used by this text console 35 43 */ 36 public TextConsole( ) {44 public TextConsole(Level traceLevel) { 37 45 Console.getInstance().registerOutputListener(this); 38 46 Console.getInstance().registerErrorListener(this); 39 47 Console.getInstance().registerTraceListener(this); 40 48 Console.getInstance().registerExceptionListener(this); 49 this.traceLevel = traceLevel; 41 50 } 42 51 … … 84 93 @Override 85 94 public void traceMsg(String traceMessage, Level level) { 86 if ( debugMode) {95 if (level.intValue()>=traceLevel.intValue()) { 87 96 System.out.print("[" + level.toString() + "] " + traceMessage); 88 97 } … … 95 104 * {@code stdin}. 96 105 * </p> 97 *98 * @param debugMode99 * true, if the application is to run in debug mode, i.e. trace100 * messages will be printed101 106 */ 102 public void run(boolean debugMode) { 103 this.debugMode = debugMode; 107 public void run() { 104 108 CommandExecuter exec = CommandExecuter.getInstance(); 105 109 while (true) { … … 136 140 } 137 141 138 /**139 * <p>140 * Configures if the debug mode of the text console is enabled.141 * </p>142 *143 * @param debug144 * if true, debug mode is enabled.145 */146 public void setDebug(boolean debug) {147 debugMode = debug;148 }149 150 142 } -
trunk/quest-runner/src/main/java/de/ugoe/cs/quest/ui/Runner.java
r660 r674 5 5 import java.io.IOException; 6 6 import java.util.List; 7 import java.util.logging.Level; 7 8 8 9 import joptsimple.OptionException; … … 70 71 parser.accepts("ui", "Allowed values: text, swt").withRequiredArg() 71 72 .ofType(UITYPE.class).defaultsTo(UITYPE.text); 72 OptionSpec<L OG4JTYPE> trace =73 parser.accepts("trace", "Allowed values: enable, disable").withRequiredArg()74 .ofType(L OG4JTYPE.class).defaultsTo(LOG4JTYPE.enable);73 OptionSpec<Level> trace = 74 parser.accepts("trace", "Allowed values: OFF, SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST, ALL").withRequiredArg() 75 .ofType(Level.class).defaultsTo(Level.WARNING); 75 76 OptionSet options = parser.parse(args); 76 77 … … 92 93 { 93 94 case text: 94 TextConsole textConsole = new TextConsole(); 95 if (options.valueOf(trace) == LOG4JTYPE.disable) { 96 textConsole.setDebug(false); 97 } 95 TextConsole textConsole = new TextConsole(options.valueOf(trace)); 98 96 for (String command : startupCommands) { 99 97 CommandExecuter.getInstance().exec(command); 100 98 } 101 textConsole.run( true);99 textConsole.run(); 102 100 break; 103 101 case swt: 104 MainWindow mainWindow = new MainWindow(startupCommands );102 MainWindow mainWindow = new MainWindow(startupCommands, options.valueOf(trace)); 105 103 mainWindow.open(); 106 104 break; -
trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/MainWindow.java
r658 r674 2 2 3 3 import java.util.List; 4 import java.util.logging.Level; 4 5 5 6 import org.eclipse.swt.widgets.Display; … … 29 30 30 31 private List<String> startupCommands; 32 33 private final Level traceLevel; 31 34 32 35 protected Shell shlEventbenchConsole; … … 45 48 protected CommandHistoryDialog historyDialog; 46 49 47 public MainWindow(List<String> startupCommands ) {50 public MainWindow(List<String> startupCommands, Level traceLevel) { 48 51 this.startupCommands = startupCommands; 52 this.traceLevel = traceLevel; 49 53 } 50 54 … … 59 63 Display display = Display.getDefault(); 60 64 createContents(); 61 new SWTConsole(consoleTabComposite.textConsoleOutput );65 new SWTConsole(consoleTabComposite.textConsoleOutput, traceLevel); 62 66 historyDialog = new CommandHistoryDialog(shlEventbenchConsole, SWT.NONE); 63 67 shlEventbenchConsole.open(); -
trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/SWTConsole.java
r655 r674 18 18 { 19 19 20 StyledText output; 20 private StyledText output; 21 22 private Level traceLevel; 21 23 22 public SWTConsole(StyledText styledText ) {24 public SWTConsole(StyledText styledText, Level traceLevel) { 23 25 Console.getInstance().registerOutputListener(this); 24 26 Console.getInstance().registerErrorListener(this); … … 26 28 Console.getInstance().registerCommandListener(this); 27 29 this.output = styledText; 30 this.traceLevel = traceLevel; 28 31 } 29 32 … … 40 43 @Override 41 44 public void traceMsg(String traceMessage, Level level) { 42 appendColored("[" + level.toString() + "] " + traceMessage, SWT.COLOR_BLUE); 45 if( level.intValue()>=traceLevel.intValue()) { 46 appendColored("[" + level.toString() + "] " + traceMessage, SWT.COLOR_BLUE); 47 } 43 48 } 44 49
Note: See TracChangeset
for help on using the changeset viewer.