
// Project: webCDwriter - Network CD Writing
// Author: Jörg Haeger, 17.05.2001

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

public class ChangePasswordDialog extends Dialog
{
	public ChangePasswordDialog()
	{
		super("CPDTitle");

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

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

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

	protected boolean apply()
	{
		String a = passwordField.getText();
		String b = passwordField2.getText();

		if (!a.equals(b))
		{
			JOptionPane.showMessageDialog(
				CDcreator.mainWin,
				i18n("CPDPasswordsDiffer"),
				i18n("error"),
				JOptionPane.ERROR_MESSAGE);
			return false;
		}
		else
		if (a.length() < 4)
		{
			JOptionPane.showMessageDialog(
				CDcreator.mainWin,
				i18n("CPDPasswordTooShort"),
				i18n("error"),
				JOptionPane.ERROR_MESSAGE);
			return false;
		}

		return true;
	}

	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);

		passwordField = new JPasswordField("");
		passwordField.setColumns(15);
		tab = 100;
		p.add(createLabelItemBox(
			new JLabel(i18n("CPDPassword")),
			passwordField));
		p.add(Box.createVerticalStrut(10));

		passwordField2 = new JPasswordField("");
		passwordField2.setColumns(15);
		p.add(createLabelItemBox(
			new JLabel(i18n("CPDRepeat")),
			passwordField2));

		return p;
	}

	String getPassword()
	{
		return passwordField.getText();
	}

	JPanel inputPanel;
	JTextField passwordField, passwordField2;
}
