package gestionnaires;

import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.File;
import java.util.Collections;
import java.util.Vector;

import javax.swing.JComboBox;

public class GestionnaireMajTabBraille implements WindowListener {

	private JComboBox comboTables;
	private JComboBox comboTablesImp;
	
	public GestionnaireMajTabBraille (JComboBox combo1, JComboBox combo2)
	{
		comboTables = combo1;
		comboTablesImp = combo2;
	}
	
	public void windowActivated(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void windowClosed(WindowEvent arg0) {
		File repertoire =new File("./xsl/tablesBraille");
		File[] listTables = repertoire.listFiles();
	    //String table = "";
	    
		int taille = listTables.length;
		Vector<String> namesList = new Vector<String>(taille);
		String selection1 = comboTables.getSelectedItem().toString();
		String selection2 = comboTablesImp.getSelectedItem().toString();
		
		for(int i=0;i<taille;i++)
	    {
	    	String nomTable = listTables[i].getName() ;
	    	if (nomTable.endsWith(".ent") && !nomTable.equals("Brltab.ent"))
	    	{
	    		namesList.add(nomTable.substring(0,nomTable.length()-4));
	    	}
	    }
		
		Collections.sort(namesList);
		
		comboTables.removeAllItems();
		comboTablesImp.removeAllItems();
		taille = namesList.size();
		
		for(int i=0;i<taille;i++)
	    {
	    	comboTables.addItem(namesList.get(i));
	    	comboTablesImp.addItem(namesList.get(i));
	    }
	    
	    comboTables.setSelectedItem(selection1);
	    comboTablesImp.setSelectedItem(selection2);
	    
	    /*for(int i=0;i<listTables.length;i++)
	    {
	    	String nomTable = listTables[i].getName() ;
	    	if (nomTable.endsWith(".ent") && !nomTable.equals("Brltab.ent"))
	    	{
	    		table = nomTable.substring(0,nomTable.length()-4);
	    		comboTables.addItem(table);
	    		comboTablesImp.addItem(table);
	    		if(table.equals(ConfigNat.getCurrentConfig().getTableBraille()))
	    		{
	    			comboTables.setSelectedIndex(comboTables.getItemCount()-1);
	    		}
	    		if(table.equals(ConfigNat.getCurrentConfig().getTableEmbossage()))
	    		{
	    			comboTablesImp.setSelectedIndex(comboTablesImp.getItemCount()-1);
	    		}
	    	}
	    }*/
	    
	    
		
	}

	public void windowClosing(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void windowDeactivated(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void windowDeiconified(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void windowIconified(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void windowOpened(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}

}
