2008-04-27 21:11:30 +00:00
|
|
|
|
|
|
|
package net.sourceforge.tuned.ui;
|
|
|
|
|
|
|
|
|
|
|
|
import java.awt.Window;
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2009-01-11 21:23:03 +00:00
|
|
|
private final Cancellable cancellable;
|
2008-04-27 21:11:30 +00:00
|
|
|
|
2012-02-24 13:39:32 +00:00
|
|
|
|
2009-01-11 21:23:03 +00:00
|
|
|
public ProgressDialog(Window owner, Cancellable cancellable) {
|
2008-04-27 21:11:30 +00:00
|
|
|
super(owner, ModalityType.DOCUMENT_MODAL);
|
|
|
|
|
2009-01-11 21:23:03 +00:00
|
|
|
this.cancellable = cancellable;
|
2008-04-27 21:11:30 +00:00
|
|
|
|
2009-01-11 21:23:03 +00:00
|
|
|
// disable window close button
|
|
|
|
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
2008-04-27 21:11:30 +00:00
|
|
|
|
2009-01-11 21:23:03 +00:00
|
|
|
headerLabel.setFont(headerLabel.getFont().deriveFont(18f));
|
|
|
|
progressBar.setIndeterminate(true);
|
2008-04-27 21:11:30 +00:00
|
|
|
progressBar.setStringPainted(true);
|
|
|
|
|
2008-10-19 12:44:55 +00:00
|
|
|
JPanel c = (JPanel) getContentPane();
|
2009-01-11 21:23:03 +00:00
|
|
|
c.setLayout(new MigLayout("insets dialog, nogrid, fill"));
|
2008-04-27 21:11:30 +00:00
|
|
|
|
2009-01-11 21:23:03 +00:00
|
|
|
c.add(iconLabel, "h pref!, w pref!");
|
|
|
|
c.add(headerLabel, "gap 3mm, wrap paragraph");
|
|
|
|
c.add(progressBar, "grow, wrap paragraph");
|
2008-04-27 21:11:30 +00:00
|
|
|
|
2009-01-11 21:23:03 +00:00
|
|
|
c.add(new JButton(cancelAction), "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
|
|
|
}
|
|
|
|
|
2012-02-24 13:39:32 +00:00
|
|
|
|
2008-04-27 21:11:30 +00:00
|
|
|
public void setIcon(Icon icon) {
|
|
|
|
iconLabel.setIcon(icon);
|
|
|
|
}
|
|
|
|
|
2012-02-24 13:39:32 +00:00
|
|
|
|
|
|
|
public void setIndeterminate(boolean b) {
|
|
|
|
progressBar.setIndeterminate(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-04 07:45:48 +00:00
|
|
|
public void setProgress(int value, int max) {
|
|
|
|
progressBar.setIndeterminate(false);
|
|
|
|
progressBar.setMinimum(0);
|
|
|
|
progressBar.setValue(value);
|
|
|
|
progressBar.setMaximum(max);
|
|
|
|
}
|
|
|
|
|
2012-02-24 13:39:32 +00:00
|
|
|
|
2008-04-27 21:11:30 +00:00
|
|
|
public void setNote(String text) {
|
2009-01-11 21:23:03 +00:00
|
|
|
progressBar.setString(text);
|
2008-04-27 21:11:30 +00:00
|
|
|
}
|
|
|
|
|
2012-02-24 13:39:32 +00:00
|
|
|
|
2009-01-11 21:23:03 +00:00
|
|
|
@Override
|
|
|
|
public void setTitle(String text) {
|
|
|
|
super.setTitle(text);
|
2008-04-27 21:11:30 +00:00
|
|
|
headerLabel.setText(text);
|
|
|
|
}
|
|
|
|
|
2012-02-24 13:39:32 +00:00
|
|
|
|
|
|
|
public void setWindowTitle(String text) {
|
|
|
|
super.setTitle(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-27 21:11:30 +00:00
|
|
|
public void close() {
|
|
|
|
setVisible(false);
|
|
|
|
dispose();
|
|
|
|
}
|
|
|
|
|
2012-02-24 13:39:32 +00:00
|
|
|
|
2009-01-11 21:23:03 +00:00
|
|
|
protected final Action cancelAction = new AbstractAction("Cancel") {
|
2008-04-27 21:11:30 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
2011-11-04 07:45:48 +00:00
|
|
|
cancelAction.setEnabled(false);
|
2009-01-11 21:23:03 +00:00
|
|
|
cancellable.cancel();
|
2008-04-27 21:11:30 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-24 13:39:32 +00:00
|
|
|
|
2009-01-11 21:23:03 +00:00
|
|
|
public static interface Cancellable {
|
2008-04-27 21:11:30 +00:00
|
|
|
|
2009-01-11 21:23:03 +00:00
|
|
|
boolean isCancelled();
|
|
|
|
|
2012-02-24 13:39:32 +00:00
|
|
|
|
2009-01-11 21:23:03 +00:00
|
|
|
boolean cancel();
|
|
|
|
}
|
2008-10-19 12:44:55 +00:00
|
|
|
|
2008-04-27 21:11:30 +00:00
|
|
|
}
|