/*
 * HyTestConclusionDialog.java
 *
 * Created on September 25, 2008, 9:47 AM
 */

package org.statcato.dialogs.stat.hytest;

import org.statcato.*;
import javax.swing.*;

/**
 * Dialog for hypothesis test conclusion tool.  Allows user to specify original 
 * claim and choose a method for rejecting null hypothesis.  Provides
 * wording of a final conclusion.
 * 
 * @author  Margaret Yau
 * @version %I%, %G%
 * @since 1.0
 */
public class HyTestConclusionDialog extends StatcatoDialog {
    private static final int LESS = 0;
    private static final int LESSEQ = 1;
    private static final int GREATER = 2;
    private static final int GREATEREQ = 3;   
    private static final int EQUAL = 4;    
    private static final int NEQUAL = 5;
    private static final int LEFTTAIL = 0;
    private static final int RIGHTTAIL = 1;
    private static final int TWOTAIL = 2;
    private int tail = -1;
    private String claim = "";
    private String h0 = "";
    private String h1 = "";
    private String parameter;   // for original claim
    private int condition;  // for original claim
    private double value;   // for original claim
    
    /** Creates new form HyTestConclusionDialog */
    public HyTestConclusionDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        this.app = (Statcato)parent;
        this.ParentSpreadsheet = app.getSpreadsheet(); 
        initComponents();
        
        ButtonGroup group = new ButtonGroup();
        group.add(TradRadioButton);
        group.add(PValueRadioButton);
        
        getRootPane().setDefaultButton(Next1Button);
        RejectPanel.setVisible(false);
        ConclusionPanel.setVisible(false);
        GraphPanel.setVisible(false);
        
        setHelpFile("stat-hytest-conc");
        name = "Hypothesis Test Conclusion Tool";
        description = "For determining the conclusion of a hypothesis test " +
                "using the traditional or p-value approaches.";
        helpStrings.add("Enter the original claim of the hypothesis test.");
        helpStrings.add("Enter the critial value and test statistic if " +
                "using the traditional approach.");
        helpStrings.add("Enter the significance and p-value if using " +
                "the p-value approach.");
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        ClearButton = new javax.swing.JButton();
        CancelButton = new javax.swing.JButton();
        ClaimPanel = new javax.swing.JPanel();
        ParamComboBox1 = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        ConditionalComboBox1 = new javax.swing.JComboBox();
        ClaimValueTextField1 = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        TailLabel = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        Next1Button = new javax.swing.JButton();
        RejectPanel = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        TSTextField = new javax.swing.JTextField();
        CVTextField = new javax.swing.JTextField();
        TradRadioButton = new javax.swing.JRadioButton();
        PValueRadioButton = new javax.swing.JRadioButton();
        SigLabel = new javax.swing.JLabel();
        PValueLabel = new javax.swing.JLabel();
        PValueTextField = new javax.swing.JTextField();
        SigTextField = new javax.swing.JTextField();
        H0Label = new javax.swing.JLabel();
        Next2Button = new javax.swing.JButton();
        ConclusionPanel = new javax.swing.JPanel();
        ConclusionLabel = new javax.swing.JLabel();
        GraphPanel = new javax.swing.JPanel();
        GraphLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Hypothesis Test: Reaching a Conclusion");

