/*
 * @(#)NewAccountDialog.java
 *
 * This file is part of webCDwriter - Network CD Writing.
 *
 * Copyright (C) 2001 Jörg P. M. Haeger
 *
 * webCDwriter is free software. See CDcreator.java for details.
 *
 * Jörg Haeger, 14.05.2001
 */

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;

public class NewAccountDialog extends Dialog
{
	public NewAccountDialog()
	{
		super("NADTitle");

		JPanel panel = new JPanel()
		{
			public Insets getInsets() {
				return new Insets(10, 10, 10, 10);
			}
		};
		panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

		userPanel = createInputGroup();
		panel.add(userPanel);

		getContentPane().add(panel, BorderLayout.CENTER);
		getContentPane().add(createControlPanel("OK"),
			BorderLayout.SOUTH);
		pack();
	}

	protected boolean apply()
	{
		String userID = userIDField.getText();
/*		String a = passwordField.getText();
		String b = passwordField2.getText();
*/		String eMail = eMailField.getText();
		if (userID.length() == 0)
		{
			JOptionPane.showMessageDialog(
				CDcreator.mainWin,
				i18n("NADNoUserName"),
				i18n("error"),
				JOptionPane.ERROR_MESSAGE);
			return false;
		}
/*		else
		if (!a.equals(b))
		{
			JOptionPane.showMessageDialog(
				CDcreator.mainWin,
				i18n("NADPasswordsDiffer"),
				i18n("error"),
				JOptionPane.ERROR_MESSAGE);
			return false;
		}
		else
		if (a.length() == 0)
		{
			JOptionPane.showMessageDialog(
				CDcreator.mainWin,
				i18n("NADNoPassword"),
				i18n("error"),
				JOptionPane.ERROR_MESSAGE);
			return false;
		}
*/		else
		if (eMail.length() == 0)
			return false;
		else {
			try {
				new NewAccount(userID, eMail).exec();
				this.setVisible(false);
				JOptionPane.showMessageDialog(
					CDcreator.mainWin,
					i18n("NADWaitForEMail"),
					i18n("NADWaitForEMailTitle"),
					JOptionPane.INFORMATION_MESSAGE);
				return true;
			}
			catch (Exception e) {
				JOptionPane.showMessageDialog(
					CDcreator.mainWin,
					i18n("NADFailed"),
					i18n("error"),
					JOptionPane.ERROR_MESSAGE);
				return false;
			}
		}
	}

	protected JPanel createInputGroup()
	{
		JPanel p = new JPanel();
		p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
		p.setBorder(
			BorderFactory.createEmptyBorder(3, 40, 5, 5));
		p.setAlignmentX(LEFT_ALIGNMENT);

		userIDField = new JTextField(State.userID);
		userIDField.setColumns(15);
		tab = 100;
		p.add(createLabelItemBox(
			new JLabel(i18n("NADUserName")),
			userIDField));
		p.add(Box.createVerticalStrut(10));

/*		passwordField = new JPasswordField("");
		passwordField.setColumns(10);
		p.add(createLabelItemBox(
			new JLabel(i18n("NADPassword")),
			passwordField));

		passwordField2 = new JPasswordField("");
		passwordField2.setColumns(10);
		p.add(createLabelItemBox(
			new JLabel(i18n("NADRepeat")),
			passwordField2));
*/
		eMailField = new JTextField("");
		eMailField.setColumns(25);
		p.add(createLabelItemBox(
			new JLabel(i18n("NADeMail")),
			eMailField));

		return p;
	}

	JPanel userPanel;
	JTextField userIDField, passwordField, passwordField2, eMailField;
}
