--- /dev/null
+package tim.prune.undo;\r
+\r
+import tim.prune.I18nManager;\r
+import tim.prune.UpdateMessageBroker;\r
+import tim.prune.data.DataPoint;\r
+import tim.prune.data.Field;\r
+import tim.prune.data.Track;\r
+import tim.prune.data.TrackInfo;\r
+\r
+/**\r
+ * Operation to undo the deletion of field values\r
+ */\r
+public class UndoDeleteFieldValues implements UndoOperation\r
+{\r
+ /** Start and end indices of section */\r
+ private int _startIndex, _endIndex;\r
+ /** Field to be deleted */\r
+ private Field _field = null;\r
+ /** Field values before operation */\r
+ private String[] _fieldValues = null;\r
+\r
+ /**\r
+ * Constructor\r
+ * @param inTrackInfo track info object to copy values from\r
+ * @param inField field to delete\r
+ */\r
+ public UndoDeleteFieldValues(TrackInfo inTrackInfo, Field inField)\r
+ {\r
+ _startIndex = inTrackInfo.getSelection().getStart();\r
+ _endIndex = inTrackInfo.getSelection().getEnd();\r
+ final int numPoints = _endIndex - _startIndex + 1;\r
+ _fieldValues = new String[numPoints];\r
+ _field = inField;\r
+ // Loop over points in selection, and copy field values\r
+ for (int i=_startIndex; i<=_endIndex; i++)\r
+ {\r
+ DataPoint point = inTrackInfo.getTrack().getPoint(i);\r
+ _fieldValues[i-_startIndex] = point.getFieldValue(inField);\r
+ }\r
+ }\r
+\r
+\r
+ /**\r
+ * @return description of operation\r
+ */\r
+ public String getDescription()\r
+ {\r
+ return I18nManager.getText("undo.deletefieldvalues");\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
+ // Sanity check\r
+ Track track = inTrackInfo.getTrack();\r
+ if (track.getNumPoints() <= _endIndex || _endIndex <= _startIndex) {\r
+ throw new UndoException("Cannot undo conversion, track length doesn't match");\r
+ }\r
+ // Loop over points in selection and replace field values\r
+ for (int i=_startIndex; i<=_endIndex; i++)\r
+ {\r
+ String storedValue = _fieldValues[i-_startIndex];\r
+ if (storedValue != null) {\r
+ track.getPoint(i).setFieldValue(_field, storedValue, true);\r
+ }\r
+ }\r
+ track.requestRescale();\r
+ inTrackInfo.getSelection().markInvalid();\r
+ UpdateMessageBroker.informSubscribers();\r
+ }\r
+}\r