1 package tim.prune.function;
4 import tim.prune.DataSubscriber;
5 import tim.prune.GenericFunction;
6 import tim.prune.I18nManager;
7 import tim.prune.UpdateMessageBroker;
8 import tim.prune.data.DataPoint;
9 import tim.prune.data.Field;
10 import tim.prune.data.TimestampUtc;
11 import tim.prune.data.Track;
12 import tim.prune.undo.UndoConvertNamesToTimes;
15 * Class to provide the function to convert waypoint names to timestamps
17 public class ConvertNamesToTimes extends GenericFunction
21 * @param inApp application object for callback
23 public ConvertNamesToTimes(App inApp)
28 /** Get the name key */
29 public String getNameKey() {
30 return "function.convertnamestotimes";
38 int selStart = _app.getTrackInfo().getSelection().getStart();
39 int selEnd = _app.getTrackInfo().getSelection().getEnd();
40 final Track track = _app.getTrackInfo().getTrack();
41 if (!track.hasData(Field.WAYPT_NAME, selStart, selEnd))
43 _app.showErrorMessage(getNameKey(), "error.convertnamestotimes.nonames");
46 UndoConvertNamesToTimes undo = new UndoConvertNamesToTimes(_app.getTrackInfo());
48 // Loop over all points in selection
49 for (int i=selStart; i<=selEnd; i++)
51 DataPoint point = track.getPoint(i);
52 if (point.isWaypoint())
54 TimestampUtc tstamp = new TimestampUtc(point.getWaypointName());
57 // timestamp could be parsed!
58 point.setFieldValue(Field.TIMESTAMP, point.getWaypointName(), false);
59 // set waypoint name to nothing (track point)
60 point.setFieldValue(Field.WAYPT_NAME, null, false);
68 _app.getTrackInfo().getTrack().requestRescale();
69 UpdateMessageBroker.informSubscribers(DataSubscriber.DATA_EDITED);
70 _app.completeFunction(undo, I18nManager.getText("confirm.convertnamestotimes"));