import java.awt.*;
import polyCanvas;

public class T2Q extends java.applet.Applet
{
    private polyCanvas pC;
    Button reset;
    TextField tf;
    /*    Button Continue;
	  Button CounterExample;*/
    // 3-Coins: Run algorithm continuously: vars
    /*Button Run3Coins;*/
    // Step through 3-coins: variables
    /*Button Step3Coins; */
    boolean Running = false;
    boolean ReadyToStart = false;
    boolean HaveData = false;
    
    public boolean action(Event evt, Object obj)
    {
	if (evt.target.equals(reset))
	    {
		pC.reset();
		/*Continue.setLabel("Proceed with my input");
		  Continue.show();
		  CounterExample.setLabel("Counter Example");
		  CounterExample.show();
		  Run3Coins.hide();
		  Step3Coins.hide();*/
		Running = false;
		ReadyToStart = false;/*
				       Run3Coins.setLabel("3-Coins: RUN");
				       Step3Coins.setLabel("3-Coins: STEP");*/
		/*tf.setText("Have fun...");*/
		pC.UsingExample = false;
		HaveData = false;
		pC.reset();
		return true;
	    }
	/*
	  if (evt.target.equals(Continue))
	  {
	  tf.setText("Here's the mean of the points you entered.");*/
	/* pC.drawPoint((new point(100, 100)), Color.red);	*/
	
	/*
	  if(HaveData)
	  {
	  tf.setText("Your original simple polygon");
	  if(pC.UsingExample)
	  {pC.DrawPolygon(pC.CEx,Color.blue);}
	  else{pC.DrawPolygon(pC.P,Color.blue);}
	  }
	  else
	  {
	  if (pC.P.closed)
	  {
	  Continue.hide();
	  CounterExample.hide();
	  Run3Coins.show();
	  Step3Coins.show();
	  
	  tf.setText("Original polygon");
	  
	  ReadyToStart = true;
	  Running = false;
	  }
	  }
	*/
	
	/* }*/
	/*
	  if (evt.target.equals(CounterExample))
	  {
	  if(HaveData)
	  {
	  tf.setText("Convex polygon computed by Sklanksy's Algorithm");
	  if(pC.UsingExample)
	  {pC.DrawConvexPolygon(pC.CEx);}
	  else{pC.DrawConvexPolygon(pC.P);}
	  }
	  else
	  {
	  pC.reset();
	  Continue.hide();
	  CounterExample.hide();
	  Step3Coins.show();
	  Run3Coins.show();
	  tf.setText("a fucking Counter Example: click RUN or STEP to start");
	  pC.CounterExample(); 
	  ReadyToStart = true;
	  Running = false;
	  }
	  }
	  
	  if (evt.target.equals(Step3Coins))
	  {
	  if (ReadyToStart || Running)
	  {
	  if(Running)
	  {
	  System.out.println("looping");
	  Running = pC.StepSklansky();
	  }
	  else
	  {
	  Run3Coins.hide();
	  Step3Coins.setLabel("Next Step...");
	  Step3Coins.show();
	  tf.setText("Sklansky's Algorithm: showing steps");
	  
	  if(ReadyToStart)
	  {
	  Running = pC.Sklansky(true);
	  ReadyToStart = false;  
	  }
	  }
	  if(!Running)
	  {tf.setText("Done: Result of Sklansky's Algorithm. Click RESET");
	  ReadyToStart = false;
	  HaveData = true;
	  Step3Coins.hide();
	  Continue.setLabel("Show Original");
	  CounterExample.setLabel("Convex Polygon");
	  Continue.show();
	  CounterExample.show();      				
	  }
	  
	  }
	  }
	  
	  if (evt.target.equals(Run3Coins))
	  {
	  if (ReadyToStart)
	  {
	  Run3Coins.hide();
	  Step3Coins.hide();
	  tf.setText("Running Sklansky's 3-Coins Algorithm");
	  Running = pC.Sklansky(false);
	  if(!Running)
	  {tf.setText("Done: Result of Sklansky's Algorithm. Click RESET");
	  ReadyToStart = false;
	  HaveData = true;
	  Continue.setLabel("Show Original");
	  CounterExample.setLabel("Convex Polygon");
	  Continue.show();
	  CounterExample.show();          				
	  } 
	  
	  }
	  return true;
	  }
	*/
	return false;
    }
    
    
    
    //*****************************************************
    public void init()
    {
	setLayout(new BorderLayout());
	pC = new polyCanvas();
	pC.resize(500,350);
	pC.setBackground(Color.white);
	add("Center",pC);
	/*
	  Panel p1 = new Panel();
	  p1.setLayout(new FlowLayout());
	  p1.setBackground(Color.gray);
	  
	  Continue = new Button("Proceed with my input");
	  p1.add(Continue);
	  
	  CounterExample = new Button("Counter Example");
	  p1.add(CounterExample);
	  
	  Run3Coins = new Button("3-Coins: RUN");
	  p1.add(Run3Coins);
	  
	  Step3Coins = new Button("3-Coins: STEP");
	  p1.add(Step3Coins);
	  
	  add("North",p1);
     */
	Panel p2 = new Panel();
	p2.setLayout(new FlowLayout());
	p2.setBackground(Color.gray);
	
	tf = new TextField("Enter some points and have fun...",52);
	tf.setEditable(false);
	tf.setBackground(Color.white);
	p2.add(tf);
	
	reset = new Button("Reset");
	p2.add(reset);
	
	add("South",p2);	
    }
}
