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

package lt.monarch.debug;

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

import javax.swing.*;

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

public class SwingListLogEngine extends JDialog
    implements ErrorLogEngine
{

    private void setup()
    {
        setTitle("Log");
        setDefaultCloseOperation(0);
        addWindowListener(new _cls1());
        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 _cls2());
        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 _cls3());
    }

    public void log(final ErrorLogEngine.LogPacket packet)
    {
        SwingUtilities.invokeLater(new _cls4(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();
    }

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









    private class _cls1 extends WindowAdapter
    {

        public void windowClosing(WindowEvent windowevent)
        {
            closeClicked();
        }

        public void constructor$0(SwingListLogEngine swinglistlogengine)
        {
        }

        public _cls1()
        {
            constructor$0(SwingListLogEngine.this);
        }
    }


    private class _cls2
        implements ActionListener
    {

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

        public void constructor$0(SwingListLogEngine swinglistlogengine)
        {
        }

        public _cls2()
        {
            constructor$0(SwingListLogEngine.this);
        }
    }


    private class _cls3
        implements Runnable
    {

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

        public void constructor$0(SwingListLogEngine swinglistlogengine)
        {
        }

        public _cls3()
        {
            constructor$0(SwingListLogEngine.this);
        }
    }


    private class _cls4
        implements Runnable
    {

        private ErrorLogEngine.LogPacket packet;

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

        public void constructor$0(SwingListLogEngine swinglistlogengine)
        {
        }

        public _cls4(ErrorLogEngine.LogPacket pck)
        {
        	packet=pck;
            constructor$0(SwingListLogEngine.this);
        }

		
    }

}
