/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package etomica.modules.vle;

import java.util.HashMap;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

import etomica.action.IAction;
import etomica.graphics.DeviceButton;
import etomica.graphics.DevicePlotPoints;
import etomica.graphics.SimulationGraphic;
import etomica.graphics.SimulationPanel;
import etomica.units.Debye;
import etomica.units.Kelvin;
import etomica.math.function.Function;


public class B2Fit extends SimulationPanel {

	private final static String APP_NAME = "CO2 Potential Fitter";

	public DevicePlotPoints dPlot;

	public B2Fit() {
		super(APP_NAME);

        //
        // Function
        //
        FunctionB2LJQ functionB2LJQ = new FunctionB2LJQ();
        final FunctionMayerB2LJQ functionMayerB2LJQ = new FunctionMayerB2LJQ();

    	dPlot = new DevicePlotPoints(new String[] {"Q", "epsilon", "sigma"},
    			new Function[]{functionB2LJQ}, new String[] {"B2"}, false);
    	dPlot.setTableColumnNames(new String[]{"T (K)","B2 (mL/mol)"});
    	dPlot.setSliderTextboxesEditable(true);

    	functionB2LJQ.dPlot = dPlot;
//    	functionMayerB2LJQ.dPlot = dPlot;

        controlPanel.add(dPlot.controlGraphic());
		graphicsPanel.add(dPlot.graphic());
		footerPanel.add(dPlot.parameterGraphic());

        dPlot.setXScale(200, 500, 300);
        dPlot.getPlotSizeSlider(DevicePlotPoints.MIN_X).setValue(200);
        dPlot.getPlotSizeSlider(DevicePlotPoints.MAX_X).setValue(400);
        dPlot.setAutoScale(true);

        dPlot.setYScale(-100, 100, 0);
		
        dPlot.getSlider("Q").setPrecision(2);
        dPlot.getSlider("Q").setValue(5.0);
		dPlot.setParameterLimits("Q", 0, 10.0);
        dPlot.setParameterLimits("epsilon", 100.0, 300.0);
        dPlot.getSlider("epsilon").setValue(200);
        dPlot.getSlider("epsilon").setNMajor(2);
        dPlot.getSlider("sigma").setPrecision(2);
        dPlot.setParameterLimits("sigma", 2.0, 5.0);

        ((JPanel)dPlot.getSlider("Q").graphic().getParent()).setBorder(new TitledBorder(null, "Q (Debye-A)",
                TitledBorder.CENTER, TitledBorder.TOP));
        ((JPanel)dPlot.getSlider("sigma").graphic().getParent()).setBorder(new TitledBorder(null, "sigma (A)",
                TitledBorder.CENTER, TitledBorder.TOP));
        ((JPanel)