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

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

/**
 * TypesDialog
 *
 * @version 20021127
 * @author Jörg P. M. Haeger
 */
public class TypesDialog extends Dialog {
	public TypesDialog(boolean canBeCancelled) {
		super("titleTypes");
		if (!canBeCancelled)
			setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);

		JPanel panel = new JPanel() {
			public Insets getInsets() {
				return new Insets(10, 10, 10, 10);
			}
		};
		panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
		panel.add(createTypeSelectionGroup());
//		panel.add(new JSeparator());
//		panel.add(createStoreGroup());
		getContentPane().add(panel, BorderLayout.CENTER);

		JPanel control;
		if (canBeCancelled)
			control = createControlPanel(i18n("OK"));
		else
			control = createControlPanel();
		getContentPane().add(control, BorderLayout.SOUTH);
		pack();
	}

	protected boolean apply() {
		if (dataButton.isSelected()) {
			Mode.type = Mode.data;
			Mode.makeImage = true;
		}
		else
		if (imageButton.isSelected()) {
			Mode.type = Mode.data;
			Mode.makeImage = false;
		}
		else
			Mode.type = Mode.audio;
		return true;
	}

	protected JPanel createControlPanel() {
		JPanel panel = new JPanel();
		panel.setLayout(new FlowLayout());

		OKButton = new JButton(i18n("OK"));
		OKButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				OKPressed();
			}
		});
		panel.add(OKButton);

		return panel;
	}

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

		IDField = new JTextField("");
		IDField.setColumns(10);
		tab = 0;
		p.add(createLabelItemBox(
			new JLabel(i18n("NewSessionDialogID")),
			IDField));
		p.add(Box.createRigidArea(new Dimension(0, 10)));
		p.add(new JLabel(i18n("NewSessionDialogWarning")));

		return p;
	}

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

		storeButton = new JCheckBox(i18n("NewSessionDialogStore"));
		storeButton.setSelected(false);
		panel.add(storeButton);

		IDInput = createIDInput();
		panel.add(IDInput);
		storeButton.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent e) {
				IDInput.setEnabled(storeButton.isSelected());
			}
		});
		IDInput.setEnabled(false);

		return panel;
	}

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

		panel.add(new JLabel(i18n("selectMode")));

		dataButton = new JRadioButton(i18n("dataCD"));
		dataButton.setSelected(true);
		panel.add(dataButton);

		imageButton = new JRadioButton(i18n("imageCD"));
		panel.add(imageButton);

		audioButton = new JRadioButton(i18n("audioCD"));
		if (CDcreator.audioCDSupport
			&& Options.medium != Options.DVDPLUSRW
			&& Options.medium != Options.DVDPLUSR)
			panel.add(audioButton);

		panel.add(new JLabel("?"));

		ButtonGroup group = new ButtonGroup();
		group.add(dataButton);
		group.add(imageButton);
		group.add(audioButton);

		return panel;
	}

	private JCheckBox storeButton;
	private JPanel IDInput;
	private JRadioButton dataButton, imageButton, audioButton;
	private JTextField IDField;
}
