/*
 This file is part of the software framework JStatCom, 
 a library for building applications for data based analysis.

 Copyright (C) 2000-2005  Markus Kraetzig

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

 This library 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
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 USA
 */

package com.jstatcom.engine.gauss;

import java.io.File;
import java.util.Iterator;

import org.apache.log4j.Logger;

import com.jstatcom.engine.AbstractConfigPanel;
import com.jstatcom.engine.ConfigHolder;
import com.jstatcom.io.FileSupport;

/**
 * An implementation of the AbstractConfigPanel to create a user
 * input mask for configuration information related to running the GAUSS
 * program.
 * 
 * @author Markus Kraetzig
 */
public final class GaussConfigPanel extends AbstractConfigPanel {
    private static final Logger log = Logger.getLogger(GaussConfigPanel.class);

    private javax.swing.JLabel ivjJLabel1 = null;

    private javax.swing.JLabel ivjJLabel2 = null;

    private javax.swing.JLabel ivjJLabel3 = null;

    IvjEventHandler ivjEventHandler = new IvjEventHandler();

    private javax.swing.JTextField ivjExecLocationField = null;

    private javax.swing.JTextField ivjTempDirField = null;

    private javax.swing.JComboBox ivjVersionCombo = null;

    private javax.swing.JButton ivjGaussLocationButton = null;

    private javax.swing.JButton ivjTempDirButton = null;

    class IvjEventHandler implements java.awt.event.ActionListener {
        public void actionPerformed(java.awt.event.ActionEvent e) {
            if (e.getSource() == GaussConfigPanel.this.getGaussLocationButton())
                connEtoC1();
            if (e.getSource() == GaussConfigPanel.this.getTempDirButton())
                connEtoC2();
        };
    };

    /**
     * GaussConfigPanel constructor comment.
     */
    public GaussConfigPanel() {
        super();
        initialize();
    }

    /**
     * connEtoC1: (GaussLocation.action. -->
     * GaussConfigPanel.gaussLocation_ActionEvents()V)
     */
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private void connEtoC1() {
        try {
            // user code begin {1}
            // user code end
            this.gaussLocation_ActionEvents();
            // user code begin {2}
            // user code end
        } catch (Throwable ivjExc) {
            // user code begin {3}
            // user code end
            handleException(ivjExc);
        }
    }

    /**
     * connEtoC2: (TempDir.action. --> GaussConfigPanel.tempDir_ActionEvents()V)
     */
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private void connEtoC2() {
        try {
            // user code begin {1}
            // user code end
            this.tempDir_ActionEvents();
            // user code begin {2}
            // user code end
        } catch (Throwable ivjExc) {
            // user code begin {3}
            // user code end
            handleException(ivjExc);
        }
    }

    /**
     * Comment
     */
    private void gaussLocation_ActionEvents() {
        File dir = FileSupport.getInstance().chooseDirectory(this,
                "Select Gauss Directory");
        if (dir != null)
            getExecLocationField().setText(dir.toString());
        return;
    }

    /**
     * Return the JTextField1 property value.
     * 
     * @return javax.swing.JTextField
     */
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private javax.swing.JTextField getExecLocationField() {
        if (ivjExecLocationField == null) {
            try {
                ivjExecLocationField = new javax.swing.JTextField();
                ivjExecLocationField.setName("ExecLocationField");
                // user code begin {1}
                // user code end
            } catch (Throwable ivjExc) {
                // user code begin {2}
                // user code end
                handleException(ivjExc);
            }
        }
        return ivjExecLocationField;
    }

    /**
     * Return the GaussLocation property value.
     * 
     * @return javax.swing.JButton
     */
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private javax.swing.JButton getGaussLocationButton() {
        if (ivjGaussLocationButton == null) {
            try {
                ivjGaussLocationButton = new javax.swing.JButton();
                ivjGaussLocationButton.setName("GaussLocationButton");
                ivjGaussLocationButton.setMnemonic('w');
                ivjGaussLocationButton.setText("Browse...");
                // user code begin {1}
                // user code end
            } catch (Throwable ivjExc) {
                // user code begin {2}
                // user code end
                handleException(ivjExc);
            }
        }
        return ivjGaussLocationButton;
    }

    /**
     * Return the JLabel1 property value.
     * 
     * @return javax.swing.JLabel
     */
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private javax.swing.JLabel getJLabel1() {
        if (ivjJLabel1 == null) {
            try {
                ivjJLabel1 = new javax.swing.JLabel();
                ivjJLabel1.setName("JLabel1");
                ivjJLabel1.setText("Location of Gauss executable ");
                // user code begin {1}
                // user code end
            } catch (Throwable ivjExc) {
                // user code begin {2}
                // user code end
                handleException(ivjExc);
            }
        }
        return ivjJLabel1;
    }

