2008-04-27 21:11:30 +00:00
|
|
|
|
|
|
|
package net.sourceforge.tuned.ui;
|
|
|
|
|
|
|
|
|
2008-10-19 12:44:55 +00:00
|
|
|
import java.awt.Font;
|
2008-04-27 21:11:30 +00:00
|
|
|
import java.awt.Window;
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
import java.awt.event.WindowAdapter;
|
|
|
|
import java.awt.event.WindowEvent;
|
|
|
|
import java.awt.event.WindowListener;
|
|
|
|
|
|
|
|
import javax.swing.AbstractAction;
|
|
|
|
import javax.swing.Action;
|
|
|
|
import javax.swing.Icon;
|
|
|
|
import javax.swing.JButton;
|
|
|
|
import javax.swing.JDialog;
|
|
|
|
import javax.swing.JLabel;
|
|
|
|
import javax.swing.JPanel;
|
|
|
|
import javax.swing.JProgressBar;
|
2008-10-19 12:44:55 +00:00
|
|
|
|
|
|
|
import net.miginfocom.swing.MigLayout;
|
2008-04-27 21:11:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
public class ProgressDialog extends JDialog {
|
|
|
|
|
|
|
|
private final JProgressBar progressBar = new JProgressBar(0, 100);
|
|
|
|
private final JLabel iconLabel = new JLabel();
|
|
|
|
private final JLabel headerLabel = new JLabel();
|
|
|
|
private final JLabel noteLabel = new JLabel();
|
|
|
|
|
|
|
|
private final JButton cancelButton;
|
|
|
|
|
|
|
|
private boolean cancelled = false;
|
|
|
|
|
|
|
|
|
|
|
|
public ProgressDialog(Window owner) {
|
|
|
|
super(owner, ModalityType.DOCUMENT_MODAL);
|
|
|
|
|
2008-10-19 12:44:55 +00:00
|
|
|
cancelButton = new JButton(cancelAction);
|
2008-04-27 21:11:30 +00:00
|
|
|
|
|
|
|
addWindowListener(closeListener);
|
|
|
|
|
2008-10-19 12:44:55 +00:00
|
|
|
headerLabel.setFont(headerLabel.getFont().deriveFont(Font.BOLD));
|
2008-04-27 21:11:30 +00:00
|
|
|
progressBar.setStringPainted(true);
|
|
|
|
|
2008-10-19 12:44:55 +00:00
|
|
|
JPanel c = (JPanel) getContentPane();
|
2008-04-27 21:11:30 +00:00
|
|
|
|
2008-10-19 12:44:55 +00:00
|
|
|
c.setLayout(new MigLayout("insets panel, fill"));
|
2008-04-27 21:11:30 +00:00
|
|
|
|
2008-10-19 12:44:55 +00:00
|
|
|
c.add(iconLabel, "spany 2, grow 0 0, gap right 1mm");
|
|
|
|
c.add(headerLabel, "align left, wmax 70%, grow 100 0, wrap");
|
|
|
|
c.add(noteLabel, "align left, wmax 70%, grow 100 0, wrap");
|
|
|
|
c.add(progressBar, "spanx 2, gap top unrel, gap bottom unrel, grow, wrap");
|
2008-04-27 21:11:30 +00:00
|
|
|
|
2008-10-19 12:44:55 +00:00
|
|
|
c.add(cancelButton, "spanx 2, align center");
|
2008-04-27 21:11:30 +00:00
|
|
|
|
2008-10-19 12:44:55 +00:00
|
|
|
setSize(240, 155);
|
2008-04-27 21:11:30 +00:00
|
|
|
|
|
|
|
setLocation(TunedUtil.getPreferredLocation(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isCancelled() {
|
|
|
|
return cancelled;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setIcon(Icon icon) {
|
|
|
|
iconLabel.setIcon(icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setNote(String text) {
|
|
|
|
noteLabel.setText(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setHeader(String text) {
|
|
|
|
headerLabel.setText(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-19 12:44:55 +00:00
|
|
|
public JProgressBar getProgressBar() {
|
|
|
|
return progressBar;
|
2008-04-27 21:11:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public JButton getCancelButton() {
|
|
|
|
return cancelButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void close() {
|
|
|
|
setVisible(false);
|
|
|
|
dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
private final Action cancelAction = new AbstractAction("Cancel") {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
cancelled = true;
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
private final WindowListener closeListener = new WindowAdapter() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void windowClosing(WindowEvent e) {
|
2008-10-19 12:44:55 +00:00
|
|
|
cancelAction.actionPerformed(null);
|
2008-04-27 21:11:30 +00:00
|
|
|
}
|
|
|
|
};
|
2008-10-19 12:44:55 +00:00
|
|
|
|
2008-04-27 21:11:30 +00:00
|
|
|
}
|