--- /dev/null
+package tim.prune.undo;\r
+\r
+import tim.prune.I18nManager;\r
+import tim.prune.data.DataPoint;\r
+import tim.prune.data.TrackInfo;\r
+\r
+/**\r
+ * Operation to undo a load operation\r
+ */\r
+public class UndoLoad implements UndoOperation\r
+{\r
+ private int _cropIndex = -1;\r
+ private int _numLoaded = -1;\r
+ private DataPoint[] _contents = null;\r
+ private String _previousFilename = null;\r
+\r
+\r
+ /**\r
+ * Constructor for appending\r
+ * @param inIndex index number of crop point\r
+ * @param inNumLoaded number of points loaded\r
+ */\r
+ public UndoLoad(int inIndex, int inNumLoaded)\r
+ {\r
+ _cropIndex = inIndex;\r
+ _numLoaded = inNumLoaded;\r
+ _contents = null;\r
+ _previousFilename = null;\r
+ }\r
+\r
+\r
+ /**\r
+ * Constructor for replacing\r
+ * @param inOldTrack track being replaced\r
+ * @param inNumLoaded number of points loaded\r
+ */\r
+ public UndoLoad(TrackInfo inOldTrackInfo, int inNumLoaded)\r
+ {\r
+ _cropIndex = -1;\r
+ _numLoaded = inNumLoaded;\r
+ _contents = inOldTrackInfo.getTrack().cloneContents();\r
+ if (inOldTrackInfo.getFileInfo().getNumFiles() == 1)\r
+ _previousFilename = inOldTrackInfo.getFileInfo().getFilename();\r
+ }\r
+\r
+\r
+ /**\r
+ * @return description of operation including number of points loaded\r
+ */\r
+ public String getDescription()\r
+ {\r
+ String desc = I18nManager.getText("undo.load");\r
+ if (_numLoaded > 0)\r
+ desc = desc + " (" + _numLoaded + ")";\r
+ return desc;\r
+ }\r
+\r
+\r
+ /**\r
+ * Perform the undo operation on the given Track\r
+ * @param inTrackInfo TrackInfo object on which to perform the operation\r
+ */\r
+ public void performUndo(TrackInfo inTrackInfo) throws UndoException\r
+ {\r
+ // remove file from fileinfo\r
+ inTrackInfo.getFileInfo().removeFile();\r
+ if (_previousFilename != null)\r
+ {\r
+ inTrackInfo.getFileInfo().setFile(_previousFilename);\r
+ }\r
+ // Crop / replace\r
+ if (_contents == null)\r
+ {\r
+ // crop track to previous size\r
+ inTrackInfo.getTrack().cropTo(_cropIndex);\r
+ }\r
+ else\r
+ {\r
+ // replace track contents with old\r
+ if (!inTrackInfo.getTrack().replaceContents(_contents))\r
+ {\r
+ throw new UndoException(getDescription());\r
+ }\r
+ }\r
+ // clear selection\r
+ inTrackInfo.getSelection().clearAll();\r
+ }\r
+}
\ No newline at end of file