X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=tim%2Fprune%2Fload%2FJpegLoader.java;h=8a376d8e6367b81aff9a9fca9f2c1f4edd1bafaa;hp=a6a45c60b5d1ffe56c8257ac29b9f5e3f31e4a3b;hb=649c5da6ee1bbc590699e11a92316ece2ea8512d;hpb=eebbb64b5d63f9eea43a0dff908c30361a376768 diff --git a/tim/prune/load/JpegLoader.java b/tim/prune/load/JpegLoader.java index a6a45c6..8a376d8 100644 --- a/tim/prune/load/JpegLoader.java +++ b/tim/prune/load/JpegLoader.java @@ -1,20 +1,13 @@ package tim.prune.load; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.io.File; import java.util.TreeSet; -import javax.swing.BorderFactory; import javax.swing.BoxLayout; -import javax.swing.JButton; import javax.swing.JCheckBox; -import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JFrame; -import javax.swing.JLabel; import javax.swing.JPanel; -import javax.swing.JProgressBar; import tim.prune.App; import tim.prune.I18nManager; @@ -27,13 +20,14 @@ import tim.prune.data.Latitude; import tim.prune.data.Longitude; import tim.prune.data.Photo; import tim.prune.data.Timestamp; +import tim.prune.function.Cancellable; import tim.prune.jpeg.ExifGateway; import tim.prune.jpeg.JpegData; /** * Class to manage the loading of Jpegs and dealing with the GPS data from them */ -public class JpegLoader implements Runnable +public class JpegLoader implements Runnable, Cancellable { private App _app = null; private JFrame _parentFrame = null; @@ -42,8 +36,7 @@ public class JpegLoader implements Runnable private JCheckBox _subdirCheckbox = null; private JCheckBox _noExifCheckbox = null; private JCheckBox _outsideAreaCheckbox = null; - private JDialog _progressDialog = null; - private JProgressBar _progressBar = null; + private MediaLoadProgressDialog _progressDialog = null; private int[] _fileCounts = null; private boolean _cancelled = false; private LatLonRectangle _trackRectangle = null; @@ -101,45 +94,16 @@ public class JpegLoader implements Runnable if (_fileChooser.showOpenDialog(_parentFrame) == JFileChooser.APPROVE_OPTION) { // Bring up dialog before starting - if (_progressDialog == null) { - createProgressDialog(); - } - // reset dialog and show it - _progressBar.setValue(0); - _progressBar.setString(""); - _progressDialog.setVisible(true); + _progressDialog = new MediaLoadProgressDialog(_parentFrame, this); + _progressDialog.show(); // start thread for processing new Thread(this).start(); } } - - /** - * Create the dialog to show the progress - */ - private void createProgressDialog() - { - _progressDialog = new JDialog(_parentFrame, I18nManager.getText("dialog.jpegload.progress.title")); - _progressDialog.setLocationRelativeTo(_parentFrame); - _progressBar = new JProgressBar(0, 100); - _progressBar.setValue(0); - _progressBar.setStringPainted(true); - _progressBar.setString(""); - JPanel panel = new JPanel(); - panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); - panel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); - panel.add(new JLabel(I18nManager.getText("dialog.jpegload.progress"))); - panel.add(_progressBar); - JButton cancelButton = new JButton(I18nManager.getText("button.cancel")); - cancelButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) - { - _cancelled = true; - } - }); - panel.add(cancelButton); - _progressDialog.getContentPane().add(panel); - _progressDialog.pack(); + /** Cancel */ + public void cancel() { + _cancelled = true; } @@ -155,14 +119,12 @@ public class JpegLoader implements Runnable // Loop recursively over selected files/directories to count files int numFiles = countFileList(files, true, _subdirCheckbox.isSelected()); // Set up the progress bar for this number of files - _progressBar.setMaximum(numFiles); - _progressBar.setValue(0); + _progressDialog.showProgress(0, numFiles); _cancelled = false; // Process the files recursively and build lists of photos processFileList(files, true, _subdirCheckbox.isSelected()); - _progressDialog.setVisible(false); - _progressDialog.dispose(); // Sometimes dialog doesn't disappear without this dispose + _progressDialog.close(); if (_cancelled) {return;} if (_fileCounts[0] == 0) @@ -196,29 +158,27 @@ public class JpegLoader implements Runnable */ private void processFileList(File[] inFiles, boolean inFirstDir, boolean inDescend) { - if (inFiles != null) + if (inFiles == null) return; + // Loop over elements in array + for (int i=0; i