4 import java.util.ArrayList;
5 import java.util.EmptyStackException;
7 import java.util.Stack;
9 import javax.swing.JFrame;
10 import javax.swing.JOptionPane;
12 import tim.prune.config.Config;
13 import tim.prune.data.Checker;
14 import tim.prune.data.DataPoint;
15 import tim.prune.data.Field;
16 import tim.prune.data.LatLonRectangle;
17 import tim.prune.data.NumberUtils;
18 import tim.prune.data.Photo;
19 import tim.prune.data.PhotoList;
20 import tim.prune.data.PointCreateOptions;
21 import tim.prune.data.RecentFile;
22 import tim.prune.data.SourceInfo;
23 import tim.prune.data.Track;
24 import tim.prune.data.TrackInfo;
25 import tim.prune.data.SourceInfo.FILE_TYPE;
26 import tim.prune.data.Unit;
27 import tim.prune.function.AsyncMediaLoader;
28 import tim.prune.function.SaveConfig;
29 import tim.prune.function.SelectTracksFunction;
30 import tim.prune.function.browser.BrowserLauncher;
31 import tim.prune.function.browser.UrlGenerator;
32 import tim.prune.function.edit.FieldEditList;
33 import tim.prune.function.edit.PointEditor;
34 import tim.prune.gui.MenuManager;
35 import tim.prune.gui.SidebarController;
36 import tim.prune.gui.UndoManager;
37 import tim.prune.gui.Viewport;
38 import tim.prune.load.FileLoader;
39 import tim.prune.load.JpegLoader;
40 import tim.prune.load.MediaLinkInfo;
41 import tim.prune.load.TrackNameList;
42 import tim.prune.save.ExifSaver;
43 import tim.prune.save.FileSaver;
44 import tim.prune.undo.*;
48 * Main controller for the application
53 private JFrame _frame = null;
54 private Track _track = null;
55 private TrackInfo _trackInfo = null;
56 private int _lastSavePosition = 0;
57 private MenuManager _menuManager = null;
58 private SidebarController _sidebarController = null;
59 private FileLoader _fileLoader = null;
60 private JpegLoader _jpegLoader = null;
61 private FileSaver _fileSaver = null;
62 private Stack<UndoOperation> _undoStack = null;
63 private boolean _mangleTimestampsConfirmed = false;
64 private Viewport _viewport = null;
65 private ArrayList<File> _dataFiles = null;
66 private boolean _autoAppendNextFile = false;
67 private boolean _busyLoading = false;
68 private AppMode _appMode = AppMode.NORMAL;
70 /** Enum for the app mode - currently only two options but may expand later */
71 public enum AppMode {NORMAL, DRAWRECT};
76 * @param inFrame frame object for application
78 public App(JFrame inFrame)
81 _undoStack = new Stack<UndoOperation>();
83 _trackInfo = new TrackInfo(_track);
84 FunctionLibrary.initialise(this);
89 * @return the current TrackInfo
91 public TrackInfo getTrackInfo()
97 * @return the dialog frame
99 public JFrame getFrame()
105 * Check if the application has unsaved data
106 * @return true if data is unsaved, false otherwise
108 public boolean hasDataUnsaved()
110 return (_undoStack.size() > _lastSavePosition
111 && (_track.getNumPoints() > 0 || _trackInfo.getPhotoList().hasModifiedMedia()));
115 * @return the undo stack
117 public Stack<UndoOperation> getUndoStack()
123 * Load the specified data files one by one
124 * @param inDataFiles arraylist containing File objects to load
126 public void loadDataFiles(ArrayList<File> inDataFiles)
128 if (inDataFiles == null || inDataFiles.size() == 0) {
133 _dataFiles = inDataFiles;
134 File f = _dataFiles.get(0);
135 _dataFiles.remove(0);
136 // Start load of specified file
137 if (_fileLoader == null)
138 _fileLoader = new FileLoader(this, _frame);
139 _autoAppendNextFile = false; // prompt for append
140 _fileLoader.openFile(f);
145 * Complete a function execution
146 * @param inUndo undo object to be added to stack
147 * @param inConfirmText confirmation text
149 public void completeFunction(UndoOperation inUndo, String inConfirmText)
151 _undoStack.add(inUndo);
152 UpdateMessageBroker.informSubscribers(inConfirmText);
153 setCurrentMode(AppMode.NORMAL);
157 * Set the MenuManager object to be informed about changes
158 * @param inManager MenuManager object
160 public void setMenuManager(MenuManager inManager)
162 _menuManager = inManager;
167 * Open a file containing track or waypoint data
169 public void openFile()
171 if (_fileLoader == null)
172 _fileLoader = new FileLoader(this, _frame);
173 _fileLoader.openFile();
178 * Add a photo or a directory of photos
180 public void addPhotos()
182 if (_jpegLoader == null)
183 _jpegLoader = new JpegLoader(this, _frame);
184 _jpegLoader.openDialog(new LatLonRectangle(_track.getLatRange(), _track.getLonRange()));
188 * Save the file in the selected format
190 public void saveFile()
192 if (_track == null) {
193 showErrorMessage("error.save.dialogtitle", "error.save.nodata");
197 if (_fileSaver == null) {
198 _fileSaver = new FileSaver(this, _frame);
201 if (_fileLoader != null) {delim = _fileLoader.getLastUsedDelimiter();}
202 _fileSaver.showDialog(delim);
208 * Exit the application if confirmed
214 _frame.requestFocus();
215 // check if ok to exit
216 Object[] buttonTexts = {I18nManager.getText("button.exit"), I18nManager.getText("button.cancel")};
217 if (!hasDataUnsaved()
218 || JOptionPane.showOptionDialog(_frame, I18nManager.getText("dialog.exit.confirm.text"),
219 I18nManager.getText("dialog.exit.confirm.title"), JOptionPane.YES_NO_OPTION,
220 JOptionPane.WARNING_MESSAGE, null, buttonTexts, buttonTexts[1])
221 == JOptionPane.YES_OPTION)
224 if (Config.getConfigBoolean(Config.KEY_AUTOSAVE_SETTINGS)) {
225 new SaveConfig(this).silentSave();
233 * Edit the currently selected point
235 public void editCurrentPoint()
239 DataPoint currentPoint = _trackInfo.getCurrentPoint();
240 if (currentPoint != null)
242 // Open point dialog to display details
243 PointEditor editor = new PointEditor(this, _frame);
244 editor.showDialog(_track, currentPoint);
251 * Complete the point edit
252 * @param inEditList field values to edit
253 * @param inUndoList field values before edit
255 public void completePointEdit(FieldEditList inEditList, FieldEditList inUndoList)
257 DataPoint currentPoint = _trackInfo.getCurrentPoint();
258 if (inEditList != null && inEditList.getNumEdits() > 0 && currentPoint != null)
260 // add information to undo stack
261 UndoOperation undo = new UndoEditPoint(currentPoint, inUndoList);
262 // pass to track for completion
263 if (_track.editPoint(currentPoint, inEditList, false))
265 _undoStack.push(undo);
266 // Confirm point edit
267 UpdateMessageBroker.informSubscribers(I18nManager.getText("confirm.point.edit"));
274 * Delete the currently selected point
276 public void deleteCurrentPoint()
278 if (_track == null) {return;}
279 DataPoint currentPoint = _trackInfo.getCurrentPoint();
280 if (currentPoint != null)
283 boolean deletePhoto = false;
284 Photo currentPhoto = currentPoint.getPhoto();
285 if (currentPhoto != null)
287 // Confirm deletion of photo or decoupling
288 int response = JOptionPane.showConfirmDialog(_frame,
289 I18nManager.getText("dialog.deletepoint.deletephoto") + " " + currentPhoto.getName(),
290 I18nManager.getText("dialog.deletepoint.title"),
291 JOptionPane.YES_NO_CANCEL_OPTION);
292 if (response == JOptionPane.CANCEL_OPTION || response == JOptionPane.CLOSED_OPTION)
294 // cancel pressed- abort delete
297 if (response == JOptionPane.YES_OPTION) {deletePhoto = true;}
299 // store necessary information to undo it later
300 int pointIndex = _trackInfo.getSelection().getCurrentPointIndex();
301 int photoIndex = _trackInfo.getPhotoList().getPhotoIndex(currentPhoto);
302 int audioIndex = _trackInfo.getAudioList().getAudioIndex(currentPoint.getAudio());
303 DataPoint nextTrackPoint = _trackInfo.getTrack().getNextTrackPoint(pointIndex + 1);
304 // Construct Undo object
305 UndoOperation undo = new UndoDeletePoint(pointIndex, currentPoint, photoIndex,
306 audioIndex, nextTrackPoint != null && nextTrackPoint.getSegmentStart());
307 // call track to delete point
308 if (_trackInfo.deletePoint())
310 // Delete was successful so add undo info to stack
311 _undoStack.push(undo);
312 if (currentPhoto != null)
314 // delete photo if necessary
317 _trackInfo.getPhotoList().deletePhoto(photoIndex);
321 // decouple photo from point
322 currentPhoto.setDataPoint(null);
324 UpdateMessageBroker.informSubscribers(DataSubscriber.PHOTOS_MODIFIED);
326 // Delete audio object (without bothering to ask)
327 if (audioIndex > -1) {
328 _trackInfo.getAudioList().deleteAudio(audioIndex);
331 UpdateMessageBroker.informSubscribers(I18nManager.getText("confirm.deletepoint.single"));
332 UpdateMessageBroker.informSubscribers(DataSubscriber.DATA_ADDED_OR_REMOVED);
339 * Finish the compression by deleting the marked points
341 public void finishCompressTrack()
343 UndoDeleteMarked undo = new UndoDeleteMarked(_track);
344 // call track to do compress
345 int numPointsDeleted = _trackInfo.deleteMarkedPoints();
346 // add to undo stack if successful
347 if (numPointsDeleted > 0)
349 undo.setNumPointsDeleted(numPointsDeleted);
350 _undoStack.add(undo);
351 UpdateMessageBroker.informSubscribers("" + numPointsDeleted + " "
352 + (numPointsDeleted==1?I18nManager.getText("confirm.deletepoint.single"):I18nManager.getText("confirm.deletepoint.multi")));
355 showErrorMessage("function.compress", "dialog.deletemarked.nonefound");
360 * Reverse the currently selected section of the track
362 public void reverseRange()
364 // check whether Timestamp field exists, and if so confirm reversal
365 int selStart = _trackInfo.getSelection().getStart();
366 int selEnd = _trackInfo.getSelection().getEnd();
367 if (!_track.hasData(Field.TIMESTAMP, selStart, selEnd)
368 || _mangleTimestampsConfirmed
369 || (JOptionPane.showConfirmDialog(_frame,
370 I18nManager.getText("dialog.confirmreversetrack.text"),
371 I18nManager.getText("dialog.confirmreversetrack.title"),
372 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION && (_mangleTimestampsConfirmed = true)))
374 UndoReverseSection undo = new UndoReverseSection(_track, selStart, selEnd);
375 // call track to reverse range
376 if (_track.reverseRange(selStart, selEnd))
378 _undoStack.add(undo);
380 UpdateMessageBroker.informSubscribers(I18nManager.getText("confirm.reverserange"));
386 * Complete the add time offset function with the specified offset
387 * @param inTimeOffset time offset to add (+ve for add, -ve for subtract)
389 public void finishAddTimeOffset(long inTimeOffset)
391 // Construct undo information
392 int selStart = _trackInfo.getSelection().getStart();
393 int selEnd = _trackInfo.getSelection().getEnd();
394 UndoAddTimeOffset undo = new UndoAddTimeOffset(selStart, selEnd, inTimeOffset);
395 if (_trackInfo.getTrack().addTimeOffset(selStart, selEnd, inTimeOffset, false))
397 _undoStack.add(undo);
398 UpdateMessageBroker.informSubscribers(DataSubscriber.DATA_EDITED);
399 UpdateMessageBroker.informSubscribers(I18nManager.getText("confirm.addtimeoffset"));
405 * Complete the add altitude offset function with the specified offset
406 * @param inOffset altitude offset to add as String
407 * @param inUnit altitude units of offset (eg Feet, Metres)
409 public void finishAddAltitudeOffset(String inOffset, Unit inUnit)
412 if (inOffset == null || inOffset.equals("") || inUnit == null) {
415 // Construct undo information
416 UndoAddAltitudeOffset undo = new UndoAddAltitudeOffset(_trackInfo);
417 int selStart = _trackInfo.getSelection().getStart();
418 int selEnd = _trackInfo.getSelection().getEnd();
419 // How many decimal places are given in the offset?
420 int numDecimals = NumberUtils.getDecimalPlaces(inOffset);
421 boolean success = false;
422 // Decimal offset given
424 double offsetd = Double.parseDouble(inOffset);
425 success = _trackInfo.getTrack().addAltitudeOffset(selStart, selEnd, offsetd, inUnit, numDecimals);
427 catch (NumberFormatException nfe) {}
430 _undoStack.add(undo);
431 _trackInfo.getSelection().markInvalid();
432 UpdateMessageBroker.informSubscribers(DataSubscriber.DATA_EDITED);
433 UpdateMessageBroker.informSubscribers(I18nManager.getText("confirm.addaltitudeoffset"));
439 * Merge the track segments within the current selection
441 public void mergeTrackSegments()
443 if (_trackInfo.getSelection().hasRangeSelected())
445 // Maybe could check segment start flags to see if it's worth merging
446 // If first track point is already start and no other seg starts then do nothing
448 int selStart = _trackInfo.getSelection().getStart();
449 int selEnd = _trackInfo.getSelection().getEnd();
451 UndoMergeTrackSegments undo = new UndoMergeTrackSegments(_track, selStart, selEnd);
452 // Call track to merge segments
453 if (_trackInfo.mergeTrackSegments(selStart, selEnd)) {
454 _undoStack.add(undo);
455 UpdateMessageBroker.informSubscribers(I18nManager.getText("confirm.mergetracksegments"));
462 * Average the selected points
464 public void averageSelection()
466 // Find following track point
467 DataPoint nextPoint = _track.getNextTrackPoint(_trackInfo.getSelection().getEnd() + 1);
468 boolean segFlag = false;
469 if (nextPoint != null) {segFlag = nextPoint.getSegmentStart();}
470 UndoInsert undo = new UndoInsert(_trackInfo.getSelection().getEnd() + 1, 1, nextPoint != null, segFlag);
471 // call track info object to do the averaging
472 if (_trackInfo.average())
474 _undoStack.add(undo);
480 * Create a new point at the end of the track
481 * @param inPoint point to add
483 public void createPoint(DataPoint inPoint)
485 // create undo object
486 UndoCreatePoint undo = new UndoCreatePoint();
487 _undoStack.add(undo);
488 // add point to track
489 inPoint.setSegmentStart(true);
490 _track.appendPoints(new DataPoint[] {inPoint});
491 // ensure track's field list contains point's fields
492 _track.extendFieldList(inPoint.getFieldList());
493 _trackInfo.selectPoint(_trackInfo.getTrack().getNumPoints()-1);
495 UpdateMessageBroker.informSubscribers(I18nManager.getText("confirm.createpoint"));
500 * Create a new point before the given position
501 * @param inPoint point to add
502 * @param inIndex index of following point
504 public void createPoint(DataPoint inPoint, int inIndex)
506 // create undo object
507 UndoInsert undo = new UndoInsert(inIndex, 1);
508 _undoStack.add(undo);
509 // add point to track
510 _track.insertPoint(inPoint, inIndex);
511 // ensure track's field list contains point's fields
512 _track.extendFieldList(inPoint.getFieldList());
513 _trackInfo.selectPoint(inIndex);
515 UpdateMessageBroker.informSubscribers(I18nManager.getText("confirm.createpoint"));
520 * Cut the current selection and move it to before the currently selected point
522 public void cutAndMoveSelection()
524 int startIndex = _trackInfo.getSelection().getStart();
525 int endIndex = _trackInfo.getSelection().getEnd();
526 int pointIndex = _trackInfo.getSelection().getCurrentPointIndex();
527 // If timestamps would be mangled by cut/move, confirm
528 if (!_track.hasData(Field.TIMESTAMP, startIndex, endIndex)
529 || _mangleTimestampsConfirmed
530 || (JOptionPane.showConfirmDialog(_frame,
531 I18nManager.getText("dialog.confirmcutandmove.text"),
532 I18nManager.getText("dialog.confirmcutandmove.title"),
533 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION && (_mangleTimestampsConfirmed = true)))
535 // Find points to set segment flags
536 DataPoint firstTrackPoint = _track.getNextTrackPoint(startIndex, endIndex);
537 DataPoint nextTrackPoint = _track.getNextTrackPoint(endIndex+1);
538 DataPoint moveToTrackPoint = _track.getNextTrackPoint(pointIndex);
540 UndoCutAndMove undo = new UndoCutAndMove(_track, startIndex, endIndex, pointIndex);
541 // Call track info to move track section
542 if (_track.cutAndMoveSection(startIndex, endIndex, pointIndex))
544 // Set segment start flags (first track point, next track point, move to point)
545 if (firstTrackPoint != null) {firstTrackPoint.setSegmentStart(true);}
546 if (nextTrackPoint != null) {nextTrackPoint.setSegmentStart(true);}
547 if (moveToTrackPoint != null) {moveToTrackPoint.setSegmentStart(true);}
549 // Add undo object to stack, set confirm message
550 _undoStack.add(undo);
551 _trackInfo.getSelection().selectRange(-1, -1);
552 UpdateMessageBroker.informSubscribers();
553 UpdateMessageBroker.informSubscribers(I18nManager.getText("confirm.cutandmove"));
561 public void selectNone()
563 // deselect point, range and photo
564 _trackInfo.getSelection().clearAll();
565 _track.clearDeletionMarkers();
569 * Receive loaded data and determine whether to filter on tracks or not
570 * @param inFieldArray array of fields
571 * @param inDataArray array of data
572 * @param inSourceInfo information about the source of the data
573 * @param inTrackNameList information about the track names
575 public void informDataLoaded(Field[] inFieldArray, Object[][] inDataArray,
576 SourceInfo inSourceInfo, TrackNameList inTrackNameList)
578 // no link array given
579 informDataLoaded(inFieldArray, inDataArray, null, inSourceInfo,
580 inTrackNameList, null);
584 * Receive loaded data and determine whether to filter on tracks or not
585 * @param inFieldArray array of fields
586 * @param inDataArray array of data
587 * @param inOptions creation options such as units
588 * @param inSourceInfo information about the source of the data
589 * @param inTrackNameList information about the track names
591 public void informDataLoaded(Field[] inFieldArray, Object[][] inDataArray,
592 PointCreateOptions inOptions, SourceInfo inSourceInfo, TrackNameList inTrackNameList)
594 // no link array given
595 informDataLoaded(inFieldArray, inDataArray, inOptions, inSourceInfo,
596 inTrackNameList, null);
600 * Receive loaded data and determine whether to filter on tracks or not
601 * @param inFieldArray array of fields
602 * @param inDataArray array of data
603 * @param inOptions creation options such as units
604 * @param inSourceInfo information about the source of the data
605 * @param inTrackNameList information about the track names
606 * @param inLinkInfo links to photo/audio clips
608 public void informDataLoaded(Field[] inFieldArray, Object[][] inDataArray, PointCreateOptions inOptions,
609 SourceInfo inSourceInfo, TrackNameList inTrackNameList, MediaLinkInfo inLinkInfo)
611 // Check whether loaded array can be properly parsed into a Track
612 Track loadedTrack = new Track();
613 loadedTrack.load(inFieldArray, inDataArray, inOptions);
614 if (loadedTrack.getNumPoints() <= 0)
616 showErrorMessage("error.load.dialogtitle", "error.load.nopoints");
617 // load next file if there's a queue
621 // Check for doubled track
622 if (Checker.isDoubledTrack(loadedTrack)) {
623 JOptionPane.showMessageDialog(_frame, I18nManager.getText("dialog.open.contentsdoubled"),
624 I18nManager.getText("function.open"), JOptionPane.WARNING_MESSAGE);
628 // Attach photos and/or audio clips to points
629 if (inLinkInfo != null)
631 String[] linkArray = inLinkInfo.getLinkArray();
632 if (linkArray != null) {
633 new AsyncMediaLoader(this, inLinkInfo.getZipFile(), linkArray, loadedTrack, inSourceInfo.getFile()).begin();
636 // Look at TrackNameList, decide whether to filter or not
637 if (inTrackNameList != null && inTrackNameList.getNumTracks() > 1)
639 // Launch a dialog to let the user choose which tracks to load, then continue
640 new SelectTracksFunction(this, loadedTrack, inSourceInfo, inTrackNameList).begin();
643 // go directly to load
644 informDataLoaded(loadedTrack, inSourceInfo);
646 setCurrentMode(AppMode.NORMAL);
651 * Receive loaded data and optionally merge with current Track
652 * @param inLoadedTrack loaded track
653 * @param inSourceInfo information about the source of the data
655 public void informDataLoaded(Track inLoadedTrack, SourceInfo inSourceInfo)
657 // Decide whether to load or append
658 if (_track.getNumPoints() > 0)
660 // ask whether to replace or append
662 if (_autoAppendNextFile) {
663 // Automatically append the next file
664 answer = JOptionPane.YES_OPTION;
667 // Ask whether to append or not
668 answer = JOptionPane.showConfirmDialog(_frame,
669 I18nManager.getText("dialog.openappend.text"),
670 I18nManager.getText("dialog.openappend.title"),
671 JOptionPane.YES_NO_CANCEL_OPTION);
673 _autoAppendNextFile = false; // reset flag to cancel autoappend
675 if (answer == JOptionPane.YES_OPTION)
677 // append data to current Track
678 UndoLoad undo = new UndoLoad(_track.getNumPoints(), inLoadedTrack.getNumPoints());
679 undo.setNumPhotosAudios(_trackInfo.getPhotoList().getNumPhotos(), _trackInfo.getAudioList().getNumAudios());
680 _undoStack.add(undo);
681 _track.combine(inLoadedTrack);
682 // set source information
683 inSourceInfo.populatePointObjects(_track, inLoadedTrack.getNumPoints());
684 _trackInfo.getFileInfo().addSource(inSourceInfo);
686 else if (answer == JOptionPane.NO_OPTION)
688 // Don't append, replace data
689 PhotoList photos = null;
690 if (_trackInfo.getPhotoList().hasCorrelatedPhotos()) {
691 photos = _trackInfo.getPhotoList().cloneList();
693 UndoLoad undo = new UndoLoad(_trackInfo, inLoadedTrack.getNumPoints(), photos);
694 undo.setNumPhotosAudios(_trackInfo.getPhotoList().getNumPhotos(), _trackInfo.getAudioList().getNumAudios());
695 _undoStack.add(undo);
696 _lastSavePosition = _undoStack.size();
697 _trackInfo.getSelection().clearAll();
698 _track.load(inLoadedTrack);
699 inSourceInfo.populatePointObjects(_track, _track.getNumPoints());
700 _trackInfo.getFileInfo().replaceSource(inSourceInfo);
701 _trackInfo.getPhotoList().removeCorrelatedPhotos();
702 _trackInfo.getAudioList().removeCorrelatedAudios();
707 // Currently no data held, so transfer received data
708 UndoLoad undo = new UndoLoad(_trackInfo, inLoadedTrack.getNumPoints(), null);
709 undo.setNumPhotosAudios(_trackInfo.getPhotoList().getNumPhotos(), _trackInfo.getAudioList().getNumAudios());
710 _undoStack.add(undo);
711 _lastSavePosition = _undoStack.size();
712 _trackInfo.getSelection().clearAll();
713 _track.load(inLoadedTrack);
714 inSourceInfo.populatePointObjects(_track, _track.getNumPoints());
715 _trackInfo.getFileInfo().addSource(inSourceInfo);
717 // Update config before subscribers are told
718 boolean isRegularLoad = (inSourceInfo.getFileType() != FILE_TYPE.GPSBABEL);
719 Config.getRecentFileList().addFile(new RecentFile(inSourceInfo.getFile(), isRegularLoad));
720 UpdateMessageBroker.informSubscribers();
722 UpdateMessageBroker.informSubscribers(I18nManager.getText("confirm.loadfile")
723 + " '" + inSourceInfo.getName() + "'");
725 _menuManager.informFileLoaded();
727 _busyLoading = false;
728 // load next file if there's a queue
733 * Inform the app that NO data was loaded, eg cancel pressed
734 * Only needed if there's another file waiting in the queue
736 public void informNoDataLoaded()
738 // Load next file if there's a queue
743 * External trigger to automatically append the next loaded file
744 * instead of prompting to replace or append
746 public void autoAppendNextFile()
748 _autoAppendNextFile = true;
752 * Load the next file in the waiting list, if any
754 private void loadNextFile()
756 if (_dataFiles == null || _dataFiles.size() == 0) {
760 new Thread(new Runnable() {
762 File f = _dataFiles.get(0);
763 _dataFiles.remove(0);
764 _autoAppendNextFile = true;
765 _fileLoader.openFile(f);
773 * Accept a list of loaded photos
774 * @param inPhotoSet Set of Photo objects
776 public void informPhotosLoaded(Set<Photo> inPhotoSet)
778 if (inPhotoSet != null && !inPhotoSet.isEmpty())
780 int[] numsAdded = _trackInfo.addPhotos(inPhotoSet);
781 int numPhotosAdded = numsAdded[0];
782 int numPointsAdded = numsAdded[1];
783 if (numPhotosAdded > 0)
785 // Save numbers so load can be undone
786 _undoStack.add(new UndoLoadPhotos(numPhotosAdded, numPointsAdded));
788 if (numPhotosAdded == 1) {
789 UpdateMessageBroker.informSubscribers("" + numPhotosAdded + " " + I18nManager.getText("confirm.jpegload.single"));
792 UpdateMessageBroker.informSubscribers("" + numPhotosAdded + " " + I18nManager.getText("confirm.jpegload.multi"));
794 // MAYBE: Improve message when photo(s) fail to load (eg already added)
795 UpdateMessageBroker.informSubscribers();
797 if (numPointsAdded > 0) _menuManager.informFileLoaded();
803 * Save the coordinates of photos in their exif data
805 public void saveExif()
807 ExifSaver saver = new ExifSaver(_frame);
808 saver.saveExifInformation(_trackInfo.getPhotoList());
813 * Inform the app that the data has been saved
815 public void informDataSaved()
817 _lastSavePosition = _undoStack.size();
824 public void beginUndo()
826 if (_undoStack.isEmpty())
829 JOptionPane.showMessageDialog(_frame, I18nManager.getText("dialog.undo.none.text"),
830 I18nManager.getText("dialog.undo.none.title"), JOptionPane.INFORMATION_MESSAGE);
834 new UndoManager(this, _frame);
840 * Clear the undo stack (losing all undo information
842 public void clearUndo()
844 // Exit if nothing to undo
845 if (_undoStack == null || _undoStack.isEmpty())
847 // Has track got unsaved data?
848 boolean unsaved = hasDataUnsaved();
849 // Confirm operation with dialog
850 int answer = JOptionPane.showConfirmDialog(_frame,
851 I18nManager.getText("dialog.clearundo.text"),
852 I18nManager.getText("dialog.clearundo.title"),
853 JOptionPane.YES_NO_OPTION);
854 if (answer == JOptionPane.YES_OPTION)
857 _lastSavePosition = 0;
858 if (unsaved) _lastSavePosition = -1;
859 UpdateMessageBroker.informSubscribers();
865 * Undo the specified number of actions
866 * @param inNumUndos number of actions to undo
868 public void undoActions(int inNumUndos)
872 for (int i=0; i<inNumUndos; i++)
874 _undoStack.pop().performUndo(_trackInfo);
876 String message = "" + inNumUndos + " "
877 + (inNumUndos==1?I18nManager.getText("confirm.undo.single"):I18nManager.getText("confirm.undo.multi"));
878 UpdateMessageBroker.informSubscribers(message);
880 catch (UndoException ue)
882 showErrorMessageNoLookup("error.undofailed.title",
883 I18nManager.getText("error.undofailed.text") + " : " + ue.getMessage());
886 catch (EmptyStackException empty) {}
887 UpdateMessageBroker.informSubscribers();
892 * Show a map url in an external browser
893 * @param inSourceIndex index of map source to use
895 public void showExternalMap(int inSourceIndex)
897 BrowserLauncher.launchBrowser(UrlGenerator.generateUrl(inSourceIndex, _trackInfo));
901 * Display a standard error message
902 * @param inTitleKey key to lookup for window title
903 * @param inMessageKey key to lookup for error message
905 public void showErrorMessage(String inTitleKey, String inMessageKey)
907 JOptionPane.showMessageDialog(_frame, I18nManager.getText(inMessageKey),
908 I18nManager.getText(inTitleKey), JOptionPane.ERROR_MESSAGE);
912 * Display a standard error message
913 * @param inTitleKey key to lookup for window title
914 * @param inMessage error message
916 public void showErrorMessageNoLookup(String inTitleKey, String inMessage)
918 JOptionPane.showMessageDialog(_frame, inMessage,
919 I18nManager.getText(inTitleKey), JOptionPane.ERROR_MESSAGE);
923 * @param inViewport viewport object
925 public void setViewport(Viewport inViewport)
927 _viewport = inViewport;
931 * @return current viewport object
933 public Viewport getViewport()
939 * Set the controller for the full screen mode
940 * @param inController controller object
942 public void setSidebarController(SidebarController inController)
944 _sidebarController = inController;
948 * Toggle sidebars on and off
950 public void toggleSidebars()
952 _sidebarController.toggle();
955 /** @return true if App is currently busy with loading data */
956 public boolean isBusyLoading() {
960 /** @return current app mode */
961 public AppMode getCurrentMode() {
965 /** @param inMode the current app mode */
966 public void setCurrentMode(AppMode inMode) {