    /**
     * Return the JLabel2 property value.
     * 
     * @return javax.swing.JLabel
     */
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private javax.swing.JLabel getJLabel2() {
        if (ivjJLabel2 == null) {
            try {
                ivjJLabel2 = new javax.swing.JLabel();
                ivjJLabel2.setName("JLabel2");
                ivjJLabel2
                        .setText(" Temporary directory (if empty, system TEMP is used)");
                // user code begin {1}
                // user code end
            } catch (Throwable ivjExc) {
                // user code begin {2}
                // user code end
                handleException(ivjExc);
            }
        }
        return ivjJLabel2;
    }

    /**
     * Return the JLabel3 property value.
     * 
     * @return javax.swing.JLabel
     */
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private javax.swing.JLabel getJLabel3() {
        if (ivjJLabel3 == null) {
            try {
                ivjJLabel3 = new javax.swing.JLabel();
                ivjJLabel3.setName("JLabel3");
                ivjJLabel3.setText("Version of Gauss ");
                // user code begin {1}
                // user code end
            } catch (Throwable ivjExc) {
                // user code begin {2}
                // user code end
                handleException(ivjExc);
            }
        }
        return ivjJLabel3;
    }

    /**
     * Return the TempDir property value.
     * 
     * @return javax.swing.JButton
     */
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private javax.swing.JButton getTempDirButton() {
        if (ivjTempDirButton == null) {
            try {
                ivjTempDirButton = new javax.swing.JButton();
                ivjTempDirButton.setName("TempDirButton");
                ivjTempDirButton.setMnemonic('w');
                ivjTempDirButton.setText("Browse...");
                // user code begin {1}
                // user code end
            } catch (Throwable ivjExc) {
                // user code begin {2}
                // user code end
                handleException(ivjExc);
            }
        }
        return ivjTempDirButton;
    }

    /**
     * Return the JTextField11 property value.
     * 
     * @return javax.swing.JTextField
     */
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private javax.swing.JTextField getTempDirField() {
        if (ivjTempDirField == null) {
            try {
                ivjTempDirField = new javax.swing.JTextField();
                ivjTempDirField.setName("TempDirField");
                // user code begin {1}
                // user code end
            } catch (Throwable ivjExc) {
                // user code begin {2}
                // user code end
                handleException(ivjExc);
            }
        }
        return ivjTempDirField;
    }

    /**
     * Return the JComboBox1 property value.
     * 
     * @return javax.swing.JComboBox
     */
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private javax.swing.JComboBox getVersionCombo() {
        if (ivjVersionCombo == null) {
            try {
                ivjVersionCombo = new javax.swing.JComboBox();
                ivjVersionCombo.setName("VersionCombo");
                ivjVersionCombo.setMinimumSize(new java.awt.Dimension(130, 23));
                // user code begin {1}

                for (Iterator iter = GaussConfigKeys.versionIterator(); iter
                        .hasNext();)
                    ivjVersionCombo.addItem(iter.next());

                // user code end
            } catch (Throwable ivjExc) {
                // user code begin {2}
                // user code end
                handleException(ivjExc);
            }
        }
        return ivjVersionCombo;
    }

    /**
     * Called whenever the part throws an exception.
     * 
     * @param exception
     *            Exception
     */
    private void handleException(Throwable exception) {

        log.error("Unhandled Exception", exception);
    }

    /**
     * Initializes connections
     * 
     * @exception Exception
     *                The exception description.
     */
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private void initConnections() throws Exception {
        // user code begin {1}
        // user code end
        getGaussLocationButton().addActionListener(ivjEventHandler);
        getTempDirButton().addActionListener(ivjEventHandler);
    }

