]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/undo/UndoDeleteAudio.java
Version 13, August 2011
[GpsPrune.git] / tim / prune / undo / UndoDeleteAudio.java
1 package tim.prune.undo;\r
2 \r
3 import tim.prune.I18nManager;\r
4 import tim.prune.UpdateMessageBroker;\r
5 import tim.prune.data.AudioClip;\r
6 import tim.prune.data.DataPoint;\r
7 import tim.prune.data.TrackInfo;\r
8 \r
9 /**\r
10  * Operation to undo a delete of a single audio item, either with or without point\r
11  */\r
12 public class UndoDeleteAudio implements UndoOperation\r
13 {\r
14         private int _audioIndex = -1;\r
15         private AudioClip _audio = null;\r
16         private int _pointIndex = -1;\r
17         private DataPoint _point = null;\r
18 \r
19 \r
20         /**\r
21          * Constructor\r
22          * @param inAudio audio item\r
23          * @param inAudioIndex index number of audio within list\r
24          * @param inPoint data point\r
25          * @param inPointIndex index number of point within track\r
26          */\r
27         public UndoDeleteAudio(AudioClip inAudio, int inAudioIndex, DataPoint inPoint, int inPointIndex)\r
28         {\r
29                 _audio = inAudio;\r
30                 _audioIndex = inAudioIndex;\r
31                 _point = inPoint;\r
32                 _pointIndex = inPointIndex;\r
33         }\r
34 \r
35 \r
36         /**\r
37          * @return description of operation including filename\r
38          */\r
39         public String getDescription() {\r
40                 return I18nManager.getText("undo.removeaudio") + " " + _audio.getName();\r
41         }\r
42 \r
43 \r
44         /**\r
45          * Perform the undo operation on the given Track\r
46          * @param inTrackInfo TrackInfo object on which to perform the operation\r
47          */\r
48         public void performUndo(TrackInfo inTrackInfo) throws UndoException\r
49         {\r
50                 // restore audio\r
51                 inTrackInfo.getAudioList().addAudio(_audio, _audioIndex);\r
52                 // if there's a point to restore, restore it\r
53                 if (_point != null)\r
54                 {\r
55                         if (!inTrackInfo.getTrack().insertPoint(_point, _pointIndex)) {\r
56                                 throw new UndoException(getDescription());\r
57                         }\r
58                 }\r
59                 else\r
60                 {\r
61                         // update needed if not already triggered by track update\r
62                         UpdateMessageBroker.informSubscribers();\r
63                 }\r
64                 // Ensure that audio is associated with point and vice versa\r
65                 _audio.setDataPoint(_point);\r
66                 if (_point != null) {\r
67                         _point.setAudio(_audio);\r
68                 }\r
69         }\r
70 }\r