// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) fieldsfirst 
// Source File Name:   SwingListLogEngine.java

package lt.monarch.debug;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

// Referenced classes of package lt.monarch.debug:
//			ErrorLogEngine, SwingLogTreeModel

public class SwingListLogEngine extends JDialog
	implements ErrorLogEngine
{

	private SwingLogTreeModel log;
	private JButton button;
	private boolean initialized;
	private boolean logEmpty;
	private boolean logClosed;
	private boolean disposeOnLogClose;

	private void setup()
	{
		setTitle("Log");
		setDefaultCloseOperation(0);
		addWindowListener(new WindowAdapter()
	{

		public void windowClosing(WindowEvent windowevent)
		{
			closeClicked();
		}
	});
		JPanel jpanel = (JPanel)getContentPane();
		jpanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(), BorderFactory.createEmptyBorder(5, 5, 5, 5)));
		log = new SwingLogTreeModel();
		JTree jtree = new JTree(log);
		jtree.setCellRenderer(new SwingLogTreeModel.CellRenderer());
		jtree.setRootVisible(false);
		JScrollPane jscrollpane = new JScrollPane();
		jscrollpane.getViewport().setView(jtree);
		jscrollpane.getViewport().setBackingStoreEnabled(false);
		JPanel jpanel1 = new JPanel(new FlowLayout(2));
		jpanel1.setBorder(BorderFactory.createEtchedBorder());
		button = new JButton();
		jpanel1.add(button);
		jpanel.add("Center", jscrollpane);
		jpanel.add("South", jpanel1);
		button.addActionListener(new ActionListener()
	{

		public void actionPerformed(ActionEvent actionevent)
		{
			if(!logEmpty)
			{
				log.clear();
				logEmpty = true;
				updateButtons();
				return;
			} else
			{
				closeClicked();
				return;
			}
		}
	});
		updateButtons();
	}

	private void updateButtons()
	{
		if(logEmpty && button.getText() != "Close")
			button.setText("Close");
		if(!logEmpty && button.getText() != "Clear")
			button.setText("Clear");
	}

	private void closeClicked()
	{
		if(logClosed)
			dispose();
		else
			setVisible(false);
	}

	public void setDisposeOnLogClose(boolean flag)
	{
		disposeOnLogClose = flag;
	}

	public void close()
	{
		if(disposeOnLogClose)
			SwingUtilities.invokeLater(new Runnable()
	{

		public void run()
		{
			logClosed = true;
			dispose();
		}
	});
	}

	public void log(final ErrorLogEngine.LogPacket packet)
	{
		SwingUtilities.invokeLater(new Runnable()
	{

		public void run()
		{
			safeLog(packet);
		}
	});
	}

	private void safeLog(ErrorLogEngine.LogPacket logpacket)
	{
		log.add(logpacket);
		logEmpty = false;
		updateButtons();
		if(!initialized)
		{
			initialized = true;
			setBounds(new Rectangle(getToolkit().getScreenSize().width / 6, getToolkit().getScreenSize().height / 6, getToolkit().getScreenSize().width / 2, getToolkit().getScreenSize().height / 3));
		}
		if(!isVisible())
			show();
	}

	public SwingListLogEngine()
	{
		this(null);
		setup();
	}

	public SwingListLogEngine(Frame frame)
	{
		super(frame);
		initialized = false;
		logEmpty = true;
		logClosed = false;
		disposeOnLogClose = false;
		setup();
	}









	





	


	
	

}
