/*
 * Wind2Select.java
 *
 * Created on October 17, 2006, 9:24 PM
 */
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

/**
 *
 * @author  davarus
 */
public class Wind2SelectNew extends javax.swing.JFrame 
	implements ActionListener {
    
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/** Creates new form Wind2Select */
    public Wind2SelectNew() {
    	WindowUtilities.setNativeLookAndFeel();
        initComponents();
	setDefaultCloseOperation(DISPOSE_ON_CLOSE);
	pack();
	setLocationRelativeTo(null);
	setVisible(true);
    }
    
    /** 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
        buttonNew = new javax.swing.JButton();
	textName = new javax.swing.JTextField(16);

        setTitle("Name Configuration");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });
	getContentPane().setLayout(new java.awt.FlowLayout());

	getContentPane().add(textName);

        buttonNew.setText("Create");
	buttonNew.setActionCommand("create");
	buttonNew.addActionListener(this);
        getContentPane().add(buttonNew);

    }//GEN-END:initComponents

    public void actionPerformed(ActionEvent e) {
    	if ("create".equals(e.getActionCommand())) {
		if ("".equals(textName.getText())) {
			JOptionPane.showMessageDialog(this,
				"You must specify a name!",
				"Blank name",
				JOptionPane.ERROR_MESSAGE);
			return;
		}
		if ((new File(textName.getText() + ".ini")).exists()) {
			JOptionPane.showMessageDialog(this,
				"Configuration file already exists!",
				"File exists",
				JOptionPane.ERROR_MESSAGE);
			return;
		}
		
		(new Wind2Config(new IniFile(textName.getText() + ".ini"))).setVisible(true);
		dispose();
	}
    }
    
    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
        //System.exit(0);
	(new Wind2Select()).setVisible(true);
	dispose();
    }//GEN-LAST:event_exitForm

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        new Wind2SelectNew().setVisible(true);
    }
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonNew;
    private javax.swing.JTextField textName;
    // End of variables declaration//GEN-END:variables
    
}
