]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/undo/UndoEditPoint.java
be41ea0d88f92c7ce15ef966a253a607b2fe853f
[GpsPrune.git] / tim / prune / undo / UndoEditPoint.java
1 package tim.prune.undo;\r
2 \r
3 import tim.prune.I18nManager;\r
4 import tim.prune.data.DataPoint;\r
5 import tim.prune.data.Field;\r
6 import tim.prune.data.TrackInfo;\r
7 import tim.prune.function.edit.FieldEditList;\r
8 \r
9 /**\r
10  * Operation to undo the edit of a single point\r
11  */\r
12 public class UndoEditPoint implements UndoOperation\r
13 {\r
14         private DataPoint _originalPoint = null;\r
15         private FieldEditList _undoFieldList = null;\r
16 \r
17 \r
18         /**\r
19          * Constructor\r
20          * @param inPoint data point\r
21          * @param inUndoFieldList FieldEditList for undo operation\r
22          */\r
23         public UndoEditPoint(DataPoint inPoint, FieldEditList inUndoFieldList)\r
24         {\r
25                 _originalPoint = inPoint;\r
26                 _undoFieldList = inUndoFieldList;\r
27         }\r
28 \r
29 \r
30         /**\r
31          * @return description of operation including point name if any\r
32          */\r
33         public String getDescription()\r
34         {\r
35                 String desc = I18nManager.getText("undo.editpoint");\r
36                 String newName = null;\r
37                 if (_undoFieldList.getEdit(0).getField() == Field.WAYPT_NAME)\r
38                         newName = _undoFieldList.getEdit(0).getValue();\r
39                 String pointName = _originalPoint.getWaypointName();\r
40                 if (newName != null && !newName.equals(""))\r
41                         desc = desc + " " + newName;\r
42                 else if (pointName != null && !pointName.equals(""))\r
43                         desc = desc + " " + pointName;\r
44                 return desc;\r
45         }\r
46 \r
47 \r
48         /**\r
49          * Perform the undo operation on the given Track\r
50          * @param inTrackInfo TrackInfo object on which to perform the operation\r
51          */\r
52         public void performUndo(TrackInfo inTrackInfo) throws UndoException\r
53         {\r
54                 // Restore contents of point into track\r
55                 if (!inTrackInfo.getTrack().editPoint(_originalPoint, _undoFieldList, true))\r
56                 {\r
57                         // throw exception if failed\r
58                         throw new UndoException(getDescription());\r
59                 }\r
60         }\r
61 }