]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - src/tim/prune/undo/UndoEditPoint.java
Moved source into separate src directory due to popular request
[GpsPrune.git] / src / tim / prune / undo / UndoEditPoint.java
diff --git a/src/tim/prune/undo/UndoEditPoint.java b/src/tim/prune/undo/UndoEditPoint.java
new file mode 100644 (file)
index 0000000..be41ea0
--- /dev/null
@@ -0,0 +1,61 @@
+package tim.prune.undo;\r
+\r
+import tim.prune.I18nManager;\r
+import tim.prune.data.DataPoint;\r
+import tim.prune.data.Field;\r
+import tim.prune.data.TrackInfo;\r
+import tim.prune.function.edit.FieldEditList;\r
+\r
+/**\r
+ * Operation to undo the edit of a single point\r
+ */\r
+public class UndoEditPoint implements UndoOperation\r
+{\r
+       private DataPoint _originalPoint = null;\r
+       private FieldEditList _undoFieldList = null;\r
+\r
+\r
+       /**\r
+        * Constructor\r
+        * @param inPoint data point\r
+        * @param inUndoFieldList FieldEditList for undo operation\r
+        */\r
+       public UndoEditPoint(DataPoint inPoint, FieldEditList inUndoFieldList)\r
+       {\r
+               _originalPoint = inPoint;\r
+               _undoFieldList = inUndoFieldList;\r
+       }\r
+\r
+\r
+       /**\r
+        * @return description of operation including point name if any\r
+        */\r
+       public String getDescription()\r
+       {\r
+               String desc = I18nManager.getText("undo.editpoint");\r
+               String newName = null;\r
+               if (_undoFieldList.getEdit(0).getField() == Field.WAYPT_NAME)\r
+                       newName = _undoFieldList.getEdit(0).getValue();\r
+               String pointName = _originalPoint.getWaypointName();\r
+               if (newName != null && !newName.equals(""))\r
+                       desc = desc + " " + newName;\r
+               else if (pointName != null && !pointName.equals(""))\r
+                       desc = desc + " " + pointName;\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
+               // Restore contents of point into track\r
+               if (!inTrackInfo.getTrack().editPoint(_originalPoint, _undoFieldList, true))\r
+               {\r
+                       // throw exception if failed\r
+                       throw new UndoException(getDescription());\r
+               }\r
+       }\r
+}
\ No newline at end of file