X-Git-Url: https://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=tim%2Fprune%2Ffunction%2FInterpolateFunction.java;h=221fdaf989c6c62141d0dfbe7ac29cfb66b069f0;hp=84826144d94e787bdea53e457e2818e57ce34270;hb=a6197ddcaac11c0b943183da7d46169742d024af;hpb=88f2c3647ed9e055090484f01a959d4581f85e7d diff --git a/tim/prune/function/InterpolateFunction.java b/tim/prune/function/InterpolateFunction.java index 8482614..221fdaf 100644 --- a/tim/prune/function/InterpolateFunction.java +++ b/tim/prune/function/InterpolateFunction.java @@ -3,7 +3,6 @@ package tim.prune.function; import javax.swing.JOptionPane; import tim.prune.App; -import tim.prune.GenericFunction; import tim.prune.I18nManager; import tim.prune.data.DataPoint; import tim.prune.data.Track; @@ -12,14 +11,14 @@ import tim.prune.undo.UndoInterpolate; /** * Function to interpolate between the points in a range */ -public class InterpolateFunction extends GenericFunction +public class InterpolateFunction extends SingleNumericParameterFunction { /** * Constructor * @param inApp app object */ public InterpolateFunction(App inApp) { - super(inApp); + super(inApp, 1, 1000); } /** @return name key */ @@ -27,10 +26,28 @@ public class InterpolateFunction extends GenericFunction return "function.interpolate"; } + /** @return description key for input parameter */ + public String getDescriptionKey() { + return "dialog.interpolate.parameter.text"; + } + + /** @return current (or default) parameter value */ + public int getCurrentParamValue() { + return 0; + } + /** * Perform the operation */ public void begin() + { + // not needed, we just use the completeFunction method instead + } + + /** + * Complete the function after the input parameter has been chosen + */ + public void completeFunction(int inParam) { // Firstly, work out whether the selected range only contains waypoints or not final int startIndex = _app.getTrackInfo().getSelection().getStart(); @@ -49,24 +66,12 @@ public class InterpolateFunction extends GenericFunction betweenWaypoints = true; } - // Get number of points to add - Object numPointsStr = JOptionPane.showInputDialog(_parentFrame, - I18nManager.getText("dialog.interpolate.parameter.text"), - I18nManager.getText(getNameKey()), - JOptionPane.QUESTION_MESSAGE, null, null, ""); - if (numPointsStr == null) {return;} - int numToAdd = parseNumber(numPointsStr); - if (numToAdd <= 0 || numToAdd > 1000) - { - _app.showErrorMessage(getNameKey(), "error.interpolate.invalidparameter"); - return; - } - if (startIndex < 0 || endIndex < 0 || endIndex <= startIndex) { return; } // construct new point array with the interpolated points + final int numToAdd = inParam; final Track track = _app.getTrackInfo().getTrack(); final int maxToAdd = (endIndex-startIndex) * numToAdd; final int extendedSize = track.getNumPoints() + maxToAdd; @@ -141,24 +146,4 @@ public class InterpolateFunction extends GenericFunction } return false; } - - /** - * Helper method to parse an Object into an integer - * @param inObject object, eg from dialog - * @return int value given - */ - private static int parseNumber(Object inObject) - { - int num = 0; - if (inObject != null) - { - try - { - num = Integer.parseInt(inObject.toString()); - } - catch (NumberFormatException nfe) - {} - } - return num; - } }