override showSaveDialog to prompt user if file exists
authoramwaterhouse <Andrew Waterhouse>
Wed, 23 Mar 2005 11:55:39 +0000 (11:55 +0000)
committeramwaterhouse <Andrew Waterhouse>
Wed, 23 Mar 2005 11:55:39 +0000 (11:55 +0000)
src/jalview/io/JalviewFileChooser.java

index 4dba60d..5b4fa21 100755 (executable)
@@ -45,6 +45,23 @@ public class JalviewFileChooser extends JFileChooser
     initColumns();\r
   }\r
 \r
+  public int showSaveDialog(Component parent) throws HeadlessException {\r
+      setDialogType(SAVE_DIALOG);\r
+      int ret = showDialog(parent, null);\r
+\r
+      if(ret == JalviewFileChooser.APPROVE_OPTION  &&  getSelectedFile().exists() )\r
+      {\r
+       int confirm =  JOptionPane.showConfirmDialog(parent,\r
+                                      "Overwrite existing file?",\r
+                                      "File exists",\r
+                                      JOptionPane.YES_NO_OPTION);\r
+       if(confirm!=JOptionPane.YES_OPTION)\r
+         ret = this.CANCEL_OPTION;\r
+      }\r
+      return ret;\r
+  }\r
+\r
+\r
   void initColumns()\r
   {\r
     if (COLUMNS == null)\r
@@ -58,7 +75,6 @@ public class JalviewFileChooser extends JFileChooser
         UIManager.getString("FileChooser.fileAttrHeaderText",l)\r
       };\r
     }\r
-\r
   }\r
 \r
   /**************************************************************************\r