/*
 * -------------------------------------------------------------------------
 *      $Id: MainFrame.java,v 1.6 2004/05/26 18:03:06 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.BondChart;
import com.imsl.demo.gallery.Describe;
import java.awt.Dimension;

/**
 *
 * @author  brophy
 * @created September 21, 2001
 */
public class MainFrame extends javax.swing.JFrame {
    private ChartPanel chartPanel;
    private boolean exitOnClose;

    /** Creates new form MainFrame */
    public MainFrame(boolean exitOnClose) {
        this.exitOnClose = exitOnClose;
        setTitle("Bond Price Sensitivity");
        initComponents();

        Describe des = new Describe(this, "/com/imsl/demo/BondChart/BondChart.html");
        des.show();
        Dimension dess = des.getSize();

        DialogSelect ds = new DialogSelect(this);
        chartPanel = new ChartPanel(ds);
        getContentPane().add(chartPanel, java.awt.BorderLayout.CENTER);

        // position windows
        Dimension ss = getToolkit().getScreenSize();
        int h = Math.min(ss.width/2, ss.height-dess.height-32);
        int w = (int)(h/0.8);
        setSize(w, h);
        Dimension dsSize = ds.getSize();
        ds.setLocation(ss.width-dess.width, dess.height);
        setLocation(ss.width-dess.width+dsSize.width, dess.height);
    }

    /** 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
        jMenuBar = new javax.swing.JMenuBar();
        jMenuFile = new javax.swing.JMenu();
        jMenuItemExit = new javax.swing.JMenuItem();

        jMenuFile.setText("File");
        jMenuItemExit.setText("Exit");
        jMenuItemExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemExitActionPerformed(evt);
            }
        });

        jMenuFile.add(jMenuItemExit);

        jMenuBar.add(jMenuFile);

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

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

    private void jMenuItemExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemExitActionPerformed
        exitForm(null);
    }//GEN-LAST:event_jMenuItemExitActionPerformed

    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
        if (exitOnClose) {
            System.exit(0);
        } else {
            dispose();
        }
    }//GEN-LAST:event_exitForm

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        boolean exitOnClose = true;
        if (args.length > 0  && args[0].equals("-noexit"))  exitOnClose = false;
        new MainFrame(exitOnClose).show();
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuBar jMenuBar;
    private javax.swing.JMenu jMenuFile;
    private javax.swing.JMenuItem jMenuItemExit;
    // End of variables declaration//GEN-END:variables
    private javax.swing.ButtonGroup buttonGroupLocale = new javax.swing.ButtonGroup();
}