]> gitweb.fperrin.net Git - GpsPrune.git/blob - src/tim/prune/function/compress/MarkAndDeleteFunction.java
Moved source into separate src directory due to popular request
[GpsPrune.git] / src / tim / prune / function / compress / MarkAndDeleteFunction.java
1 package tim.prune.function.compress;
2
3 import javax.swing.JOptionPane;
4
5 import tim.prune.App;
6 import tim.prune.FunctionLibrary;
7 import tim.prune.GenericFunction;
8 import tim.prune.I18nManager;
9
10 /**
11  * Superclass of those functions which mark points for deletion
12  * (and optionally delete them automatically)
13  */
14 public abstract class MarkAndDeleteFunction extends GenericFunction
15 {
16         /** flag to remember whether the automatic deletion has been set to always */
17         private boolean _automaticallyDelete = false;
18
19
20         /**
21          * Constructor
22          * @param inApp App object
23          */
24         public MarkAndDeleteFunction(App inApp)
25         {
26                 super(inApp);
27         }
28
29         /**
30          * optionally delete the marked points
31          */
32         protected void optionallyDeleteMarkedPoints(int inNumMarked)
33         {
34                 // Allow calling of delete function with one click
35                 final String[] buttonTexts = {I18nManager.getText("button.yes"), I18nManager.getText("button.no"),
36                         I18nManager.getText("button.always")};
37                 int answer = _automaticallyDelete ? JOptionPane.YES_OPTION :
38                         JOptionPane.showOptionDialog(_parentFrame,
39                         I18nManager.getTextWithNumber("dialog.compress.confirm", inNumMarked),
40                         I18nManager.getText(getNameKey()), JOptionPane.YES_NO_CANCEL_OPTION,
41                         JOptionPane.WARNING_MESSAGE, null, buttonTexts, buttonTexts[1]);
42                 if (answer == JOptionPane.CANCEL_OPTION) {_automaticallyDelete = true;} // "always" is third option
43
44                 // Make sure function knows what to do, whether we'll call it now or later
45                 FunctionLibrary.FUNCTION_DELETE_MARKED_POINTS.setParentFunction(
46                                 getNameKey(), getShouldSplitSegments());
47                 if (_automaticallyDelete || answer == JOptionPane.YES_OPTION)
48                 {
49                         new Thread(new Runnable() {
50                                 public void run()
51                                 {
52                                         FunctionLibrary.FUNCTION_DELETE_MARKED_POINTS.begin();
53                                 }
54                         }).start();
55                 }
56         }
57
58         /** by default, segments are not split at deleted points */
59         protected boolean getShouldSplitSegments() {
60                 return false;
61         }
62 }