3 import java.awt.BorderLayout;
4 import java.awt.Component;
5 import java.awt.Dimension;
6 import java.awt.FlowLayout;
7 import java.awt.event.ActionEvent;
8 import java.awt.event.ActionListener;
10 import javax.swing.JButton;
11 import javax.swing.JDialog;
12 import javax.swing.JFrame;
13 import javax.swing.JLabel;
14 import javax.swing.JPanel;
15 import javax.swing.JProgressBar;
17 import tim.prune.I18nManager;
20 * Class to show a simple progress dialog
21 * similar to swing's ProgressMonitor but with a few
24 public class ProgressDialog
27 private JFrame _parentFrame = null;
28 /** Key for title text */
29 private String _titleKey = null;
30 /** function dialog */
31 private JDialog _dialog = null;
32 /** Progress bar for function */
33 private JProgressBar _progressBar = null;
35 private boolean _cancelled = false;
40 * @param inParentFrame parent frame
41 * @param inNameKey key for title
43 public ProgressDialog(JFrame inParentFrame, String inNameKey)
45 _parentFrame = inParentFrame;
46 _titleKey = inNameKey;
53 _dialog = new JDialog(_parentFrame, I18nManager.getText(_titleKey), false);
54 _dialog.setLocationRelativeTo(_parentFrame);
55 _dialog.getContentPane().add(makeDialogComponents());
58 _progressBar.setMinimum(0);
59 _progressBar.setMaximum(100);
60 _progressBar.setValue(0);
61 _progressBar.setIndeterminate(true);
63 _dialog.setVisible(true);
67 * Make the dialog components
68 * @return the GUI components for the dialog
70 private Component makeDialogComponents()
72 JPanel dialogPanel = new JPanel();
73 dialogPanel.setLayout(new BorderLayout());
74 dialogPanel.add(new JLabel(I18nManager.getText("confirm.running")), BorderLayout.NORTH);
75 _progressBar = new JProgressBar();
76 _progressBar.setPreferredSize(new Dimension(250, 30));
77 dialogPanel.add(_progressBar, BorderLayout.CENTER);
78 // Cancel button at the bottom
79 JPanel buttonPanel = new JPanel();
80 buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
81 JButton cancelButton = new JButton(I18nManager.getText("button.cancel"));
82 cancelButton.addActionListener(new ActionListener() {
83 public void actionPerformed(ActionEvent e) {
88 buttonPanel.add(cancelButton);
89 dialogPanel.add(buttonPanel, BorderLayout.SOUTH);
93 /** Set the maximum value of the progress bar */
94 public void setMaximum(int inMax) {
95 _progressBar.setMaximum(inMax);
96 _progressBar.setIndeterminate(inMax <= 1);
99 /** Set the current value of the progress bar */
100 public void setValue(int inValue) {
101 _progressBar.setValue(inValue);
104 /** Close the dialog */
105 public void dispose() {
110 * @return true if cancel button was pressed
112 public boolean isCancelled() {