1 /* 2 * Copyright the original author or authors. 3 * 4 * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.mozilla.org/MPL/MPL-1.1.html 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 import org.as2lib.util.Stringifier; 18 import org.as2lib.env.log.LogHandler; 19 import org.as2lib.env.log.LogMessage; 20 import org.as2lib.env.log.handler.AbstractLogHandler; 21 22 /** 23 * {@code MusicTheoryHandler} writes messages to the SWF Console from Ricci Adams' 24 * Musictheory. 25 * 26 * @author Simon Wacker 27 * @see org.as2lib.env.log.logger.MusicTheoryLogger 28 * @see <a href="http://source.musictheory.net/swfconsole">SWF Console</a> 29 */ 30 class org.as2lib.env.log.handler.MusicTheoryHandler extends AbstractLogHandler implements LogHandler { 31 32 /** Holds a music theory handler instance. */ 33 private static var musicTheoryHandler:MusicTheoryHandler; 34 35 /** 36 * Returns an instance of this class. 37 * 38 * <p>This method always returns the same instance. 39 * 40 * <p>The {@code messageStringifier} argument is only recognized on first 41 * invocation of this method. 42 * 43 * @param messageStringifier (optional) the log message stringifier to be used by 44 * the returned handler 45 * @return a music theory handler 46 */ 47 public static function getInstance(messageStringifier):MusicTheoryHandler { 48 if (!musicTheoryHandler) musicTheoryHandler = new MusicTheoryHandler(messageStringifier); 49 return musicTheoryHandler; 50 } 51 52 /** 53 * Constructs a new {@code MusicTheoryHandler} instance. 54 * 55 * <p>You can use one and the same instance for multiple loggers. So think about 56 * using the handler returned by the static {@link #getInstance} method. Using 57 * this instance prevents the instantiation of unnecessary music theory handlers 58 * and saves storage. 59 * 60 * @param messageStringifier (optional) the log message stringifier to use 61 */ 62 public function MusicTheoryHandler(messageStringifier:Stringifier) { 63 super (messageStringifier); 64 } 65 66 /** 67 * Writes the passed-in {@code message} to the Musictheory SWF Console. 68 * 69 * <p>The string representation of the {@code message} to log is obtained via 70 * the {@code convertMessage} method. 71 * 72 * @param message the log message to write 73 */ 74 public function write(message:LogMessage):Void { 75 getURL("javascript:showText('" + convertMessage(message) + "')"); 76 } 77 78 }