]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - src/tim/prune/undo/UndoDisconnectMedia.java
Moved source into separate src directory due to popular request
[GpsPrune.git] / src / tim / prune / undo / UndoDisconnectMedia.java
diff --git a/src/tim/prune/undo/UndoDisconnectMedia.java b/src/tim/prune/undo/UndoDisconnectMedia.java
new file mode 100644 (file)
index 0000000..f40ab2d
--- /dev/null
@@ -0,0 +1,73 @@
+package tim.prune.undo;\r
+\r
+import tim.prune.I18nManager;\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 disconnection of a photo or audio from a point\r
+ */\r
+public class UndoDisconnectMedia implements UndoOperation\r
+{\r
+       private DataPoint _point = null;\r
+       private Photo _photo = null;\r
+       private AudioClip _audio = null;\r
+       private String _filename = null;\r
+\r
+\r
+       /**\r
+        * Constructor\r
+        * @param inPoint data point\r
+        * @param inPhoto true if photo was disconnected\r
+        * @param inAudio true if audio was disconnected\r
+        * @param inFilename filename of photo / audio\r
+        */\r
+       public UndoDisconnectMedia(DataPoint inPoint, boolean inPhoto, boolean inAudio, String inFilename)\r
+       {\r
+               _point = inPoint;\r
+               if (inPhoto) {\r
+                       _photo = inPoint.getPhoto();\r
+               }\r
+               if (inAudio) {\r
+                       _audio = inPoint.getAudio();\r
+               }\r
+               _filename = inFilename;\r
+       }\r
+\r
+\r
+       /**\r
+        * @return description of operation including filename\r
+        */\r
+       public String getDescription()\r
+       {\r
+               return I18nManager.getText("undo.disconnect") + " " + _filename;\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
+               // Connect again\r
+               if (_point != null && _photo != null)\r
+               {\r
+                       _point.setPhoto(_photo);\r
+                       _photo.setDataPoint(_point);\r
+               }\r
+               else if (_point != null && _audio != null)\r
+               {\r
+                       _point.setAudio(_audio);\r
+                       _audio.setDataPoint(_point);\r
+               }\r
+               else {\r
+                       // throw exception if failed\r
+                       throw new UndoException(getDescription());\r
+               }\r
+               // clear selection\r
+               inTrackInfo.getSelection().clearAll();\r
+       }\r
+}
\ No newline at end of file