package ch.unige.gl.tp13;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

public class CalculatorView extends JFrame {

	private JPanel contentPane;
	private JTextField displayField;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					CalculatorView frame = new CalculatorView();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public CalculatorView() {
		setTitle("Calculatrice");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 326, 351);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		JPanel buttonPanel = new JPanel();
		contentPane.add(buttonPanel, BorderLayout.SOUTH);
		
		JButton btnResult = new JButton("Résultat");
		buttonPanel.add(btnResult);
		
		JButton btnQuit = new JButton("Quit");
		btnQuit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		buttonPanel.add(btnQuit);
		
		displayField = new JTextField();
		contentPane.add(displayField, BorderLayout.NORTH);
		displayField.setColumns(10);
		
		JPanel buttonsPanel = new JPanel();
		contentPane.add(buttonsPanel, BorderLayout.CENTER);
		GridBagLayout gridbagLayout = new GridBagLayout();
		gridbagLayout.columnWidths = new int[] {50, 50, 50, 50, 0};
		gridbagLayout.rowHeights = new int[] {50, 50, 50, 50, 50, 0};
		gridbagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		gridbagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		buttonsPanel.setLayout(gridbagLayout);
		
		JButton btn7 = new JButton("7");
		GridBagConstraints constraintBtn7 = new GridBagConstraints();
		constraintBtn7.fill = GridBagConstraints.BOTH;
		constraintBtn7.insets = new Insets(0, 0, 5, 5);
		constraintBtn7.gridx = 0;
		constraintBtn7.gridy = 0;
		buttonsPanel.add(btn7, constraintBtn7);
		
		JButton btn6 = new JButton("6");
		GridBagConstraints constraintBtn6 = new GridBagConstraints();
		constraintBtn6.fill = GridBagConstraints.BOTH;
		constraintBtn6.insets = new Insets(0, 0, 5, 5);
		constraintBtn6.gridx = 1;
		constraintBtn6.gridy = 0;
		buttonsPanel.add(btn6, constraintBtn6);
		
		JButton btn5 = new JButton("5");
		GridBagConstraints constraintBtn5 = new GridBagConstraints();
		constraintBtn5.fill = GridBagConstraints.BOTH;
		constraintBtn5.insets = new Insets(0, 0, 5, 5);
		constraintBtn5.gridx = 2;
		constraintBtn5.gridy = 0;
		buttonsPanel.add(btn5, constraintBtn5);
		
		JButton btnDivide = new JButton("/");
		GridBagConstraints constraintBtnDivide = new GridBagConstraints();
		constraintBtnDivide.insets = new Insets(0, 0, 5, 0);
		constraintBtnDivide.fill = GridBagConstraints.BOTH;
		constraintBtnDivide.gridx = 3;
		constraintBtnDivide.gridy = 0;
		buttonsPanel.add(btnDivide, constraintBtnDivide);
		
		JButton btn4 = new JButton("4");
		GridBagConstraints constraintBtn4 = new GridBagConstraints();
		constraintBtn4.fill = GridBagConstraints.BOTH;
		constraintBtn4.insets = new Insets(0, 0, 5, 5);
		constraintBtn4.gridx = 0;
		constraintBtn4.gridy = 1;
		buttonsPanel.add(btn4, constraintBtn4);
		
		JButton btn3 = new JButton("3");
		GridBagConstraints constraintBtn3 = new GridBagConstraints();
		constraintBtn3.fill = GridBagConstraints.BOTH;
		constraintBtn3.insets = new Insets(0, 0, 5, 5);
		constraintBtn3.gridx = 1;
		constraintBtn3.gridy = 1;
		buttonsPanel.add(btn3, constraintBtn3);
		
		JButton btn2 = new JButton("2");
		GridBagConstraints constraintBtn2 = new GridBagConstraints();
		constraintBtn2.fill = GridBagConstraints.BOTH;
		constraintBtn2.insets = new Insets(0, 0, 5, 5);
		constraintBtn2.gridx = 2;
		constraintBtn2.gridy = 1;
		buttonsPanel.add(btn2, constraintBtn2);
		
		JButton btnMultiply = new JButton("*");
		GridBagConstraints constraintBtnMultiply = new GridBagConstraints();
		constraintBtnMultiply.fill = GridBagConstraints.BOTH;
		constraintBtnMultiply.insets = new Insets(0, 0, 5, 0);
		constraintBtnMultiply.gridx = 3;
		constraintBtnMultiply.gridy = 1;
		buttonsPanel.add(btnMultiply, constraintBtnMultiply);
		
		JButton btn1 = new JButton("1");
		GridBagConstraints constraintBtn1 = new GridBagConstraints();
		constraintBtn1.fill = GridBagConstraints.BOTH;
		constraintBtn1.insets = new Insets(0, 0, 5, 5);
		constraintBtn1.gridx = 0;
		constraintBtn1.gridy = 2;
		buttonsPanel.add(btn1, constraintBtn1);
		
		JButton btn0 = new JButton("0");
		GridBagConstraints constraintBtn0 = new GridBagConstraints();
		constraintBtn0.fill = GridBagConstraints.BOTH;
		constraintBtn0.insets = new Insets(0, 0, 5, 5);
		constraintBtn0.gridx = 1;
		constraintBtn0.gridy = 2;
		buttonsPanel.add(btn0, constraintBtn0);
		
		JButton btnDot = new JButton(".");
		GridBagConstraints constraintBtnDot = new GridBagConstraints();
		constraintBtnDot.fill = GridBagConstraints.BOTH;
		constraintBtnDot.insets = new Insets(0, 0, 5, 5);
		constraintBtnDot.gridx = 2;
		constraintBtnDot.gridy = 2;
		buttonsPanel.add(btnDot, constraintBtnDot);
		
		JButton btnMinus = new JButton("-");
		GridBagConstraints constraintBtnMinus = new GridBagConstraints();
		constraintBtnMinus.fill = GridBagConstraints.BOTH;
		constraintBtnMinus.insets = new Insets(0, 0, 5, 0);
		constraintBtnMinus.gridx = 3;
		constraintBtnMinus.gridy = 2;
		buttonsPanel.add(btnMinus, constraintBtnMinus);
		
		JButton btnPlus = new JButton("+");
		GridBagConstraints constraintBtnPlus = new GridBagConstraints();
		constraintBtnPlus.insets = new Insets(0, 0, 5, 0);
		constraintBtnPlus.fill = GridBagConstraints.BOTH;
		constraintBtnPlus.gridx = 3;
		constraintBtnPlus.gridy = 3;
		buttonsPanel.add(btnPlus, constraintBtnPlus);
		
		JButton btnSinus = new JButton("sinus");
		GridBagConstraints gbc_btnSinus = new GridBagConstraints();
		gbc_btnSinus.fill = GridBagConstraints.BOTH;
		gbc_btnSinus.insets = new Insets(0, 0, 5, 0);
		gbc_btnSinus.gridx = 3;
		gbc_btnSinus.gridy = 4;
		buttonsPanel.add(btnSinus, gbc_btnSinus);
	}

}