Changeset 199 for trunk/JavaHelperLib/src
- Timestamp:
- 09/26/11 22:55:19 (13 years ago)
- Location:
- trunk/JavaHelperLib/src/de/ugoe/cs/util/console
- Files:
-
- 6 added
- 3 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 } -
trunk/JavaHelperLib/src/de/ugoe/cs/util/console/ConsoleObserver.java
r186 r199 1 1 package de.ugoe.cs.util.console; 2 3 import de.ugoe.cs.util.console.listener.ICommandListener; 4 import de.ugoe.cs.util.console.listener.IErrorListener; 5 import de.ugoe.cs.util.console.listener.IExceptionListener; 6 import de.ugoe.cs.util.console.listener.IOutputListener; 7 import de.ugoe.cs.util.console.listener.ITraceListener; 2 8 3 9 /** … … 7 13 * 8 14 * @author Steffen Herbold 9 * @version 1.0 15 * @version 2.0 16 * @deprecated Use listeners defined in the package de.ugoe.cs.console.listeners instead. 10 17 */ 11 public interface ConsoleObserver { 12 13 /** 14 * <p> 15 * If a new message is send to the console, all observers are updated using 16 * this method. 17 * </p> 18 * 19 * @param newMessage 20 * message that was send to the console. 21 */ 22 public void updateText(String newMessage); 23 24 /** 25 * <p> 26 * Send messages to the error stream of all observers. 27 * </p> 28 * 29 * @param errMessage 30 * error message 31 */ 32 public void errStream(String errMessage); 33 34 /** 35 * <p> 36 * Send messages to the trace stream of all observers. 37 * </p> 38 * 39 * @param traceMesssage 40 * error message 41 */ 42 public void trace(String traceMessage); 43 44 /** 45 * <p> 46 * Prints the stack trace of an exception. 47 * </p> 48 * 49 * @param e 50 * exception whose stack trace is to be printed 51 */ 52 public void printStacktrace(Exception e); 53 54 /** 55 * <p> 56 * Receives the command strings of all executed commands. 57 * </p> 58 * 59 * @param command 60 * string of the command. 61 */ 62 public void commandNotification(String command); 18 public interface ConsoleObserver extends ITraceListener, IOutputListener, IErrorListener, ICommandListener, IExceptionListener { 63 19 64 20 } -
trunk/JavaHelperLib/src/de/ugoe/cs/util/console/TextConsole.java
r186 r199 2 2 3 3 import java.io.IOException; 4 5 import de.ugoe.cs.util.console.listener.IErrorListener; 6 import de.ugoe.cs.util.console.listener.IExceptionListener; 7 import de.ugoe.cs.util.console.listener.IOutputListener; 8 import de.ugoe.cs.util.console.listener.ITraceListener; 4 9 5 10 /** … … 12 17 * @version 1.0 13 18 */ 14 public class TextConsole implements ConsoleObserver { 19 public class TextConsole implements IOutputListener, IErrorListener, 20 ITraceListener, IExceptionListener { 15 21 16 22 /** … … 27 33 */ 28 34 public TextConsole() { 29 Console.getInstance().registerObserver(this); 35 Console.getInstance().registerOutputListener(this); 36 Console.getInstance().registerErrorListener(this); 37 Console.getInstance().registerTraceListener(this); 38 Console.getInstance().registerExceptionListener(this); 30 39 } 31 40 … … 118 127 } 119 128 120 /**121 * <p>122 * The {@link TextConsole} ignores this notification.123 * </p>124 *125 * @see de.ugoe.cs.util.console.ConsoleObserver#commandNotification(java.lang.String)126 */127 @Override128 public void commandNotification(String command) {129 // ignores the notification130 }131 129 }
Note: See TracChangeset
for help on using the changeset viewer.