/*
 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.io;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.BevelBorder;

import org.apache.log4j.Logger;

import com.jstatcom.component.TopFrameReference;
import com.jstatcom.ts.TSDate;

/**
 * A dialog for gathering user information if a pure ASCII file is read in.
 * 
 * @author Markus Kraetzig 
 */
public final class TSDataDialog extends JDialog {
    private static final Logger log = Logger.getLogger(TSDataDialog.class);

    private TSDate tsDate = TSDate.valueOf("1960 Q1");

    private JButton ivjJButton1 = null;

    private JPanel ivjJDialogContentPane = null;

    private JLabel ivjJLabel3 = null;

    private JPanel ivjJPanel1 = null;

    private JScrollPane ivjJScrollPane1 = null;

    private JTextArea ivjNames = null;

    private JTextField ivjStartDate = null;

    IvjEventHandler ivjEventHandler = new IvjEventHandler();

    private JButton ivjCancel = null;

    private boolean cancelDialog = false;

    private JPanel ivjJPanel2 = null;

    private JTextArea jTextArea = null;

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

    /**
     * Creates a TSASCIIDialog.
     * 
     * @param owner
     *            parent frame
     * @param modal
     *            boolean
     */
    public TSDataDialog(java.awt.Frame owner, boolean modal) {
        super(owner, modal);
        initialize();
    }

    /**
     * Comment
     */
    private void Cancel_ActionEvents() {
        setVisible(false);
        setCancelDialog(true);
        return;
    }

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

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

    /**
     * Return the Cancel property value.
     * 
     * @return javax.swing.JButton
     */
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private javax.swing.JButton getCancel() {
        if (ivjCancel == null) {
            try {
                ivjCancel = new javax.swing.JButton();
                ivjCancel.setName("Cancel");
                ivjCancel.setPreferredSize(new java.awt.Dimension(80, 27));
                ivjCancel.setText("Cancel");
                ivjCancel.setMinimumSize(new java.awt.Dimension(80, 27));
                ivjCancel.setMaximumSize(new java.awt.Dimension(80, 27));
                // user code begin {1}
                // user code end
            } catch (Throwable ivjExc) {
                // user code begin {2}
                // user code end
                handleException(ivjExc);
            }
        }
        return ivjCancel;
    }

    /**
     * Return the JButton1 property value.
     * 
     * @return javax.swing.JButton
     */
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private javax.swing.JButton getOKButton() {
        if (ivjJButton1 == null) {
            try {
                ivjJButton1 = new javax.swing.JButton();
                ivjJButton1.setName("JButton1");
                ivjJButton1.setPreferredSize(new java.awt.Dimension(80, 27));
                ivjJButton1.setText("OK");
                ivjJButton1.setMaximumSize(new java.awt.Dimension(80, 27));
                ivjJButton1.setMinimumSize(new java.awt.Dimension(80, 27));
                // user code begin {1}
                // user code end
            } catch (Throwable ivjExc) {
                // user code begin {2}
                // user code end
                handleException(ivjExc);
            }
        }
        return ivjJButton1;
    }

    /**
     * Return the JDialogContentPane property value.
     * 
     * @return javax.swing.JPanel
     */
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private javax.swing.JPanel getJDialogContentPane() {
        if (ivjJDialogContentPane == null) {
            try {
                ivjJDialogContentPane = new javax.swing.JPanel();
                ivjJDialogContentPane.setName("JDialogContentPane");
                ivjJDialogContentPane.setLayout(new java.awt.BorderLayout());
                getJDialogContentPane().add(getJPanel1(), "Center");
                getJDialogContentPane().add(getJPanel2(), "South");
                // user code begin {1}
                // user code end
            } catch (Throwable ivjExc) {
                // user code begin {2}
                // user code end
                handleException(ivjExc);
            }
        }
        return ivjJDialogContentPane;
    }

