JAL-3048 revert saveAs action so it works in Javascript too
[jalview.git] / src / jalview / gui / AlignFrame.java
index 7525f47..f8e5e30 100644 (file)
@@ -140,7 +140,6 @@ import java.util.Vector;
 import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JComponent;
 import javax.swing.JEditorPane;
-import javax.swing.JFileChooser;
 import javax.swing.JInternalFrame;
 import javax.swing.JLabel;
 import javax.swing.JLayeredPane;
@@ -148,7 +147,6 @@ import javax.swing.JMenu;
 import javax.swing.JMenuItem;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
-import javax.swing.JTextPane;
 import javax.swing.SwingUtilities;
 
 /**
@@ -1154,7 +1152,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     if (fileName == null || (currentFileFormat == null)
             || fileName.startsWith("http"))
     {
-      saveAs_actionPerformed(null);
+      saveAs_actionPerformed();
     }
     else
     {
@@ -1163,51 +1161,48 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   }
 
   /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
+   * Saves the alignment to a file with a name chosen by the user, if necessary
+   * warning if a file would be overwritten
    */
   @Override
-  public void saveAs_actionPerformed(ActionEvent e)
+  public void saveAs_actionPerformed()
   {
     String format = currentFileFormat == null ? null
             : currentFileFormat.getName();
-    final JalviewFileChooser chooser = JalviewFileChooser
+    JalviewFileChooser chooser = JalviewFileChooser
             .forWrite(Cache.getProperty("LAST_DIRECTORY"), format);
-    final AlignFrame us = this;
+
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(
             MessageManager.getString("label.save_alignment_to_file"));
     chooser.setToolTipText(MessageManager.getString("action.save"));
 
-    chooser.response(new RunResponse(JalviewFileChooser.APPROVE_OPTION)
+    int value = chooser.showSaveDialog(this);
+
+    if (value == JalviewFileChooser.APPROVE_OPTION)
     {
-      @Override
-      public void run()
+      currentFileFormat = chooser.getSelectedFormat();
+      while (currentFileFormat == null)
       {
+        JvOptionPane.showInternalMessageDialog(Desktop.desktop,
+                MessageManager.getString(
+                        "label.select_file_format_before_saving"),
+                MessageManager.getString("label.file_format_not_specified"),
+                JvOptionPane.WARNING_MESSAGE);
         currentFileFormat = chooser.getSelectedFormat();
-        while (currentFileFormat == null)
+        value = chooser.showSaveDialog(this);
+        if (value != JalviewFileChooser.APPROVE_OPTION)
         {
-          JvOptionPane.showInternalMessageDialog(Desktop.desktop,
-                  MessageManager.getString(
-                          "label.select_file_format_before_saving"),
-                  MessageManager
-                          .getString("label.file_format_not_specified"),
-                  JvOptionPane.WARNING_MESSAGE);
-          currentFileFormat = chooser.getSelectedFormat();
-          chooser.showSaveDialog(us);
+          return;
         }
+      }
 
-        fileName = chooser.getSelectedFile().getPath();
-
-        Cache.setProperty("DEFAULT_FILE_FORMAT",
-                currentFileFormat.getName());
+      fileName = chooser.getSelectedFile().getPath();
 
-        Cache.setProperty("LAST_DIRECTORY", fileName);
-        saveAlignment(fileName, currentFileFormat);
-      }
-    }).showSaveDialog(this);
+      Cache.setProperty("DEFAULT_FILE_FORMAT", currentFileFormat.getName());
+      Cache.setProperty("LAST_DIRECTORY", fileName);
+      saveAlignment(fileName, currentFileFormat);
+    }
   }
 
   private boolean lastSaveSuccessful = false;