X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Ffunction%2Fcompress%2FMarkAndDeleteFunction.java;fp=src%2Ftim%2Fprune%2Ffunction%2Fcompress%2FMarkAndDeleteFunction.java;h=dddc897480942648b603569c325b226f3831089f;hp=0000000000000000000000000000000000000000;hb=ce6f2161b8596f7018d6a76bff79bc9e571f35fd;hpb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465 diff --git a/src/tim/prune/function/compress/MarkAndDeleteFunction.java b/src/tim/prune/function/compress/MarkAndDeleteFunction.java new file mode 100644 index 0000000..dddc897 --- /dev/null +++ b/src/tim/prune/function/compress/MarkAndDeleteFunction.java @@ -0,0 +1,62 @@ +package tim.prune.function.compress; + +import javax.swing.JOptionPane; + +import tim.prune.App; +import tim.prune.FunctionLibrary; +import tim.prune.GenericFunction; +import tim.prune.I18nManager; + +/** + * Superclass of those functions which mark points for deletion + * (and optionally delete them automatically) + */ +public abstract class MarkAndDeleteFunction extends GenericFunction +{ + /** flag to remember whether the automatic deletion has been set to always */ + private boolean _automaticallyDelete = false; + + + /** + * Constructor + * @param inApp App object + */ + public MarkAndDeleteFunction(App inApp) + { + super(inApp); + } + + /** + * optionally delete the marked points + */ + protected void optionallyDeleteMarkedPoints(int inNumMarked) + { + // Allow calling of delete function with one click + final String[] buttonTexts = {I18nManager.getText("button.yes"), I18nManager.getText("button.no"), + I18nManager.getText("button.always")}; + int answer = _automaticallyDelete ? JOptionPane.YES_OPTION : + JOptionPane.showOptionDialog(_parentFrame, + I18nManager.getTextWithNumber("dialog.compress.confirm", inNumMarked), + I18nManager.getText(getNameKey()), JOptionPane.YES_NO_CANCEL_OPTION, + JOptionPane.WARNING_MESSAGE, null, buttonTexts, buttonTexts[1]); + if (answer == JOptionPane.CANCEL_OPTION) {_automaticallyDelete = true;} // "always" is third option + + // Make sure function knows what to do, whether we'll call it now or later + FunctionLibrary.FUNCTION_DELETE_MARKED_POINTS.setParentFunction( + getNameKey(), getShouldSplitSegments()); + if (_automaticallyDelete || answer == JOptionPane.YES_OPTION) + { + new Thread(new Runnable() { + public void run() + { + FunctionLibrary.FUNCTION_DELETE_MARKED_POINTS.begin(); + } + }).start(); + } + } + + /** by default, segments are not split at deleted points */ + protected boolean getShouldSplitSegments() { + return false; + } +}