/*
 * -------------------------------------------------------------------------
 *      $Id: InfoDialog.java,v 1.2 2004/05/26 18:10:03 estewart Exp $
 * -------------------------------------------------------------------------
 *      Copyright (c) 1999 Visual Numerics Inc. All Rights Reserved.
 *
 *      This software is confidential information which is proprietary to
 *      and a trade secret of Visual Numerics, Inc.  Use, duplication or
 *      disclosure is subject to the terms of an appropriate license
 *      agreement.
 *
 *      VISUAL NUMERICS MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE
 *      SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING
 *      BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY,
 *      FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. VISUAL
 *      NUMERICS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 *      AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR
 *      ITS DERIVATIVES.
 *--------------------------------------------------------------------------
 */

package com.imsl.demo.Efficient;

/**
 *
 * @author  Ed Stewart
 * @created March 10, 2003
 */
public class InfoDialog extends javax.swing.JDialog {
    
    private final Efficient eParent;
    private final Computer cParent;
    private final java.awt.Cursor waitCursor = new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR);
    private final java.awt.Cursor defaultCursor = new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR);
    
    /** Creates new form InfoDialog */
    public InfoDialog(javax.swing.JFrame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        setTitle("Method Selection");
        eParent = (Efficient) parent;
        cParent = eParent.getComputer();;
    }
    
    /** 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.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        jEditorPane = new javax.swing.JEditorPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jRadioButtonEWMA = new javax.swing.JRadioButton();
        jRadioButtonSMA = new javax.swing.JRadioButton();
        jRadioButtonAHP = new javax.swing.JRadioButton();

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        jEditorPane.setEditable(false);
        jEditorPane.setContentType("text/html");
        jEditorPane.setMinimumSize(new java.awt.Dimension(320, 350));
        jEditorPane.setPreferredSize(new java.awt.Dimension(320, 350));
        getContentPane().add(jEditorPane, java.awt.BorderLayout.CENTER);

        jPanel1.setMinimumSize(new java.awt.Dimension(320, 35));
        jPanel1.setPreferredSize(new java.awt.Dimension(320, 35));
        jLabel1.setText("Select Method:");
        jPanel1.add(jLabel1);

        jRadioButtonEWMA.setSelected(true);
        jRadioButtonEWMA.setText("EWMA");
        jRadioButtonEWMA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonEWMAActionPerformed(evt);
            }
        });

        jPanel1.add(jRadioButtonEWMA);

        jRadioButtonSMA.setText("SMA");
        jRadioButtonSMA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonSMAActionPerformed(evt);
            }
        });

        jPanel1.add(jRadioButtonSMA);

        jRadioButtonAHP.setText("AHP");
        jRadioButtonAHP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonAHPActionPerformed(evt);
            }
        });

        jPanel1.add(jRadioButtonAHP);

        getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);

        pack();
    }//GEN-END:initComponents

    private void jRadioButtonSMAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonSMAActionPerformed
        jRadioButtonEWMA.setSelected(false);
        jRadioButtonSMA.setSelected(true);
        jRadioButtonAHP.setSelected(false);
        execute(Computer.MODEL_SMA);
    }//GEN-LAST:event_jRadioButtonSMAActionPerformed

    private void jRadioButtonEWMAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonEWMAActionPerformed
        jRadioButtonEWMA.setSelected(true);
        jRadioButtonSMA.setSelected(false);
        jRadioButtonAHP.setSelected(false);
        execute(Computer.MODEL_EWMA);
    }//GEN-LAST:event_jRadioButtonEWMAActionPerformed

    private void jRadioButtonAHPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonAHPActionPerformed
        jRadioButtonEWMA.setSelected(false);
        jRadioButtonSMA.setSelected(false);
        jRadioButtonAHP.setSelected(true);
        execute(Computer.MODEL_AHP);
    }//GEN-LAST:event_jRadioButtonAHPActionPerformed
    
    /** Closes the dialog */
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
        setVisible(false);
        dispose();
    }//GEN-LAST:event_closeDialog

    private void execute(int model) {
        setCursor(waitCursor);
        cParent.setModel(model);
        cParent.compute();
        eParent.redrawChart();
        setCursor(defaultCursor);
    }
    
    void setText(String text) {
        jEditorPane.setText(text);
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        new InfoDialog(new javax.swing.JFrame(), true).show();
    }
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JRadioButton jRadioButtonAHP;
    private javax.swing.JRadioButton jRadioButtonSMA;
    private javax.swing.JEditorPane jEditorPane;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JRadioButton jRadioButtonEWMA;
    // End of variables declaration//GEN-END:variables
    
}