/* Copyright (c) 2005 Stanford University and Christopher Bruns
 * 
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including 
 * without limitation the rights to use, copy, modify, merge, publish, 
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject
 * to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included 
 * in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

/*
 * Created on Feb 6, 2006
 * Original author: Christopher Bruns
 */
package org.simtk.isimsu;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

import java.text.*;

/**
 *  
  * @author Christopher Bruns
  * 
  * Displays counts of individual ion types after a run of ISIM.
 */
public class SimulationDetailsDialog extends JDialog implements ActionListener {
    JButton dismissButton = new JButton("Close");
    ISIMWrapper isimWrapper;

    SimulationDetailsDialog(ISIMWrapper isimWrapper) {
        super(isimWrapper); // preserves title bar icon from parent
        
        this.isimWrapper = isimWrapper;
        setTitle(isimWrapper.programName + " Simulation Details");
        
        dismissButton.addActionListener(this);
        
        Container pane = getContentPane();
        pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS)); // vertical

        JPanel runInfoPanel = new JPanel();
        runInfoPanel.setLayout(new BoxLayout(runInfoPanel, BoxLayout.Y_AXIS));
        runInfoPanel.setBorder(BorderFactory.createEmptyBorder(12,12,12,12));

        runInfoPanel.add(new JLabel("Simulation details: "));
        runInfoPanel.add(Box.createVerticalStrut(12));
        
        double macroionPermittivity = isimWrapper.apbsParameters.getMoleculePermittivity();
        DecimalFormat permittivityFormat = new DecimalFormat("0.0");
        String macroionPermittivityString = permittivityFormat.format(macroionPermittivity);
        runInfoPanel.add(new JLabel("<html>Macromolecule dielectric \u220A<sub>mol</sub> = " + macroionPermittivityString + "</html>"));

        double solventPermittivity = isimWrapper.apbsParameters.getSolventPermittivity();
        String solventPermittivityString = permittivityFormat.format(solventPermittivity);
        runInfoPanel.add(new JLabel("<html>Solvent delectric \u220A<sub>solv</sub> = " + solventPermittivityString + "</html>"));

        double kelvinTemperature = isimWrapper.apbsParameters.getTemperature();
        double celsiusTemperature = kelvinTemperature - 273.15;
        DecimalFormat temperatureFormat = new DecimalFormat("0.00");
        String kelvinString = temperatureFormat.format(kelvinTemperature);
        String celsiusString = temperatureFormat.format(celsiusTemperature);
        runInfoPanel.add(new JLabel("Temperature = " + kelvinString + " K  ( " + celsiusString + " \u00b0C )"));
        
        // Left justify run information
        JPanel outerRunInfoPanel = new JPanel();
        outerRunInfoPanel.setLayout(new BoxLayout(outerRunInfoPanel, BoxLayout.X_AXIS));
        outerRunInfoPanel.add(runInfoPanel);
        outerRunInfoPanel.add(Box.createHorizontalGlue());
        
        pane.add(outerRunInfoPanel);
        
        // dismiss button
        JPanel buttonPanel = new JPanel();
        buttonPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
        buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
        buttonPanel.add(Box.createHorizontalGlue());
        buttonPanel.add(Box.createHorizontalStrut(5));
        buttonPanel.add(dismissButton);
        pane.add(buttonPanel);

        setLocationRelativeTo(isimWrapper);
        
        pack();
    }
    
    /**
     * Respond to pressing the "dismiss" button
     * @param event
     */
    public void actionPerformed(ActionEvent event) {
        if (event.getSource() == dismissButton) {
            setVisible(false);
        }
    }    
}


