]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - src/tim/prune/undo/UndoInsert.java
Moved source into separate src directory due to popular request
[GpsPrune.git] / src / tim / prune / undo / UndoInsert.java
diff --git a/src/tim/prune/undo/UndoInsert.java b/src/tim/prune/undo/UndoInsert.java
new file mode 100644 (file)
index 0000000..f238921
--- /dev/null
@@ -0,0 +1,81 @@
+package tim.prune.undo;\r
+\r
+import tim.prune.I18nManager;\r
+import tim.prune.data.DataPoint;\r
+import tim.prune.data.TrackInfo;\r
+\r
+/**\r
+ * Operation to undo an insertion (eg average)\r
+ */\r
+public class UndoInsert implements UndoOperation\r
+{\r
+       private int _startPosition = 0;\r
+       private int _numInserted = 0;\r
+       private boolean _hasSegmentFlag = false;\r
+       private boolean _segmentFlag = false;\r
+\r
+\r
+       /**\r
+        * Constructor without segment flag\r
+        * @param inStart start of insert\r
+        * @param inNumInserted number of points inserted\r
+        */\r
+       public UndoInsert(int inStart, int inNumInserted)\r
+       {\r
+               this(inStart, inNumInserted, false, false);\r
+       }\r
+\r
+\r
+       /**\r
+        * Constructor with segment flag\r
+        * @param inStart start of insert\r
+        * @param inNumInserted number of points inserted\r
+        * @param inSegmentFlag segment flag of following point\r
+        */\r
+       public UndoInsert(int inStart, int inNumInserted, boolean inSegmentFlag)\r
+       {\r
+               this(inStart, inNumInserted, true, inSegmentFlag);\r
+       }\r
+\r
+\r
+       /**\r
+        * Constructor\r
+        * @param inStart start of insert\r
+        * @param inNumInserted number of points inserted\r
+        * @param inHasFlag is there a segment flag present\r
+        * @param inFlag segment flag, if any\r
+        */\r
+       public UndoInsert(int inStart, int inNumInserted, boolean inHasFlag, boolean inFlag)\r
+       {\r
+               _startPosition = inStart;\r
+               _numInserted = inNumInserted;\r
+               _hasSegmentFlag = inHasFlag;\r
+               _segmentFlag = inFlag;\r
+       }\r
+\r
+\r
+       /**\r
+        * @return description of operation including parameters\r
+        */\r
+       public String getDescription()\r
+       {\r
+               return I18nManager.getText("undo.insert") + " (" + _numInserted + ")";\r
+       }\r
+\r
+\r
+       /**\r
+        * Perform the undo operation on the given TrackInfo\r
+        * @param inTrackInfo TrackInfo object on which to perform the operation\r
+        */\r
+       public void performUndo(TrackInfo inTrackInfo) throws UndoException\r
+       {\r
+               // restore track to previous values\r
+               inTrackInfo.getTrack().deleteRange(_startPosition, _startPosition + _numInserted - 1);\r
+               if (_hasSegmentFlag) {\r
+                       DataPoint nextPoint = inTrackInfo.getTrack().getNextTrackPoint(_startPosition);\r
+                       if (nextPoint != null) {nextPoint.setSegmentStart(_segmentFlag);}\r
+               }\r
+               // reset selection\r
+               inTrackInfo.getSelection().clearAll();\r
+       }\r
+}
\ No newline at end of file