    /**
     * 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("Date of first observation");
                ivjJLabel3.setPreferredSize(new java.awt.Dimension(136, 20));
                // user code end
            } catch (Throwable ivjExc) {
                // user code begin {2}
                // user code end
                handleException(ivjExc);
            }
        }
        return ivjJLabel3;
    }

    /**
     * Return the JPanel1 property value.
     * 
     * @return javax.swing.JPanel
     */
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private javax.swing.JPanel getJPanel1() {
        if (ivjJPanel1 == null) {
            try {
                GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
                GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
                GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
                GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
                ivjJPanel1 = new javax.swing.JPanel();
                ivjJPanel1.setName("JPanel1");
                ivjJPanel1.setPreferredSize(new java.awt.Dimension(400, 230));
                ivjJPanel1.setBorder(new BevelBorder(BevelBorder.LOWERED));
                ivjJPanel1.setLayout(new GridBagLayout());
                ivjJPanel1.setMinimumSize(new java.awt.Dimension(400, 230));
                gridBagConstraints1.gridx = 1;
                gridBagConstraints1.gridy = 0;
                gridBagConstraints1.ipadx = 0;
                gridBagConstraints1.ipady = 0;
                gridBagConstraints1.insets = new java.awt.Insets(10, 10, 0, 10);
                gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
                gridBagConstraints2.gridx = 0;
                gridBagConstraints2.gridy = 2;
                gridBagConstraints2.gridwidth = 2;
                gridBagConstraints2.weightx = 1.0;
                gridBagConstraints2.weighty = 1.0;
                gridBagConstraints2.fill = java.awt.GridBagConstraints.BOTH;
                gridBagConstraints2.ipadx = 0;
                gridBagConstraints2.ipady = 0;
                gridBagConstraints2.insets = new java.awt.Insets(5, 5, 0, 5);
                gridBagConstraints3.gridx = 0;
                gridBagConstraints3.gridy = 0;
                gridBagConstraints3.weightx = 1.0D;
                gridBagConstraints3.fill = java.awt.GridBagConstraints.HORIZONTAL;
                gridBagConstraints3.ipadx = 0;
                gridBagConstraints3.insets = new java.awt.Insets(10, 5, 0, 0);
                gridBagConstraints3.anchor = java.awt.GridBagConstraints.NORTHWEST;
                gridBagConstraints4.gridx = 0;
                gridBagConstraints4.gridy = 1;
                gridBagConstraints4.gridwidth = 2;
                gridBagConstraints4.weightx = 1.0;
                gridBagConstraints4.weighty = 0.0D;
                gridBagConstraints4.fill = java.awt.GridBagConstraints.BOTH;
                gridBagConstraints4.ipadx = 0;
                gridBagConstraints4.ipady = 0;
                gridBagConstraints4.insets = new java.awt.Insets(5, 5, 5, 5);
                ivjJPanel1.add(getJLabel3(), gridBagConstraints1);
                ivjJPanel1.add(getJScrollPane1(), gridBagConstraints2);
                ivjJPanel1.add(getStartDate(), gridBagConstraints3);
                ivjJPanel1.add(getJTextArea(), gridBagConstraints4);
            } catch (Throwable ivjExc) {
                // user code begin {2}
                // user code end
                handleException(ivjExc);
            }
        }
        return ivjJPanel1;
    }

    /**
     * Return the JPanel2 property value.
     * 
     * @return javax.swing.JPanel
     */
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private javax.swing.JPanel getJPanel2() {
        if (ivjJPanel2 == null) {
            try {
                ivjJPanel2 = new javax.swing.JPanel();
                ivjJPanel2.setName("JPanel2");
                ivjJPanel2.setPreferredSize(new java.awt.Dimension(175, 50));
                ivjJPanel2.setLayout(getJPanel2FlowLayout());
                getJPanel2().add(getOKButton(), getOKButton().getName());
                getJPanel2().add(getCancel(), getCancel().getName());
                // user code begin {1}
                // user code end
            } catch (Throwable ivjExc) {
                // user code begin {2}
                // user code end
                handleException(ivjExc);
            }
        }
        return ivjJPanel2;
    }

    /**
     * Return the JPanel2FlowLayout property value.
     * 
     * @return java.awt.FlowLayout
     */
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private java.awt.FlowLayout getJPanel2FlowLayout() {
        java.awt.FlowLayout ivjJPanel2FlowLayout = null;
        try {
            /* Create part */
            ivjJPanel2FlowLayout = new java.awt.FlowLayout();
            ivjJPanel2FlowLayout.setVgap(10);
            ivjJPanel2FlowLayout.setHgap(40);
        } catch (Throwable ivjExc) {
            handleException(ivjExc);
        }
        ;
        return ivjJPanel2FlowLayout;
    }

    /**
     * Return the JScrollPane1 property value.
     * 
     * @return javax.swing.JScrollPane
     */
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private javax.swing.JScrollPane getJScrollPane1() {
        if (ivjJScrollPane1 == null) {
            try {
                ivjJScrollPane1 = new javax.swing.JScrollPane();
                ivjJScrollPane1.setName("JScrollPane1");
                getJScrollPane1().setViewportView(getNames());
                // user code begin {1}
                ivjJScrollPane1
                        .setBorder(javax.swing.BorderFactory
                                .createTitledBorder(
                                        javax.swing.BorderFactory
                                                .createEtchedBorder(javax.swing.border.EtchedBorder.RAISED),
                                        "Optional: Space Separated Variable Names, e.g. invest income cons",
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION,
                                        null, null));
                // user code end
            } catch (Throwable ivjExc) {
                // user code begin {2}
                // user code end
                handleException(ivjExc);
            }
        }
        return ivjJScrollPane1;
    }

