package gui.simulator;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import java.util.TimerTask;

import javax.swing.BorderFactory;
import javax.swing.JPanel;

import agenda.Agenda;

public class SimulatorPane extends JPanel{
	
	private Agenda agenda;
	private Terrain terrain;

	private Timer framestimer, updatetimer;
	
	//terrain type enums
	public enum Terrains{BEACH, GRASS, URBAN, UNDEFINED};
	//object type enums
	public enum Objects{STAGE, DRINK, SNACKBAR, RESTROOM, SUNGLAS, WAYPOINT, ENTRANCE, EXIT, BORDER, TREE1, PALMTREE1, FENCE, BEERBAR};
	//time control enums
	public enum Time{STOP, PAUZE, PLAY, FASTER, FASTEST};
	
	public SimulatorPane(Agenda agenda, int length, int width, Terrains terrains){
        super.setLayout(new BorderLayout());
		this.agenda = agenda;
        this.setOpaque(true);
        this.setBackground(Color.WHITE);
        this.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        this.terrain = new Terrain(length, width, terrains, this.agenda, this);
        this.add(this.terrain, BorderLayout.CENTER);
       framestimer =  new Timer(1000/30, new ActionListener() {
        	@Override
			public void actionPerformed(ActionEvent arg0) {
				terrain.repaint();	
			}
		});
        updatetimer = new Timer(1000/100, new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				terrain.calculate();
			}
		});
        
        framestimer.start();
        //updatetimer.start();
	}
	
	public void changeSpeed(Time time){
		switch(time){
		case FASTEST:
			updatetimer.setDelay(1000/150); break;
		case FASTER:
			updatetimer.setDelay(1000/100); break;
		case PLAY:
			updatetimer.start(); updatetimer.setDelay(1000/50); break;
		case PAUZE:
			updatetimer.stop(); break;
		case STOP:
			updatetimer.stop(); terrain.clearVisitors(); break;
		default:
			break;
		}
	}
	
	public Terrain getTerrain() {
		return terrain;
	}
	
	public void setTerrain(Terrain terrain) {
		this.terrain = terrain;
	}
	
}
