]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/function/compress/MarkAndDeleteFunction.java
Version 17, September 2014
[GpsPrune.git] / 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.GenericFunction;
7 import tim.prune.I18nManager;
8
9 /**
10  * Superclass of those functions which mark points for deletion
11  * (and optionally delete them automatically)
12  */
13 public abstract class MarkAndDeleteFunction extends GenericFunction
14 {
15         /** flag to remember whether the automatic deletion has been set to always */
16         private boolean _automaticallyDelete = false;
17
18
19         /**
20          * Constructor
21          * @param inApp App object
22          */
23         public MarkAndDeleteFunction(App inApp)
24         {
25                 super(inApp);
26         }
27
28         /**
29          * optionally delete the marked points
30          */
31         protected void optionallyDeleteMarkedPoints(int inNumMarked)
32         {
33                 // Allow calling of delete function with one click
34                 final String[] buttonTexts = {I18nManager.getText("button.yes"), I18nManager.getText("button.no"),
35                         I18nManager.getText("button.always")};
36                 int answer = _automaticallyDelete ? JOptionPane.YES_OPTION :
37                         JOptionPane.showOptionDialog(_parentFrame,
38                         I18nManager.getTextWithNumber("dialog.compress.confirm", inNumMarked),
39                         I18nManager.getText(getNameKey()), JOptionPane.YES_NO_CANCEL_OPTION,
40                         JOptionPane.WARNING_MESSAGE, null, buttonTexts, buttonTexts[1]);
41                 if (answer == JOptionPane.CANCEL_OPTION) {_automaticallyDelete = true;} // "always" is third option
42                 if (_automaticallyDelete || answer == JOptionPane.YES_OPTION)
43                 {
44                         new Thread(new Runnable() {
45                                 public void run() {
46                                         _app.finishCompressTrack();
47                                 }
48                         }).start();
49                 }
50         }
51 }