/*
 * -------------------------------------------------------------------------
 *      $Id: Options.java,v 1.3 2003/04/04 14:11:53 trudisch 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.WallStreet;
import java.util.*;

/**
 *
 * @author  brophy
 * @created January 25, 2002
 */
public class Options extends javax.swing.JDialog {
    static private class Label {
        String  label;
        int     index;
        Label(String label, int index) {
            this.label = label;
            this.index = index;
        }
        public String toString() {
            return label;
        }
    }

    private Model   model;

    /** Creates new form Options */
    public Options(java.awt.Frame parent, Model model) {
        super(parent);
        this.model = model;
        initComponents();

        /*
         *  ComboBox Period
         */
        Label labelPeriod[] = {
            new Label("Day", GregorianCalendar.DAY_OF_WEEK),
            new Label("Week", GregorianCalendar.WEEK_OF_YEAR),
            new Label("Month", GregorianCalendar.MONTH)
        };
        int period = model.getPeriod();
        for (int k = 0;  k < labelPeriod.length;  k++) {
            jComboBoxPeriod.addItem(labelPeriod[k]);
            if (labelPeriod[k].index == period) {
                jComboBoxPeriod.setSelectedIndex(k);
            }
        }

        /*
         *  ComboBox Style
         */
        Label labelStyle[] = {
            new Label("Close", Model.STYLE_CLOSE),
            new Label("Candlestick", Model.STYLE_CANDLESTICK),
            new Label("High-Low-Close", Model.STYLE_HIGH_LOW_CLOSE)
        };
        int style = model.getStyle();
        for (int k = 0;  k < labelStyle.length;  k++) {
            jComboBoxStyle.addItem(labelStyle[k]);
            if (labelStyle[k].index == style) {
                jComboBoxStyle.setSelectedIndex(k);
            }
        }

        /*
         *  ComboBox Volume Style
         */
        Label labelVolumeStyle[] = {
            new Label("None", Model.VOLUME_NONE),
            new Label("Bars", Model.VOLUME_BARS),
            new Label("Line", Model.VOLUME_LINE),
            new Label("Area", Model.VOLUME_AREA)
        };
        int volumeStyle = model.getVolumeStyle();
        for (int k = 0;  k < labelVolumeStyle.length;  k++) {
            jComboBoxVolumeStyle.addItem(labelVolumeStyle[k]);
            if (labelVolumeStyle[k].index == volumeStyle) {
                jComboBoxVolumeStyle.setSelectedIndex(k);
            }
        }

        /*
         *  ComboBox Scaling
         */
        Label labelScaling[] = {
            new Label("Linear", Model.SCALING_LINEAR),
            new Label("Log", Model.SCALING_LOG)
        };
        int scaling = model.getScaling();
        for (int k = 0;  k < labelScaling.length;  k++) {
            jComboBoxScaling.addItem(labelScaling[k]);
            if (labelScaling[k].index == scaling) {
                jComboBoxScaling.setSelectedIndex(k);
            }
        }

        /*
         *  ComboBox Interval
         */
        Label labelInterval[] = {
            new Label("Week", Model.INTERVAL_WEEK),
            new Label("1 Month", Model.INTERVAL_MONTH),
            new Label("3 Months", Model.INTERVAL_QUARTER),
            new Label("Year", Model.INTERVAL_YEAR)
        };
        int interval = model.getInterval();
        for (int k = 0;  k < labelInterval.length;  k++) {
            jComboBoxInterval.addItem(labelInterval[k]);
            if (labelInterval[k].index == interval) {
                jComboBoxInterval.setSelectedIndex(k);
            }
        }

        /*
         *  ComboBox Overlay
         */
        Label labelOverlay[] = {
            new Label("None", Model.OVERLAY_NONE),
            new Label("Parabolic SAR", Model.OVERLAY_SAR),
            new Label("Moving Average", Model.OVERLAY_MA20),
            new Label("Kalman Filter", Model.OVERLAY_KAL)
        };
        int overlay = model.getOverlay();
        for (int k = 0;  k < labelOverlay.length;  k++) {
            jComboBoxOverlay.addItem(labelOverlay[k]);
            if (labelOverlay[k].index == overlay) {
                jComboBoxOverlay.setSelectedIndex(k);
            }
        }

        pack();
    }

