--- /dev/null
+package tim.prune.undo;\r
+\r
+import tim.prune.I18nManager;\r
+import tim.prune.UpdateMessageBroker;\r
+import tim.prune.data.AudioFile;\r
+import tim.prune.data.DataPoint;\r
+import tim.prune.data.TrackInfo;\r
+\r
+/**\r
+ * Operation to undo a delete of a single audio item, either with or without point\r
+ */\r
+public class UndoDeleteAudio implements UndoOperation\r
+{\r
+ private int _audioIndex = -1;\r
+ private AudioFile _audio = null;\r
+ private int _pointIndex = -1;\r
+ private DataPoint _point = null;\r
+\r
+\r
+ /**\r
+ * Constructor\r
+ * @param inAudio audio item\r
+ * @param inAudioIndex index number of audio within list\r
+ * @param inPoint data point\r
+ * @param inPointIndex index number of point within track\r
+ */\r
+ public UndoDeleteAudio(AudioFile inAudio, int inAudioIndex, DataPoint inPoint, int inPointIndex)\r
+ {\r
+ _audio = inAudio;\r
+ _audioIndex = inAudioIndex;\r
+ _point = inPoint;\r
+ _pointIndex = inPointIndex;\r
+ }\r
+\r
+\r
+ /**\r
+ * @return description of operation including filename\r
+ */\r
+ public String getDescription() {\r
+ return I18nManager.getText("undo.removeaudio") + " " + _audio.getFile().getName();\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
+ // restore audio\r
+ inTrackInfo.getAudioList().addAudio(_audio, _audioIndex);\r
+ // if there's a point to restore, restore it\r
+ if (_point != null)\r
+ {\r
+ if (!inTrackInfo.getTrack().insertPoint(_point, _pointIndex)) {\r
+ throw new UndoException(getDescription());\r
+ }\r
+ }\r
+ else\r
+ {\r
+ // update needed if not already triggered by track update\r
+ UpdateMessageBroker.informSubscribers();\r
+ }\r
+ // Ensure that audio is associated with point and vice versa\r
+ _audio.setDataPoint(_point);\r
+ if (_point != null) {\r
+ _point.setAudio(_audio);\r
+ }\r
+ }\r
+}\r