    /**
     * Initialize the class.
     */
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private void initialize() {
        try {
            // user code begin {1}
            // user code end
            setName("GaussConfigPanel");
            setPreferredSize(new java.awt.Dimension(300, 200));
            setLayout(new java.awt.GridBagLayout());
            setSize(487, 235);
            setMinimumSize(new java.awt.Dimension(300, 200));

            java.awt.GridBagConstraints constraintsExecLocationField = new java.awt.GridBagConstraints();
            constraintsExecLocationField.gridx = 0;
            constraintsExecLocationField.gridy = 1;
            constraintsExecLocationField.gridwidth = 2;
            constraintsExecLocationField.fill = java.awt.GridBagConstraints.HORIZONTAL;
            constraintsExecLocationField.weightx = 1.0;
            constraintsExecLocationField.insets = new java.awt.Insets(5, 10, 0,
                    0);
            add(getExecLocationField(), constraintsExecLocationField);

            java.awt.GridBagConstraints constraintsJLabel1 = new java.awt.GridBagConstraints();
            constraintsJLabel1.gridx = 0;
            constraintsJLabel1.gridy = 0;
            constraintsJLabel1.gridwidth = 3;
            constraintsJLabel1.fill = java.awt.GridBagConstraints.HORIZONTAL;
            constraintsJLabel1.insets = new java.awt.Insets(20, 10, 0, 0);
            add(getJLabel1(), constraintsJLabel1);

            java.awt.GridBagConstraints constraintsJLabel2 = new java.awt.GridBagConstraints();
            constraintsJLabel2.gridx = 0;
            constraintsJLabel2.gridy = 2;
            constraintsJLabel2.gridwidth = 3;
            constraintsJLabel2.fill = java.awt.GridBagConstraints.HORIZONTAL;
            constraintsJLabel2.insets = new java.awt.Insets(20, 10, 0, 0);
            add(getJLabel2(), constraintsJLabel2);

            java.awt.GridBagConstraints constraintsTempDirField = new java.awt.GridBagConstraints();
            constraintsTempDirField.gridx = 0;
            constraintsTempDirField.gridy = 3;
            constraintsTempDirField.gridwidth = 2;
            constraintsTempDirField.fill = java.awt.GridBagConstraints.HORIZONTAL;
            constraintsTempDirField.weightx = 1.0;
            constraintsTempDirField.insets = new java.awt.Insets(5, 10, 0, 0);
            add(getTempDirField(), constraintsTempDirField);

            java.awt.GridBagConstraints constraintsJLabel3 = new java.awt.GridBagConstraints();
            constraintsJLabel3.gridx = 0;
            constraintsJLabel3.gridy = 4;
            constraintsJLabel3.fill = java.awt.GridBagConstraints.HORIZONTAL;
            constraintsJLabel3.anchor = java.awt.GridBagConstraints.NORTHWEST;
            constraintsJLabel3.insets = new java.awt.Insets(20, 10, 0, 0);
            add(getJLabel3(), constraintsJLabel3);

            java.awt.GridBagConstraints constraintsVersionCombo = new java.awt.GridBagConstraints();
            constraintsVersionCombo.gridx = 0;
            constraintsVersionCombo.gridy = 5;
            constraintsVersionCombo.fill = java.awt.GridBagConstraints.HORIZONTAL;
            constraintsVersionCombo.anchor = java.awt.GridBagConstraints.NORTHWEST;
            constraintsVersionCombo.weightx = 1.0;
            constraintsVersionCombo.weighty = 1.0;
            constraintsVersionCombo.insets = new java.awt.Insets(5, 10, 0, 0);
            add(getVersionCombo(), constraintsVersionCombo);

            java.awt.GridBagConstraints constraintsGaussLocationButton = new java.awt.GridBagConstraints();
            constraintsGaussLocationButton.gridx = 2;
            constraintsGaussLocationButton.gridy = 1;
            constraintsGaussLocationButton.insets = new java.awt.Insets(5, 10,
                    0, 10);
            add(getGaussLocationButton(), constraintsGaussLocationButton);

            java.awt.GridBagConstraints constraintsTempDirButton = new java.awt.GridBagConstraints();
            constraintsTempDirButton.gridx = 2;
            constraintsTempDirButton.gridy = 3;
            constraintsTempDirButton.insets = new java.awt.Insets(5, 10, 0, 10);
            add(getTempDirButton(), constraintsTempDirButton);
            initConnections();
        } catch (Throwable ivjExc) {
            handleException(ivjExc);
        }
        // user code begin {2}
        // user code end
    }

    /**
     * @see com.jstatcom.engine.AbstractConfigPanel
     * 
     * @throws IllegalArgumentException
     *             if (configHolder == null)
     */
    public void setConfig(ConfigHolder configHolder) {

        if (configHolder == null)
            throw new IllegalArgumentException("Argument was null.");

        getExecLocationField().setText(
                configHolder.getConfig(GaussConfigKeys.EXE_LOCATION));

        getTempDirField().setText(
                configHolder.getConfig(GaussConfigKeys.TEMP_DIR));

        getVersionCombo().setSelectedItem(
                configHolder.getConfig(GaussConfigKeys.GAUSS_VERSION));

    }

    /**
     * @see com.jstatcom.engine.AbstractConfigPanel
     * 
     * @throws IllegalArgumentException
     *             if (configHolder == null)
     */
    public String storeConfig(ConfigHolder configHolder) {

        if (configHolder == null)
            throw new IllegalArgumentException("Argument was null.");

        configHolder.setConfig(GaussConfigKeys.EXE_LOCATION,
                getExecLocationField().getText().trim());
        configHolder.setConfig(GaussConfigKeys.TEMP_DIR, getTempDirField()
                .getText().trim());
        configHolder.setConfig(GaussConfigKeys.GAUSS_VERSION, getVersionCombo()
                .getSelectedItem().toString());

        return null;

    }

    /**
     * Comment
     */
    private void tempDir_ActionEvents() {
        File dir = FileSupport.getInstance().chooseDirectory(this,
                "Select Temporary Directory");
        if (dir != null)
            getTempDirField().setText(dir.toString());
        return;
    }
}
 

Ads help maintain this website.