    /** 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
        java.awt.GridBagConstraints gridBagConstraints;

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jComboBoxPeriod = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jComboBoxStyle = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jComboBoxVolumeStyle = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jComboBoxScaling = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jComboBoxInterval = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jComboBoxOverlay = new javax.swing.JComboBox();

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

        jPanel1.setLayout(new java.awt.GridBagLayout());

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel1.setText("Period");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 4);
        jPanel1.add(jLabel1, gridBagConstraints);

        jComboBoxPeriod.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxPeriodActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        jPanel1.add(jComboBoxPeriod, gridBagConstraints);

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel2.setText("Style");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 4);
        jPanel1.add(jLabel2, gridBagConstraints);

        jComboBoxStyle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxStyleActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        jPanel1.add(jComboBoxStyle, gridBagConstraints);

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel3.setText("Volume");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 4);
        jPanel1.add(jLabel3, gridBagConstraints);

        jComboBoxVolumeStyle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxVolumeStyleActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        jPanel1.add(jComboBoxVolumeStyle, gridBagConstraints);

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel4.setText("Scaling");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 4);
        jPanel1.add(jLabel4, gridBagConstraints);

        jComboBoxScaling.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxScalingActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        jPanel1.add(jComboBoxScaling, gridBagConstraints);

        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel5.setText("Interval");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 4);
        jPanel1.add(jLabel5, gridBagConstraints);

        jComboBoxInterval.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxIntervalActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        jPanel1.add(jComboBoxInterval, gridBagConstraints);

        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel6.setText("Overlay");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 4);
        jPanel1.add(jLabel6, gridBagConstraints);

        jComboBoxOverlay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxOverlayActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        jPanel1.add(jComboBoxOverlay, gridBagConstraints);

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

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

    private void jComboBoxOverlayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxOverlayActionPerformed
        model.setOverlay(((Label)jComboBoxOverlay.getSelectedItem()).index);
    }//GEN-LAST:event_jComboBoxOverlayActionPerformed

    private void jComboBoxIntervalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxIntervalActionPerformed
        model.setInterval(((Label)jComboBoxInterval.getSelectedItem()).index);
    }//GEN-LAST:event_jComboBoxIntervalActionPerformed

    private void jComboBoxScalingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxScalingActionPerformed
        model.setScaling(((Label)jComboBoxScaling.getSelectedItem()).index);
    }//GEN-LAST:event_jComboBoxScalingActionPerformed

    private void jComboBoxVolumeStyleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxVolumeStyleActionPerformed
        model.setVolumeStyle(((Label)jComboBoxVolumeStyle.getSelectedItem()).index);
    }//GEN-LAST:event_jComboBoxVolumeStyleActionPerformed

    private void jComboBoxStyleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxStyleActionPerformed
        model.setStyle(((Label)jComboBoxStyle.getSelectedItem()).index);
    }//GEN-LAST:event_jComboBoxStyleActionPerformed

    private void jComboBoxPeriodActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxPeriodActionPerformed
        model.setPeriod(((Label)jComboBoxPeriod.getSelectedItem()).index);
    }//GEN-LAST:event_jComboBoxPeriodActionPerformed

    /** Closes the dialog */
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
        setVisible(false);
        dispose();
    }//GEN-LAST:event_closeDialog


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel4;
    private javax.swing.JComboBox jComboBoxOverlay;
    private javax.swing.JComboBox jComboBoxScaling;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JComboBox jComboBoxInterval;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JComboBox jComboBoxStyle;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JComboBox jComboBoxPeriod;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JComboBox jComboBoxVolumeStyle;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel5;
    // End of variables declaration//GEN-END:variables
}