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

package lt.ktu.gmj.ui;

import lt.ktu.gmj.Method;
import lt.monarch.debug.ErrorLog;

// Referenced classes of package lt.ktu.gmj.ui:
//			MinimizerDirector, ResultSet

public class Minimizer extends Thread
{

	protected ResultSet set;
	protected MinimizerDirector director;
	protected boolean suspended;

	public Minimizer(MinimizerDirector minimizerdirector, ResultSet resultset)
	{
		director = minimizerdirector;
		set = resultset;
		setPriority(4);
		set.startLog();
	}

	public boolean isSuspended()
	{
		return suspended;
	}

	public void resumeMinimizer()
	{
		suspended = false;
		set.resume();
		director.minimizerStateChanged();
	}

	public void run()
	{
		try
		{
			lt.ktu.gmj.Result result = set.method.run(set, set.task);
			set.setResult(result);
		}
		catch(lt.ktu.gmj.ResultLogger.AbortedError _ex) { }
		catch(Exception exception)
		{
			ErrorLog.defaultLog().log("Method execution failed", exception);
		}
		director.minimizationComplete();
	}

	public void startMinimizer()
	{
		suspended = false;
		set.resume();
		start();
		director.minimizerStateChanged();
	}

	public synchronized void stopMinimizer()
	{
		if(isAlive())
		{
			suspended = false;
			set.blockOn(this);
			interrupt();
		}
	}

	public void suspendMinimizer()
	{
		suspended = true;
		set.blockOn(this);
		director.minimizerStateChanged();
	}
}
