/*
 * -------------------------------------------------------------------------
 *      $Id: FittingMain.java,v 1.5 2006/05/23 19:51:01 brophy 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.
 *--------------------------------------------------------------------------
 */

/*
 * FittingMain.java
 *
 * Created on August 19, 2003, 4:26 PM
 */

package com.imsl.demo.fitting;

import com.imsl.demo.gallery.Describe;

public class FittingMain extends javax.swing.JFrame {

    private javax.swing.JMenu dataMenu;
    private javax.swing.JTabbedPane jTabbedPane;

    /** Creates a new instance of FittingMain */
    public FittingMain(boolean exitOnClose) {
        if (!exitOnClose) {
            // remove the WindowListener,  installed by JFrameChart, that
            // exits the application when the window is closed.
            Object l[] = getListeners(java.awt.event.WindowListener.class);
            for (int k = 0;  k < l.length;  k++) {
                removeWindowListener((java.awt.event.WindowListener)l[k]);
            }
        }
        Describe des = new Describe(this, "/com/imsl/demo/fitting/Fitting.html");
        des.show();
        java.awt.Dimension ds = des.getSize();

        setTitle("Data Fitting");
        java.awt.Dimension ss = getToolkit().getScreenSize();
        int w = Math.min(ss.width/2, ss.height-ds.height-32);
        setSize((int)(1.25*w), w);
        setLocation(ss.width-ds.width, ds.height);

        initComponents();
    }

    public javax.swing.JMenu getDataMenu() {
        return dataMenu;
    }

    private void reset() {
        dataMenu.removeAll();
        repaint();
    }

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

        javax.swing.JMenuBar jMenu = new javax.swing.JMenuBar();
        dataMenu = new javax.swing.JMenu();
        dataMenu.setMnemonic('D');
        dataMenu.setText("Data");
        jMenu.add(dataMenu);
        setJMenuBar(jMenu);

        jTabbedPane = new javax.swing.JTabbedPane();
        jTabbedPane.addTab("Linear Regression", new LRPanel(this));
        jTabbedPane.addTab("Cubic Splines", new CsPanel(this));
        jTabbedPane.addTab("Nonlinear Model", new NLPanel(this));
        jTabbedPane.addTab("Radial Basis", new RBPanel(this));
        //jTabbedPane.addTab("Radial Basis (Contour)", new RBPanel(this));
        getContentPane().add(jTabbedPane, java.awt.BorderLayout.NORTH);
        jTabbedPane.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                reset();
            }
        });

        dataMenu.removeAll();
    }

    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {
        setVisible(false);
        dispose();
    }

    /**
     * @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 FittingMain(exitOnClose).show();
    }
}