package chronoSave;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;

import chrono.ChronoFrame;
import chrono.ChronoPanel;
import chrono.Main;
import chronoDivers.Arrow;
import signals.Signals;

public class save
{
	public static void save(File saveDir)
	{
		try
		{
			ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(saveDir)));
      
			oos.writeObject(Integer.valueOf(((ChronoPanel)ChronoFrame.chrono.get(ChronoFrame.active)).signals.size()));
      
			for (int i = 0; i < ((ChronoPanel)ChronoFrame.chrono.get(ChronoFrame.active)).signals.size(); i++) 
			{
				oos.writeObject(((ChronoPanel)ChronoFrame.chrono.get(ChronoFrame.active)).signals.get(i));
			}
			
			oos.writeObject(Integer.valueOf(((ChronoPanel)ChronoFrame.chrono.get(ChronoFrame.active)).nbrTimeLapse));
			oos.writeObject(((ChronoPanel)ChronoFrame.chrono.get(ChronoFrame.active)).timeLapse);
			oos.writeObject(Boolean.valueOf(((ChronoPanel)ChronoFrame.chrono.get(ChronoFrame.active)).displayBackLines));
			oos.writeObject(Main.version);
      
			oos.writeObject(Boolean.valueOf(((ChronoPanel)ChronoFrame.chrono.get(ChronoFrame.active)).antialiasing));
			oos.writeObject(Integer.valueOf(((ChronoPanel)ChronoFrame.chrono.get(ChronoFrame.active)).arrows.size()));
      
			for (int i = 0; i < ((ChronoPanel)ChronoFrame.chrono.get(ChronoFrame.active)).arrows.size(); i++) 
			{
				oos.writeObject(((ChronoPanel)ChronoFrame.chrono.get(ChronoFrame.active)).arrows.get(i));
			}
			oos.close();
		}
		catch (FileNotFoundException e)
		{
			e.printStackTrace();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}
 /* 
	public static void load(File openDir)
	{
		
		int size = 0;
    
		try
		{
			ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(new FileInputStream(openDir)));
      
			try
			{
				size = ((Integer)ois.readObject()).intValue();
				for (int i = 0; i < size; i++)
				{
					((ChronoPanel)ChronoFrame.chrono.get(ChronoFrame.active)).signals.add(new AdaptSignals((Signals)ois.readObject()));
				}
				((ChronoPanel)ChronoFrame.chrono.get(ChronoFrame.active)).nbrTimeLapse = ((Integer)ois.readObject()).intValue();
				((ChronoPanel)ChronoFrame.chrono.get(ChronoFrame.active)).timeLapse = ((int[][])ois.readObject());
				((ChronoPanel)ChronoFrame.chrono.get(ChronoFrame.active)).displayBackLines = ((Boolean)ois.readObject()).booleanValue();
				String version = (String)ois.readObject();
        
				((ChronoPanel)ChronoFrame.chrono.get(ChronoFrame.active)).antialiasing = ((Boolean)ois.readObject()).booleanValue();
				int arrowSize = ((Integer)ois.readObject()).intValue();
        
				for (int i = 0; i < arrowSize; i++)
				{
					((ChronoPanel)ChronoFrame.chrono.get(ChronoFrame.active)).arrows.add((Arrow)ois.readObject());
				}
			}
			catch (ClassNotFoundException e)
			{
				e.printStackTrace();
			}
			ois.close();
		}
		catch (FileNotFoundException e)
		{
			e.printStackTrace();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}
	*/
	
}
