]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/undo/UndoCorrelateAudios.java
e0c1f9591eeb8be80e9abf2409b35e61d245853f
[GpsPrune.git] / tim / prune / undo / UndoCorrelateAudios.java
1 package tim.prune.undo;\r
2 \r
3 import tim.prune.I18nManager;\r
4 import tim.prune.data.AudioFile;\r
5 import tim.prune.data.DataPoint;\r
6 import tim.prune.data.TrackInfo;\r
7 \r
8 /**\r
9  * Operation to undo an auto-correlation of audios with points\r
10  * (very similar to UndoCorrelatePhotos)\r
11  */\r
12 public class UndoCorrelateAudios implements UndoOperation\r
13 {\r
14         private DataPoint[] _contents = null;\r
15         private DataPoint[] _audioPoints = null;\r
16         private int _numCorrelated = -1;\r
17 \r
18 \r
19         /**\r
20          * Constructor\r
21          * @param inTrackInfo track information\r
22          */\r
23         public UndoCorrelateAudios(TrackInfo inTrackInfo)\r
24         {\r
25                 // Copy track contents\r
26                 _contents = inTrackInfo.getTrack().cloneContents();\r
27                 // Copy points associated with audios before correlation\r
28                 int numAudios = inTrackInfo.getAudioList().getNumAudios();\r
29                 _audioPoints = new DataPoint[numAudios];\r
30                 for (int i=0; i<numAudios; i++) {\r
31                         _audioPoints[i] = inTrackInfo.getAudioList().getAudio(i).getDataPoint();\r
32                 }\r
33         }\r
34 \r
35         /**\r
36          * @param inNumCorrelated number of audios correlated\r
37          */\r
38         public void setNumAudiosCorrelated(int inNumCorrelated)\r
39         {\r
40                 _numCorrelated = inNumCorrelated;\r
41         }\r
42 \r
43         /**\r
44          * @return description of operation including parameters\r
45          */\r
46         public String getDescription()\r
47         {\r
48                 return I18nManager.getText("undo.correlateaudios") + " (" + _numCorrelated + ")";\r
49         }\r
50 \r
51 \r
52         /**\r
53          * Perform the undo operation on the given Track\r
54          * @param inTrackInfo TrackInfo object on which to perform the operation\r
55          */\r
56         public void performUndo(TrackInfo inTrackInfo) throws UndoException\r
57         {\r
58                 // restore track to previous values\r
59                 inTrackInfo.getTrack().replaceContents(_contents);\r
60                 // restore audio association\r
61                 for (int i=0; i<_audioPoints.length; i++)\r
62                 {\r
63                         AudioFile audio = inTrackInfo.getAudioList().getAudio(i);\r
64                         // Only need to look at connected ones, since correlation wouldn't disconnect\r
65                         if (audio.getCurrentStatus() == AudioFile.Status.CONNECTED)\r
66                         {\r
67                                 DataPoint prevPoint = _audioPoints[i];\r
68                                 DataPoint currPoint = audio.getDataPoint();\r
69                                 audio.setDataPoint(prevPoint);\r
70                                 if (currPoint != null) {\r
71                                         currPoint.setAudio(null); // disconnect\r
72                                 }\r
73                                 if (prevPoint != null) {\r
74                                         prevPoint.setAudio(audio); // reconnect to prev point\r
75                                 }\r
76                         }\r
77                 }\r
78                 // clear selection\r
79                 inTrackInfo.getSelection().clearAll();\r
80         }\r
81 }\r