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

class PutDialog extends JDialog
{
	JLabel label;
	JProgressBar bar;
	boolean buttonPressed = false;

	PutDialog()
	{
		super(CDcreator.mainWin, "PutDialog", true);

		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				handleButton();
			}
		});

		getContentPane().setLayout(new BoxLayout(
			getContentPane(), BoxLayout.Y_AXIS));

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

		label = new JLabel();
		label.setBorder(
			BorderFactory.createTitledBorder(
				CDcreator.i18n("file")));
		label.setAlignmentX(CENTER_ALIGNMENT);
		Dimension d = new Dimension(400, 30 + 20);
		label.setMaximumSize(d);
		label.setMinimumSize(d);
		label.setPreferredSize(d);
		panel.add(label);

		panel.add(Box.createVerticalStrut(10));

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

		getContentPane().add(panel);

		JPanel buttons = new JPanel()
		{
			public Insets getInsets() {
				return new Insets(5, 10, 10, 10);
			}
		};
		buttons.setLayout(new FlowLayout(FlowLayout.CENTER));
		getContentPane().add(buttons);

		JButton button = new JButton(CDcreator.i18n("cancel"));
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				handleButton();
			}
		});
		buttons.add(button);
		pack();
	}

	public void handleButton()
	{
		buttonPressed = true;
		this.setVisible(false);
	}

	public void pack()
	{
		super.pack();

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

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

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

	public boolean wasButtonPressed()
	{
		return buttonPressed;
	}
}

