]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/save/ExifSaver.java
Version 8, September 2009
[GpsPrune.git] / tim / prune / save / ExifSaver.java
index 1e597201d5f2842197531159ec3452f542fb428c..f8e04de67a5a1308ca6d5706ed0f3ab505de1fec 100644 (file)
@@ -19,14 +19,15 @@ import javax.swing.JProgressBar;
 import javax.swing.JScrollPane;
 import javax.swing.JTable;
 
+import tim.prune.Config;
 import tim.prune.ExternalTools;
 import tim.prune.I18nManager;
+import tim.prune.UpdateMessageBroker;
 import tim.prune.data.Altitude;
 import tim.prune.data.Coordinate;
 import tim.prune.data.DataPoint;
 import tim.prune.data.Photo;
 import tim.prune.data.PhotoList;
-import tim.prune.data.PhotoStatus;
 
 /**
  * Class to call Exiftool to save coordinate information in jpg files
@@ -35,9 +36,11 @@ public class ExifSaver implements Runnable
 {
        private Frame _parentFrame = null;
        private JDialog _dialog = null;
+       private JButton _okButton = null;
        private JCheckBox _overwriteCheckbox = null;
        private JProgressBar _progressBar = null;
        private PhotoTableModel _photoTableModel = null;
+       private boolean _saveCancelled = false;
 
 
        // To preserve timestamps of file use parameter -P
@@ -72,11 +75,12 @@ public class ExifSaver implements Runnable
         * Save exif information to all photos in the list
         * whose coordinate information has changed since loading
         * @param inPhotoList list of photos to save
+        * @return true if saved
         */
        public boolean saveExifInformation(PhotoList inPhotoList)
        {
                // Check if external exif tool can be called
-               boolean exifToolInstalled = ExternalTools.isExiftoolInstalled();
+               boolean exifToolInstalled = ExternalTools.isToolInstalled(ExternalTools.TOOL_EXIFTOOL);
                if (!exifToolInstalled)
                {
                        // show warning
@@ -111,7 +115,7 @@ public class ExifSaver implements Runnable
                _dialog.pack();
                // set progress bar and show dialog
                _progressBar.setVisible(false);
-               _dialog.show();
+               _dialog.setVisible(true);
                return true;
        }
 
@@ -166,19 +170,22 @@ public class ExifSaver implements Runnable
                // Lower panel with ok and cancel buttons
                JPanel buttonPanel = new JPanel();
                buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
-               JButton okButton = new JButton(I18nManager.getText("button.ok"));
-               okButton.addActionListener(new ActionListener() {
+               _okButton = new JButton(I18nManager.getText("button.ok"));
+               _okButton.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e)
                        {
+                               // disable ok button
+                               _okButton.setEnabled(false);
                                // start new thread to do save
                                new Thread(ExifSaver.this).start();
                        }
                });
-               buttonPanel.add(okButton);
+               buttonPanel.add(_okButton);
                JButton cancelButton = new JButton(I18nManager.getText("button.cancel"));
                cancelButton.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e)
                        {
+                               _saveCancelled = true;
                                _dialog.dispose();
                        }
                });
@@ -208,6 +215,7 @@ public class ExifSaver implements Runnable
         */
        public void run()
        {
+               _saveCancelled = false;
                PhotoTableEntry entry = null;
                Photo photo = null;
                int numPhotos = _photoTableModel.getRowCount();
@@ -220,7 +228,7 @@ public class ExifSaver implements Runnable
                for (int i=0; i<numPhotos; i++)
                {
                        entry = _photoTableModel.getPhotoTableEntry(i);
-                       if (entry != null && entry.getSaveFlag())
+                       if (entry != null && entry.getSaveFlag() && !_saveCancelled)
                        {
                                // Only look at photos which are selected and whose status has changed since load
                                photo = entry.getPhoto();
@@ -237,10 +245,9 @@ public class ExifSaver implements Runnable
                        _progressBar.setValue(i + 1);
                }
                _progressBar.setVisible(false);
-               // Show confirmation dialog
-               JOptionPane.showMessageDialog(_dialog, I18nManager.getText("dialog.saveexif.ok1") + " "
-                       + numSaved + " " + I18nManager.getText("dialog.saveexif.ok2"),
-                       I18nManager.getText("dialog.saveexif.title"), JOptionPane.INFORMATION_MESSAGE);
+               // Show confirmation
+               UpdateMessageBroker.informSubscribers(I18nManager.getText("confirm.saveexif.ok1") + " "
+                       + numSaved + " " + I18nManager.getText("confirm.saveexif.ok2"));
                // close dialog, all finished
                _dialog.dispose();
        }
@@ -284,7 +291,7 @@ public class ExifSaver implements Runnable
                        }
                }
                String[] command = null;
-               if (inPhoto.getCurrentStatus() == PhotoStatus.NOT_CONNECTED)
+               if (inPhoto.getCurrentStatus() == Photo.Status.NOT_CONNECTED)
                {
                        // Photo is no longer connected, so delete gps tags
                        command = getDeleteGpsExifTagsCommand(inPhoto.getFile(), inOverwriteFlag);
@@ -297,7 +304,12 @@ public class ExifSaver implements Runnable
                // Execute exif command
                try
                {
-                       Runtime.getRuntime().exec(command);
+                       Process process = Runtime.getRuntime().exec(command);
+                       // Wait for process to finish so not too many run in parallel
+                       try {
+                               process.waitFor();
+                       }
+                       catch (InterruptedException ie) {}
                }
                catch (Exception e)
                {
@@ -320,7 +332,7 @@ public class ExifSaver implements Runnable
        {
                // Make a string array to construct the command and its parameters
                String[] result = new String[inOverwrite?5:4];
-               result[0] = "exiftool";
+               result[0] = Config.getConfigString(Config.KEY_EXIFTOOL_PATH);
                result[1] = "-P";
                if (inOverwrite) {result[2] = " -overwrite_original_in_place";}
                // remove all gps tags
@@ -342,7 +354,7 @@ public class ExifSaver implements Runnable
        {
                // Make a string array to construct the command and its parameters
                String[] result = new String[inOverwrite?10:9];
-               result[0] = "exiftool";
+               result[0] = Config.getConfigString(Config.KEY_EXIFTOOL_PATH);
                result[1] = "-P";
                if (inOverwrite) {result[2] = "-overwrite_original_in_place";}
                int paramOffset = inOverwrite?3:2;
@@ -357,7 +369,7 @@ public class ExifSaver implements Runnable
                result[paramOffset + 3] = "-GPSLongitudeRef=" + inPoint.getLongitude().output(Coordinate.FORMAT_CARDINAL);
                // add altitude if it has it
                result[paramOffset + 4] = "-GPSAltitude="
-                + (inPoint.hasAltitude()?inPoint.getAltitude().getValue(Altitude.FORMAT_METRES):0);
+                + (inPoint.hasAltitude()?inPoint.getAltitude().getValue(Altitude.Format.METRES):0);
                result[paramOffset + 5] = "-GPSAltitudeRef='Above Sea Level'";
                // add the filename to modify
                result[paramOffset + 6] = inFile.getAbsolutePath();