/*
 * @(#)Log.java
 *
 * This file is part of webCDwriter - Network CD Writing.
 *
 * Copyright (C) 1999-2002 Jörg P. M. Haeger
 *
 * webCDwriter is free software. See CDcreator.java for details.
 *
 * Jörg Haeger, 10.08.2000
 */

import javax.swing.*;

public class Log {
	private static String buf = "";
	private static JTextArea textArea = new JTextArea();
	private static JScrollPane scrollPane = init();

	public static void clear() {
		textArea.setText("");
	}

	public static JComponent getView() {
		return scrollPane;
	}

	private static JScrollPane init() {
		scrollPane = new JScrollPane(textArea);
		scrollPane.setHorizontalScrollBarPolicy(
			JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		return scrollPane;
	}

	public static void put(String str) {
		synchronized(buf) {
			buf = buf + str + "\n";
		}
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				put2();
			}
		});
	}

	private static void put2() {
		synchronized(buf) {
			textArea.append(buf);
			buf = "";
		}
		JScrollBar scrollBar = scrollPane.getVerticalScrollBar();
		scrollBar.setValue(scrollBar.getMaximum());
	}
}
