//==============================================================================
// The Society of Actuaries (SOA) makes this computer model and its computer
// code available to its members for educational purposes. The model and its
// code may be modified and redistributed without prior authorization from the
// SOA. The SOA distributes this computer model and its computer code in the
// hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE.
//==============================================================================

package implementation;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.event.*;

public class UserPanelTab_Simulation extends JPanel
{
	private static final long serialVersionUID = 1L;
	
	JLabel 	label_Title, label_A1, label_A1a, label_B1, label_C1, label_C2;
	JSlider component_A1;
	JButton component_B1, component_C1;
	JTextField 	component_C2;
	String 	text_Override, text_OverrideOn, text_OverrideOff,
			text_FileOutput, text_FileOutputOn, text_FileOutputOff;
	
	public UserPanelTab_Simulation()
	{
		// Set the layout manager for the pane to be a "grid bag".
		// Grid bag is a flexible and easily modifiable layout format.		
		// (see: www.ugrad.cs.ubc.ca/~cs219/CourseNotes/Swing/swing-LayoutManagers-GridBag.html)
		// The Simulation panel has two columns.
		GridBagLayout gridBagLayout = new GridBagLayout();
		setLayout(gridBagLayout);

		// Title label
		label_Title = new JLabel("<html><b><i>Detailed Simulation parameters</i></b><br>" +
                "<font color=\"blue\">(After making a change, be sure to press ENTER.)</font></html>");
		GridBagConstraints c = new GridBagConstraints();
		c.gridx 		= 0;
		c.gridy 		= 0;
		c.gridwidth 	= 1;
		c.gridheight 	= 1;
		c.weightx 		= 1.0;
		c.weighty 		= 1.0;
		c.anchor 		= GridBagConstraints.WEST;
		c.fill 			= GridBagConstraints.NONE;
		c.insets 		= new Insets(0,10,10,0);
		c.ipadx			= 0;
		c.ipady			= 0;
		gridBagLayout.setConstraints(label_Title, c);
		add(label_Title);	

		// A1 label
		JLabel label_A1 = new JLabel("A1. Maximum simulation periods:");
		label_A1.setToolTipText("Set the maximum number of simulation periods.");
		c.gridx 		= 0;
		c.gridy 		= 1;
		c.gridwidth 	= 1;
		c.gridheight 	= 2;
		c.weightx 		= 1.0;
		c.weighty 		= 1.0;
		c.anchor 		= GridBagConstraints.EAST;
		c.fill 			= GridBagConstraints.NONE;
		c.insets 		= new Insets(0,0,0,10);
		c.ipadx			= 0;
		c.ipady			= 0;
		gridBagLayout.setConstraints(label_A1, c);
		add(label_A1);			
		
		// A1 component
		component_A1 = new JSlider(0, 500, SimulationUserPanel.getMaximumSimulationPeriods());
		component_A1.setMajorTickSpacing(100);
		component_A1.setMinorTickSpacing(50);		
		component_A1.setLabelTable(component_A1.createStandardLabels(100));
		component_A1.setPaintTicks(true);
		component_A1.setPaintLabels(true);
		component_A1.setToolTipText("Set the maximum number of simulation periods.");
		c.gridx 		= 1;
		c.gridy 		= 2;
		c.gridwidth 	= 2;
		c.gridheight 	= 1;
		c.weightx 		= 1.0;
		c.weighty 		= 1.0;
		c.anchor 		= GridBagConstraints.NORTHWEST;
		c.fill 			= GridBagConstraints.HORIZONTAL;
		c.insets 		= new Insets(0,0,0,10);
		c.ipadx			= 0;
		c.ipady			= 0;
		gridBagLayout.setConstraints(component_A1, c);
		component_A1.addChangeListener(new ChangeListener()
		{
			public void stateChanged(ChangeEvent event)
			{
				if (component_A1.getValueIsAdjusting()) return;
				else
				{
					label_A1a.setText("Value:  " + component_A1.getValue());
					SimulationUserPanel.setMaximumSimulationPeriods(component_A1.getValue());
					
					//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
					//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  					
//				    System.out.println("Simulation A1. maximumSimulationPeriods:  " +
//				    		 SimulationUserPanel.getMaximumSimulationPeriods()); //Simulation:  A1
				    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
				    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  				    
				    
				}
			}//end stateChanged()
		}
		);
		add(component_A1);

		// A1a label
		label_A1a = new JLabel("Value:  " + component_A1.getValue());
		c.gridx 		= 1;
		c.gridy 		= 1;
		c.gridwidth 	= 1;
		c.gridheight 	= 1;
		c.weightx 		= 1.0;
		c.weighty 		= 1.0;
		c.anchor 		= GridBagConstraints.SOUTHWEST;
		c.fill 			= GridBagConstraints.NONE;
		c.insets 		= new Insets(0,10,0,0);
		c.ipadx			= 0;
		c.ipady			= 0;
		gridBagLayout.setConstraints(label_A1a, c);
		add(label_A1a);	


		// B1 label
		label_B1 = new JLabel("B1. Press to toggle the parameter override:");
		label_B1.setToolTipText("Press the button to toggle on/off the parameter override.");
		c.gridx 		= 0;
		c.gridy 		= 3;
		c.gridwidth 	= 1;
		c.gridheight 	= 1;
		c.weightx 		= 1.0;
		c.weighty 		= 1.0;
		c.anchor 		= GridBagConstraints.EAST;
		c.fill 			= GridBagConstraints.NONE;
		c.insets 		= new Insets(15,0,0,10);
		c.ipadx			= 0;
		c.ipady			= 0;
		gridBagLayout.setConstraints(label_B1, c);
		add(label_B1);		
		
		// B1 component
		text_OverrideOn = " Override on " ;
		text_OverrideOff = " Override off ";		
		if (SimulationUserPanel.isParameterOverride() == true) text_Override = text_OverrideOn;
		else text_Override = text_OverrideOff;

		component_B1  = new JButton(text_Override);
		component_B1.setToolTipText("Press the button to toggle on/off the parameter override.");
		c.gridx 		= 1;
		c.gridy 		= 3;
		c.gridwidth 	= 1;
		c.gridheight 	= 1;
		c.weightx 		= 1.0;
		c.weighty 		= 1.0;
		c.anchor 		= GridBagConstraints.WEST;
		c.fill 			= GridBagConstraints.NONE;
		c.insets 		= new Insets(15,0,0,10);
		c.ipadx			= 0;
		c.ipady			= 0;
		gridBagLayout.setConstraints(component_B1, c);
		component_B1.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent event)
			{
				if(component_B1.getText().equals(text_OverrideOff))
				{
					component_B1.setText(text_OverrideOn);
					SimulationUserPanel.setParameterOverride(true);
				}
				else
				{
					component_B1.setText(text_OverrideOff);
					SimulationUserPanel.setParameterOverride(false);
				}
				//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
				//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  					
//			    System.out.println("Simulation B1. parameterOverride:  " +
//			    		 SimulationUserPanel.isParameterOverride());
			    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
			    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  	
			}//end actionPerformed()
		}
		);
		add(component_B1);

		// C1 label
		label_C1 = new JLabel("C1. Press to toggle whether there is an output file:");
		label_C1.setToolTipText("Press the button to toggle on/off the existence of an output file.");
		c.gridx 		= 0;
		c.gridy 		= 4;
		c.gridwidth 	= 1;
		c.gridheight 	= 1;
		c.weightx 		= 1.0;
		c.weighty 		= 1.0;
		c.anchor 		= GridBagConstraints.EAST;
		c.fill 			= GridBagConstraints.NONE;
		c.insets 		= new Insets(15,0,0,10);
		c.ipadx			= 0;
		c.ipady			= 0;
		gridBagLayout.setConstraints(label_C1, c);
		add(label_C1);		
		
		// C1 component
		text_FileOutputOn = "File output on";
		text_FileOutputOff = "File output off";		
		if (SimulationUserPanel.isFileOutput() == true) text_FileOutput = text_FileOutputOn;
		else text_FileOutput = text_FileOutputOff;

		component_C1  = new JButton(text_FileOutput);
		component_C1.setToolTipText("Press the button to toggle on/off the existence of an output file.");
		c.gridx 		= 1;
		c.gridy 		= 4;
		c.gridwidth 	= 1;
		c.gridheight 	= 1;
		c.weightx 		= 1.0;
		c.weighty 		= 1.0;
		c.anchor 		= GridBagConstraints.WEST;
		c.fill 			= GridBagConstraints.NONE;
		c.insets 		= new Insets(15,0,0,10);
		c.ipadx			= 0;
		c.ipady			= 0;
		gridBagLayout.setConstraints(component_C1, c);
		component_C1.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent event)
			{
				if(component_C1.getText().equals(text_FileOutputOff))
				{
					component_C1.setText(text_FileOutputOn);
					SimulationUserPanel.setFileOutput(true);
				}
				else
				{
					component_C1.setText(text_FileOutputOff);
					SimulationUserPanel.setFileOutput(false);
				}
				//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
				//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  					
//			    System.out.println("Simulation C1. fileOutput:  " +
//			    		 SimulationUserPanel.isFileOutput());
			    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
			    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  	
			}//end actionPerformed()
		}
		);
		add(component_C1);


		// C2 label
		JLabel label_C2 = new JLabel("C2. Output file name:");
		label_C2.setToolTipText("<html>If the output file toggle is \'on\' (item C1 above) <br>" +
				"provide the output file name.</html>");
		c.gridx 		= 0;
		c.gridy 		= 5;
		c.gridwidth 	= 1;
		c.gridheight 	= 1;
		c.weightx 		= 1.0;
		c.weighty 		= 1.0;
		c.anchor 		= GridBagConstraints.EAST;
		c.fill 			= GridBagConstraints.NONE;
		c.insets 		= new Insets(0,0,525,10);
		c.ipadx			= 0;
		c.ipady			= 0;
		gridBagLayout.setConstraints(label_C2, c);
		add(label_C2);		
			
		// C2 component
		component_C2 = new JTextField(SimulationUserPanel.getOutputFileName(), 10);
		component_C2.setToolTipText("<html>If the output file toggle is \'on\' (item C1 above) <br>" +
				"provide the output file name.</html>.");
		c.gridx 		= 1;
		c.gridy 		= 5;
		c.gridwidth 	= 1;
		c.gridheight 	= 1;
		c.weightx 		= 1.0;
		c.weighty 		= 1.0;
		c.anchor 		= GridBagConstraints.WEST;
		c.fill 			= GridBagConstraints.HORIZONTAL;
		c.insets 		= new Insets(0,0,525,10);
		c.ipadx			= 0;
		c.ipady			= 0;
		gridBagLayout.setConstraints(component_C2, c);
		component_C2.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent event)
			{
				SimulationUserPanel.setOutputFileName(component_C2.getText());

				//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
				//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  					
//			     System.out.println("Simulation C2. outputFileName:  " +
//			    		 SimulationUserPanel.getOutputFileName()); //Simulation: C2
			    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
			    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  	
			}//end actionPerformed()
		}
		);
		add(component_C2);

		
	}//end UserPanelTab_Simulation()

}//end UserPanelTab_Simulation class
