Changeset 33494 in osm for applications
- Timestamp:
- 2017-08-13T16:26:30+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/photo_geotagging/src/org/openstreetmap/josm/plugins/photo_geotagging/GeotaggingAction.java
r30967 r33494 8 8 import java.awt.GridBagLayout; 9 9 import java.awt.event.ActionEvent; 10 import java.awt.event.ActionListener;11 10 import java.io.File; 12 11 import java.io.IOException; 12 import java.lang.reflect.InvocationTargetException; 13 13 import java.nio.file.Files; 14 import java.nio.file.NoSuchFileException; 14 15 import java.text.DecimalFormat; 15 16 import java.util.ArrayList; … … 42 43 import org.openstreetmap.josm.tools.GBC; 43 44 import org.openstreetmap.josm.tools.ImageProvider; 45 import org.openstreetmap.josm.tools.JosmRuntimeException; 44 46 45 47 /** … … 113 115 settingsPanel.add(mTimeMode, GBC.eol().insets(3,3,3,3)); 114 116 115 setMTime.addActionListener(new ActionListener(){ 116 @Override 117 public void actionPerformed(ActionEvent e) { 118 if (setMTime.isSelected()) { 119 mTimeMode.setEnabled(true); 120 } else { 121 mTimeMode.setSelectedIndex(0); 122 mTimeMode.setEnabled(false); 123 } 117 setMTime.addActionListener(e -> { 118 if (setMTime.isSelected()) { 119 mTimeMode.setEnabled(true); 120 } else { 121 mTimeMode.setSelectedIndex(0); 122 mTimeMode.setEnabled(false); 124 123 } 125 124 }); … … 177 176 private File fileDelete; 178 177 178 private int currentIndex; 179 179 180 public GeoTaggingRunnable(List<ImageEntry> images, boolean keep_backup, int mTimeMode) { 180 181 super(tr("Photo Geotagging Plugin")); … … 183 184 this.mTimeMode = mTimeMode; 184 185 } 186 187 private void processEntry(ImageEntry e) throws IOException { 188 fileFrom = null; 189 fileTo = null; 190 fileDelete = null; 191 192 if (mTimeMode != 0) { 193 testMTimeReadAndWrite(e.getFile()); 194 } 195 196 Long mTime = null; 197 if (mTimeMode == MTIME_MODE_GPS) { 198 // check GPS time fields, do nothing if all fails 199 Date time; 200 if (e.hasGpsTime()) { 201 time = e.getGpsTime(); 202 } else { 203 time = e.getExifGpsTime(); 204 } 205 if (time != null) { 206 mTime = time.getTime(); 207 } 208 } 209 if ( mTimeMode == MTIME_MODE_PREVIOUS_VALUE 210 // this is also the fallback if one of the other 211 // modes failed to determine the modification time 212 || (mTimeMode != 0 && mTime == null)) { 213 mTime = e.getFile().lastModified(); 214 if (mTime.equals(0L)) 215 throw new IOException(tr("Could not read mtime.")); 216 } 217 218 chooseFiles(e.getFile()); 219 if (canceled) return; 220 ExifGPSTagger.setExifGPSTag(fileFrom, fileTo, e.getPos().lat(), e.getPos().lon(), 221 e.getGpsTime(), e.getSpeed(), e.getElevation(), e.getExifImgDir()); 222 223 if (mTime != null) { 224 if (!fileTo.setLastModified(mTime)) 225 throw new IOException(tr("Could not write mtime.")); 226 } 227 228 cleanupFiles(); 229 e.unflagNewGpsData(); 230 } 231 185 232 @Override 186 233 protected void realRun() { … … 188 235 progressMonitor.setTicksCount(images.size()); 189 236 190 for (int i=0; i<images.size(); ++i) { 237 currentIndex = 0; 238 while (currentIndex < images.size()) { 191 239 if (canceled) return; 192 193 ImageEntry e = images.get(i); 240 ImageEntry e = images.get(currentIndex); 194 241 if (debug) { 195 System.err.print("i:"+i+" "+e.getFile().getName()+" "); 196 } 197 198 fileFrom = null; 199 fileTo = null; 200 fileDelete = null; 201 242 System.err.print("i:"+currentIndex+" "+e.getFile().getName()+" "); 243 } 202 244 try { 203 if (mTimeMode != 0) { 204 testMTimeReadAndWrite(e.getFile()); 205 } 206 207 Long mTime = null; 208 if (mTimeMode == MTIME_MODE_GPS) { 209 // check GPS time fields, do nothing if all fails 210 Date time; 211 if (e.hasGpsTime()) { 212 time = e.getGpsTime(); 213 } else { 214 time = e.getExifGpsTime(); 215 } 216 if (time != null) { 217 mTime = time.getTime(); 218 } 219 } 220 if ( mTimeMode == MTIME_MODE_PREVIOUS_VALUE 221 // this is also the fallback if one of the other 222 // modes failed to determine the modification time 223 || (mTimeMode != 0 && mTime == null)) { 224 mTime = e.getFile().lastModified(); 225 if (mTime.equals(0L)) 226 throw new IOException(tr("Could not read mtime.")); 227 } 228 229 chooseFiles(e.getFile()); 230 if (canceled) return; 231 ExifGPSTagger.setExifGPSTag(fileFrom, fileTo, e.getPos().lat(), e.getPos().lon(), 232 e.getGpsTime(), e.getSpeed(), e.getElevation(), e.getExifImgDir()); 233 234 if (mTime != null) { 235 if (!fileTo.setLastModified(mTime)) 236 throw new IOException(tr("Could not write mtime.")); 237 } 238 239 cleanupFiles(); 240 e.unflagNewGpsData(); 241 245 processEntry(e); 242 246 } catch (final IOException ioe) { 243 247 ioe.printStackTrace(); 244 // need this so the dialogs don't block 245 SwingUtilities.invokeLater(new Runnable() { 246 @Override 247 public void run() { 248 JOptionPane.showMessageDialog(Main.parent, ioe.getMessage(), tr("Error"), JOptionPane.ERROR_MESSAGE); 249 } 250 }); 251 return; 248 try { 249 SwingUtilities.invokeAndWait(() -> { 250 ExtendedDialog dlg = new ExtendedDialog(progressMonitor.getWindowParent(), tr("Error"), new String[] {tr("Abort"), tr("Retry"), tr("Ignore")}); 251 dlg.setIcon(JOptionPane.ERROR_MESSAGE); 252 dlg.setButtonIcons("cancel", "dialogs/refresh", "dialogs/next"); 253 String msg; 254 if (ioe instanceof NoSuchFileException) { 255 msg = tr("File not found."); 256 } else { 257 msg = ioe.toString(); 258 } 259 dlg.setContent(tr("Unable to process file ''{0}'':", e.getFile().toString()) + "<br/>" + msg); 260 dlg.showDialog(); 261 switch (dlg.getValue()) { 262 case 2: // retry 263 currentIndex--; 264 break; 265 case 3: // continue 266 break; 267 default: // abort 268 canceled = true; 269 } 270 }); 271 } catch (InterruptedException | InvocationTargetException ex) { 272 throw new JosmRuntimeException(ex); 273 } 252 274 } 253 275 progressMonitor.worked(1); 254 276 if (debug) { 255 System.err.println(""); 256 } 277 System.err.println("finished " + e.getFile()); 278 } 279 currentIndex++; 257 280 } 258 281 } … … 319 342 return; 320 343 try { 321 SwingUtilities.invokeAndWait(new Runnable() { 322 @Override 323 public void run() { 324 JLabel l = new JLabel(tr("<html><h3>There are old backup files in the image directory!</h3>")); 325 l.setIcon(UIManager.getIcon("OptionPane.warningIcon")); 326 int override = new ExtendedDialog( 327 progressMonitor.getWindowParent(), 328 tr("Override old backup files?"), 329 new String[] {tr("Cancel"), tr("Keep old backups and continue"), tr("Override")}) 330 .setButtonIcons(new String[] {"cancel.png", "ok.png", "dialogs/delete.png"}) 331 .setContent(l) 332 .setCancelButton(1) 333 .setDefaultButton(2) 334 .showDialog() 335 .getValue(); 336 if (override == 2) { 337 override_backup = false; 338 } else if (override == 3) { 339 override_backup = true; 340 } else { 341 canceled = true; 342 } 344 SwingUtilities.invokeAndWait(() -> { 345 JLabel l = new JLabel(tr("<html><h3>There are old backup files in the image directory!</h3>")); 346 l.setIcon(UIManager.getIcon("OptionPane.warningIcon")); 347 int override = new ExtendedDialog( 348 progressMonitor.getWindowParent(), 349 tr("Override old backup files?"), 350 new String[] {tr("Cancel"), tr("Keep old backups and continue"), tr("Override")}) 351 .setButtonIcons(new String[] {"cancel.png", "ok.png", "dialogs/delete.png"}) 352 .setContent(l) 353 .setCancelButton(1) 354 .setDefaultButton(2) 355 .showDialog() 356 .getValue(); 357 if (override == 2) { 358 override_backup = false; 359 } else if (override == 3) { 360 override_backup = true; 361 } else { 362 canceled = true; 343 363 } 344 364 });
Note:
See TracChangeset
for help on using the changeset viewer.