        ClearButton.setText("Clear");
        ClearButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ClearButtonActionPerformed(evt);
            }
        });

        CancelButton.setText("Cancel");
        CancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CancelButtonActionPerformed(evt);
            }
        });

        ClaimPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Original Claim"));

        ParamComboBox1.setEditable(true);
        ParamComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "mean ", "proportion", "variance", "standard deviation", "" }));

        jLabel11.setText("Parameter");

        jLabel12.setText("Condition");

        ConditionalComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "<html>&lt;</html", "<html>&le;</html>", "<html>&gt;</html>", "<html>&ge;</html>", "<html>=</html>", "<html>&ne;</html>" }));
        ConditionalComboBox1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                ConditionalComboBox1ItemStateChanged(evt);
            }
        });

        ClaimValueTextField1.setText("0");

        jLabel13.setText("<html>Parameter name is editable if desired name is not <br>\navailable in the drop-down menu.<br>\nExamples of claims: mean &lt; 5, proportion = 0.4, <br>\nvariance &gt; 2.3, standard deviation &ne; 1.2</html>");

        jLabel2.setText("Value");

        Next1Button.setText("Next >>");
        Next1Button.setToolTipText("Next >>");
        Next1Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Next1ButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout ClaimPanelLayout = new javax.swing.GroupLayout(ClaimPanel);
        ClaimPanel.setLayout(ClaimPanelLayout);
        ClaimPanelLayout.setHorizontalGroup(
            ClaimPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ClaimPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(ClaimPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(ClaimPanelLayout.createSequentialGroup()
                        .addGroup(ClaimPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(ParamComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel11))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(ClaimPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(ClaimPanelLayout.createSequentialGroup()
                                .addComponent(jLabel12)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel2))
                            .addGroup(ClaimPanelLayout.createSequentialGroup()
                                .addGap(4, 4, 4)
                                .addComponent(ConditionalComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ClaimValueTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(ClaimPanelLayout.createSequentialGroup()
                        .addComponent(Next1Button)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(TailLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel13))
                .addContainerGap(60, Short.MAX_VALUE))
        );
        ClaimPanelLayout.setVerticalGroup(
            ClaimPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ClaimPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(ClaimPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(jLabel12)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(ClaimPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ParamComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ClaimValueTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ConditionalComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel13)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(ClaimPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(Next1Button)
                    .addComponent(TailLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(12, Short.MAX_VALUE))
        );

        RejectPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Hypotheses and Sample Statistics"));

        jLabel6.setText("Select method:");

        jLabel7.setText("Critical Value:");

        jLabel8.setText("Test Statistic:");

        TradRadioButton.setSelected(true);
        TradRadioButton.setText("Traditional Method:");
        TradRadioButton.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                TradRadioButtonStateChanged(evt);
            }
        });

        PValueRadioButton.setText("p-Value Method:");
        PValueRadioButton.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                PValueRadioButtonStateChanged(evt);
            }
        });

        SigLabel.setText("Significance:");

        PValueLabel.setText("p-Value:");

        PValueTextField.setEnabled(false);

        SigTextField.setEnabled(false);

        H0Label.setText("Null Hypothesis:");

        Next2Button.setText("Next >>");
        Next2Button.setToolTipText("Next >>");
        Next2Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Next2ButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout RejectPanelLayout = new javax.swing.GroupLayout(RejectPanel);
        RejectPanel.setLayout(RejectPanelLayout);
        RejectPanelLayout.setHorizontalGroup(
            RejectPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(RejectPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(RejectPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(RejectPanelLayout.createSequentialGroup()
                        .addGroup(RejectPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(H0Label)
                            .addGroup(RejectPanelLayout.createSequentialGroup()
                                .addGroup(RejectPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(RejectPanelLayout.createSequentialGroup()
                                        .addGroup(RejectPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(jLabel7)
                                            .addComponent(jLabel8))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(RejectPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(TSTextField)
                                            .addComponent(CVTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 64, Short.MAX_VALUE)))
                                    .addComponent(TradRadioButton))
                                .addGroup(RejectPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(RejectPanelLayout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
                                        .addGroup(RejectPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(SigLabel)
                                            .addComponent(PValueLabel))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(RejectPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(PValueTextField)
                                            .addComponent(SigTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 59, Short.MAX_VALUE)))
                                    .addGroup(RejectPanelLayout.createSequentialGroup()
                                        .addGap(18, 18, 18)
                                        .addComponent(PValueRadioButton)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addContainerGap())
                    .addGroup(RejectPanelLayout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addContainerGap(221, Short.MAX_VALUE))
                    .addGroup(RejectPanelLayout.createSequentialGroup()
                        .addComponent(Next2Button)
                        .addContainerGap(216, Short.MAX_VALUE))))
        );
        RejectPanelLayout.setVerticalGroup(
            RejectPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(RejectPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(H0Label)
                .addGap(72, 72, 72)
                .addComponent(jLabel6)
                .addGap(18, 18, 18)
                .addGroup(RejectPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TradRadioButton)
                    .addComponent(PValueRadioButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(RejectPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(CVTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(SigTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(SigLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(RejectPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TSTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)
                    .addComponent(PValueTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(PValueLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Next2Button)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        ConclusionPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Conclusion"));

        ConclusionLabel.setText("conclusion");

        javax.swing.GroupLayout ConclusionPanelLayout = new javax.swing.GroupLayout(ConclusionPanel);
        ConclusionPanel.setLayout(ConclusionPanelLayout);
        ConclusionPanelLayout.setHorizontalGroup(
            ConclusionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ConclusionPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(ConclusionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 357, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(18, Short.MAX_VALUE))
        );
        ConclusionPanelLayout.setVerticalGroup(
            ConclusionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ConclusionPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(ConclusionLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 121, Short.MAX_VALUE)
                .addContainerGap())
        );

        GraphPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Type of Test"));

        javax.swing.GroupLayout GraphPanelLayout = new javax.swing.GroupLayout(GraphPanel);
        GraphPanel.setLayout(GraphPanelLayout);
        GraphPanelLayout.setHorizontalGroup(
            GraphPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, GraphPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(GraphLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 365, Short.MAX_VALUE)
                .addContainerGap())
        );
        GraphPanelLayout.setVerticalGroup(
            GraphPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(GraphPanelLayout.createSequentialGroup()
                .addComponent(GraphLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(6, 6, 6)
                                .addComponent(ClaimPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(RejectPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(GraphPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(ConclusionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(258, 258, 258)
                        .addComponent(ClearButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(CancelButton)))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {CancelButton, ClearButton});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(ClaimPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(RejectPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(GraphPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ConclusionPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ClearButton)
                    .addComponent(CancelButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void Next1ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Next1ButtonActionPerformed
        parameter = "";
        value = 0;
   
        constructHypotheses();
        getRootPane().setDefaultButton(Next2Button);
        RejectPanel.setVisible(true);
        GraphPanel.setVisible(true);
        pack();
    }//GEN-LAST:event_Next1ButtonActionPerformed

    private void constructHypotheses() {
        // get parameter name
        String selected = (String) ParamComboBox1.getSelectedItem();
        if (selected.equals("")) {
            app.showErrorDialog("Enter the paramter name or select " +
                        "one in the paramter list.");
            return;
        }
        else
            parameter = selected; 
        
        // get condition
        condition = ConditionalComboBox1.getSelectedIndex();
        
        setTestType(condition);
        String conditionString = convertConditionToString(condition);

        // get value
        try {
            value = Double.parseDouble(ClaimValueTextField1.getText());
        }
        catch (NumberFormatException e) {
            app.showErrorDialog("Enter a number for hypothesized value in " +
                    "the original claim");
            return;
        }

        conditionString = convertConditionToString(condition);
        claim = parameter + " " + conditionString + " " + value;
        h0 = parameter + " = " + value;
        h1 = parameter + " " + 
                convertConditionToString(returnAlternativeCondition(condition))
                + " " + value;
        H0Label.setText("<html><b>Claim:</b>  " + claim + "<br>" + 
                "<b>Null Hypothesis:</b>  " + h0 + "<br>" + 
                "<b>Alternative Hypothesis:</b> " + h1 + "</html>");
    }
    
    private void setTestType(int condition) {
        switch (condition) {
            case LESS:
                tail = LEFTTAIL; break;
            case LESSEQ:
                tail = RIGHTTAIL; break;
            case GREATER:
                tail = RIGHTTAIL; break;
            case GREATEREQ: 
                tail = LEFTTAIL; break;
            case EQUAL:
                tail = TWOTAIL; break;
            case NEQUAL:
                tail = TWOTAIL;    break;
        }
        
        // print type of test
        if (tail == LEFTTAIL) {
            TailLabel.setText("Left tail test");
            ImageIcon icon = app.createImageIcon("normal-ltt.gif", "ltt");
            GraphLabel.setIcon(icon);
        }
        else if (tail == RIGHTTAIL) {
            TailLabel.setText("Right tail test");
            ImageIcon icon = app.createImageIcon("normal-rtt.gif", "ltt");
            GraphLabel.setIcon(icon);
        }
        else {
            TailLabel.setText("Two tail test");
            ImageIcon icon = app.createImageIcon("normal-ttt.gif", "ltt");
            GraphLabel.setIcon(icon);
        }
    }
    
    /**
     * Return a string of HTML code representing the given condition.
     * 
     * @param condition comparison condition (LESS, LESSEQ, GREATER, GREATEREQ,
     * EQUAL, NEQUAL)
     * @return HTML string
     */
    private String convertConditionToString(int condition) {
        switch (condition) {
            case LESS:          return "&lt;"; 
            case LESSEQ:        return "&le;"; 
            case GREATER:       return "&gt;"; 
            case GREATEREQ:     return "&ge;"; 
            case EQUAL:         return "="; 
            case NEQUAL:        return "&ne;";           
        }        
        return "";
    }
    
    /**
     * Return the comparison condition of the alternative hypothesis given the
     * condition of the claim
     * 
     * @param condition (LESS, LESSEQ, GREATER, GREATEREQ,
     * EQUAL, NEQUAL)
     * @return condition of the null
     */
    private int returnAlternativeCondition(int condition) {
        switch (condition) {
            case LESS:          return LESS; 
            case LESSEQ:        return GREATER; 
            case GREATER:       return GREATER; 
            case GREATEREQ:     return LESS; 
            case EQUAL:         return NEQUAL; 
            case NEQUAL:        return NEQUAL;           
        }        
        return -1;        
    }
    
    private void TradRadioButtonStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_TradRadioButtonStateChanged
        if (TradRadioButton.isSelected()) {
            CVTextField.setEnabled(true);
            TSTextField.setEnabled(true);
        }
        else {
            CVTextField.setEnabled(false);
            TSTextField.setEnabled(false);
        }
    }//GEN-LAST:event_TradRadioButtonStateChanged

    private void PValueRadioButtonStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_PValueRadioButtonStateChanged
        if (PValueRadioButton.isSelected()) {
            SigTextField.setEnabled(true);
            PValueTextField.setEnabled(true);
        }
        else {
            SigTextField.setEnabled(false);
            PValueTextField.setEnabled(false);
        }
    }//GEN-LAST:event_PValueRadioButtonStateChanged

    private void Next2ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Next2ButtonActionPerformed
        Next1ButtonActionPerformed(null);
        boolean rejectNull = false;
        if (TradRadioButton.isSelected()) {
            // traditional method
            // read input values
            try {
                double CV = Double.parseDouble(CVTextField.getText());
                double TS = Double.parseDouble(TSTextField.getText());

                if (tail == RIGHTTAIL) {
                    if (TS >= CV)
                        rejectNull = true;
                    else
                        rejectNull = false;
                }
                else if (tail == LEFTTAIL) {
                    if (TS <= CV)
                        rejectNull = true;
                    else
                        rejectNull = false;
                }
                else { // two tail
                    if (Math.abs(TS) >= Math.abs(CV))
                        rejectNull = true;
                    else
                        rejectNull = false;
                }                     
            }
            catch (NumberFormatException e) {
                app.showErrorDialog("Enter valid numbers for the critical " +
                        "value and test statistic.");
                return;
            }
        }
        else {
            // p-Value method
            // read input values 
            try {
                double significance = Double.parseDouble(SigTextField.getText());
                double pvalue = Double.parseDouble(PValueTextField.getText());
                if (pvalue <= significance)
                    rejectNull = true;
                else
                    rejectNull = false;
            }
            catch (NumberFormatException e) {
                app.showErrorDialog("Enter valid numbers for the " +
                        "significance and p-Value.");
                return;
            }
        }
        
        // make conclusion
        String text = "<html>";
        if (rejectNull) 
            text += "Reject null hypothesis.<br><br>";
        else
            text += "Fail to reject null hypothesis.<br><br>";
        
        condition = ConditionalComboBox1.getSelectedIndex();
        
        if (condition == EQUAL || condition == LESSEQ || condition == GREATEREQ) {
            // original claim contains equality
            if (rejectNull)
                text += "This is sufficient evidence to warrant rejection " +
                        "of the claim that ";
            else
                text += "There is not sufficient evidence to warrant rejection " +
                        "of the claim that ";
        }
        else {
            // original claim does not contain equality
            if (rejectNull) 
                text += "The sample data support the claim that ";
            else
                text += "There is not sufficient evidence to support the claim that ";
        }
        text += claim + ".</html>";
        
        ConclusionLabel.setText(text);
        ConclusionPanel.setVisible(true);
        pack();
    }//GEN-LAST:event_Next2ButtonActionPerformed

    private void ClearButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ClearButtonActionPerformed
        ParamComboBox1.setSelectedIndex(0);
        ConditionalComboBox1.setSelectedIndex(0);
        ClaimValueTextField1.setText("0");
        CVTextField.setText("");
        TSTextField.setText("");
        SigTextField.setText("");
        PValueTextField.setText("");
        RejectPanel.setVisible(false);
        ConclusionPanel.setVisible(false);
        GraphPanel.setVisible(false);
        pack();
    }//GEN-LAST:event_ClearButtonActionPerformed

    private void CancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CancelButtonActionPerformed
        setVisible(false);
    }//GEN-LAST:event_CancelButtonActionPerformed

    private void ConditionalComboBox1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_ConditionalComboBox1ItemStateChanged
        condition = ConditionalComboBox1.getSelectedIndex();
        
        setTestType(condition);
    }//GEN-LAST:event_ConditionalComboBox1ItemStateChanged
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField CVTextField;
    private javax.swing.JButton CancelButton;
    private javax.swing.JPanel ClaimPanel;
    private javax.swing.JTextField ClaimValueTextField1;
    private javax.swing.JButton ClearButton;
    private javax.swing.JLabel ConclusionLabel;
    private javax.swing.JPanel ConclusionPanel;
    private javax.swing.JComboBox ConditionalComboBox1;
    private javax.swing.JLabel GraphLabel;
    private javax.swing.JPanel GraphPanel;
    private javax.swing.JLabel H0Label;
    private javax.swing.JButton Next1Button;
    private javax.swing.JButton Next2Button;
    private javax.swing.JLabel PValueLabel;
    private javax.swing.JRadioButton PValueRadioButton;
    private javax.swing.JTextField PValueTextField;
    private javax.swing.JComboBox ParamComboBox1;
    private javax.swing.JPanel RejectPanel;
    private javax.swing.JLabel SigLabel;
    private javax.swing.JTextField SigTextField;
    private javax.swing.JTextField TSTextField;
    private javax.swing.JLabel TailLabel;
    private javax.swing.JRadioButton TradRadioButton;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    // End of variables declaration//GEN-END:variables
    
}
