package view.history;

import controller.history.History_Controller;
import net.miginfocom.swing.MigLayout;
import org.sig.fw.db.corrida.model.History;
import org.sig.fw.layout.component.SLabel;
import org.sig.fw.layout.contener.SDialog;
import org.sig.fw.layout.pane.SPanel;
import org.sig.fw.layout.pane.SScrollPane;

import javax.swing.*;
import java.awt.*;
import java.util.List;

public class History_View extends SDialog 
{
	private static final long serialVersionUID = 8943597977203540324L;
	
	private History_Controller ctrl_history;
	
	private SScrollPane jsp_content;
	private SPanel jp_content;

	public History_View(History_Controller ctrl_history) 
	{
		super("Historique", true);
		this.ctrl_history = ctrl_history;
		setBounds(100, 100, 550, 452);
		
		jsp_content = new SScrollPane();
		jsp_content.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		jsp_content.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		getContentPane().add(jsp_content, BorderLayout.CENTER);
		
		jp_content = new SPanel();
		jp_content.setLayout(new MigLayout("insets -1px -1px, gap 0px 0px", "[grow]", ""));
		jsp_content.setViewportView(jp_content);
		
		SLabel lblNewLabel = new SLabel("Pas d'historique.", SLabel.TYPE_COMMUN);
		jp_content.add(lblNewLabel, "cell 0 0, alignx center");
		
		computePosition();
		
		SwingUtilities.invokeLater(new Runnable()
		{
			@Override
			public void run() 
			{
				ctrl_history.updateData();				
			}
		});
	}
	
	public void updateList(List<History> histories)
	{
		if(histories.size() > 0)
		{
			jp_content.removeAll();
			for(int i = 0; i < histories.size(); i++)
			{
				History_Content hc = new History_Content(ctrl_history, histories.get(i));
				jp_content.add(hc, "cell 0 " + i +", growx");
			}
			jp_content.revalidate();
		}
	}
}







