]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - src/tim/prune/undo/UndoConnectMedia.java
Moved source into separate src directory due to popular request
[GpsPrune.git] / src / tim / prune / undo / UndoConnectMedia.java
diff --git a/src/tim/prune/undo/UndoConnectMedia.java b/src/tim/prune/undo/UndoConnectMedia.java
new file mode 100644 (file)
index 0000000..d7feb63
--- /dev/null
@@ -0,0 +1,75 @@
+package tim.prune.undo;\r
+\r
+import tim.prune.I18nManager;\r
+import tim.prune.UpdateMessageBroker;\r
+import tim.prune.data.AudioClip;\r
+import tim.prune.data.DataPoint;\r
+import tim.prune.data.Photo;\r
+import tim.prune.data.TrackInfo;\r
+\r
+/**\r
+ * Operation to undo the connection of a photo and/or audio to a point\r
+ */\r
+public class UndoConnectMedia implements UndoOperation\r
+{\r
+       private DataPoint _point = null;\r
+       private String _photoFilename = null;\r
+       private String _audioFilename = null;\r
+\r
+\r
+       /**\r
+        * Constructor\r
+        * @param inPoint data point\r
+        * @param inPhotoFilename filename of photo, or null if photo not connected\r
+        * @param inAudioFilename filename of audio, or null of audio not connected\r
+        */\r
+       public UndoConnectMedia(DataPoint inPoint, String inPhotoFilename, String inAudioFilename)\r
+       {\r
+               _point = inPoint;\r
+               _photoFilename = inPhotoFilename;\r
+               _audioFilename = inAudioFilename;\r
+       }\r
+\r
+\r
+       /**\r
+        * @return description of operation including photo and/or audio filename(s)\r
+        */\r
+       public String getDescription()\r
+       {\r
+               String desc = I18nManager.getText("undo.connect") + " " + (_photoFilename==null?"":_photoFilename)\r
+                + (_photoFilename!=null && _audioFilename!=null?", ":"")\r
+                + (_audioFilename==null?"":_audioFilename);\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
+               if (_photoFilename != null)\r
+               {\r
+                       // Disconnect photo\r
+                       Photo photo = _point.getPhoto();\r
+                       if (photo != null)\r
+                       {\r
+                               _point.setPhoto(null);\r
+                               photo.setDataPoint(null);\r
+                       }\r
+               }\r
+               if (_audioFilename != null)\r
+               {\r
+                       // Disconnect audio\r
+                       AudioClip audio = _point.getAudio();\r
+                       if (audio != null)\r
+                       {\r
+                               _point.setAudio(null);\r
+                               audio.setDataPoint(null);\r
+                       }\r
+               }\r
+               // inform subscribers\r
+               UpdateMessageBroker.informSubscribers();\r
+       }\r
+}
\ No newline at end of file