JAL-4001 Check --nousagestats before doing analytics in headless mode
[jalview.git] / src / jalview / io / JalviewFileChooser.java
index 6dbf4f8..cb47610 100755 (executable)
@@ -45,6 +45,7 @@ import javax.swing.JCheckBox;
 import javax.swing.JDialog;
 import javax.swing.JFileChooser;
 import javax.swing.JList;
+import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.SpringLayout;
@@ -490,10 +491,13 @@ public class JalviewFileChooser extends JFileChooser
 
     if (selectedFile.exists())
     {
-      int confirm = JvOptionPane.showConfirmDialog(this,
-              MessageManager.getString("label.overwrite_existing_file"),
-              MessageManager.getString("label.file_already_exists"),
-              JvOptionPane.YES_NO_OPTION);
+      int confirm = Cache.getDefault("CONFIRM_OVERWRITE_FILE", true)
+              ? JvOptionPane.showConfirmDialog(this,
+                      MessageManager
+                              .getString("label.overwrite_existing_file"),
+                      MessageManager.getString("label.file_already_exists"),
+                      JvOptionPane.YES_NO_OPTION)
+              : JOptionPane.YES_OPTION;
 
       if (confirm != JvOptionPane.YES_OPTION)
       {
@@ -598,6 +602,24 @@ public class JalviewFileChooser extends JFileChooser
 
   }
 
+  /*
+  @Override
+  public JalviewFileChooser setResponseHandler(Object response,
+          Runnable action)
+  {
+    callbacks.put(response, new Callable<Void>()
+    {
+      @Override
+      public Void call()
+      {
+        action.run();
+        return null;
+      }
+    });
+    return this;
+  }
+  */
+
   @Override
   public DialogRunnerI setResponseHandler(Object response, Runnable action)
   {
@@ -618,7 +640,13 @@ public class JalviewFileChooser extends JFileChooser
     Runnable action = callbacks.get(response);
     if (action != null)
     {
-      action.run();
+      try
+      {
+        action.run();
+      } catch (Exception e)
+      {
+        e.printStackTrace();
+      }
     }
   }