X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Fundo%2FUndoEditPoint.java;fp=src%2Ftim%2Fprune%2Fundo%2FUndoEditPoint.java;h=be41ea0d88f92c7ce15ef966a253a607b2fe853f;hp=0000000000000000000000000000000000000000;hb=ce6f2161b8596f7018d6a76bff79bc9e571f35fd;hpb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465 diff --git a/src/tim/prune/undo/UndoEditPoint.java b/src/tim/prune/undo/UndoEditPoint.java new file mode 100644 index 0000000..be41ea0 --- /dev/null +++ b/src/tim/prune/undo/UndoEditPoint.java @@ -0,0 +1,61 @@ +package tim.prune.undo; + +import tim.prune.I18nManager; +import tim.prune.data.DataPoint; +import tim.prune.data.Field; +import tim.prune.data.TrackInfo; +import tim.prune.function.edit.FieldEditList; + +/** + * Operation to undo the edit of a single point + */ +public class UndoEditPoint implements UndoOperation +{ + private DataPoint _originalPoint = null; + private FieldEditList _undoFieldList = null; + + + /** + * Constructor + * @param inPoint data point + * @param inUndoFieldList FieldEditList for undo operation + */ + public UndoEditPoint(DataPoint inPoint, FieldEditList inUndoFieldList) + { + _originalPoint = inPoint; + _undoFieldList = inUndoFieldList; + } + + + /** + * @return description of operation including point name if any + */ + public String getDescription() + { + String desc = I18nManager.getText("undo.editpoint"); + String newName = null; + if (_undoFieldList.getEdit(0).getField() == Field.WAYPT_NAME) + newName = _undoFieldList.getEdit(0).getValue(); + String pointName = _originalPoint.getWaypointName(); + if (newName != null && !newName.equals("")) + desc = desc + " " + newName; + else if (pointName != null && !pointName.equals("")) + desc = desc + " " + pointName; + return desc; + } + + + /** + * Perform the undo operation on the given Track + * @param inTrackInfo TrackInfo object on which to perform the operation + */ + public void performUndo(TrackInfo inTrackInfo) throws UndoException + { + // Restore contents of point into track + if (!inTrackInfo.getTrack().editPoint(_originalPoint, _undoFieldList, true)) + { + // throw exception if failed + throw new UndoException(getDescription()); + } + } +} \ No newline at end of file