    /**
     * Return the Names property value.
     * 
     * @return javax.swing.JTextArea
     */
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private javax.swing.JTextArea getNames() {
        if (ivjNames == null) {
            try {
                ivjNames = new javax.swing.JTextArea();
                ivjNames.setName("Names");
                ivjNames.setBounds(0, 0, 160, 120);
                // user code begin {1}
                // user code end
            } catch (Throwable ivjExc) {
                // user code begin {2}
                // user code end
                handleException(ivjExc);
            }
        }
        return ivjNames;
    }

    /**
     * Return the StartDate property value.
     * 
     * @return javax.swing.JTextField
     */
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private javax.swing.JTextField getStartDate() {
        if (ivjStartDate == null) {
            try {
                ivjStartDate = new javax.swing.JTextField();
                ivjStartDate.setName("StartDate");
                ivjStartDate.setText("1960 Q1");
                ivjStartDate.setPreferredSize(new java.awt.Dimension(200, 20));
                // user code end
            } catch (Throwable ivjExc) {
                // user code begin {2}
                // user code end
                handleException(ivjExc);
            }
        }
        return ivjStartDate;
    }

    /**
     * Gets the selected start date.
     * 
     * @return start date of sample
     */
    public TSDate getTSDate() {
        return tsDate;
    }

    /**
     * Gets a string with the variable names.
     * 
     * @return string containing all names
     */
    public String getVariableNames() {
        return getNames().getText();
    }

    /**
     * Sets the displayed variable names.
     * 
     * @param names
     *            array with the names to display
     * @throws IllegalArgumentException
     *             if (names == null)
     */
    public void setVariableNames(String[] names) {
        if (names == null)
            throw new IllegalArgumentException("Argument was null.");
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < names.length; i++)
            buffer.append(names[i] + " ");

        getNames().setText(buffer.toString());
    }

    /**
     * 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
        getOKButton().addActionListener(ivjEventHandler);
        getCancel().addActionListener(ivjEventHandler);
    }

    /**
     * Initialize the class.
     */
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private void initialize() {
        try {
            // user code begin {1}
            // user code end
            setName("DataFileDialog");
            setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
            setResizable(true);
            setSize(540, 434);
            setTitle("Specify Dataset");
            setContentPane(getJDialogContentPane());
            initConnections();
        } catch (Throwable ivjExc) {
            handleException(ivjExc);
        }
        // user code begin {2}
        getRootPane().setDefaultButton(getOKButton());
        // user code end
    }

    /**
     * Gets whether dialog was canceled.
     * 
     * @return true if canceled
     */
    public boolean isCanceled() {
        return cancelDialog;
    }

    /**
     * This method initializes jTextArea
     * 
     * @return javax.swing.JTextArea
     */
    private JTextArea getJTextArea() {
        if (jTextArea == null) {
            jTextArea = new JTextArea();
            jTextArea.setBackground(getJDialogContentPane().getBackground());
            StringBuffer txt = new StringBuffer();
            txt.append("  quarterly: \"1960 Q1\"\n");
            txt.append("  monthly: \"1960 M10\"\n");
            txt.append("  annual: \"1960\"\n");
            txt.append("  semi-annual: \"1960 I\" or \"1960 II\"\n");
            txt.append("  daily (5 day week): \"11/25/2004 (5)\"\n");
            txt.append("  daily (7 day week): \"12/11/1982 (7)\"\n");
            txt.append("  undated: \"1\" \n");
            txt.append("  arbitrary spec: \"1960 30/265\"");

            jTextArea.setText(txt.toString());
            jTextArea.setEditable(false);
            jTextArea
                    .setBorder(javax.swing.BorderFactory
                            .createTitledBorder(
                                    javax.swing.BorderFactory
                                            .createEtchedBorder(javax.swing.border.EtchedBorder.RAISED),
                                    "Examples",
                                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
                                    javax.swing.border.TitledBorder.DEFAULT_POSITION,
                                    null, null));

            jTextArea.setPreferredSize(new java.awt.Dimension(12, 160));
            jTextArea.setMinimumSize(new java.awt.Dimension(12, 160));
        }
        return jTextArea;
    }

    /**
     * Comment
     */
    private void OK_ActionEvents() {

        String exp = getStartDate().getText();
        try {
            tsDate = TSDate.valueOf(exp);
        } catch (Throwable ex) {
            JOptionPane.showMessageDialog(TopFrameReference.getTopFrameRef(),
                    "Could not parse \"" + exp + "\" to a valid date.",
                    "Input Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        setVisible(false);
        setCancelDialog(false);
        return;
    }

    /**
     * Insert the method's description here. Creation date: (21.03.01 11:22:51)
     * 
     * @param newCancelDialog
     *            boolean
     */
    private void setCancelDialog(boolean newCancelDialog) {
        cancelDialog = newCancelDialog;
    }
} // @jve:decl-index=0:visual-constraint="10,10"

 

Ads help maintain this website.