

import java.awt.Dimension;
import java.awt.GridLayout;
import java.util.List;

import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;



/**
 * Porgramme principal
 * @author Magic Penguins
 *
 */
public class FenetrePrincipale {

	final public static ConfirmExitDialog f = new ConfirmExitDialog("SIE Project");
	/**
	 * Initialisation de la {@link JFrame} principale
	 */
	public static void setFrame() {
		f.setPreferredSize(new Dimension(1024, 600));
		f.setResizable(false);

		JTabbedPane tab = new JTabbedPane();
		JPanel principal = new JPanel(new GridLayout(1, 2));
		JPanel selectionPrincipale = new JPanel(new GridLayout(2, 1));

		JPanel selectionQuest = new JPanel(new GridLayout(4,1));
		JPanel selection_promotion = new JPanel();
		JLabel nomPromo = new JLabel("Choisir promotion: ");
		JComboBox promo = new JComboBox();
		promo.addItem("ING 1");
		selection_promotion.add(nomPromo);
		selection_promotion.add(promo);
		selectionQuest.add(selection_promotion);
		
		JPanel selection_annee = new JPanel();
		JLabel nomAnnee = new JLabel("Choisir annee du questionnaire");
		JComboBox annee = new JComboBox();
		annee.addItem("2011");
		selection_annee.add(nomAnnee);
		selection_annee.add(annee);
		selectionQuest.add(selection_annee);
		
		JPanel selection_prof = new JPanel();
		JLabel nomProf = new JLabel("Choisir annee du questionnaire");
		JComboBox prof = new JComboBox();
		prof.addItem("blop !");
		selection_prof.add(nomProf);
		selection_prof.add(prof);
		selectionQuest.add(selection_prof);
		
		JPanel selection_questionnaire = new JPanel();
		JLabel nomQuestionnaire = new JLabel("Choisir questionnaire");
		JComboBox questionnaire = new JComboBox();
		questionnaire.addItem("questionnaire 1 !");
		selection_questionnaire.add(nomQuestionnaire);
		selection_questionnaire.add(questionnaire);
		selectionQuest.add(selection_questionnaire);
		
		JTabbedPane unibi = new JTabbedPane();
		
		JPanel uni = new JPanel(new GridLayout(2, 1));
	
		JPanel selection_question = new JPanel();
		JLabel nomQuestion = new JLabel("Choisir question");
		JComboBox question = new JComboBox();
		question.addItem("question 1 !");
		selection_question.add(nomQuestion);
		selection_question.add(question);
		
		JPanel filtreUni = new JPanel();
		JCheckBox fUni = new JCheckBox();
		filtreUni.add(new JLabel("Ajouter filtre: "));
		filtreUni.add(fUni);
		fUni.addActionListener(new EventsBouttons(fUni));
		
		uni.add(selection_question);
		uni.add(filtreUni);
		
		
		JPanel bi = new JPanel(new GridLayout(3,1));
		
		JPanel selection_question1 = new JPanel();
		JLabel nomQuestion1 = new JLabel("Choisir question 1");
		JComboBox question1 = new JComboBox();
		question1.addItem("question 1 !");
		selection_question1.add(nomQuestion1);
		selection_question1.add(question1);
		bi.add(selection_question1);
		
		JPanel selection_question2 = new JPanel();
		JLabel nomQuestion2 = new JLabel("Choisir question 2");
		JComboBox question2 = new JComboBox();
		question1.addItem("question 2 !");
		selection_question2.add(nomQuestion2);
		selection_question2.add(question2);
		bi.add(selection_question2);
		
		JPanel filtreBi = new JPanel();
		JCheckBox fBi = new JCheckBox();
		filtreBi.add(new JLabel("Ajouter filtre: "));
		filtreBi.add(fBi);
		
		bi.add(filtreBi);
		
		unibi.add("Univariee", uni);
		unibi.add("Bivariee", bi);
		
		selectionPrincipale.add(selectionQuest);
		selectionPrincipale.add(unibi);
		
		
		
		JPanel graphiqueHist = new JPanel();
		JPanel graphiqueCamembert = new JPanel();
		tab.add("Histogramme", graphiqueHist);
		tab.add("Camembert", graphiqueCamembert);
		
		principal.add(tab);
		principal.add(selectionPrincipale);

		
		f.getContentPane().add(principal);
		f.pack();
		f.setVisible(true);
	}
	
	/**
	 * On charge les donnees avant d'initialiser la JFrame
	 * @param args
	 */
	public static void main(String[] args) {
		setFrame();
	}
	
	/****************histogramme****************/
	public void afficherHistogrammGraphique(){
	DefaultCategoryDataset dataset = new DefaultCategoryDataset();  
	/*for (Classe c : ecole){
		  dataset.addValue(new Integer(c.getNbGarcons()), c.getNom(),"");   
		  dataset.addValue(new Integer(c.getNbGarcons()), c.getNom(),"");  
		  dataset.addValue(new Integer(c.getNbGarcons()), c.getNom(),"");   
		}*/
	    JFreeChart barChart = ChartFactory.createBarChart("Repartition des garçons par classe", "",       
			"Unité vendue", dataset, PlotOrientation.VERTICAL, true, true, false);  	
			ChartPanel cPane2 = new ChartPanel(barChart); 
			jpnl_Graph.removeAll();
			 jpnl_Graph.add(cPane2);
		     this.pack();
	}
	/**************************************************************/		
			
	/********** camembert **********/
	public void afficherPieGraphique(){
		DefaultPieDataset pieDataset = new DefaultPieDataset(); 
		
		for (Classe c : ecole){
		  pieDataset.setValue(c.getNom(), new Integer(c.getNbGarcons()));   
		  pieDataset.setValue(c.getNom(), new Integer(c.getNbGarcons()));  
		  pieDataset.setValue(c.getNom(), new Integer(c.getNbGarcons()));   
		}	   
		JFreeChart pieChart = ChartFactory.createPieChart("Repartition des garçons par classe",pieDataset, true, true, false);     
		ChartPanel cPane1 = new ChartPanel(pieChart);
		jpnl_Graph.removeAll();
		jpnl_Graph.add(cPane1);
		this.pack();
	}
	/*********************************************/
}

