package automatvgi;


import javax.swing.JFrame;

import automatvgi.components.RoadAutomaton;
import road.*;
import partition.Partition;
import partition.TablePartition;

public class Main {

	/**
	 * Methode main
	 * Lance MainPanel qui est la fenetre principale
	 */
	public static void main(String[] args) throws Exception {
         //////////////////////////////////////////////////
		 if (args.length == 0) throw new Exception("file name missing");
	     DeterministicAutomaton a = GraphReader.readGraph(args[0]);
	     ////////////////////////////////////////////////////////:
	     Partition partition = new TablePartition(a.size());
	     Quotient quotient = new Quotient(a,partition);
	     quotient.update();
	     System.out.print("Main:1:"); System.out.println(quotient); 
	     RoadAutomaton ra = new RoadAutomaton(quotient);
	     ra.updateRoadAutomaton();
	     ////////////////// init /////////////////////////////////
	     Partition initPartition = new TablePartition(a.size());
		 DeterministicAutomaton det = new ImpDetAutomaton(a.size(),a.arity());
		 det.setEdges(quotient.getG().getEdges());
	     Quotient init = new Quotient(det,initPartition); // data separees
	     init.update();
	     RoadAutomaton initialGraph = new RoadAutomaton(init);
	     initialGraph.updateRoadAutomaton();
	     RoadAutomaton.setInitialGraph(initialGraph);
	     System.out.print("Main:2:"); System.out.println(init); 
	     //////////////////////////////////////////////////////////
		//  La Frame
//		new Memento();
		JFrame f=new JFrame();
		f.setSize(630,800);
		f.setTitle("Automaton");
		f.setResizable(true) ; 
	 	InitPanel initialGraphPanel = new InitPanel(RoadAutomaton.getInitialGraph());
		f.setContentPane(initialGraphPanel);
		f.setVisible(true);
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		/////////////////////////////////////////
		JFrame g=new JFrame();
		g.setSize(630,800);
		g.setTitle("Quotient");
		g.setResizable(true) ; 
		MainPanel quotientPanel = new MainPanel(ra,initialGraphPanel);
		g.setContentPane(quotientPanel);
		g.setVisible(true);
		g.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
}
