]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/function/compress/CompressTrackFunction.java
Version 16, February 2014
[GpsPrune.git] / tim / prune / function / compress / CompressTrackFunction.java
index 35ff61da1ea3b73cd7618315d73af34647096a32..ce0203cb9e221d3b8f00dd82e0d998629d6e1ee1 100644 (file)
@@ -11,6 +11,7 @@ import javax.swing.Box;
 import javax.swing.BoxLayout;
 import javax.swing.JButton;
 import javax.swing.JDialog;
+import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 
 import tim.prune.App;
@@ -30,6 +31,8 @@ public class CompressTrackFunction extends GenericFunction
        private JButton _okButton = null;
        private CompressionAlgorithm[] _algorithms = null;
        private SummaryLabel _summaryLabel = null;
+       /** flag to remember whether the automatic deletion has been set to always */
+       private boolean _automaticallyDelete = false;
 
 
        /**
@@ -156,7 +159,8 @@ public class CompressTrackFunction extends GenericFunction
                        new DuplicatePointAlgorithm(_track, details, changeListener),
                        new ClosePointsAlgorithm(_track, details, changeListener),
                        new WackyPointAlgorithm(_track, details, changeListener),
-                       new SingletonAlgorithm(_track, details, changeListener)
+                       new SingletonAlgorithm(_track, details, changeListener),
+                       new DouglasPeuckerAlgorithm(_track, details, changeListener)
                };
        }
 
@@ -168,14 +172,43 @@ public class CompressTrackFunction extends GenericFunction
        {
                boolean[] deleteFlags = preview();
                // All flags are now combined in deleteFlags array
+               int numMarked = 0;
                for (int i=0; i<deleteFlags.length; i++)
                {
                        DataPoint point = _track.getPoint(i);
-                       point.setMarkedForDeletion(deleteFlags[i] && point.getPhoto() == null);
+                       boolean deletePoint = deleteFlags[i] && !point.hasMedia();
+                       point.setMarkedForDeletion(deletePoint);
+                       if (deletePoint) numMarked++;
                }
 
                // Close dialog and inform listeners
                UpdateMessageBroker.informSubscribers();
                _dialog.dispose();
+               // Show confirmation dialog with OK button (not status bar message)
+               if (numMarked > 0)
+               {
+                       // 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", numMarked),
+                               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
+                       if (_automaticallyDelete || answer == JOptionPane.YES_OPTION)
+                       {
+                               new Thread(new Runnable() {
+                                       public void run() {
+                                               _app.finishCompressTrack();
+                                       }
+                               }).start();
+                       }
+               }
+               else
+               {
+                       JOptionPane.showMessageDialog(_parentFrame, I18nManager.getText("dialog.compress.confirmnone"),
+                               I18nManager.getText(getNameKey()), JOptionPane.INFORMATION_MESSAGE);
+               }
        }
 }