// 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:   GlobalTools.java

import java.applet.Applet;
import java.awt.FileDialog;
import java.awt.Frame;
import java.io.*;
import lt.ktu.gmj.*;

import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JApplet;

public class GlobalTools
{

    private GlobalTools()
    {
    }

    public void deleteInstance()
    {
        gSelf = null;
    }

    protected void finalize()
        throws Throwable
    {
        deleteInstance();
        super.finalize();
    }

    public static JApplet getApplet()
    {
        return gApplet;
    }

    public static String getCodeBase()
    {
        if (gCodeBase == null)
        {
            gCodeBase = "";
            if (getApplet() != null)
            {
                URL url = getApplet().getCodeBase();
                gCodeBase = url.toString();
            }
        }
        System.out.println("CodeBase=" + gCodeBase);
        return gCodeBase;
    }

    public static String getDocumentBase()
    {
        if (gDocumentBase == null)
        {
            gDocumentBase = "";
            if (getApplet() != null)
            {
                URL url = getApplet().getDocumentBase();
                gDocumentBase = url.toString();
            }
        }
        System.out.println("DocumentBase=" + gDocumentBase);
        return gDocumentBase;
    }

    public static FileDialog getFileDialog()
    {
        if (filedialog == null)
            filedialog = new FileDialog(getFrame());
        return filedialog;
    }

    static Frame getFrame()
    {
        if (frame == null)
            frame = new Frame();
        return frame;
    }

    static InputStreamReader getInputStreamReader(String s)
        throws IOException
    {
        Object obj = null;
        try
        {
            if (obj == null)
                obj = new InputStreamReader((new URL(s)).openStream());
        }
        catch (MalformedURLException _ex) { }
        catch (IOException _ex) { }
        try
        {
            if (obj == null)
                obj = new FileReader(s);
        }
        catch (IOException _ex) { }
        if (obj == null)
            throw new IOException("Cann't open input stream " + s);
        else
            return ((InputStreamReader) (obj));
    }

    public static GlobalTools getInstance()
    {
        if (gSelf == null)
            gSelf = new GlobalTools();
        return gSelf;
    }

    public static void setApplet(JApplet japplet)
    {
        gApplet = japplet;
    }

    public static synchronized void showError(String s)
    {
        (new ShowMessage(getFrame(), s.toString(), "Error", true)).show();
    }

    public static synchronized void showError(Throwable throwable)
    {
        throwable.printStackTrace();
        ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
        PrintWriter printwriter = new PrintWriter(bytearrayoutputstream);
        throwable.printStackTrace(printwriter);
        byte abyte0[] = bytearrayoutputstream.toByteArray();
        String s = new String(abyte0);
        (new ShowMessage(getFrame(), s, throwable.toString(), true)).show();
    }

    public static void showMsgFromUrl(String s, String s1)
    {
        String s2 = "";
        try
        {
            BufferedReader bufferedreader = new BufferedReader(getInputStreamReader(s1));
            String s3;
            while ((s3 = bufferedreader.readLine()) != null) 
                s2 = s2 + s3 + "\n";
            bufferedreader.close();
        }
        catch (IOException _ex) { }
        (new ShowMessage(getFrame(), s2, s, true)).show();
    }

    static JApplet gApplet = null;
    static String gCodeBase = null;
    static String gDocumentBase = null;
    private static GlobalTools gSelf = null;
    static FileDialog filedialog = null;
    static Frame frame = null;

}
