Changeset 250 for trunk/JavaHelperLib/src/de/ugoe/cs/util
- Timestamp:
- 10/10/11 22:15:34 (13 years ago)
- Location:
- trunk/JavaHelperLib/src/de/ugoe/cs/util/console
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaHelperLib/src/de/ugoe/cs/util/console/Console.java
r210 r250 71 71 * </p> 72 72 */ 73 private static Console theInstance = n ull;73 private static Console theInstance = new Console(); 74 74 75 75 /** … … 82 82 */ 83 83 public static Console getInstance() { 84 if (theInstance == null) {85 theInstance = new Console();86 }87 84 return theInstance; 88 85 } … … 90 87 /** 91 88 * <p> 89 * Resets the Console by creating a new instance that has no registered 90 * observers. 91 * </p> 92 */ 93 public static void reset() { 94 theInstance.init(); 95 } 96 97 /** 98 * <p> 92 99 * Creates a new Console. Private to prevent multiple instances (Singleton). 93 100 * </p> 94 101 */ 95 102 private Console() { 103 init(); 104 } 105 106 /** 107 * <p> 108 * Initializes the console. 109 * </p> 110 */ 111 private void init() { 96 112 outputListener = new LinkedHashSet<IOutputListener>(); 97 113 errorListener = new LinkedHashSet<IErrorListener>(); … … 257 273 /** 258 274 * <p> 275 * Checks if a listener is registered. 276 * </p> 277 * 278 * @param listener 279 * listener that is checked 280 * @return true, is listener is registered; false, otherwise 281 */ 282 public boolean hasOutputListener(IOutputListener listener) { 283 return outputListener.contains(listener); 284 } 285 286 /** 287 * <p> 288 * Checks if a listener is registered. 289 * </p> 290 * 291 * @param listener 292 * listener that is checked 293 * @return true, is listener is registered; false, otherwise 294 */ 295 public boolean hasErrorListener(IErrorListener listener) { 296 return errorListener.contains(listener); 297 } 298 299 /** 300 * <p> 301 * Checks if a listener is registered. 302 * </p> 303 * 304 * @param listener 305 * listener that is checked 306 * @return true, is listener is registered; false, otherwise 307 */ 308 public boolean hasTraceListener(ITraceListener listener) { 309 return traceListener.contains(listener); 310 } 311 312 /** 313 * <p> 314 * Checks if a listener is registered. 315 * </p> 316 * 317 * @param listener 318 * listener that is checked 319 * @return true, is listener is registered; false, otherwise 320 */ 321 public boolean hasCommandListener(ICommandListener listener) { 322 return commandListener.contains(listener); 323 } 324 325 /** 326 * <p> 327 * Checks if a listener is registered. 328 * </p> 329 * 330 * @param listener 331 * listener that is checked 332 * @return true, is listener is registered; false, otherwise 333 */ 334 public boolean hasExceptionListener(IExceptionListener listener) { 335 return exceptionListener.contains(listener); 336 } 337 338 /** 339 * <p> 259 340 * Sends a message to all observers containing the message that was passed 260 341 * to this function. … … 265 346 */ 266 347 public static void print(String msg) { 267 if (theInstance == null) {268 getInstance();269 }270 348 for (IOutputListener observer : theInstance.outputListener) { 271 349 observer.outputMsg(msg); … … 283 361 */ 284 362 public static void println(String msg) { 285 if (theInstance == null) {286 getInstance();287 }288 363 for (IOutputListener observer : theInstance.outputListener) { 289 364 observer.outputMsg(msg + StringTools.ENDLINE); … … 301 376 */ 302 377 public static void printerr(String errMsg) { 303 if (theInstance == null) {304 getInstance();305 }306 378 for (IErrorListener observer : theInstance.errorListener) { 307 379 observer.errorMsg(errMsg); … … 319 391 */ 320 392 public static void printerrln(String errMsg) { 321 if (theInstance == null) {322 getInstance();323 }324 393 for (IErrorListener observer : theInstance.errorListener) { 325 394 observer.errorMsg(errMsg + StringTools.ENDLINE); … … 336 405 */ 337 406 public static void logException(Exception e) { 338 if (theInstance == null) {339 getInstance();340 }341 407 for (IExceptionListener observer : theInstance.exceptionListener) { 342 408 observer.logException(e); … … 354 420 */ 355 421 public static void trace(String traceMsg) { 356 if (theInstance == null) {357 getInstance();358 }359 422 for (ITraceListener observer : theInstance.traceListener) { 360 423 observer.traceMsg(traceMsg); … … 373 436 */ 374 437 public static void traceln(String traceMsg) { 375 if (theInstance == null) {376 getInstance();377 }378 438 for (ITraceListener observer : theInstance.traceListener) { 379 439 observer.traceMsg(traceMsg + StringTools.ENDLINE); … … 390 450 */ 391 451 static void commandNotification(String command) { 392 if (theInstance == null) {393 getInstance();394 }395 452 for (ICommandListener observer : theInstance.commandListener) { 396 453 observer.commandNotification(command); -
trunk/JavaHelperLib/src/de/ugoe/cs/util/console/FileOutputListener.java
r243 r250 39 39 * </p> 40 40 */ 41 FileWriter writer ;41 FileWriter writer = null; 42 42 43 43 /** … … 78 78 public void stop() { 79 79 Console.getInstance().removeOutputListener(this); 80 try { 81 writer.close(); 82 } catch (IOException e) { 83 Console.printerrln("Failed to close file " + filename + ": " 84 + e.getMessage()); 80 if( writer!=null ) { 81 try { 82 writer.close(); 83 writer = null; 84 } catch (IOException e) { 85 Console.printerrln("Failed to close file " + filename + ": " 86 + e.getMessage()); 87 } 85 88 } 86 89 } … … 95 98 @Override 96 99 public void outputMsg(String newMessage) { 97 try { 98 writer.write(newMessage); 99 } catch (IOException e) { 100 if (!failureLogged) { 101 Console.printerrln("FileOutpustListener for file " + filename 102 + " broken: " + e.getMessage()); 103 failureLogged = true; 100 if( writer!=null ) { 101 try { 102 writer.write(newMessage); 103 } catch (IOException e) { 104 if (!failureLogged) { 105 Console.printerrln("FileOutpustListener for file " + filename 106 + " broken: " + e.getMessage()); 107 failureLogged = true; 108 } 104 109 } 105 110 } 106 111 } 107 112 113 /** 114 * <p> 115 * Returns the name of the log file used by this listener. 116 * </p> 117 * 118 * @return name of the log file 119 */ 120 public String getFilename() { 121 return filename; 122 } 123 108 124 } -
trunk/JavaHelperLib/src/de/ugoe/cs/util/console/TextConsole.java
r210 r250 126 126 return new String(buffer); 127 127 } 128 129 /** 130 * <p> 131 * Configures if the debug mode of the text console is enabled. 132 * </p> 133 * @param debug if true, debug mode is enabled. 134 */ 135 public void setDebug(boolean debug) { 136 debugMode = debug; 137 } 128 138 129 139 }
Note: See TracChangeset
for help on using the changeset viewer.