import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

//import java.util.*;

//tests sauvegarde
//import java.io.*;


public class TeleportJDialog extends JDialog implements ActionListener{
	
	private JLabel Xlbl=new JLabel("World X");
	private JTextField Xtxt=new JTextField("0");
	
	private JLabel Ylbl=new JLabel("World Y");
	private JTextField Ytxt=new JTextField("0");
	
	private JLabel Zlbl=new JLabel("World Z");
	private JTextField Ztxt=new JTextField("0");
	
	private JLabel xlbl=new JLabel("Local x");
	private JTextField xtxt=new JTextField("25");
	
	private JLabel ylbl=new JLabel("Local y");
	private JTextField ytxt=new JTextField("28");
	
	private ParcheminFond pfond=new ParcheminFond();
	
	private JButton okBtn=new JButton("OK");
	
	private Monde monde;
	
	Font police;
	
	public TeleportJDialog(Monde world){
		
		police=world.getPolice();
		Xlbl.setFont(police);
		Ylbl.setFont(police);
		Zlbl.setFont(police);
		xlbl.setFont(police);
		ylbl.setFont(police);
		okBtn.setFont(police);
		
		
		monde=world;
		
		Container c=getContentPane();
		c.setLayout(null);
		
		
		okBtn.setBounds(50,130,70,20);
		c.add(okBtn);
		okBtn.addActionListener(this);
		
		Xlbl.setBounds(10,10,70,20);
		Ylbl.setBounds(10,30,70,20);
		Zlbl.setBounds(10,50,70,20);
		xlbl.setBounds(10,70,70,20);
		ylbl.setBounds(10,90,70,20);
		
		Xtxt.setBounds(80,10,70,20);
		Ytxt.setBounds(80,30,70,20);
		Ztxt.setBounds(80,50,70,20);
		xtxt.setBounds(80,70,70,20);
		ytxt.setBounds(80,90,70,20);
		
		c.add(Xlbl);
		c.add(Ylbl);
		c.add(Zlbl);
		c.add(xlbl);
		c.add(ylbl);
		c.add(Xtxt);
		c.add(Ytxt);
		c.add(Ztxt);
		c.add(xtxt);
		c.add(ytxt);
		
		setTitle("TELEPORTATION");
		
		
		
		//if(monde.jeuPan.lang){
			
		//}
		
		pfond.setBounds(0,0,200,200);
		add(pfond);
		
		setSize(200,200);
		show();
		
	}
	
	
	public void actionPerformed(ActionEvent e){
		
		Object source=e.getSource();
		
		if(source==okBtn){
			if(Xtxt.getText().compareTo("")!=0&&
			Ytxt.getText().compareTo("")!=0&&
			Ztxt.getText().compareTo("")!=0&&
			xtxt.getText().compareTo("")!=0&&
			ytxt.getText().compareTo("")!=0&&
			
			Integer.valueOf(xtxt.getText()).intValue()>9&&
			Integer.valueOf(ytxt.getText()).intValue()>9&&
			Integer.valueOf(xtxt.getText()).intValue()<90&&
			Integer.valueOf(ytxt.getText()).intValue()<90
			
			
			){
				String [] tstr=new String[8];
				
				if(Integer.valueOf(Xtxt.getText()).intValue()<0){
					tstr[0]="-";
				}
				else{
					tstr[0]="+";
				}
				
				if(Integer.valueOf(Ytxt.getText()).intValue()<0){
					tstr[2]="-";
				}
				else{
					tstr[2]="+";
				}
				
				if(Integer.valueOf(Ztxt.getText()).intValue()<0){
					tstr[4]="-";
				}
				else{
					tstr[4]="+";
				}
				
				
				tstr[1]=Integer.toString(Math.abs(Integer.valueOf(Xtxt.getText()).intValue()));
				
				tstr[3]=Integer.toString(Math.abs(Integer.valueOf(Ytxt.getText()).intValue()));
				
				tstr[5]=Integer.toString(Math.abs(Integer.valueOf(Ztxt.getText()).intValue()));
			
				tstr[6]=Integer.toString(Integer.valueOf(xtxt.getText()).intValue());
				
				tstr[7]=Integer.toString(Integer.valueOf(ytxt.getText()).intValue());
				
				monde.teleportation(tstr);
				
				
				
				//String coordMondeCible=new String("+T0T-T2T+T0T39T82");
				//String [] tstr=coordMondeCible.split("T");
				//monde.teleportation(tstr);
				
				dispose();
				
				
				
					
			}
			
			
			
		}
		
	}
}