package dmrgvisu2;

import java.awt.Color;
import java.awt.Font;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import java.util.Dictionary;
import java.util.Hashtable;

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;

import java.util.Locale;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JDialog;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JRadioButton;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public final class hamCon extends JDialog 
{ 
	private static final long serialVersionUID = 1L;
	double J1;
	double Jy1;
	double D1;
	double hx1;
	double hz1;
	double J2;
	double Jy2;
	double D2;
	double hx2;
	double hz2;
	
	JTextField JText1;
	JTextField JyText1;
	JTextField JText2;
	JTextField JyText2;
	JTextField DText1;
	JTextField DText2;
	JTextField hxText1;
	JTextField hxText2;
	JTextField hzText1;
	JTextField hzText2;
	
	boolean OK;
	
	JRadioButton Radio1;
	JRadioButton Radio2;
	
	int selection;
	
	public hamCon(double Jin, double Jyin, double Din, double hxin, double hzin, int selectionin) 
	{
		super();
		this.setSize(new Dimension(600, 125));
		DecimalFormat twoPlaces = new DecimalFormat("0.0000", new DecimalFormatSymbols(Locale.US));
		this.selection = 0;
		this.J1 = Jin;
		this.J2 = Jin;
		this.Jy1 = Jin;
		this.Jy2 = Jyin;
		this.D1 = Din;
		this.D2 = Din;
		this.hx1 = hxin;
		this.hx2 = hxin;
		this.hz1 = hzin;
		this.hz2 = hzin;
		this.selection = selectionin;
		
		JComponent Choice = new JPanel();
		JComponent Choice1 = new JPanel();
		JComponent Choice2 = new JPanel();
		JComponent Choice3 = new JPanel();
		ButtonGroup ChoiceGroup = new ButtonGroup();
		Choice.setLayout(new BoxLayout(Choice, BoxLayout.Y_AXIS));
		Choice1.setLayout(new BoxLayout(Choice1, BoxLayout.X_AXIS));
		Choice2.setLayout(new BoxLayout(Choice2, BoxLayout.X_AXIS));
		this.Radio1 = new JRadioButton("H=");
		this.Radio2 = new JRadioButton("H=");
		ChoiceGroup.add(Radio1);
		ChoiceGroup.add(Radio2);
		Choice1.add(Radio1);
		Choice2.add(Radio2);
		if (this.selection == 0)
			Radio1.setSelected(true);
		else
			Radio2.setSelected(true);		
		JLabel welcome = new JLabel("Welcome");
		int height = (int)(welcome.getMaximumSize().height*1.3);
		this.JText1 = new JTextField(twoPlaces.format(this.J1));
		JText1.setMaximumSize(new Dimension(100, height));
		Choice1.add(JText1);
		this.JText2 = new JTextField(twoPlaces.format(this.J2));
		JText2.setMaximumSize(new Dimension(100, height));
		Choice2.add(JText2);
		
		JLabel JLabel1 = new JLabel("/2 (S+S- + ");
		Choice1.add(JLabel1);
		JLabel JLabel2 = new JLabel(" SxSx + ");
		Choice2.add(JLabel2);

		JLabel JyLabel1 = new JLabel(" S-S+) + ");
		Choice1.add(JyLabel1);		
		this.JyText2 = new JTextField(twoPlaces.format(this.Jy2));
		JyText2.setMaximumSize(new Dimension(100, height));
		Choice2.add(JyText2);
		JLabel JyLabel2 = new JLabel(" SySy + ");
		Choice2.add(JyLabel2);		
		
		this.DText1 = new JTextField(twoPlaces.format(this.D1));
		DText1.setMaximumSize(new Dimension(100, height));
		Choice1.add(DText1);
		this.DText2 = new JTextField(twoPlaces.format(this.D2));
		DText2.setMaximumSize(new Dimension(100, height));
		Choice2.add(DText2);
		
		JLabel DLabel1 = new JLabel(" SzSz + ");
		Choice1.add(DLabel1);
		JLabel DLabel2 = new JLabel(" SzSz + ");
		Choice2.add(DLabel2);
		
		this.hzText1 = new JTextField(twoPlaces.format(this.hz1));
		hzText1.setMaximumSize(new Dimension(100, height));
		Choice1.add(hzText1);
		this.hzText2 = new JTextField(twoPlaces.format(this.hz2));
		hzText2.setMaximumSize(new Dimension(100, height));
		Choice2.add(hzText2);
		
		JLabel hzLabel1 = new JLabel(" Sz + ");
		Choice1.add(hzLabel1);
		JLabel hzLabel2 = new JLabel(" Sz + ");
		Choice2.add(hzLabel2);

		this.hxText1 = new JTextField(twoPlaces.format(this.hx1));
		hxText1.setMaximumSize(new Dimension(100, height));
		Choice1.add(hxText1);
		this.hxText2 = new JTextField(twoPlaces.format(this.hx2));
		hxText2.setMaximumSize(new Dimension(100, height));
		Choice2.add(hxText2);
		
		JLabel hxLabel1 = new JLabel(" Sx");
		Choice1.add(hxLabel1);
		JLabel hxLabel2 = new JLabel(" Sx");
		Choice2.add(hxLabel2);		
		
		Choice.add(Choice1);
		Choice.add(Choice2);
		
		JButton OK = new JButton("OK");
		OK.setBackground(Color.WHITE);
		OK.addActionListener
		(
			new ActionListener() 
			{
				public void actionPerformed(final ActionEvent e) 
				{
					hamCon.this.J1 = Double.valueOf(hamCon.this.JText1.getText()).doubleValue();
					hamCon.this.Jy1 = Double.valueOf(hamCon.this.JText1.getText()).doubleValue();
					hamCon.this.J2 = Double.valueOf(hamCon.this.JText2.getText()).doubleValue();
					hamCon.this.Jy2 = Double.valueOf(hamCon.this.JyText2.getText()).doubleValue();
					hamCon.this.D1 = Double.valueOf(hamCon.this.DText1.getText()).doubleValue();
					hamCon.this.D2 = Double.valueOf(hamCon.this.DText2.getText()).doubleValue();
					hamCon.this.hx1 = Double.valueOf(hamCon.this.hxText1.getText()).doubleValue();
					hamCon.this.hx2 = Double.valueOf(hamCon.this.hxText2.getText()).doubleValue();
					hamCon.this.hz1 = Double.valueOf(hamCon.this.hzText1.getText()).doubleValue();
					hamCon.this.hz2 = Double.valueOf(hamCon.this.hzText2.getText()).doubleValue();
					hamCon.this.OK = true;
					hamCon.this.selection = (hamCon.this.Radio1.isSelected()?0:1);
					hamCon.this.setVisible(false);
				}
			}
		);
		Choice3.add(OK);
		JButton Cancel = new JButton("Cancel");
		Cancel.setBackground(Color.WHITE);
		Cancel.addActionListener
		(
			new ActionListener() 
			{
				public void actionPerformed(final ActionEvent e) 
				{
					hamCon.this.OK = false;
					hamCon.this.setVisible(false);
				}
			}
		);
		Choice3.add(Cancel);
		Choice.add(Choice3);
		this.add(Choice);
	}
}
