import java.applet.Applet;
import java.awt.*;
//import OsmosisCanvas;
//import gjt.*;

/*
 *
 * Osmosis
 *
 */
public class Osmosis extends Nernst
{
	int Particles[] = {0,2,5,10,20,30};
	OsmReportPanel pReport;
	OsmControlPanel pControl;
	//OsmCanvas CDiff;
	int NewNum = -1;

	public void init(){
		Panel pnl=new Panel();
	   CDiff=new OsmCanvas(this);
	   //setLayout(new BorderLayout()); //
	   //add("Center",CDiff);	  //
		Panel pnl2=new Panel();
	   tdbDisplay=new ThreeDBorder(pnl2,5);
	   pnl2.setLayout(new BorderLayout());
	   pnl2.add("Center",CDiff);
	   pnl2.add("East", OutBar);

	   //tdbDisplay=new ThreeDBorder(CDiff,5);
	 //  tdbDisplay.inset();
	   pReport=new OsmReportPanel(this);
	   pControl=new OsmControlPanel(this);
	   setLayout(new BorderLayout());
	   add("Center",new ThreeDBorder(pnl));
	   pnl.setLayout(new BorderLayout());
	   pnl.add("Center",CDiff);
	   pnl.add("North", pReport);
	   pnl.add("South", pControl);

    }

	public boolean action(Event event, Object what){
		if(event.target==Start_Stop){
			if (running){
				if (NewNum > -1) {
					CDiff.stop();
					OutBar.stop();
				}
				running=false;
				Start_Stop.setLabel("Start");
			}
			else {
				if (NewNum > -1) {
					CDiff.start();
					OutBar.start();
				}
				running=true;
				Start_Stop.setLabel("Stop");
			}
		}else if (event.target==Num_Particles){
			NewNum = Num_Particles.getSelectedIndex() < 6? Particles[Num_Particles.getSelectedIndex()] : 0;
			if (running) CDiff.stop();
			((OsmCanvas)CDiff).OutIon=NewNum;
			((OsmCanvas)CDiff).OutWater=150-(((OsmCanvas)CDiff).Hydration+1)*NewNum;
			CDiff.init();
			if (running) CDiff.start();
		}

		return true;

	}

}


class OsmControlPanel extends Panel{

	Osmosis app;

	public OsmControlPanel(Applet applet){
		app=(Osmosis)applet;
		app.Num_Particles= new Choice();
		app.Num_Particles.addItem("0 Particles");
		app.Num_Particles.addItem("2 Particles");
		app.Num_Particles.addItem("5 Particles");
		app.Num_Particles.addItem("10 Particles");
		app.Num_Particles.addItem("20 Particles");
		app.Num_Particles.addItem("30 Particles");
		app.Num_Particles.addItem("Choose Particles Num");
		app.Num_Particles.select(6);

		app.Start_Stop= new Button("Start");

		setLayout(new GridLayout(1,2,10,10));

		add(new ThreeDBorder(app.Start_Stop));
		add(new ThreeDBorder(app.Num_Particles));

	}

	public Insets insets(){
		return new Insets(5,5,5,5);
	}

}





	

