JAL-2344 FileFormats singleton for formats, FileFormatI simplified
[jalview.git] / src / jalview / gui / AlignFrame.java
index df2a742..370e649 100644 (file)
@@ -66,6 +66,7 @@ import jalview.io.BioJsHTMLOutput;
 import jalview.io.DataSourceType;
 import jalview.io.FileFormat;
 import jalview.io.FileFormatI;
+import jalview.io.FileFormats;
 import jalview.io.FileLoader;
 import jalview.io.FormatAdapter;
 import jalview.io.HtmlSvgOutput;
@@ -131,6 +132,8 @@ import java.awt.print.PageFormat;
 import java.awt.print.PrinterJob;
 import java.beans.PropertyChangeEvent;
 import java.io.File;
+import java.io.FileWriter;
+import java.io.PrintWriter;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -1115,7 +1118,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   public void saveAs_actionPerformed(ActionEvent e)
   {
     String format = currentFileFormat == null ? null : currentFileFormat
-            .toString();
+            .getName();
     JalviewFileChooser chooser = JalviewFileChooser.forWrite(
             Cache.getProperty("LAST_DIRECTORY"), format);
 
@@ -1149,8 +1152,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
       fileName = chooser.getSelectedFile().getPath();
 
-      Cache.setProperty("DEFAULT_FILE_FORMAT",
-              currentFileFormat.toString());
+      Cache.setProperty("DEFAULT_FILE_FORMAT", currentFileFormat.getName());
 
       Cache.setProperty("LAST_DIRECTORY", fileName);
       saveAlignment(fileName, currentFileFormat);
@@ -1180,17 +1182,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     }
     else
     {
-      // if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
-      // {
-      // warningMessage("Cannot save file " + fileName + " using format "
-      // + format, "Alignment output format not supported");
-      // if (!Jalview.isHeadlessMode())
-      // {
-      // saveAs_actionPerformed(null);
-      // }
-      // return false;
-      // }
-
       AlignmentExportData exportData = getAlignmentForExport(format,
               viewport, null);
       if (exportData.getSettings().isCancelled())
@@ -1215,15 +1206,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       {
         try
         {
-          java.io.PrintWriter out = new java.io.PrintWriter(
-                  new java.io.FileWriter(file));
+          PrintWriter out = new PrintWriter(new FileWriter(file));
 
           out.print(output);
           out.close();
           this.setTitle(file);
           statusBar.setText(MessageManager.formatMessage(
                   "label.successfully_saved_to_file_in_format",
-                  new Object[] { fileName, format }));
+                  new Object[] { fileName, format.getName() }));
         } catch (Exception ex)
         {
           success = false;
@@ -1268,8 +1258,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   protected void outputText_actionPerformed(ActionEvent e)
   {
-
-    FileFormatI fileFormat = FileFormat.forName(e.getActionCommand());
+    FileFormatI fileFormat = FileFormats.getInstance().forName(
+            e.getActionCommand());
     AlignmentExportData exportData = getAlignmentForExport(fileFormat,
             viewport, null);
     if (exportData.getSettings().isCancelled())