X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=tim%2Fprune%2Ffunction%2FConvertNamesToTimes.java;fp=tim%2Fprune%2Ffunction%2FConvertNamesToTimes.java;h=c0286ab6ca3419479454697f45e324f48ca53c00;hp=0000000000000000000000000000000000000000;hb=1ee49ae3c8ef3aa2e63eadd458531e5f8bd4f92c;hpb=112bb0c9b46894adca9a33ed8c99ea712b253185 diff --git a/tim/prune/function/ConvertNamesToTimes.java b/tim/prune/function/ConvertNamesToTimes.java new file mode 100644 index 0000000..c0286ab --- /dev/null +++ b/tim/prune/function/ConvertNamesToTimes.java @@ -0,0 +1,73 @@ +package tim.prune.function; + +import tim.prune.App; +import tim.prune.DataSubscriber; +import tim.prune.GenericFunction; +import tim.prune.I18nManager; +import tim.prune.UpdateMessageBroker; +import tim.prune.data.DataPoint; +import tim.prune.data.Field; +import tim.prune.data.Timestamp; +import tim.prune.data.Track; +import tim.prune.undo.UndoConvertNamesToTimes; + +/** + * Class to provide the function to convert waypoint names to timestamps + */ +public class ConvertNamesToTimes extends GenericFunction +{ + /** + * Constructor + * @param inApp application object for callback + */ + public ConvertNamesToTimes(App inApp) + { + super(inApp); + } + + /** Get the name key */ + public String getNameKey() { + return "function.convertnamestotimes"; + } + + /** + * Begin the function + */ + public void begin() + { + int selStart = _app.getTrackInfo().getSelection().getStart(); + int selEnd = _app.getTrackInfo().getSelection().getEnd(); + final Track track = _app.getTrackInfo().getTrack(); + if (!track.hasData(Field.WAYPT_NAME, selStart, selEnd)) + { + _app.showErrorMessage(getNameKey(), "error.convertnamestotimes.nonames"); + return; + } + UndoConvertNamesToTimes undo = new UndoConvertNamesToTimes(_app.getTrackInfo()); + int numConverted = 0; + // Loop over all points in selection + for (int i=selStart; i<=selEnd; i++) + { + DataPoint point = track.getPoint(i); + if (point.isWaypoint()) + { + Timestamp tstamp = new Timestamp(point.getWaypointName()); + if (tstamp.isValid()) { + // timestamp could be parsed! + point.setFieldValue(Field.TIMESTAMP, point.getWaypointName(), false); + // set waypoint name to nothing (track point) + point.setFieldValue(Field.WAYPT_NAME, null, false); + // increment counter + numConverted++; + } + } + } + if (numConverted > 0) + { + _app.getTrackInfo().getTrack().requestRescale(); + UpdateMessageBroker.informSubscribers(DataSubscriber.DATA_EDITED); + _app.completeFunction(undo, I18nManager.getText("confirm.convertnamestotimes")); + } + } + +}