1 package tim.prune.load;
3 import java.awt.event.ActionEvent;
4 import java.awt.event.ActionListener;
6 import javax.swing.BorderFactory;
7 import javax.swing.BoxLayout;
8 import javax.swing.JButton;
9 import javax.swing.JDialog;
10 import javax.swing.JFrame;
11 import javax.swing.JLabel;
12 import javax.swing.JPanel;
13 import javax.swing.JProgressBar;
15 import tim.prune.I18nManager;
16 import tim.prune.function.Cancellable;
19 * Class to show a progress dialog for loading media.
20 * Used for regular photo / audio loads plus the async
23 public class MediaLoadProgressDialog
25 private JDialog _progressDialog = null;
26 private JProgressBar _progressBar = null;
27 private JFrame _parentFrame = null;
28 private Cancellable _function = null;
32 * @param inParentFrame parent frame for creating dialog
33 * @param inFunction function which can be cancelled
35 public MediaLoadProgressDialog(JFrame inParentFrame, Cancellable inFunction)
37 _parentFrame = inParentFrame;
38 _function = inFunction;
42 * Create the dialog to show the progress
44 private void createProgressDialog()
46 _progressDialog = new JDialog(_parentFrame, I18nManager.getText("dialog.jpegload.progress.title"));
47 _progressDialog.setLocationRelativeTo(_parentFrame);
48 _progressBar = new JProgressBar(0, 100);
49 _progressBar.setValue(0);
50 _progressBar.setStringPainted(true);
51 _progressBar.setString("");
52 JPanel panel = new JPanel();
53 panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
54 panel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
55 panel.add(new JLabel(I18nManager.getText("dialog.jpegload.progress")));
56 panel.add(_progressBar);
57 JButton cancelButton = new JButton(I18nManager.getText("button.cancel"));
58 cancelButton.addActionListener(new ActionListener() {
59 public void actionPerformed(ActionEvent e)
64 panel.add(cancelButton);
65 _progressDialog.getContentPane().add(panel);
66 _progressDialog.pack();
67 _progressDialog.setVisible(true);
71 * Show the dialog in indeterminate mode, before limits are calculated
75 if (_progressDialog == null)
77 createProgressDialog();
78 _progressBar.setIndeterminate(true);
83 * Update the progress bar
84 * @param inCurrent current value
85 * @param inMax maximum value
87 public void showProgress(int inCurrent, int inMax)
89 if (_progressDialog == null)
90 createProgressDialog();
91 if (_progressBar.isIndeterminate())
92 _progressBar.setIndeterminate(false);
94 _progressBar.setMaximum(inMax);
95 _progressBar.setValue(inCurrent);
96 _progressBar.setString("" + inCurrent + " / " + _progressBar.getMaximum());
97 // TODO: Need to repaint?
105 if (_progressDialog != null)
106 _progressDialog.dispose();