JAL-2344 FileFormats singleton for formats, FileFormatI simplified
[jalview.git] / src / jalview / io / AppletFormatAdapter.java
index 45d65d6..1bb7ba3 100755 (executable)
@@ -77,9 +77,16 @@ public class AppletFormatAdapter
 
   public static String INVALID_CHARACTERS = "Contains invalid characters";
 
-  public static String SUPPORTED_FORMATS = "Formats currently supported are\n"
-          + prettyPrint(FileFormat.getReadableFormats());
-
+  /**
+   * Returns an error message with a list of supported readable file formats
+   * 
+   * @return
+   */
+  public static String getSupportedFormats()
+  {
+    return "Formats currently supported are\n"
+          + prettyPrint(FileFormats.getInstance().getReadableFormats());
+  }
   public AppletFormatAdapter()
   {
   }
@@ -157,7 +164,7 @@ public class AppletFormatAdapter
         }
         else
         {
-          // todo is MCview parsing obsolete yet?
+          // todo is MCview parsing obsolete yet? JAL-2120
           StructureImportSettings.setShowSeqFeatures(true);
           alignFile = new MCview.PDBfile(annotFromStructure,
                   localSecondaryStruct, serviceSecondaryStruct, inFile,
@@ -168,7 +175,9 @@ public class AppletFormatAdapter
       }
       else
       {
-        alignFile = fileFormat.getAlignmentFile(inFile, sourceType);
+        // alignFile = fileFormat.getAlignmentFile(inFile, sourceType);
+        alignFile = fileFormat.getReader(new FileParse(inFile,
+                sourceType));
       }
       return buildAlignmentFromFile();
     } catch (Exception e)
@@ -208,7 +217,7 @@ public class AppletFormatAdapter
         throw new IOException(e.getMessage());
       }
     }
-    throw new FileFormatException(SUPPORTED_FORMATS);
+    throw new FileFormatException(getSupportedFormats());
   }
 
   /**
@@ -248,7 +257,7 @@ public class AppletFormatAdapter
       }
       else
       {
-        alignFile = format.getAlignmentFile(source);
+        alignFile = format.getReader(source);
       }
 
       return buildAlignmentFromFile();
@@ -287,7 +296,7 @@ public class AppletFormatAdapter
       }
 
       // If we get to this stage, the format was not supported
-      throw new FileFormatException(SUPPORTED_FORMATS);
+      throw new FileFormatException(getSupportedFormats());
     }
   }
 
@@ -361,7 +370,7 @@ public class AppletFormatAdapter
   {
     try
     {
-      AlignmentFileI afile = format.getAlignmentFile(alignment);
+      AlignmentFileI afile = format.getWriter(alignment);
 
       afile.setNewlineString(newline);
       afile.setExportSettings(exportSettings);
@@ -389,7 +398,8 @@ public class AppletFormatAdapter
       return afileresp;
     } catch (Exception e)
     {
-      System.err.println("Failed to write alignment as a '" + format
+      System.err.println("Failed to write alignment as a '"
+              + format.getName()
               + "' file\n");
       e.printStackTrace();
     }