package view.vueFermeture;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.SwingConstants;

import view.Vue;
import view.tool.jEasyTable.JEasyScrollTable;

/**
 * @author alexis
 *
 */
public class Fermeture extends Vue implements ActionListener{

	/**
	 * 
	 */
	private static final long serialVersionUID = -3888974415136869560L;
	private final String[] column = {"Facture","Chambre","Status","Nom","Date","Total"};
	private JEasyScrollTable table;
	private JButton button;
	
	private GridBagConstraints contraint;
	
	
	public Fermeture() throws Exception {
		super(new GridBagLayout());
		initVariable();
		initComponent();
		initListener();
		setMnemonic();
	}
	
	private void initVariable() throws Exception{
		table = new JEasyScrollTable(column);
		button = new JButton("Creer Fermeture");
		
		contraint = new GridBagConstraints();
	}
	
	private void initComponent(){
		contraint.anchor = GridBagConstraints.NORTH;
		contraint.fill = GridBagConstraints.HORIZONTAL;
		contraint.weightx = 1.0;
		contraint.weighty = 1.0;
		contraint.gridx = 0;
		contraint.gridy = 0;
		add(table,contraint);
		
		contraint.anchor = GridBagConstraints.EAST;
		contraint.fill = GridBagConstraints.NONE;
		contraint.weightx = 1.0;
		contraint.weighty = 0.0;
		contraint.gridx = 0;
		contraint.gridy = 1;
		add(button,contraint);
	}
	
	private void initListener(){
		button.addActionListener(this);
	}
	
	private void setMnemonic(){
		button.setMnemonic('C');
	}
	
	public void setContent(JComponent[][] content){
		table.setContent(content);
		//scroll.revalidate();
	}
	
	public void clear(){
		table.clear();
		//scroll.revalidate();
	}
	
	@Override
	public void actionPerformed(ActionEvent arg0) {
		this.getObservable().notifyObservers(this);
	}

	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		JFrame a = new JFrame("window");
		JTabbedPane tabpane = new JTabbedPane(SwingConstants.LEFT);
		JPanel pane = new JPanel(new GridBagLayout());
		JLabel[][] labels = {{new JLabel("1"),new JLabel("2"),new JLabel("3"),new JLabel("4"),new JLabel("5"),new JLabel("6")},{new JLabel("12"),new JLabel("22"),new JLabel("32"),new JLabel("42"),new JLabel("52"),new JLabel("62")},{new JLabel("1"),new JLabel("2"),new JLabel("3"),new JLabel("4"),new JLabel("5"),new JLabel("6")},{new JLabel("12"),new JLabel("22"),new JLabel("32"),new JLabel("42"),new JLabel("52"),new JLabel("62")},{new JLabel("1"),new JLabel("2"),new JLabel("3"),new JLabel("4"),new JLabel("5"),new JLabel("6")},{new JLabel("12"),new JLabel("22"),new JLabel("32"),new JLabel("42"),new JLabel("52"),new JLabel("62")}};
		Fermeture fer = new Fermeture();
		fer.setContent(labels);
		//a.setLayout(new GridBagLayout());
		
		GridBagConstraints contraint = new GridBagConstraints();
		contraint.fill = GridBagConstraints.BOTH;
		contraint.weightx = 1.0;
		contraint.weighty = 1.0;
		contraint.gridx = 0;
		contraint.gridy = 0;
		
		tabpane.addTab("main",pane);
		pane.add(fer,contraint);
		a.add(tabpane);
		a.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		a.pack();
		a.setVisible(true);
	}
}