]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - src/tim/prune/App.java
Merge remote-tracking branch 'upstream/master' into fp-integration
[GpsPrune.git] / src / tim / prune / App.java
index 2e7594178ae2b379eccffd2d3cf41bb9f6494e61..f76edb177d2ffb4f8ba09e3feda928022be052d5 100644 (file)
@@ -51,6 +51,7 @@ public class App
 {
        // Instance variables
        private JFrame _frame = null;
+       private String _titlePrefix = null;
        private Track _track = null;
        private TrackInfo _trackInfo = null;
        private int _lastSavePosition = 0;
@@ -69,7 +70,7 @@ public class App
        private AppMode _appMode = AppMode.NORMAL;
 
        /** Enum for the app mode - currently only two options but may expand later */
-       public enum AppMode {NORMAL, DRAWRECT};
+       public enum AppMode {NORMAL, DRAWRECT}
 
 
        /**
@@ -79,6 +80,7 @@ public class App
        public App(JFrame inFrame)
        {
                _frame = inFrame;
+               _titlePrefix = _frame.getTitle();
                _undoStack = new UndoStack();
                _track = new Track();
                _trackInfo = new TrackInfo(_track);
@@ -454,6 +456,22 @@ public class App
        }
 
 
+       /**
+        * Remove altitudes from selected points
+        */
+       public void removeAltitudes(int selStart, int selEnd)
+       {
+               UndoRemoveAltitudes undo = new UndoRemoveAltitudes(_trackInfo, selStart, selEnd);
+               if (_trackInfo.getTrack().removeAltitudes(selStart, selEnd))
+               {
+                       _undoStack.add(undo);
+                       _trackInfo.getSelection().markInvalid();
+                       UpdateMessageBroker.informSubscribers(DataSubscriber.DATA_EDITED);
+                       UpdateMessageBroker.informSubscribers(I18nManager.getText("confirm.removealtitudes"));
+               }
+       }
+
+
        /**
         * Merge the track segments within the current selection
         */
@@ -649,7 +667,8 @@ public class App
                loadedTrack.load(inFieldArray, inDataArray, inOptions);
                if (loadedTrack.getNumPoints() <= 0)
                {
-                       showErrorMessage("error.load.dialogtitle", "error.load.nopoints");
+                       String msgKey = (inSourceInfo == null ? "error.load.nopointsintext" : "error.load.nopoints");
+                       showErrorMessage("error.load.dialogtitle", msgKey);
                        // load next file if there's a queue
                        loadNextFile();
                        return;
@@ -715,9 +734,12 @@ public class App
                                undo.setNumPhotosAudios(_trackInfo.getPhotoList().getNumPhotos(), _trackInfo.getAudioList().getNumAudios());
                                _undoStack.add(undo);
                                _track.combine(inLoadedTrack);
-                               // set source information
-                               inSourceInfo.populatePointObjects(_track, inLoadedTrack.getNumPoints());
-                               _trackInfo.getFileInfo().addSource(inSourceInfo);
+                               if (inSourceInfo != null)
+                               {
+                                       // set source information
+                                       inSourceInfo.populatePointObjects(_track, inLoadedTrack.getNumPoints());
+                                       _trackInfo.getFileInfo().addSource(inSourceInfo);
+                               }
                        }
                        else if (answer == JOptionPane.NO_OPTION)
                        {
@@ -732,8 +754,12 @@ public class App
                                _lastSavePosition = _undoStack.size();
                                _trackInfo.getSelection().clearAll();
                                _track.load(inLoadedTrack);
-                               inSourceInfo.populatePointObjects(_track, _track.getNumPoints());
-                               _trackInfo.getFileInfo().replaceSource(inSourceInfo);
+                               if (inSourceInfo != null)
+                               {
+                                       // set source information
+                                       inSourceInfo.populatePointObjects(_track, _track.getNumPoints());
+                                       _trackInfo.getFileInfo().replaceSource(inSourceInfo);
+                               }
                                _trackInfo.getPhotoList().removeCorrelatedPhotos();
                                _trackInfo.getAudioList().removeCorrelatedAudios();
                        }
@@ -747,20 +773,28 @@ public class App
                        _lastSavePosition = _undoStack.size();
                        _trackInfo.getSelection().clearAll();
                        _track.load(inLoadedTrack);
-                       inSourceInfo.populatePointObjects(_track, _track.getNumPoints());
-                       _trackInfo.getFileInfo().addSource(inSourceInfo);
+                       if (inSourceInfo != null)
+                       {
+                               inSourceInfo.populatePointObjects(_track, _track.getNumPoints());
+                               _trackInfo.getFileInfo().addSource(inSourceInfo);
+                       }
                }
                // Update config before subscribers are told
-               boolean isRegularLoad = (inSourceInfo.getFileType() != FILE_TYPE.GPSBABEL);
-               Config.getRecentFileList().addFile(new RecentFile(inSourceInfo.getFile(), isRegularLoad));
+               if (inSourceInfo != null)
+               {
+                       boolean isRegularLoad = (inSourceInfo.getFileType() != FILE_TYPE.GPSBABEL);
+                       Config.getRecentFileList().addFile(new RecentFile(inSourceInfo.getFile(), isRegularLoad));
+                       // Update status bar
+                       UpdateMessageBroker.informSubscribers(I18nManager.getText("confirm.loadfile")
+                               + " '" + inSourceInfo.getName() + "'");
+               }
                UpdateMessageBroker.informSubscribers();
-               // Update status bar
-               UpdateMessageBroker.informSubscribers(I18nManager.getText("confirm.loadfile")
-                       + " '" + inSourceInfo.getName() + "'");
                // update menu
                _menuManager.informFileLoaded();
                // recentre viewport on new file data
                _viewport.recentreViewport();
+               // update main window title
+               updateTitle();
                // Remove busy lock
                _busyLoading = false;
                // load next file if there's a queue
@@ -1003,4 +1037,16 @@ public class App
        public void setCurrentMode(AppMode inMode) {
                _appMode = inMode;
        }
+
+       /** Update main window title **/
+       public void updateTitle() {
+               ArrayList<String> filenames = _trackInfo.getFileInfo().getFilenames();
+               if (filenames.size() > 0) {
+                       _frame.setTitle(_titlePrefix + ": " + String.join(", ", filenames));
+               }
+               else
+               {
+                       _frame.setTitle(_titlePrefix);
+               }
+       }
 }