/*
	A basic extension of the java.applet.Applet class
 */

import java.awt.*;
import java.applet.*;

import simulate.Simulation;
import simulate.Phase;
import simulate.Controller;
import simulate.IntegratorHard;
import simulate.SpacePeriodicCubic;
import simulate.SpeciesDisk;
import simulate.P2HardDisk;
public class pbcCubic extends Applet
{
    public void update(Graphics g) {paint(g);}
	public void init()
	{
		// Take out this line if you don't use symantec.itools.net.RelativeURL or symantec.itools.awt.util.StatusScroller
		symantec.itools.lang.Context.setApplet(this);
	
		// This code is automatically generated by Visual Cafe when you add
		// components to the visual environment. It instantiates and initializes
		// the components. To modify the code, only use code syntax that matches
		// what Visual Cafe can generate, or Visual Cafe may be unable to back
		// parse your Java file into its visual environment.
		//{{INIT_CONTROLS
		setLayout(null);
		setSize(401,394);
		setBackground(new Color(16777215));
		simulation1 = new simulate.Simulation();
		simulation1.setLayout(null);
		simulation1.setBounds(48,24,400,300);
		add(simulation1);
		phase1 = new simulate.Phase();
		phase1.setLayout(null);
		phase1.setBounds(0,0,300,300);
		phase1.setBackground(new Color(8421504));
		simulation1.add(phase1);
		spacePeriodicCubic1 = new simulate.SpacePeriodicCubic();
		spacePeriodicCubic1.setBounds(60,120,20,40);
		phase1.add(spacePeriodicCubic1);
		speciesDisk1 = new simulate.SpeciesDisk();
		speciesDisk1.setDiameter(0.15);
		speciesDisk1.setNeighborUpdateSquareDisplacement(179769313486231570000000000000.);
		speciesDisk1.setBounds(0,0,300,300);
		phase1.add(speciesDisk1);
		p2HardDisk1 = new simulate.P2HardDisk();
		p2HardDisk1.setCollisionDiameter(0.15);
		p2HardDisk1.setBounds(60,216,30,40);
		phase1.add(p2HardDisk1);
		controller1 = new simulate.Controller();
		controller1.setLayout(null);
		controller1.setBounds(300,36,100,40);
		simulation1.add(controller1);
		integratorHard1 = new simulate.IntegratorHard();
		integratorHard1.setLayout(null);
		integratorHard1.setBounds(60,0,20,40);
		controller1.add(integratorHard1);
		button1 = new java.awt.Button();
		button1.setLabel("First shell");
		button1.setBounds(24,336,108,40);
		button1.setForeground(new Color(10066278));
		button1.setBackground(new Color(0));
		add(button1);
		button2 = new java.awt.Button();
		button2.setLabel("Hide boundaries");
		button2.setBounds(144,336,108,40);
		button2.setForeground(new Color(10066278));
		button2.setBackground(new Color(0));
		add(button2);
		button3 = new java.awt.Button();
		button3.setLabel("All black");
		button3.setBounds(264,336,108,40);
		button3.setForeground(new Color(10066278));
		button3.setBackground(new Color(0));
		add(button3);
		//}}
		controller1.start();
		phase1.firstAtom.setColor(myRed);
	
		//{{REGISTER_LISTENERS
		SymMouse aSymMouse = new SymMouse();
		button1.addMouseListener(aSymMouse);
		button2.addMouseListener(aSymMouse);
		button3.addMouseListener(aSymMouse);
		//}}
	}
	
	//{{DECLARE_CONTROLS
	simulate.Simulation simulation1;
	simulate.Phase phase1;
	simulate.SpacePeriodicCubic spacePeriodicCubic1;
	simulate.SpeciesDisk speciesDisk1;
	simulate.P2HardDisk p2HardDisk1;
	simulate.Controller controller1;
	simulate.IntegratorHard integratorHard1;
	java.awt.Button button1;
	java.awt.Button button2;
	java.awt.Button button3;
	//}}

	class SymMouse extends java.awt.event.MouseAdapter
	{
		public void mouseClicked(java.awt.event.MouseEvent event)
		{
			Object object = event.getSource();
			if (object == button1)
				button1_MouseClicked(event);
			else if (object == button2)
				button2_MouseClicked(event);
			else if (object == button3)
				button3_MouseClicked(event);
		}
	}

	void button1_MouseClicked(java.awt.event.MouseEvent event)
	{
		// to do: code goes here.
	    int shells = phase1.getImageShells();
	    if(shells==0) {
	        phase1.setImageShells(1);
	        phase1.setDrawOverflowImages(true);
	        button1.setLabel("Central image");
	    }
	    else {
	        phase1.setImageShells(0);
	        phase1.setDrawOverflowImages(false);
	        button1.setLabel("First shell");
	    }
		//{{CONNECTION
		// setImageShells... getImageShells
		{
			phase1.setImageShells(phase1.getImageShells());
		}
		//}}
	}

	void button2_MouseClicked(java.awt.event.MouseEvent event)
	{
		// to do: code goes here.
		if(spacePeriodicCubic1.isVisible()) {
		    button2.setLabel("Show boundaries");
		}
		else {
		    button2.setLabel("Hide boundaries");
		}
		//{{CONNECTION
		// Toggle show/hide
		{
			spacePeriodicCubic1.setVisible(!spacePeriodicCubic1.isVisible());
		}
		//}}
	}

    private boolean firstIsBlue = true;
    private Color myRed = new Color(153,0,0);
	void button3_MouseClicked(java.awt.event.MouseEvent event)
	{
		// to do: code goes here.
		if(firstIsBlue) {
		    phase1.firstAtom.setColor(Color.black);
		    button3.setLabel("One red");
		}
		else {
		    phase1.firstAtom.setColor(myRed);
		    button3.setLabel("All black");
		}
		firstIsBlue = !firstIsBlue;
		//{{CONNECTION
		// Set the Background Color...
		{
			phase1.setBackground(phase1.getBackground());
		}
		//}}
	}
}
