- Timestamp:
- 09/26/11 22:55:19 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaHelperLib/src/de/ugoe/cs/util/console/Console.java
r186 r199 1 1 package de.ugoe.cs.util.console; 2 2 3 import java.util. ArrayList;4 import java.util.Li st;3 import java.util.Collection; 4 import java.util.LinkedHashSet; 5 5 6 6 import de.ugoe.cs.util.StringTools; 7 import de.ugoe.cs.util.console.listener.ICommandListener; 8 import de.ugoe.cs.util.console.listener.IErrorListener; 9 import de.ugoe.cs.util.console.listener.IExceptionListener; 10 import de.ugoe.cs.util.console.listener.IOutputListener; 11 import de.ugoe.cs.util.console.listener.ITraceListener; 7 12 8 13 /** … … 26 31 public final class Console { 27 32 28 /** 29 * <p> 30 * List of observers. 31 * </p> 32 */ 33 private List<ConsoleObserver> observers; 33 private Collection<IOutputListener> outputListener; 34 private Collection<IErrorListener> errorListener; 35 private Collection<ITraceListener> traceListener; 36 private Collection<ICommandListener> commandListener; 37 private Collection<IExceptionListener> exceptionListener; 34 38 35 39 /** … … 61 65 */ 62 66 private Console() { 63 observers = new ArrayList<ConsoleObserver>(); 67 outputListener = new LinkedHashSet<IOutputListener>(); 68 errorListener = new LinkedHashSet<IErrorListener>(); 69 traceListener = new LinkedHashSet<ITraceListener>(); 70 commandListener = new LinkedHashSet<ICommandListener>(); 71 exceptionListener = new LinkedHashSet<IExceptionListener>(); 64 72 } 65 73 … … 69 77 * </p> 70 78 * 79 * @deprecated use registerXYZListener instead 71 80 * @param observer 72 81 * observer to be added 73 82 */ 74 83 public void registerObserver(ConsoleObserver observer) { 75 observers.add(observer); 84 registerOutputListener(observer); 85 registerErrorListener(observer); 86 registerTraceListener(observer); 87 registerCommandListener(observer); 88 registerExceptionListener(observer); 89 } 90 91 /** 92 * <p> 93 * Registers an output listener. 94 * </p> 95 * 96 * @param listener 97 * listener that is registered 98 */ 99 public void registerOutputListener(IOutputListener listener) { 100 outputListener.add(listener); 101 } 102 103 /** 104 * <p> 105 * Registers an error listener. 106 * </p> 107 * 108 * @param listener 109 * listener that is registered 110 */ 111 public void registerErrorListener(IErrorListener listener) { 112 errorListener.add(listener); 113 } 114 115 /** 116 * <p> 117 * Registers a trace listener. 118 * </p> 119 * 120 * @param listener 121 * listener that is registered 122 */ 123 public void registerTraceListener(ITraceListener listener) { 124 traceListener.add(listener); 125 } 126 127 /** 128 * <p> 129 * Registers a command listener. 130 * </p> 131 * 132 * @param listener 133 * listener that is registered 134 */ 135 public void registerCommandListener(ICommandListener listener) { 136 commandListener.add(listener); 137 } 138 139 /** 140 * <p> 141 * Registers an exception listener. 142 * </p> 143 * 144 * @param listener 145 * listener that is registered 146 */ 147 public void registerExceptionListener(IExceptionListener listener) { 148 exceptionListener.add(listener); 76 149 } 77 150 … … 81 154 * </p> 82 155 * 156 * @deprecated use removeXYZListener instead 83 157 * @param observer 84 158 * observer to be removed 85 159 */ 86 160 public void deleteObserver(ConsoleObserver observer) { 87 observers.remove(observer); 161 removeOutputListener(observer); 162 removeErrorListener(observer); 163 removeTraceListener(observer); 164 removeCommandListener(observer); 165 removeExceptionListener(observer); 166 } 167 168 /** 169 * <p> 170 * Removes an output listener. 171 * </p> 172 * 173 * @param listener 174 * listener that is removed 175 */ 176 public void removeOutputListener(IOutputListener listener) { 177 outputListener.remove(listener); 178 } 179 180 /** 181 * <p> 182 * Removes an error listener. 183 * </p> 184 * 185 * @param listener 186 * listener that is removed 187 */ 188 public void removeErrorListener(IErrorListener listener) { 189 errorListener.remove(listener); 190 } 191 192 /** 193 * <p> 194 * Removes an trace listener. 195 * </p> 196 * 197 * @param listener 198 * listener that is removed 199 */ 200 public void removeTraceListener(ITraceListener listener) { 201 traceListener.remove(listener); 202 } 203 204 /** 205 * <p> 206 * Removes a command listener. 207 * </p> 208 * 209 * @param listener 210 * listener that is removed 211 */ 212 public void removeCommandListener(ICommandListener listener) { 213 commandListener.remove(listener); 214 } 215 216 /** 217 * <p> 218 * Removes an exception listener. 219 * </p> 220 * 221 * @param listener 222 * listener that is removed 223 */ 224 public void removeExceptionListener(IExceptionListener listener) { 225 exceptionListener.remove(listener); 88 226 } 89 227 … … 101 239 getInstance(); 102 240 } 103 for ( ConsoleObserver observer : theInstance.observers) {241 for (IOutputListener observer : theInstance.outputListener) { 104 242 observer.updateText(msg); 105 243 } … … 119 257 getInstance(); 120 258 } 121 for ( ConsoleObserver observer : theInstance.observers) {259 for (IOutputListener observer : theInstance.outputListener) { 122 260 observer.updateText(msg + StringTools.ENDLINE); 123 261 } … … 137 275 getInstance(); 138 276 } 139 for ( ConsoleObserver observer : theInstance.observers) {277 for (IErrorListener observer : theInstance.errorListener) { 140 278 observer.errStream(errMsg); 141 279 } … … 155 293 getInstance(); 156 294 } 157 for ( ConsoleObserver observer : theInstance.observers) {295 for (IErrorListener observer : theInstance.errorListener) { 158 296 observer.errStream(errMsg + StringTools.ENDLINE); 159 297 } … … 172 310 getInstance(); 173 311 } 174 for ( ConsoleObserver observer : theInstance.observers) {312 for (IExceptionListener observer : theInstance.exceptionListener) { 175 313 observer.printStacktrace(e); 176 314 } … … 190 328 getInstance(); 191 329 } 192 for ( ConsoleObserver observer : theInstance.observers) {330 for (ITraceListener observer : theInstance.traceListener) { 193 331 observer.trace(traceMsg); 194 332 } … … 209 347 getInstance(); 210 348 } 211 for ( ConsoleObserver observer : theInstance.observers) {349 for (ITraceListener observer : theInstance.traceListener) { 212 350 observer.trace(traceMsg + StringTools.ENDLINE); 213 351 } … … 226 364 getInstance(); 227 365 } 228 for ( ConsoleObserver observer : theInstance.observers) {366 for (ICommandListener observer : theInstance.commandListener) { 229 367 observer.commandNotification(command); 230 368 }
Note: See TracChangeset
for help on using the changeset viewer.