1 package tim.prune.undo;
3 import tim.prune.I18nManager;
4 import tim.prune.data.DataPoint;
5 import tim.prune.data.Track;
6 import tim.prune.data.TrackInfo;
9 * Undo reversal of track section
11 public class UndoReverseSection implements UndoOperation
13 /** Start and end indices of section */
14 private int _startIndex, _endIndex;
15 /** First and last track point in section and next track point after */
16 private DataPoint _firstTrackPoint, _lastTrackPoint, _nextTrackPoint;
17 /** Segment flags for these points */
18 private boolean _firstSegmentFlag, _lastSegmentFlag, _nextSegmentFlag;
23 * @param inTrack track object for copying segment flags
24 * @param inStart start index of section
25 * @param inEnd end index of section
27 public UndoReverseSection(Track inTrack, int inStart, int inEnd)
29 _startIndex = inStart;
31 // Look for first track point in section to be reversed, store flag
32 _firstTrackPoint = inTrack.getNextTrackPoint(inStart);
33 if (_firstTrackPoint != null) {
34 _firstSegmentFlag = _firstTrackPoint.getSegmentStart();
36 // Look for last track point in section to be reversed, store flag
37 _lastTrackPoint = inTrack.getPreviousTrackPoint(inEnd);
38 if (_lastTrackPoint != null) {
39 _lastSegmentFlag = _lastTrackPoint.getSegmentStart();
41 // Look for following track point, store flag
42 _nextTrackPoint = inTrack.getNextTrackPoint(inEnd + 1);
43 if (_nextTrackPoint != null) {
44 _nextSegmentFlag = _nextTrackPoint.getSegmentStart();
50 * @return description of operation
52 public String getDescription()
54 return I18nManager.getText("undo.reverse");
59 * Perform the undo operation on the given Track
60 * @param inTrackInfo TrackInfo object on which to perform the operation
62 public void performUndo(TrackInfo inTrackInfo) throws UndoException
64 if (!inTrackInfo.getTrack().reverseRange(_startIndex, _endIndex))
66 throw new UndoException(getDescription());
68 // Restore segment start flags
69 if (_firstTrackPoint != null) {
70 _firstTrackPoint.setSegmentStart(_firstSegmentFlag);
72 if (_lastTrackPoint != null) {
73 _lastTrackPoint.setSegmentStart(_lastSegmentFlag);
75 if (_nextTrackPoint != null) {
76 _nextTrackPoint.setSegmentStart(_nextSegmentFlag);