001: /*
002: Launch4j (http://launch4j.sourceforge.net/)
003: Cross-platform Java application wrapper for creating Windows native executables.
004:
005: Copyright (c) 2004, 2007 Grzegorz Kowal
006:
007: All rights reserved.
008:
009: Redistribution and use in source and binary forms, with or without modification,
010: are permitted provided that the following conditions are met:
011:
012: * Redistributions of source code must retain the above copyright notice,
013: this list of conditions and the following disclaimer.
014: * Redistributions in binary form must reproduce the above copyright notice,
015: this list of conditions and the following disclaimer in the documentation
016: and/or other materials provided with the distribution.
017: * Neither the name of the Launch4j nor the names of its contributors
018: may be used to endorse or promote products derived from this software without
019: specific prior written permission.
020:
021: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
022: "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
023: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
024: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
025: CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
026: EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
027: PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
028: PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
029: LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
030: NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
031: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
032: */
033:
034: /*
035: * Created on May 12, 2005
036: */
037: package net.sf.launch4j;
038:
039: import javax.swing.JTextArea;
040: import javax.swing.SwingUtilities;
041:
042: /**
043: * @author Copyright (C) 2005 Grzegorz Kowal
044: */
045: public abstract class Log {
046: private static final Log _consoleLog = new ConsoleLog();
047: private static final Log _antLog = new AntLog();
048:
049: public abstract void clear();
050:
051: public abstract void append(String line);
052:
053: public static Log getConsoleLog() {
054: return _consoleLog;
055: }
056:
057: public static Log getAntLog() {
058: return _antLog;
059: }
060:
061: public static Log getSwingLog(JTextArea textArea) {
062: return new SwingLog(textArea);
063: }
064: }
065:
066: class ConsoleLog extends Log {
067: public void clear() {
068: System.out.println("\n");
069: }
070:
071: public void append(String line) {
072: System.out.println("launch4j: " + line);
073: }
074: }
075:
076: class AntLog extends Log {
077: public void clear() {
078: System.out.println("\n");
079: }
080:
081: public void append(String line) {
082: System.out.println(line);
083: }
084: }
085:
086: class SwingLog extends Log {
087: private final JTextArea _textArea;
088:
089: public SwingLog(JTextArea textArea) {
090: _textArea = textArea;
091: }
092:
093: public void clear() {
094: SwingUtilities.invokeLater(new Runnable() {
095: public void run() {
096: _textArea.setText("");
097: }
098: });
099: }
100:
101: public void append(final String line) {
102: SwingUtilities.invokeLater(new Runnable() {
103: public void run() {
104: _textArea.append(line + "\n");
105: }
106: });
107: }
108: }
|