/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | Copyright (C) 1991-2005 OpenCFD Ltd.
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
    Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM; if not, write to the Free Software Foundation,
    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

\*---------------------------------------------------------------------------*/
package FoamX.Options;

class OptionsDlg
    extends javax.swing.JDialog
{
    //--------------------------------------------------------------------------

    private OptionsManager optionsMgr_;
    private boolean wasCancelled_;

    private GeneralOptionsTab generalTab_;
    private DocServerTab docServerTab_;
    private HostsTab hostsTab_;
    private FieldTypesTab foamTypesTab_;
    private PatchTypesTab patchTypesTab_;
    private PatchFieldTypesTab patchFieldTypesTab_;

    //--------------------------------------------------------------------------
    /** Creates new form OptionsDlg */
    OptionsDlg(java.awt.Frame parent, OptionsManager optionsMgr)
    {
        super(parent, true);  // Modal.

        optionsMgr_   = optionsMgr;
        wasCancelled_ = false;

        // Create tabs.
        generalTab_         = new GeneralOptionsTab(optionsMgr_);
        docServerTab_       = new DocServerTab(optionsMgr_);
        hostsTab_           = new HostsTab(optionsMgr_);
        foamTypesTab_      = new FieldTypesTab(optionsMgr_);
        patchTypesTab_      = new PatchTypesTab(optionsMgr_);
        patchFieldTypesTab_ = new PatchFieldTypesTab(optionsMgr_);

        // Initialise components and add tabs.
        initComponents();
        tabbedPane_.addTab("General", generalTab_);
        tabbedPane_.addTab("Doc Server", docServerTab_);
        tabbedPane_.addTab("Hosts", hostsTab_);
        tabbedPane_.addTab("Field Types", foamTypesTab_);
        tabbedPane_.addTab("Patch Types", patchTypesTab_);
        tabbedPane_.addTab("Patch Field Types", patchFieldTypesTab_);
    }

    //--------------------------------------------------------------------------

    boolean wasCancelled()
    {
        return wasCancelled_;
    }

    //--------------------------------------------------------------------------
    /** 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 FormEditor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        tabbedPane_ = new javax.swing.JTabbedPane();
        buttonPanel_ = new javax.swing.JPanel();
        buttonOK_ = new javax.swing.JButton();
        buttonCancel_ = new javax.swing.JButton();
        
        getContentPane().setLayout(new java.awt.GridBagLayout());
        java.awt.GridBagConstraints gridBagConstraints1;
        
        setTitle("FoamX Options...");
        setName("FoamX Options");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });
        
        tabbedPane_.setFont(new java.awt.Font("Dialog", 0, 10));
        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 0;
        gridBagConstraints1.gridy = 0;
        gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints1.anchor = java.awt.GridBagConstraints.NORTH;
        gridBagConstraints1.weightx = 1.0;
        gridBagConstraints1.weighty = 1.0;
        getContentPane().add(tabbedPane_, gridBagConstraints1);
        
        buttonPanel_.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
        
        buttonPanel_.setBorder(new javax.swing.border.EtchedBorder(javax.swing.border.EtchedBorder.RAISED));
        buttonOK_.setFont(new java.awt.Font("Dialog", 0, 10));
        buttonOK_.setText("OK");
        buttonOK_.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonOKActionPerformed_(evt);
            }
        });
        
        buttonPanel_.add(buttonOK_);
        
        buttonCancel_.setFont(new java.awt.Font("Dialog", 0, 10));
        buttonCancel_.setText("Cancel");
        buttonCancel_.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonCancelActionPerformed_(evt);
            }
        });
        
        buttonPanel_.add(buttonCancel_);
        
        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 0;
        gridBagConstraints1.gridy = 1;
        gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints1.anchor = java.awt.GridBagConstraints.SOUTH;
        getContentPane().add(buttonPanel_, gridBagConstraints1);
        
        pack();
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setSize(new java.awt.Dimension(400, 350));
        setLocation((screenSize.width-400)/2,(screenSize.height-350)/2);
    }//GEN-END:initComponents

    //--------------------------------------------------------------------------

private void buttonCancelActionPerformed_ (java.awt.event.ActionEvent evt)
    {//GEN-FIRST:event_buttonCancelActionPerformed_
        wasCancelled_ = true;
        setVisible(false);
        dispose();
  }//GEN-LAST:event_buttonCancelActionPerformed_

    //--------------------------------------------------------------------------

private void buttonOKActionPerformed_ (java.awt.event.ActionEvent evt)
    {//GEN-FIRST:event_buttonOKActionPerformed_
        wasCancelled_ = false;
        
        docServerTab_.updateModel();

        setVisible(false);
        dispose();
  }//GEN-LAST:event_buttonOKActionPerformed_

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

    //--------------------------------------------------------------------------

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JTabbedPane tabbedPane_;
  private javax.swing.JPanel buttonPanel_;
  private javax.swing.JButton buttonOK_;
  private javax.swing.JButton buttonCancel_;
  // End of variables declaration//GEN-END:variables

    //--------------------------------------------------------------------------
    //--------------------------------------------------------------------------
    //--------------------------------------------------------------------------
    //--------------------------------------------------------------------------
}




