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.BorderFactory;
11 import javax.swing.JButton;
12 import javax.swing.JDialog;
13 import javax.swing.JFrame;
14 import javax.swing.JLabel;
15 import javax.swing.JPanel;
16 import javax.swing.JProgressBar;
18 import tim.prune.I18nManager;
21 * Class to show a simple progress dialog
22 * similar to swing's ProgressMonitor but with a few
25 public class ProgressDialog
28 private JFrame _parentFrame = null;
29 /** Key for title text */
30 private String _titleKey = null;
31 /** function dialog */
32 private JDialog _dialog = null;
33 /** Progress bar for function */
34 private JProgressBar _progressBar = null;
36 private boolean _cancelled = false;
41 * @param inParentFrame parent frame
42 * @param inNameKey key for title
44 public ProgressDialog(JFrame inParentFrame, String inNameKey)
46 _parentFrame = inParentFrame;
47 _titleKey = inNameKey;
54 _dialog = new JDialog(_parentFrame, I18nManager.getText(_titleKey), false);
55 _dialog.setLocationRelativeTo(_parentFrame);
56 _dialog.getContentPane().add(makeDialogComponents());
59 _progressBar.setMinimum(0);
60 _progressBar.setMaximum(100);
61 _progressBar.setValue(0);
62 _progressBar.setIndeterminate(true);
64 _dialog.setVisible(true);
68 * Make the dialog components
69 * @return the GUI components for the dialog
71 private Component makeDialogComponents()
73 JPanel dialogPanel = new JPanel();
74 dialogPanel.setLayout(new BorderLayout());
75 dialogPanel.add(new JLabel(I18nManager.getText("confirm.running")), BorderLayout.NORTH);
76 // Centre panel with an empty border
77 JPanel centrePanel = new JPanel();
78 centrePanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
79 centrePanel.setLayout(new BorderLayout());
80 _progressBar = new JProgressBar();
81 _progressBar.setPreferredSize(new Dimension(250, 30));
82 centrePanel.add(_progressBar, BorderLayout.CENTER);
83 dialogPanel.add(centrePanel, BorderLayout.CENTER);
84 // Cancel button at the bottom
85 JPanel buttonPanel = new JPanel();
86 buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
87 JButton cancelButton = new JButton(I18nManager.getText("button.cancel"));
88 cancelButton.addActionListener(new ActionListener() {
89 public void actionPerformed(ActionEvent e) {
94 buttonPanel.add(cancelButton);
95 dialogPanel.add(buttonPanel, BorderLayout.SOUTH);
99 /** Set the maximum value of the progress bar */
100 public void setMaximum(int inMax) {
101 _progressBar.setMaximum(inMax);
102 _progressBar.setIndeterminate(inMax <= 1);
105 /** Set the current value of the progress bar */
106 public void setValue(int inValue) {
107 _progressBar.setValue(inValue);
110 /** Close the dialog */
111 public void dispose() {
116 * @return true if cancel button was pressed
118 public boolean isCancelled() {