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

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

/**
 * BurnDialog
 *
 * @version 20021107
 * @author Jörg P. M. Haeger
 */
class BurnDialog extends JDialog {
	JPanel panel;
	JLabel label;
	JProgressBar bar;
	Component space;
	JPanel buttons;
	JPanel hideBar;
	JPanel showBar;

	BurnDialog() {
		super(CDcreator.mainWin, "burnDialog", true);
		setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);

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

		label = new JLabel();
		label.setAlignmentX(CENTER_ALIGNMENT);
		Dimension d = new Dimension(400, 30);
		label.setPreferredSize(d);
		panel.add(label);

		panel.add(Box.createRigidArea(new Dimension(300, 10)));

		bar = new JProgressBar();
		bar.setStringPainted(true);
		panel.add(bar);

		space = Box.createRigidArea(new Dimension(300, 15));
		panel.add(space);

		JButton button = new JButton(CDcreator.i18n("details"));
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				panel.remove(buttons);
				panel.remove(space);
				showDetails();
			}
		});
		buttons = new JPanel();
		buttons.setLayout(new FlowLayout());
		buttons.add(button);
		panel.add(buttons);

		getContentPane().add(panel);
		pack();
		center();
	}

	void center() {
		// center dialog in parent
		Rectangle r = getParent().getBounds(), r1 = getBounds();
		setLocation(r.x + (r.width - r1.width) / 2,
			r.y + (r.height - r1.height) / 2);
	}

	public void setMessage(String str) {
		label.setText(str);
		pack();
	}

	public void setRange(int a, int b) {
		bar.setMinimum(a);
		bar.setMaximum(b);
	}

	public void setProgress(int n) {
		bar.setValue(n);
	}

	void showDetails() {
		JButton hide = new JButton(MainWin.getIcon("up.png"));
		hide.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				panel.remove(Log.getView());
				panel.remove(hideBar);
				panel.add(showBar);
				panel.add(Box.createVerticalGlue());
				pack();
			}
		});
		hide.setPreferredSize(new Dimension(25, 25));
		hideBar = new JPanel();
		hideBar.setLayout(
			new BoxLayout(hideBar, BoxLayout.X_AXIS));
		hideBar.add(Box.createHorizontalGlue());
		hideBar.add(hide);

		panel.add(hideBar);
		Log.getView().setPreferredSize(
			new Dimension(300, 160));
		panel.add(Log.getView());
		pack();

		JButton show = new JButton(MainWin.getIcon("down.png"));
		show.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				panel.remove(showBar);
				panel.add(hideBar);
				panel.add(Log.getView());
				pack();
			}
		});
		show.setPreferredSize(new Dimension(25, 25));
		showBar = new JPanel();
		showBar.setLayout(
			new BoxLayout(showBar, BoxLayout.X_AXIS));
		showBar.add(Box.createHorizontalGlue());
		showBar.add(show);
	}
}
