X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fload%2FJpegLoader.java;h=3e22eba029ccb76ce341a2fffaea6327669a28f1;hb=92dad5df664287acb51728e9ea599f150765d34a;hp=c506236f44eb3e3e3aa2a37ce6683cd382da85de;hpb=52bf9e8686c916be37a26a0b75340393d4478b05;p=GpsPrune.git diff --git a/tim/prune/load/JpegLoader.java b/tim/prune/load/JpegLoader.java index c506236..3e22eba 100644 --- a/tim/prune/load/JpegLoader.java +++ b/tim/prune/load/JpegLoader.java @@ -1,42 +1,35 @@ 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.JOptionPane; import javax.swing.JPanel; -import javax.swing.JProgressBar; import tim.prune.App; -import tim.prune.Config; import tim.prune.I18nManager; +import tim.prune.config.Config; import tim.prune.data.Altitude; import tim.prune.data.DataPoint; import tim.prune.data.LatLonRectangle; import tim.prune.data.Latitude; import tim.prune.data.Longitude; import tim.prune.data.Photo; -import tim.prune.data.PhotoStatus; import tim.prune.data.Timestamp; -import tim.prune.drew.jpeg.ExifReader; -import tim.prune.drew.jpeg.JpegData; -import tim.prune.drew.jpeg.JpegException; -import tim.prune.drew.jpeg.Rational; +import tim.prune.data.TimestampLocal; +import tim.prune.data.TimestampUtc; +import tim.prune.data.UnitSetLibrary; +import tim.prune.function.Cancellable; +import tim.prune.jpeg.InternalExifLibrary; +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; @@ -45,12 +38,11 @@ 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; - private TreeSet _photos = null; + private TreeSet _photos = null; /** @@ -62,8 +54,7 @@ public class JpegLoader implements Runnable { _app = inApp; _parentFrame = inParentFrame; - String[] fileTypes = {"jpg", "jpe", "jpeg"}; - _fileFilter = new GenericFileFilter("filetype.jpeg", fileTypes); + _fileFilter = new JpegFileFilter(); } @@ -94,8 +85,9 @@ public class JpegLoader implements Runnable panel.add(_outsideAreaCheckbox); _fileChooser.setAccessory(panel); // start from directory in config if already set by other operations - File configDir = Config.getWorkingDirectory(); - if (configDir != null) {_fileChooser.setCurrentDirectory(configDir);} + String configDir = Config.getConfigString(Config.KEY_PHOTO_DIR); + if (configDir == null) {configDir = Config.getConfigString(Config.KEY_TRACK_DIR);} + if (configDir != null) {_fileChooser.setCurrentDirectory(new File(configDir));} } // enable/disable track checkbox _trackRectangle = inRectangle; @@ -104,39 +96,16 @@ public class JpegLoader implements Runnable if (_fileChooser.showOpenDialog(_parentFrame) == JFileChooser.APPROVE_OPTION) { // Bring up dialog before starting - showDialog(); + _progressDialog = new MediaLoadProgressDialog(_parentFrame, this); + _progressDialog.show(); + // start thread for processing new Thread(this).start(); } } - - /** - * Show the main dialog - */ - private void showDialog() - { - _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(); - _progressDialog.show(); + /** Cancel */ + public void cancel() { + _cancelled = true; } @@ -146,46 +115,34 @@ public class JpegLoader implements Runnable public void run() { // Initialise arrays, errors, summaries - _fileCounts = new int[4]; // files, jpegs, exifs, gps - _photos = new TreeSet(new PhotoSorter()); + _fileCounts = new int[3]; // files, jpegs, gps + _photos = new TreeSet(new MediaSorter()); File[] files = _fileChooser.getSelectedFiles(); // 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.hide(); + _progressDialog.close(); if (_cancelled) {return;} - //System.out.println("Finished - counts are: " + _fileCounts[0] + ", " + _fileCounts[1] - // + ", " + _fileCounts[2] + ", " + _fileCounts[3]); if (_fileCounts[0] == 0) { // No files found at all - JOptionPane.showMessageDialog(_parentFrame, I18nManager.getText("error.jpegload.nofilesfound"), - I18nManager.getText("error.jpegload.dialogtitle"), JOptionPane.ERROR_MESSAGE); + _app.showErrorMessage("error.jpegload.dialogtitle", "error.jpegload.nofilesfound"); } else if (_fileCounts[1] == 0) { // No jpegs found - JOptionPane.showMessageDialog(_parentFrame, I18nManager.getText("error.jpegload.nojpegsfound"), - I18nManager.getText("error.jpegload.dialogtitle"), JOptionPane.ERROR_MESSAGE); + _app.showErrorMessage("error.jpegload.dialogtitle", "error.jpegload.nojpegsfound"); } else if (!_noExifCheckbox.isSelected() && _fileCounts[2] == 0) - { - // Need coordinates but no exif found - JOptionPane.showMessageDialog(_parentFrame, I18nManager.getText("error.jpegload.noexiffound"), - I18nManager.getText("error.jpegload.dialogtitle"), JOptionPane.ERROR_MESSAGE); - } - else if (!_noExifCheckbox.isSelected() && _fileCounts[3] == 0) { // Need coordinates but no gps information found - JOptionPane.showMessageDialog(_parentFrame, I18nManager.getText("error.jpegload.nogpsfound"), - I18nManager.getText("error.jpegload.dialogtitle"), JOptionPane.ERROR_MESSAGE); + _app.showErrorMessage("error.jpegload.dialogtitle", "error.jpegload.nogpsfound"); } else { @@ -203,34 +160,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