Merge branch 'develop' into features/filetypeEnum
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 30 Aug 2016 11:56:34 +0000 (12:56 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 30 Aug 2016 11:56:34 +0000 (12:56 +0100)
Conflicts:
src/jalview/io/AppletFormatAdapter.java
src/jalview/io/FormatAdapter.java
src/jalview/io/MSFfile.java
src/jalview/io/RnamlFile.java
src/jalview/io/StockholmFile.java
src/jalview/ws/dbsources/Pdb.java
test/jalview/ext/jmol/JmolParserTest.java
test/jalview/gui/AlignViewportTest.java
test/jalview/ws/jabaws/RNAStructExportImport.java

139 files changed:
src/MCview/AppletPDBCanvas.java
src/MCview/AppletPDBViewer.java
src/MCview/PDBCanvas.java
src/MCview/PDBViewer.java
src/MCview/PDBfile.java
src/jalview/api/AlignViewControllerI.java
src/jalview/appletgui/APopupMenu.java
src/jalview/appletgui/AlignFrame.java
src/jalview/appletgui/AppletJmol.java
src/jalview/appletgui/AppletJmolBinding.java
src/jalview/appletgui/CutAndPasteTransfer.java
src/jalview/appletgui/ExtJmol.java
src/jalview/bin/Jalview.java
src/jalview/bin/JalviewLite.java
src/jalview/bin/JalviewLiteURLRetrieve.java
src/jalview/controller/AlignViewController.java
src/jalview/datamodel/Alignment.java
src/jalview/datamodel/PDBEntry.java
src/jalview/ext/ensembl/EnsemblRestClient.java
src/jalview/ext/jmol/JalviewJmolBinding.java
src/jalview/ext/jmol/JmolParser.java
src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java
src/jalview/gui/AlignExportSettings.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/AlignViewport.java
src/jalview/gui/AnnotationChooser.java
src/jalview/gui/AnnotationLabels.java
src/jalview/gui/AppJmolBinding.java
src/jalview/gui/AssociatePdbFileWithSeq.java
src/jalview/gui/ChimeraViewFrame.java
src/jalview/gui/CutAndPasteTransfer.java
src/jalview/gui/Desktop.java
src/jalview/gui/FeatureSettings.java
src/jalview/gui/Jalview2XML.java
src/jalview/gui/Jalview2XML_V1.java
src/jalview/gui/JalviewChimeraBindingModel.java
src/jalview/gui/PopupMenu.java
src/jalview/gui/Preferences.java
src/jalview/gui/SequenceFetcher.java
src/jalview/gui/StructureChooser.java
src/jalview/gui/StructureViewerBase.java
src/jalview/gui/TreePanel.java
src/jalview/gui/UserDefinedColours.java
src/jalview/gui/WsParamSetManager.java
src/jalview/io/AMSAFile.java
src/jalview/io/AlignFile.java
src/jalview/io/AlignmentFileI.java [new file with mode: 0644]
src/jalview/io/AnnotationFile.java
src/jalview/io/AppletFormatAdapter.java
src/jalview/io/BLCFile.java
src/jalview/io/BioJsHTMLOutput.java
src/jalview/io/ClustalFile.java
src/jalview/io/DBRefFile.java
src/jalview/io/DataSourceType.java [new file with mode: 0644]
src/jalview/io/FastaFile.java
src/jalview/io/FeaturesFile.java
src/jalview/io/FileFormat.java [new file with mode: 0644]
src/jalview/io/FileFormatException.java [new file with mode: 0644]
src/jalview/io/FileFormatI.java [new file with mode: 0644]
src/jalview/io/FileLoader.java
src/jalview/io/FileParse.java
src/jalview/io/FormatAdapter.java
src/jalview/io/HTMLOutput.java
src/jalview/io/HtmlFile.java
src/jalview/io/HtmlSvgOutput.java
src/jalview/io/IdentifyFile.java
src/jalview/io/JPredFile.java
src/jalview/io/JSONFile.java
src/jalview/io/JalviewFileChooser.java
src/jalview/io/MSFfile.java
src/jalview/io/NewickFile.java
src/jalview/io/PIRFile.java
src/jalview/io/PfamFile.java
src/jalview/io/PhylipFile.java
src/jalview/io/PileUpfile.java
src/jalview/io/RnamlFile.java
src/jalview/io/SimpleBlastFile.java
src/jalview/io/StockholmFile.java
src/jalview/io/StructureFile.java
src/jalview/io/TCoffeeScoreFile.java
src/jalview/io/packed/ParsePackedSet.java
src/jalview/jbgui/GAlignExportSettings.java
src/jalview/jbgui/GDesktop.java
src/jalview/jbgui/GFinder.java
src/jalview/structure/StructureImportSettings.java
src/jalview/structure/StructureSelectionManager.java
src/jalview/structures/models/AAStructureBindingModel.java
src/jalview/util/ImageMaker.java
src/jalview/ws/dbsources/Pdb.java
src/jalview/ws/dbsources/Pfam.java
src/jalview/ws/dbsources/Xfam.java
src/jalview/ws/jws1/Annotate3D.java
src/jalview/ws/jws1/JPredThread.java
src/jalview/ws/jws1/SeqSearchWSThread.java
src/jalview/ws/rest/params/Alignment.java
src/jalview/ws/seqfetcher/DbSourceProxyImpl.java
test/MCview/PDBfileTest.java
test/jalview/analysis/AlignmentAnnotationUtilsTest.java
test/jalview/analysis/AlignmentUtilsTests.java
test/jalview/analysis/DnaAlignmentGenerator.java
test/jalview/analysis/DnaTest.java
test/jalview/analysis/scoremodels/FeatureScoreModelTest.java
test/jalview/datamodel/AlignmentAnnotationTests.java
test/jalview/datamodel/AlignmentTest.java
test/jalview/ext/ensembl/EnsemblSeqProxyTest.java
test/jalview/ext/jmol/JmolParserTest.java
test/jalview/ext/jmol/JmolViewerTest.java
test/jalview/ext/jmol/JmolVsJalviewPDBParserEndToEndTest.java
test/jalview/ext/paradise/TestAnnotate3D.java
test/jalview/ext/rbvi/chimera/JalviewChimeraView.java
test/jalview/gui/AlignViewportTest.java
test/jalview/gui/AnnotationChooserTest.java
test/jalview/gui/PopupMenuTest.java
test/jalview/io/AnnotatedPDBFileInputTest.java
test/jalview/io/AnnotationFileIOTest.java
test/jalview/io/FeaturesFileTest.java
test/jalview/io/FileIOTester.java
test/jalview/io/FormatAdapterTest.java
test/jalview/io/IdentifyFileTest.java
test/jalview/io/JSONFileTest.java
test/jalview/io/Jalview2xmlTests.java
test/jalview/io/JalviewExportPropertiesTests.java
test/jalview/io/NewickFileTests.java
test/jalview/io/PfamFormatInputTest.java
test/jalview/io/PhylipFileTests.java
test/jalview/io/RNAMLfileTest.java
test/jalview/io/StockholmFileTest.java
test/jalview/io/TCoffeeScoreFileTest.java
test/jalview/io/gff/ExonerateHelperTest.java
test/jalview/io/gff/GffTests.java
test/jalview/structure/Mapping.java
test/jalview/structure/StructureSelectionManagerTest.java
test/jalview/structures/models/AAStructureBindingModelTest.java
test/jalview/util/MappingUtilsTest.java
test/jalview/ws/jabaws/DisorderAnnotExportImport.java
test/jalview/ws/jabaws/JpredJabaStructExportImport.java
test/jalview/ws/jabaws/RNAStructExportImport.java
test/jalview/ws/rest/ShmmrRSBSService.java
test/jalview/ws/sifts/SiftsClientTest.java

index df98833..1a7e7f5 100644 (file)
@@ -26,6 +26,7 @@ import jalview.appletgui.FeatureRenderer;
 import jalview.appletgui.SequenceRenderer;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
+import jalview.io.DataSourceType;
 import jalview.io.StructureFile;
 import jalview.structure.AtomSpec;
 import jalview.structure.StructureListener;
@@ -145,7 +146,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
   StructureSelectionManager ssm;
 
   public AppletPDBCanvas(PDBEntry pdbentry, SequenceI[] seq,
-          String[] chains, AlignmentPanel ap, String protocol)
+          String[] chains, AlignmentPanel ap, DataSourceType protocol)
 
   {
     this.ap = ap;
@@ -159,7 +160,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
     {
       pdb = ssm.setMapping(seq, chains, pdbentry.getFile(), protocol);
 
-      if (protocol.equals(jalview.io.AppletFormatAdapter.PASTE))
+      if (protocol == DataSourceType.PASTE)
       {
         pdbentry.setFile("INLINE" + pdb.getId());
       }
index 8233ac3..76ee4b0 100644 (file)
@@ -24,6 +24,7 @@ import jalview.appletgui.AlignmentPanel;
 import jalview.appletgui.EmbmenuFrame;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
+import jalview.io.DataSourceType;
 import jalview.schemes.BuriedColourScheme;
 import jalview.schemes.HelixColourScheme;
 import jalview.schemes.HydrophobicColourScheme;
@@ -51,7 +52,7 @@ public class AppletPDBViewer extends EmbmenuFrame implements
   AppletPDBCanvas pdbcanvas;
 
   public AppletPDBViewer(PDBEntry pdbentry, SequenceI[] seq,
-          String[] chains, AlignmentPanel ap, String protocol)
+          String[] chains, AlignmentPanel ap, DataSourceType protocol)
   {
     try
     {
@@ -73,6 +74,7 @@ public class AppletPDBViewer extends EmbmenuFrame implements
 
   }
 
+  @Override
   public void actionPerformed(ActionEvent evt)
   {
     if (evt.getSource() == mapping)
@@ -143,6 +145,7 @@ public class AppletPDBViewer extends EmbmenuFrame implements
 
   }
 
+  @Override
   public void itemStateChanged(ItemEvent evt)
   {
     if (evt.getSource() == allchains)
index 1c7a1f7..7b4e0f0 100644 (file)
@@ -26,6 +26,7 @@ import jalview.datamodel.SequenceI;
 import jalview.gui.AlignmentPanel;
 import jalview.gui.FeatureRenderer;
 import jalview.gui.SequenceRenderer;
+import jalview.io.DataSourceType;
 import jalview.io.StructureFile;
 import jalview.structure.AtomSpec;
 import jalview.structure.StructureListener;
@@ -141,7 +142,7 @@ public class PDBCanvas extends JPanel implements MouseListener,
   String errorMessage;
 
   void init(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
-          AlignmentPanel ap, String protocol)
+          AlignmentPanel ap, DataSourceType protocol)
   {
     this.ap = ap;
     this.pdbentry = pdbentry;
@@ -153,7 +154,7 @@ public class PDBCanvas extends JPanel implements MouseListener,
     {
       pdb = ssm.setMapping(seq, chains, pdbentry.getFile(), protocol);
 
-      if (protocol.equals(jalview.io.AppletFormatAdapter.PASTE))
+      if (protocol.equals(jalview.io.DataSourceType.PASTE))
       {
         pdbentry.setFile("INLINE" + pdb.getId());
       }
index d5f0d0b..39bc4ef 100755 (executable)
@@ -26,6 +26,7 @@ import jalview.gui.AlignmentPanel;
 import jalview.gui.Desktop;
 import jalview.gui.OOMWarning;
 import jalview.gui.UserDefinedColours;
+import jalview.io.DataSourceType;
 import jalview.io.JalviewFileChooser;
 import jalview.io.JalviewFileView;
 import jalview.schemes.BuriedColourScheme;
@@ -79,12 +80,12 @@ public class PDBViewer extends JInternalFrame implements Runnable
 
   AlignmentPanel ap;
 
-  String protocol;
+  DataSourceType protocol;
 
   String tmpPDBFile;
 
   public PDBViewer(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
-          AlignmentPanel ap, String protocol)
+          AlignmentPanel ap, DataSourceType protocol)
   {
     this.pdbentry = pdbentry;
     this.seq = seq;
@@ -113,7 +114,7 @@ public class PDBViewer extends JInternalFrame implements Runnable
       {
         tmpPDBFile = pdbentry.getFile();
         PDBfile pdbfile = new PDBfile(false, false, false, tmpPDBFile,
-                jalview.io.AppletFormatAdapter.FILE);
+                DataSourceType.FILE);
 
         pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
 
index 2746807..060de45 100755 (executable)
@@ -23,6 +23,7 @@ package MCview;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.DBRefSource;
 import jalview.datamodel.SequenceI;
+import jalview.io.DataSourceType;
 import jalview.io.FileParse;
 import jalview.io.StructureFile;
 import jalview.util.MessageManager;
@@ -46,10 +47,11 @@ public class PDBfile extends StructureFile
   }
 
   public PDBfile(boolean addAlignmentAnnotations, boolean predictSecStr,
-          boolean externalSecStr, String dataObject, String protocol)
+          boolean externalSecStr, String dataObject,
+          DataSourceType sourceType)
           throws IOException
   {
-    super(false, dataObject, protocol);
+    super(false, dataObject, sourceType);
     addSettings(addAlignmentAnnotations, predictSecStr, externalSecStr);
     doParse();
   }
@@ -64,7 +66,7 @@ public class PDBfile extends StructureFile
   }
 
   @Override
-  public String print()
+  public String print(SequenceI[] seqs, boolean jvSuffix)
   {
     return null;
   }
index 26966ba..b868ee5 100644 (file)
@@ -20,6 +20,8 @@
  */
 package jalview.api;
 
+import jalview.io.DataSourceType;
+
 import java.util.List;
 
 /**
@@ -88,13 +90,13 @@ public interface AlignViewControllerI
    * add a features file of some kind to the current view
    * 
    * @param file
-   * @param protocol
+   * @param sourceType
    * @param relaxedIdMatching
    *          if true, try harder to match up IDs with local sequence data
    * @return true if parsing resulted in something being imported to the view or
    *         dataset
    */
-  public boolean parseFeaturesFile(String file, String protocol,
+  public boolean parseFeaturesFile(String file, DataSourceType sourceType,
           boolean relaxedIdMatching);
 
 }
index ec7cd25..abb6848 100644 (file)
@@ -24,6 +24,7 @@ import jalview.analysis.AAFrequency;
 import jalview.analysis.AlignmentAnnotationUtils;
 import jalview.analysis.AlignmentUtils;
 import jalview.analysis.Conservation;
+import jalview.bin.JalviewLite;
 import jalview.commands.ChangeCaseCommand;
 import jalview.commands.EditCommand;
 import jalview.commands.EditCommand.Action;
@@ -35,6 +36,8 @@ import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.io.AppletFormatAdapter;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
 import jalview.io.SequenceAnnotationReport;
 import jalview.schemes.Blosum62ColourScheme;
 import jalview.schemes.BuriedColourScheme;
@@ -824,15 +827,16 @@ public class APopupMenu extends java.awt.PopupMenu implements
 
     Frame frame = new Frame();
     frame.add(cap);
-    jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
+    JalviewLite.addFrame(frame, MessageManager.formatMessage(
             "label.selection_output_command",
             new Object[] { e.getActionCommand() }), 600, 500);
     // JBPNote: getSelectionAsNewSequence behaviour has changed - this method
     // now returns a full copy of sequence data
     // TODO consider using getSequenceSelection instead here
 
-    cap.setText(new jalview.io.AppletFormatAdapter().formatSequences(
-            e.getActionCommand(), ap.av.getShowJVSuffix(), ap, true));
+    FileFormat fileFormat = FileFormat.valueOf(e.getActionCommand());
+    cap.setText(new AppletFormatAdapter().formatSequences(fileFormat,
+            ap.av.getShowJVSuffix(), ap, true));
 
   }
 
@@ -900,12 +904,12 @@ public class APopupMenu extends java.awt.PopupMenu implements
       if (ap.av.applet.jmolAvailable)
       {
         new jalview.appletgui.AppletJmol(entry, new SequenceI[] { seq },
-                null, ap, AppletFormatAdapter.URL);
+                null, ap, DataSourceType.URL);
       }
       else
       {
         new MCview.AppletPDBViewer(entry, new SequenceI[] { seq }, null,
-                ap, AppletFormatAdapter.URL);
+                ap, DataSourceType.URL);
       }
 
     }
index 0312015..2ee86f1 100644 (file)
@@ -49,7 +49,9 @@ import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.io.AnnotationFile;
 import jalview.io.AppletFormatAdapter;
+import jalview.io.DataSourceType;
 import jalview.io.FeaturesFile;
+import jalview.io.FileFormat;
 import jalview.io.TCoffeeScoreFile;
 import jalview.schemes.Blosum62ColourScheme;
 import jalview.schemes.BuriedColourScheme;
@@ -346,7 +348,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
    *          is protocol for accessing data referred to by file
    */
 
-  public boolean parseFeaturesFile(String file, String type)
+  public boolean parseFeaturesFile(String file, DataSourceType type)
   {
     return parseFeaturesFile(file, type, true);
   }
@@ -356,14 +358,14 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
    * 
    * @param file
    *          file URL, content, or other resolvable path
-   * @param type
+   * @param paste
    *          is protocol for accessing data referred to by file
    * @param autoenabledisplay
    *          when true, display features flag will be automatically enabled if
    *          features are loaded
    * @return true if data parsed as a features file
    */
-  public boolean parseFeaturesFile(String file, String type,
+  public boolean parseFeaturesFile(String file, DataSourceType paste,
           boolean autoenabledisplay)
   {
     boolean featuresFile = false;
@@ -373,7 +375,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
               .getFeatureRenderer().getFeatureColours();
       boolean relaxedIdMatching = viewport.applet.getDefaultParameter(
               "relaxedidmatch", false);
-      featuresFile = new FeaturesFile(file, type).parse(
+      featuresFile = new FeaturesFile(file, paste).parse(
               viewport.getAlignment(), colours, true, relaxedIdMatching);
     } catch (Exception ex)
     {
@@ -1360,13 +1362,13 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
     Frame frame = new Frame();
     frame.add(cap);
-    jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
+    JalviewLite.addFrame(frame, MessageManager.formatMessage(
             "label.alignment_output_command",
             new Object[] { e.getActionCommand() }), 600, 500);
 
-    FeatureRenderer fr = this.alignPanel.cloneFeatureRenderer();
+    FileFormat fileFormat = FileFormat.valueOf(e.getActionCommand());
     cap.setText(new AppletFormatAdapter(alignPanel).formatSequences(
-            e.getActionCommand(), viewport.getAlignment(),
+            fileFormat, viewport.getAlignment(),
             viewport.getShowJVSuffix()));
   }
 
@@ -4021,7 +4023,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       }
       // resolve data source
       // TODO: this code should be a refactored to an io package
-      String protocol = AppletFormatAdapter.resolveProtocol(pdbFile, "PDB");
+      DataSourceType protocol = AppletFormatAdapter.resolveProtocol(
+              pdbFile, FileFormat.PDB);
       if (protocol == null)
       {
         return false;
@@ -4031,9 +4034,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
         // make a note of the access mode and add
         if (pdbentry.getProperty() == null)
         {
-          pdbentry.setProperty(new Hashtable());
+          pdbentry.setProperty(new Hashtable<String, String>());
         }
-        pdbentry.getProperty().put("protocol", protocol);
+        pdbentry.getProperty().put("protocol", protocol.toString());
         toaddpdb.addPDBId(pdbentry);
         alignPanel.getStructureSelectionManager()
                 .registerPDBEntry(pdbentry);
@@ -4070,7 +4073,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   }
 
   public void newStructureView(JalviewLite applet, PDBEntry pdb,
-          SequenceI[] seqs, String[] chains, String protocol)
+          SequenceI[] seqs, String[] chains, DataSourceType protocol)
   {
     // Scrub any null sequences from the array
     Object[] sqch = cleanSeqChainArrays(seqs, chains);
@@ -4081,10 +4084,16 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       System.err
               .println("JalviewLite.AlignFrame:newStructureView: No sequence to bind structure to.");
     }
-    if (protocol == null || protocol.trim().length() == 0
-            || protocol.equals("null"))
+    if (protocol == null)
     {
-      protocol = (String) pdb.getProperty().get("protocol");
+      String sourceType = pdb.getProperty().get("protocol");
+      try
+      {
+        protocol = DataSourceType.valueOf(sourceType);
+      } catch (IllegalArgumentException e)
+      {
+        // ignore
+      }
       if (protocol == null)
       {
         System.err.println("Couldn't work out protocol to open structure: "
@@ -4107,12 +4116,11 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     {
       // can only do alignments with Jmol
       // find the last jmol window assigned to this alignment
-      jalview.appletgui.AppletJmol ajm = null, tajm;
-      Vector jmols = applet
-              .getAppletWindow(jalview.appletgui.AppletJmol.class);
+      AppletJmol ajm = null, tajm;
+      Vector jmols = applet.getAppletWindow(AppletJmol.class);
       for (int i = 0, iSize = jmols.size(); i < iSize; i++)
       {
-        tajm = (jalview.appletgui.AppletJmol) jmols.elementAt(i);
+        tajm = (AppletJmol) jmols.elementAt(i);
         if (tajm.ap.alignFrame == this)
         {
           ajm = tajm;
@@ -4131,7 +4139,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     // otherwise, create a new window
     if (applet.jmolAvailable)
     {
-      new jalview.appletgui.AppletJmol(pdb, seqs, chains, alignPanel,
+      new AppletJmol(pdb, seqs, chains, alignPanel,
               protocol);
       applet.lastFrameX += 40;
       applet.lastFrameY += 40;
index 8374721..18e7d1a 100644 (file)
  */
 package jalview.appletgui;
 
+import jalview.bin.JalviewLite;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
-import jalview.io.AppletFormatAdapter;
 import jalview.io.FileParse;
+import jalview.io.DataSourceType;
 import jalview.io.StructureFile;
 import jalview.schemes.BuriedColourScheme;
 import jalview.schemes.HelixColourScheme;
@@ -176,7 +177,7 @@ public class AppletJmol extends EmbmenuFrame implements
   }
 
   public AppletJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
-          AlignmentPanel ap, String protocol)
+          AlignmentPanel ap, DataSourceType protocol)
   {
     this.ap = ap;
     jmb = new AppletJmolBinding(this, ap.getStructureSelectionManager(),
@@ -185,7 +186,7 @@ public class AppletJmol extends EmbmenuFrame implements
     jmb.setColourBySequence(true);
     if (pdbentry.getId() == null || pdbentry.getId().length() < 1)
     {
-      if (protocol.equals(AppletFormatAdapter.PASTE))
+      if (protocol == DataSourceType.PASTE)
       {
         pdbentry.setId("PASTED PDB"
                 + (chains == null ? "_" : chains.toString()));
@@ -196,7 +197,7 @@ public class AppletJmol extends EmbmenuFrame implements
       }
     }
 
-    if (jalview.bin.JalviewLite.debug)
+    if (JalviewLite.debug)
     {
       System.err
               .println("AppletJmol: PDB ID is '" + pdbentry.getId() + "'");
@@ -292,20 +293,20 @@ public class AppletJmol extends EmbmenuFrame implements
     });
     if (pdbentry.getProperty() == null)
     {
-      pdbentry.setProperty(new Hashtable());
-      pdbentry.getProperty().put("protocol", protocol);
+      pdbentry.setProperty(new Hashtable<String, String>());
+      pdbentry.getProperty().put("protocol", protocol.toString());
     }
     if (pdbentry.getFile() != null)
     {
       // import structure data from pdbentry.getFile based on given protocol
-      if (protocol.equals(AppletFormatAdapter.PASTE))
+      if (protocol == DataSourceType.PASTE)
       {
         // TODO: JAL-623 : correctly record file contents for matching up later
         // pdbentry.getProperty().put("pdbfilehash",""+pdbentry.getFile().hashCode());
         loadInline(pdbentry.getFile());
       }
-      else if (protocol.equals(AppletFormatAdapter.FILE)
-              || protocol.equals(AppletFormatAdapter.URL))
+      else if (protocol == DataSourceType.FILE
+              || protocol == DataSourceType.URL)
       {
         jmb.viewer.openFile(pdbentry.getFile());
       }
index 6ec5b4d..92dff7b 100644 (file)
@@ -24,6 +24,7 @@ import jalview.api.AlignmentViewPanel;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.ext.jmol.JalviewJmolBinding;
+import jalview.io.DataSourceType;
 import jalview.structure.StructureSelectionManager;
 
 import java.awt.Container;
@@ -45,7 +46,7 @@ class AppletJmolBinding extends JalviewJmolBinding
 
   public AppletJmolBinding(AppletJmol appletJmol,
           StructureSelectionManager sSm, PDBEntry[] pdbentry,
-          SequenceI[][] seq, String[][] chains, String protocol)
+          SequenceI[][] seq, String[][] chains, DataSourceType protocol)
   {
     super(sSm, pdbentry, seq, chains, protocol);
     appletJmolBinding = appletJmol;
@@ -113,12 +114,14 @@ class AppletJmolBinding extends JalviewJmolBinding
     appletJmolBinding.updateTitleAndMenus();
   }
 
+  @Override
   public void updateColours(Object source)
   {
     AlignmentPanel ap = (AlignmentPanel) source;
     colourBySequence(ap);
   }
 
+  @Override
   public void showUrl(String url)
   {
     try
@@ -143,6 +146,7 @@ class AppletJmolBinding extends JalviewJmolBinding
     // do nothing.
   }
 
+  @Override
   public void selectionChanged(BS arg0)
   {
     // TODO Auto-generated method stub
index bbaeb68..d50fcef 100644 (file)
@@ -28,9 +28,11 @@ import jalview.datamodel.AlignmentI;
 import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
+import jalview.io.AlignmentFileI;
 import jalview.io.AnnotationFile;
 import jalview.io.AppletFormatAdapter;
-import jalview.io.FileParse;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormatI;
 import jalview.io.IdentifyFile;
 import jalview.io.NewickFile;
 import jalview.io.TCoffeeScoreFile;
@@ -51,6 +53,7 @@ import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
+import java.io.IOException;
 
 public class CutAndPasteTransfer extends Panel implements ActionListener,
         MouseListener
@@ -65,7 +68,7 @@ public class CutAndPasteTransfer extends Panel implements ActionListener,
 
   AlignFrame alignFrame;
 
-  FileParse source = null;
+  AlignmentFileI source = null;
 
   public CutAndPasteTransfer(boolean forImport, AlignFrame alignFrame)
   {
@@ -194,7 +197,8 @@ public class CutAndPasteTransfer extends Panel implements ActionListener,
   {
     try
     {
-      NewickFile fin = new NewickFile(textarea.getText(), "Paste");
+      NewickFile fin = new NewickFile(textarea.getText(),
+              DataSourceType.PASTE);
 
       fin.parse();
       if (fin.getTree() != null)
@@ -225,17 +229,14 @@ public class CutAndPasteTransfer extends Panel implements ActionListener,
   {
     AlignmentI al = null;
 
-    String format = new IdentifyFile().identify(text,
-            AppletFormatAdapter.PASTE);
-    AppletFormatAdapter afa = new AppletFormatAdapter(alignFrame.alignPanel);
     try
     {
-      al = afa.readFile(text, AppletFormatAdapter.PASTE, format);
+      FileFormatI format = new IdentifyFile().identify(text,
+              DataSourceType.PASTE);
+      AppletFormatAdapter afa = new AppletFormatAdapter(
+              alignFrame.alignPanel);
+      al = afa.readFile(text, DataSourceType.PASTE, format);
       source = afa.getAlignFile();
-    } catch (java.io.IOException ex)
-    {
-      ex.printStackTrace();
-    }
 
     if (al != null)
     {
@@ -296,6 +297,10 @@ public class CutAndPasteTransfer extends Panel implements ActionListener,
                 .getString("label.successfully_pasted_alignment_file"));
       }
     }
+    } catch (IOException ex)
+    {
+      ex.printStackTrace();
+    }
   }
 
   /**
@@ -306,7 +311,7 @@ public class CutAndPasteTransfer extends Panel implements ActionListener,
    * @param al
    * @return
    */
-  protected boolean openSplitFrame(AlignmentI al, String format)
+  protected boolean openSplitFrame(AlignmentI al, FileFormatI format)
   {
     final AlignmentI thisAlignment = this.alignFrame.getAlignViewport()
             .getAlignment();
@@ -376,7 +381,7 @@ public class CutAndPasteTransfer extends Panel implements ActionListener,
     try
     {
       tcf = new TCoffeeScoreFile(textarea.getText(),
-              jalview.io.AppletFormatAdapter.PASTE);
+              jalview.io.DataSourceType.PASTE);
       if (tcf.isValid())
       {
         if (tcf.annotateAlignment(alignFrame.viewport.getAlignment(), true))
@@ -409,7 +414,7 @@ public class CutAndPasteTransfer extends Panel implements ActionListener,
     if (tcf == null)
     {
       if (new AnnotationFile().annotateAlignmentView(alignFrame.viewport,
-              textarea.getText(), jalview.io.AppletFormatAdapter.PASTE))
+              textarea.getText(), jalview.io.DataSourceType.PASTE))
       {
         alignFrame.alignPanel.fontChanged();
         alignFrame.alignPanel.setScrollValues(0, 0);
@@ -421,7 +426,7 @@ public class CutAndPasteTransfer extends Panel implements ActionListener,
       else
       {
         if (!alignFrame.parseFeaturesFile(textarea.getText(),
-                jalview.io.AppletFormatAdapter.PASTE))
+                jalview.io.DataSourceType.PASTE))
         {
           alignFrame.statusBar
                   .setText(MessageManager
@@ -445,12 +450,12 @@ public class CutAndPasteTransfer extends Panel implements ActionListener,
     if (alignFrame.alignPanel.av.applet.jmolAvailable)
     {
       new jalview.appletgui.AppletJmol(pdb, new SequenceI[] { seq }, null,
-              alignFrame.alignPanel, AppletFormatAdapter.PASTE);
+              alignFrame.alignPanel, DataSourceType.PASTE);
     }
     else
     {
       new MCview.AppletPDBViewer(pdb, new SequenceI[] { seq }, null,
-              alignFrame.alignPanel, AppletFormatAdapter.PASTE);
+              alignFrame.alignPanel, DataSourceType.PASTE);
     }
   }
 
index 929a871..a402ae0 100644 (file)
@@ -26,6 +26,7 @@ import jalview.api.SequenceRenderer;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.ext.jmol.JalviewJmolBinding;
+import jalview.io.DataSourceType;
 
 import java.awt.Container;
 import java.util.ArrayList;
@@ -48,9 +49,9 @@ public class ExtJmol extends JalviewJmolBinding
 
   private AlignmentPanel ap;
 
-  protected ExtJmol(jalview.appletgui.AlignFrame alframe,
+  protected ExtJmol(AlignFrame alframe,
           PDBEntry[] pdbentry, SequenceI[][] seq, String[][] chains,
-          String protocol)
+          DataSourceType protocol)
   {
     super(alframe.alignPanel.getStructureSelectionManager(), pdbentry, seq,
             chains, protocol);
@@ -64,6 +65,7 @@ public class ExtJmol extends JalviewJmolBinding
     notifyFileLoaded(null, null, null, null, 0);
   }
 
+  @Override
   public void updateColours(Object source)
   {
 
@@ -71,6 +73,7 @@ public class ExtJmol extends JalviewJmolBinding
 
   }
 
+  @Override
   public void showUrl(String arg0)
   {
     showUrl(arg0, "jmol");
@@ -126,6 +129,7 @@ public class ExtJmol extends JalviewJmolBinding
     // ignore
   }
 
+  @Override
   public void selectionChanged(BS arg0)
   {
     System.out.println(arg0);
index 3294c26..1ab837f 100755 (executable)
@@ -28,8 +28,11 @@ import jalview.gui.Desktop;
 import jalview.gui.PromptUserConfig;
 import jalview.io.AppletFormatAdapter;
 import jalview.io.BioJsHTMLOutput;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
+import jalview.io.FileFormatException;
+import jalview.io.FileFormatI;
 import jalview.io.FileLoader;
-import jalview.io.FormatAdapter;
 import jalview.io.HtmlSvgOutput;
 import jalview.io.IdentifyFile;
 import jalview.io.NewickFile;
@@ -344,7 +347,9 @@ public class Jalview
       BioJsHTMLOutput.updateBioJS();
     }
 
-    String file = null, protocol = null, format = null, data = null;
+    String file = null, data = null;
+    FileFormatI format = null;
+    DataSourceType protocol = null;
     FileLoader fileLoader = new FileLoader(!headless);
     Vector<String> getFeatures = null; // vector of das source nicknames to
                                        // fetch
@@ -377,13 +382,13 @@ public class Jalview
       {
         try
         {
-          String viprotocol = AppletFormatAdapter
+          DataSourceType viprotocol = AppletFormatAdapter
                   .checkProtocol(vamsasImport);
-          if (viprotocol == jalview.io.FormatAdapter.FILE)
+          if (viprotocol == DataSourceType.FILE)
           {
             inSession = desktop.vamsasImport(new File(vamsasImport));
           }
-          else if (viprotocol == FormatAdapter.URL)
+          else if (viprotocol == DataSourceType.URL)
           {
             inSession = desktop.vamsasImport(new URL(vamsasImport));
           }
@@ -472,7 +477,13 @@ public class Jalview
 
       protocol = AppletFormatAdapter.checkProtocol(file);
 
-      format = new IdentifyFile().identify(file, protocol);
+      try
+      {
+        format = new IdentifyFile().identify(file, protocol);
+      } catch (FileFormatException e1)
+      {
+        // TODO ?
+      }
 
       AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
               format);
@@ -617,17 +628,17 @@ public class Jalview
         String imageName = "unnamed.png";
         while (aparser.getSize() > 1)
         {
-          format = aparser.nextValue();
+          String outputFormat = aparser.nextValue();
           file = aparser.nextValue();
 
-          if (format.equalsIgnoreCase("png"))
+          if (outputFormat.equalsIgnoreCase("png"))
           {
             af.createPNG(new File(file));
             imageName = (new File(file)).getName();
             System.out.println("Creating PNG image: " + file);
             continue;
           }
-          else if (format.equalsIgnoreCase("svg"))
+          else if (outputFormat.equalsIgnoreCase("svg"))
           {
             File imageFile = new File(file);
             imageName = imageFile.getName();
@@ -635,7 +646,7 @@ public class Jalview
             System.out.println("Creating SVG image: " + file);
             continue;
           }
-          else if (format.equalsIgnoreCase("html"))
+          else if (outputFormat.equalsIgnoreCase("html"))
           {
             File imageFile = new File(file);
             imageName = imageFile.getName();
@@ -643,13 +654,13 @@ public class Jalview
             System.out.println("Creating HTML image: " + file);
             continue;
           }
-          else if (format.equalsIgnoreCase("imgMap"))
+          else if (outputFormat.equalsIgnoreCase("imgMap"))
           {
             af.createImageMap(new File(file), imageName);
             System.out.println("Creating image map: " + file);
             continue;
           }
-          else if (format.equalsIgnoreCase("eps"))
+          else if (outputFormat.equalsIgnoreCase("eps"))
           {
             File outputFile = new File(file);
             System.out.println("Creating EPS file: "
@@ -698,20 +709,26 @@ public class Jalview
         jalview.bin.Cache.removeProperty("STARTUP_FILE");
       }
 
-      protocol = "File";
+      protocol = DataSourceType.FILE;
 
       if (file.indexOf("http:") > -1)
       {
-        protocol = "URL";
+        protocol = DataSourceType.URL;
       }
 
       if (file.endsWith(".jar"))
       {
-        format = "Jalview";
+        format = FileFormat.Jalview;
       }
       else
       {
-        format = new IdentifyFile().identify(file, protocol);
+        try
+        {
+          format = new IdentifyFile().identify(file, protocol);
+        } catch (FileFormatException e)
+        {
+          // TODO what?
+        }
       }
 
       startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
index 210a07a..7f15b3e 100644 (file)
@@ -37,6 +37,9 @@ import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.io.AnnotationFile;
 import jalview.io.AppletFormatAdapter;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
+import jalview.io.FileFormatI;
 import jalview.io.FileParse;
 import jalview.io.IdentifyFile;
 import jalview.io.JPredFile;
@@ -63,6 +66,7 @@ import java.awt.event.ActionEvent;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
 import java.io.BufferedReader;
+import java.io.IOException;
 import java.io.InputStreamReader;
 import java.net.URL;
 import java.util.ArrayList;
@@ -513,21 +517,23 @@ public class JalviewLite extends Applet implements
   {
     try
     {
+      FileFormatI theFormat = FileFormat.valueOf(format);
       boolean seqlimits = suffix.equalsIgnoreCase(TRUE);
       if (alf.viewport.getSelectionGroup() != null)
       {
         // JBPNote: getSelectionAsNewSequence behaviour has changed - this
         // method now returns a full copy of sequence data
         // TODO consider using getSequenceSelection instead here
-        String reply = new AppletFormatAdapter().formatSequences(format,
+        String reply = new AppletFormatAdapter().formatSequences(theFormat,
                 new Alignment(alf.viewport.getSelectionAsNewSequence()),
                 seqlimits);
         return reply;
       }
-    } catch (Exception ex)
+    } catch (IllegalArgumentException ex)
     {
       ex.printStackTrace();
-      return "Error retrieving alignment in " + format + " format. ";
+      return "Error retrieving alignment, possibly invalid format specifier: "
+              + format;
     }
     return "";
   }
@@ -709,13 +715,15 @@ public class JalviewLite extends Applet implements
     {
       boolean seqlimits = suffix.equalsIgnoreCase(TRUE);
 
-      String reply = new AppletFormatAdapter().formatSequences(format,
+      FileFormatI theFormat = FileFormat.valueOf(format);
+      String reply = new AppletFormatAdapter().formatSequences(theFormat,
               alf.viewport.getAlignment(), seqlimits);
       return reply;
-    } catch (Exception ex)
+    } catch (IllegalArgumentException ex)
     {
       ex.printStackTrace();
-      return "Error retrieving alignment in " + format + " format. ";
+      return "Error retrieving alignment, possibly invalid format specifier: "
+              + format;
     }
   }
 
@@ -741,14 +749,14 @@ public class JalviewLite extends Applet implements
   public void loadAnnotationFrom(AlignFrame alf, String annotation)
   {
     if (new AnnotationFile().annotateAlignmentView(alf.getAlignViewport(),
-            annotation, AppletFormatAdapter.PASTE))
+            annotation, DataSourceType.PASTE))
     {
       alf.alignPanel.fontChanged();
       alf.alignPanel.setScrollValues(0, 0);
     }
     else
     {
-      alf.parseFeaturesFile(annotation, AppletFormatAdapter.PASTE);
+      alf.parseFeaturesFile(annotation, DataSourceType.PASTE);
     }
   }
 
@@ -774,7 +782,7 @@ public class JalviewLite extends Applet implements
   public boolean loadFeaturesFrom(AlignFrame alf, String features,
           boolean autoenabledisplay)
   {
-    return alf.parseFeaturesFile(features, AppletFormatAdapter.PASTE,
+    return alf.parseFeaturesFile(features, DataSourceType.PASTE,
             autoenabledisplay);
   }
 
@@ -882,17 +890,17 @@ public class JalviewLite extends Applet implements
   {
     AlignmentI al = null;
 
-    String format = new IdentifyFile().identify(text,
-            AppletFormatAdapter.PASTE);
     try
     {
-      al = new AppletFormatAdapter().readFile(text,
-              AppletFormatAdapter.PASTE, format);
+      FileFormatI format = new IdentifyFile().identify(text,
+              DataSourceType.PASTE);
+      al = new AppletFormatAdapter().readFile(text, DataSourceType.PASTE,
+              format);
       if (al.getHeight() > 0)
       {
         return new AlignFrame(al, this, title, false);
       }
-    } catch (java.io.IOException ex)
+    } catch (IOException ex)
     {
       ex.printStackTrace();
     }
@@ -1818,7 +1826,7 @@ public class JalviewLite extends Applet implements
     /**
      * State variable: protocol for access to file source
      */
-    String protocol;
+    DataSourceType protocol;
 
     String _file; // alignment file or URL spec
 
@@ -1848,7 +1856,7 @@ public class JalviewLite extends Applet implements
        */
       if (path.startsWith("PASTE"))
       {
-        protocol = AppletFormatAdapter.PASTE;
+        protocol = DataSourceType.PASTE;
         return path.substring(5);
       }
 
@@ -1857,7 +1865,7 @@ public class JalviewLite extends Applet implements
        */
       if (path.indexOf("://") != -1)
       {
-        protocol = AppletFormatAdapter.URL;
+        protocol = DataSourceType.URL;
         return path;
       }
 
@@ -1873,7 +1881,7 @@ public class JalviewLite extends Applet implements
           System.err.println("Prepended document base '" + documentBase
                   + "' to make: '" + withDocBase + "'");
         }
-        protocol = AppletFormatAdapter.URL;
+        protocol = DataSourceType.URL;
         return withDocBase;
       }
 
@@ -1886,7 +1894,7 @@ public class JalviewLite extends Applet implements
       if (!withCodeBase.equals(withDocBase)
               && HttpUtils.isValidUrl(withCodeBase))
       {
-        protocol = AppletFormatAdapter.URL;
+        protocol = DataSourceType.URL;
         if (debug)
         {
           System.err.println("Prepended codebase '" + codeBase
@@ -1901,7 +1909,7 @@ public class JalviewLite extends Applet implements
        */
       if (inArchive(path))
       {
-        protocol = AppletFormatAdapter.CLASSLOADER;
+        protocol = DataSourceType.CLASSLOADER;
       }
       return path;
     }
@@ -2015,11 +2023,12 @@ public class JalviewLite extends Applet implements
         return null;
       }
       String resolvedFile = resolveFileProtocol(fileParam);
-      String format = new IdentifyFile().identify(resolvedFile, protocol);
-      dbgMsg("File identified as '" + format + "'");
       AlignmentI al = null;
       try
       {
+        FileFormatI format = new IdentifyFile().identify(resolvedFile,
+                protocol);
+        dbgMsg("File identified as '" + format + "'");
         al = new AppletFormatAdapter().readFile(resolvedFile, protocol,
                 format);
         if ((al != null) && (al.getHeight() > 0))
@@ -2036,7 +2045,7 @@ public class JalviewLite extends Applet implements
           // update the focus.
           currentAlignFrame = newAlignFrame;
 
-          if (protocol == AppletFormatAdapter.PASTE)
+          if (protocol == DataSourceType.PASTE)
           {
             newAlignFrame.setTitle(MessageManager.formatMessage(
                     "label.sequences_from", new Object[] { applet
@@ -2207,8 +2216,7 @@ public class JalviewLite extends Applet implements
             }
             else
             {
-              pdbs.addElement(new Object[] { pdb, seqs, chains,
-                  new String(protocol) });
+              pdbs.addElement(new Object[] { pdb, seqs, chains, protocol });
             }
           }
         }
index fd88028..156e146 100644 (file)
@@ -22,7 +22,11 @@ package jalview.bin;
 
 import jalview.datamodel.AlignmentI;
 import jalview.io.AppletFormatAdapter;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
+import jalview.io.FileFormatI;
 import jalview.io.FileParse;
+import jalview.io.IdentifyFile;
 
 import java.applet.Applet;
 import java.io.InputStream;
@@ -45,6 +49,7 @@ public class JalviewLiteURLRetrieve extends Applet
    * 
    * @return void
    */
+  @Override
   public void init()
   {
     this.setSize(300, 200);
@@ -55,7 +60,7 @@ public class JalviewLiteURLRetrieve extends Applet
               .println("Specify a resource to read on the file parameter");
       return;
     }
-    String protocol = null;
+    DataSourceType protocol = null;
     try
     {
       System.out.println("Loading thread started with:\n>>file\n" + file
@@ -75,7 +80,7 @@ public class JalviewLiteURLRetrieve extends Applet
                 + (rtn ? "" : "not") + " located by classloader.");
         if (rtn)
         {
-          protocol = AppletFormatAdapter.CLASSLOADER;
+          protocol = DataSourceType.CLASSLOADER;
         }
 
       } catch (Exception ex)
@@ -85,12 +90,12 @@ public class JalviewLiteURLRetrieve extends Applet
       }
       if (file.indexOf("://") > -1)
       {
-        protocol = AppletFormatAdapter.URL;
+        protocol = DataSourceType.URL;
       }
       else
       {
         // skipping codebase prepend check.
-        protocol = AppletFormatAdapter.FILE;
+        protocol = DataSourceType.FILE;
       }
 
       System.out.println("Trying to get contents of resource:");
@@ -110,10 +115,10 @@ public class JalviewLiteURLRetrieve extends Applet
                 + " cannot be read with protocol==" + protocol);
         return;
       }
-      String format = getParameter("format");
-      if (format == null || format.length() == 0)
+      FileFormatI format = FileFormat.valueOf(getParameter("format"));
+      if (format == null)
       {
-        format = new jalview.io.IdentifyFile().identify(file, protocol);
+        format = new IdentifyFile().identify(file, protocol);
         System.out.println("Format is " + format);
       }
       else
@@ -132,7 +137,7 @@ public class JalviewLiteURLRetrieve extends Applet
       if (al != null)
       {
         System.out.println(new AppletFormatAdapter().formatSequences(
-                "FASTA", al, false));
+                FileFormat.Fasta, al, false));
       }
     } catch (Exception e)
     {
index f508bc3..7d60dc8 100644 (file)
@@ -33,6 +33,7 @@ import jalview.datamodel.SequenceCollectionI;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
+import jalview.io.DataSourceType;
 import jalview.io.FeaturesFile;
 import jalview.util.MessageManager;
 
@@ -349,7 +350,7 @@ public class AlignViewController implements AlignViewControllerI
   }
 
   @Override
-  public boolean parseFeaturesFile(String file, String protocol,
+  public boolean parseFeaturesFile(String file, DataSourceType protocol,
           boolean relaxedIdMatching)
   {
     boolean featuresFile = false;
index 32bb761..286e284 100755 (executable)
@@ -1742,7 +1742,7 @@ public class Alignment implements AlignmentI
   @Override
   public String toString()
   {
-    return new FastaFile().print(getSequencesArray());
+    return new FastaFile().print(getSequencesArray(), true);
   }
 
   /**
index 1c7df49..37dfdbf 100755 (executable)
@@ -34,10 +34,30 @@ public class PDBEntry
 
   public enum Type
   {
-    PDB, MMCIF, FILE
+    // TODO is FILE needed; if not is this needed or can we
+    // use FileFormatI for PDB, MMCIF?
+    PDB("pdb", "xml"), MMCIF("mmcif", "mmcif"), FILE("?", "?");
+    String ext;
+
+    String format;
+
+    private Type(String fmt, String ex)
+    {
+      format = fmt;
+      ext = ex;
+    }
+
+    public String getFormat()
+    {
+      return format;
+    }
+    public String getExtension()
+    {
+      return ext;
+    }
   }
 
-  Hashtable properties;
+  Hashtable<String, String> properties;
 
   /*
    * (non-Javadoc)
@@ -153,7 +173,7 @@ public class PDBEntry
     this.properties = property;
   }
 
-  public Hashtable getProperty()
+  public Hashtable<String, String> getProperty()
   {
     return properties;
   }
index 72efdc1..653d5d5 100644 (file)
@@ -1,5 +1,6 @@
 package jalview.ext.ensembl;
 
+import jalview.io.DataSourceType;
 import jalview.io.FileParse;
 import jalview.util.StringUtils;
 
@@ -208,7 +209,7 @@ abstract class EnsemblRestClient extends EnsemblSequenceFetcher
     URL url = getUrl(ids);
   
     BufferedReader reader = getHttpResponse(url, ids);
-    FileParse fp = new FileParse(reader, url.toString(), "HTTP_POST");
+    FileParse fp = new FileParse(reader, url.toString(), DataSourceType.URL);
     return fp;
   }
 
index 2ccf118..3ee8a34 100644 (file)
@@ -27,7 +27,7 @@ import jalview.datamodel.AlignmentI;
 import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
-import jalview.io.AppletFormatAdapter;
+import jalview.io.DataSourceType;
 import jalview.io.StructureFile;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ResidueProperties;
@@ -104,7 +104,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
 
   public JalviewJmolBinding(StructureSelectionManager ssm,
           PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains,
-          String protocol)
+          DataSourceType protocol)
   {
     super(ssm, pdbentry, sequenceIs, chains, protocol);
     /*
@@ -1140,7 +1140,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
           // see JAL-623 - need method of matching pasted data up
           {
             pdb = getSsm().setMapping(getSequence()[pe], getChains()[pe],
-                    pdbfile, AppletFormatAdapter.PASTE);
+                    pdbfile, DataSourceType.PASTE);
             getPdbEntry(modelnum).setFile("INLINE" + pdb.getId());
             matches = true;
             foundEntry = true;
@@ -1158,12 +1158,12 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
             // needs
             // to be tested. See mantis bug
             // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605
-            String protocol = AppletFormatAdapter.URL;
+            DataSourceType protocol = DataSourceType.URL;
             try
             {
               if (fl.exists())
               {
-                protocol = AppletFormatAdapter.FILE;
+                protocol = DataSourceType.FILE;
               }
             } catch (Exception e)
             {
index 848e7db..858aac7 100644 (file)
@@ -23,6 +23,7 @@ package jalview.ext.jmol;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.Annotation;
 import jalview.datamodel.SequenceI;
+import jalview.io.DataSourceType;
 import jalview.io.FileParse;
 import jalview.io.StructureFile;
 import jalview.schemes.ResidueProperties;
@@ -60,10 +61,10 @@ public class JmolParser extends StructureFile implements JmolStatusListener
   Viewer viewer = null;
 
   public JmolParser(boolean addAlignmentAnnotations, boolean predictSecStr,
-          boolean externalSecStr, String inFile, String type)
+          boolean externalSecStr, String inFile, DataSourceType sourceType)
           throws IOException
   {
-    super(inFile, type);
+    super(inFile, sourceType);
   }
 
   public JmolParser(boolean addAlignmentAnnotations, boolean predictSecStr,
@@ -443,7 +444,7 @@ public class JmolParser extends StructureFile implements JmolStatusListener
    * Not implemented - returns null
    */
   @Override
-  public String print()
+  public String print(SequenceI[] seqs, boolean jvSuffix)
   {
     return null;
   }
index 944ef52..dca7038 100644 (file)
@@ -29,6 +29,7 @@ import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.httpserver.AbstractRequestHandler;
+import jalview.io.DataSourceType;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ResidueProperties;
 import jalview.structure.AtomSpec;
@@ -197,7 +198,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
    */
   public JalviewChimeraBinding(StructureSelectionManager ssm,
           PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains,
-          String protocol)
+          DataSourceType protocol)
   {
     super(ssm, pdbentry, sequenceIs, chains, protocol);
     viewer = new ChimeraManager(
index 2a12630..50af20a 100644 (file)
@@ -22,6 +22,7 @@ package jalview.gui;
 
 import jalview.api.AlignExportSettingI;
 import jalview.bin.Jalview;
+import jalview.io.FileFormatI;
 import jalview.jbgui.GAlignExportSettings;
 import jalview.util.MessageManager;
 
@@ -41,9 +42,9 @@ public class AlignExportSettings extends GAlignExportSettings implements
   JDialog dialog;
 
   public AlignExportSettings(boolean hasHiddenSeq, boolean hasHiddenCols,
-          String alignFileFormat)
+          FileFormatI format)
   {
-    super(hasHiddenSeq, hasHiddenCols, alignFileFormat);
+    super(hasHiddenSeq, hasHiddenCols, format);
     if (!Jalview.isHeadlessMode() && isShowDialog())
     {
 
@@ -53,6 +54,7 @@ public class AlignExportSettings extends GAlignExportSettings implements
               MessageManager.getString("label.export_settings"));
       dialog.addWindowListener(new WindowAdapter()
       {
+        @Override
         public void windowClosing(WindowEvent e)
         {
           cancelled = true;
@@ -66,6 +68,7 @@ public class AlignExportSettings extends GAlignExportSettings implements
     }
   }
 
+  @Override
   public void ok_actionPerformed(ActionEvent e)
   {
     cancelled = false;
@@ -73,6 +76,7 @@ public class AlignExportSettings extends GAlignExportSettings implements
     dialog.dispose();
   }
 
+  @Override
   public void cancel_actionPerformed(ActionEvent e)
   {
     cancelled = true;
@@ -110,6 +114,7 @@ public class AlignExportSettings extends GAlignExportSettings implements
     return chkExportGrps.isSelected();
   }
 
+  @Override
   public boolean isCancelled()
   {
     return cancelled;
index f6268c0..38223c7 100644 (file)
@@ -65,10 +65,14 @@ import jalview.gui.ViewSelectionMenu.ViewSetProvider;
 import jalview.io.AlignmentProperties;
 import jalview.io.AnnotationFile;
 import jalview.io.BioJsHTMLOutput;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
+import jalview.io.FileFormatI;
 import jalview.io.FileLoader;
 import jalview.io.FormatAdapter;
 import jalview.io.HtmlSvgOutput;
 import jalview.io.IdentifyFile;
+import jalview.io.JPredFile;
 import jalview.io.JalviewFileChooser;
 import jalview.io.JalviewFileView;
 import jalview.io.JnetAnnotationMaker;
@@ -179,7 +183,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   /**
    * Last format used to load or save alignments in this window
    */
-  String currentFileFormat = null;
+  FileFormatI currentFileFormat = null;
 
   /**
    * Current filename for this alignment
@@ -488,7 +492,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param format
    *          format of file
    */
-  public void setFileName(String file, String format)
+  public void setFileName(String file, FileFormatI format)
   {
     fileName = file;
     setFileFormat(format);
@@ -1007,7 +1011,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       // originating file's format
       // TODO: work out how to recover feature settings for correct view(s) when
       // file is reloaded.
-      if (currentFileFormat.equals("Jalview"))
+      if (currentFileFormat == FileFormat.Jalview)
       {
         JInternalFrame[] frames = Desktop.desktop.getAllFrames();
         for (int i = 0; i < frames.length; i++)
@@ -1029,7 +1033,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         Desktop.instance.closeAssociatedWindows();
 
         FileLoader loader = new FileLoader();
-        String protocol = fileName.startsWith("http:") ? "URL" : "File";
+        DataSourceType protocol = fileName.startsWith("http:") ? DataSourceType.URL
+                : DataSourceType.FILE;
         loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
       }
       else
@@ -1037,7 +1042,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         Rectangle bounds = this.getBounds();
 
         FileLoader loader = new FileLoader();
-        String protocol = fileName.startsWith("http:") ? "URL" : "File";
+        DataSourceType protocol = fileName.startsWith("http:") ? DataSourceType.URL
+                : DataSourceType.FILE;
         AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
                 protocol, currentFileFormat);
 
@@ -1081,9 +1087,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   public void save_actionPerformed(ActionEvent e)
   {
-    if (fileName == null
-            || (currentFileFormat == null || !jalview.io.FormatAdapter
-                    .isValidIOFormat(currentFileFormat, true))
+    if (fileName == null || (currentFileFormat == null)
             || fileName.startsWith("http"))
     {
       saveAs_actionPerformed(null);
@@ -1103,11 +1107,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   public void saveAs_actionPerformed(ActionEvent e)
   {
-    JalviewFileChooser chooser = new JalviewFileChooser(
-            jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
-            jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
-            jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
-            currentFileFormat, false);
+    JalviewFileChooser chooser = JalviewFileChooser.forWrite(
+            Cache.getProperty("LAST_DIRECTORY"),
+            // AppletFormatAdapter.WRITABLE_EXTENSIONS,
+            // AppletFormatAdapter.WRITABLE_FNAMES,
+            currentFileFormat.toString(), false);
 
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager
@@ -1139,24 +1143,19 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
       fileName = chooser.getSelectedFile().getPath();
 
-      jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
-              currentFileFormat);
+      Cache.setProperty("DEFAULT_FILE_FORMAT",
+              currentFileFormat.toString());
 
-      jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
-      if (currentFileFormat.indexOf(" ") > -1)
-      {
-        currentFileFormat = currentFileFormat.substring(0,
-                currentFileFormat.indexOf(" "));
-      }
+      Cache.setProperty("LAST_DIRECTORY", fileName);
       saveAlignment(fileName, currentFileFormat);
     }
   }
 
-  public boolean saveAlignment(String file, String format)
+  public boolean saveAlignment(String file, FileFormatI format)
   {
     boolean success = true;
 
-    if (format.equalsIgnoreCase("Jalview"))
+    if (format == FileFormat.Jalview)
     {
       String shortName = title;
 
@@ -1175,16 +1174,16 @@ 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;
-      }
+      // 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);
@@ -1264,8 +1263,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   protected void outputText_actionPerformed(ActionEvent e)
   {
 
+    FileFormat fileFormat = FileFormat.valueOf(e.getActionCommand());
     AlignmentExportData exportData = getAlignmentForExport(
-            e.getActionCommand(), viewport, null);
+fileFormat,
+            viewport, null);
     if (exportData.getSettings().isCancelled())
     {
       return;
@@ -1274,8 +1275,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     cap.setForInput(null);
     try
     {
+      FileFormatI format = fileFormat;
       cap.setText(new FormatAdapter(alignPanel, exportData.getSettings())
-              .formatSequences(e.getActionCommand(),
+              .formatSequences(format,
                       exportData.getAlignment(),
                       exportData.getOmitHidden(),
                       exportData.getStartEndPostions(),
@@ -1292,7 +1294,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   }
 
   public static AlignmentExportData getAlignmentForExport(
-          String exportFormat, AlignViewportI viewport,
+          FileFormatI format, AlignViewportI viewport,
           AlignExportSettingI exportSettings)
   {
     AlignmentI alignmentToExport = null;
@@ -1308,7 +1310,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     if (settings == null)
     {
       settings = new AlignExportSettings(hasHiddenSeqs,
-              viewport.hasHiddenColumns(), exportFormat);
+              viewport.hasHiddenColumns(), format);
     }
     // settings.isExportAnnotations();
 
@@ -1865,7 +1867,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       omitHidden = viewport.getViewAsString(true);
     }
 
-    String output = new FormatAdapter().formatSequences("Fasta", seqs,
+    String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
+            seqs,
             omitHidden, null);
 
     StringSelection ss = new StringSelection(output);
@@ -1952,7 +1955,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         return;
       }
 
-      String str, format;
+      String str;
+      FileFormatI format;
       try
       {
         str = (String) contents.getTransferData(DataFlavor.stringFlavor);
@@ -1961,7 +1965,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           return;
         }
 
-        format = new IdentifyFile().identify(str, "Paste");
+        format = new IdentifyFile().identify(str, DataSourceType.PASTE);
 
       } catch (OutOfMemoryError er)
       {
@@ -1991,7 +1995,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       else
       {
         // parse the clipboard as an alignment.
-        alignment = new FormatAdapter().readFile(str, "Paste", format);
+        alignment = new FormatAdapter().readFile(str, DataSourceType.PASTE,
+                format);
         sequences = alignment.getSequencesArray();
       }
 
@@ -4306,7 +4311,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       jalview.io.NewickFile fin = null;
       try
       {
-        fin = new jalview.io.NewickFile(choice, "File");
+        fin = new NewickFile(choice, DataSourceType.FILE);
         viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
       } catch (Exception ex)
       {
@@ -4967,11 +4972,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   /**
    * Set the file format
    * 
-   * @param fileFormat
+   * @param format
    */
-  public void setFileFormat(String fileFormat)
+  public void setFileFormat(FileFormatI format)
   {
-    this.currentFileFormat = fileFormat;
+    this.currentFileFormat = format;
   }
 
   /**
@@ -4979,14 +4984,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @param file
    *          contents or path to retrieve file
-   * @param type
+   * @param sourceType
    *          access mode of file (see jalview.io.AlignFile)
    * @return true if features file was parsed correctly.
    */
-  public boolean parseFeaturesFile(String file, String type)
+  public boolean parseFeaturesFile(String file, DataSourceType sourceType)
   {
-    return avc.parseFeaturesFile(file, type,
-            jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
+    return avc.parseFeaturesFile(file, sourceType,
+            Cache.getDefault("RELAXEDSEQIDMATCHING", false));
 
   }
 
@@ -5028,7 +5033,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   public void drop(DropTargetDropEvent evt)
   {
     Transferable t = evt.getTransferable();
-    java.util.List<String> files = new ArrayList<String>(), protocols = new ArrayList<String>();
+    List<String> files = new ArrayList<String>();
+    List<DataSourceType> protocols = new ArrayList<DataSourceType>();
 
     try
     {
@@ -5054,13 +5060,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         {
           String file = files.get(i).toString();
           String pdbfn = "";
-          String protocol = FormatAdapter.checkProtocol(file);
-          if (protocol == jalview.io.FormatAdapter.FILE)
+          DataSourceType protocol = FormatAdapter.checkProtocol(file);
+          if (protocol == DataSourceType.FILE)
           {
             File fl = new File(file);
             pdbfn = fl.getName();
           }
-          else if (protocol == jalview.io.FormatAdapter.URL)
+          else if (protocol == DataSourceType.URL)
           {
             URL url = new URL(file);
             pdbfn = url.getFile();
@@ -5084,7 +5090,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
             }
             if (mtch != null)
             {
-              String type = null;
+              FileFormatI type = null;
               try
               {
                 type = new IdentifyFile().identify(file, protocol);
@@ -5094,7 +5100,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               }
               if (type != null)
               {
-                if (type.equalsIgnoreCase("PDB"))
+                if (type == FileFormat.PDB)
                 {
                   filesmatched.add(new Object[] { file, protocol, mtch });
                   continue;
@@ -5134,7 +5140,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               {
                 PDBEntry pe = new AssociatePdbFileWithSeq()
                         .associatePdbWithSeq((String) fm[0],
-                                (String) fm[1], toassoc, false,
+                                (DataSourceType) fm[1], toassoc, false,
                                 Desktop.instance);
                 if (pe != null)
                 {
@@ -5193,21 +5199,20 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param file
    *          either a filename or a URL string.
    */
-  public void loadJalviewDataFile(String file, String protocol,
-          String format, SequenceI assocSeq)
+  public void loadJalviewDataFile(String file, DataSourceType sourceType,
+          FileFormatI format, SequenceI assocSeq)
   {
     try
     {
-      if (protocol == null)
+      if (sourceType == null)
       {
-        protocol = FormatAdapter.checkProtocol(file);
+        sourceType = FormatAdapter.checkProtocol(file);
       }
       // if the file isn't identified, or not positively identified as some
       // other filetype (PFAM is default unidentified alignment file type) then
       // try to parse as annotation.
-      boolean isAnnotation = (format == null || format
-              .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
-              .annotateAlignmentView(viewport, file, protocol) : false;
+      boolean isAnnotation = (format == null || format == FileFormat.Pfam) ? new AnnotationFile()
+              .annotateAlignmentView(viewport, file, sourceType) : false;
 
       if (!isAnnotation)
       {
@@ -5215,7 +5220,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         TCoffeeScoreFile tcf = null;
         try
         {
-          tcf = new TCoffeeScoreFile(file, protocol);
+          tcf = new TCoffeeScoreFile(file, sourceType);
           if (tcf.isValid())
           {
             if (tcf.annotateAlignment(viewport.getAlignment(), true))
@@ -5261,12 +5266,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           // try to parse it as a features file
           if (format == null)
           {
-            format = new IdentifyFile().identify(file, protocol);
+            format = new IdentifyFile().identify(file, sourceType);
           }
-          if (format.equalsIgnoreCase("JnetFile"))
+          if (format == FileFormat.Jnet)
           {
-            jalview.io.JPredFile predictions = new jalview.io.JPredFile(
-                    file, protocol);
+            JPredFile predictions = new JPredFile(
+                    file, sourceType);
             new JnetAnnotationMaker();
             JnetAnnotationMaker.add_annotation(predictions,
                     viewport.getAlignment(), 0, false);
@@ -5279,14 +5284,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           }
           else if (IdentifyFile.FeaturesFile.equals(format))
           {
-            if (parseFeaturesFile(file, protocol))
+            if (parseFeaturesFile(file, sourceType))
             {
               alignPanel.paintAlignment(true);
             }
           }
           else
           {
-            new FileLoader().LoadFile(viewport, file, protocol, format);
+            new FileLoader().LoadFile(viewport, file, sourceType, format);
           }
         }
       }
@@ -5311,8 +5316,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       }
       new OOMWarning(
               "loading data "
-                      + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
-                              : "using " + protocol + " from " + file)
+                      + (sourceType != null ? (sourceType == DataSourceType.PASTE ? "from clipboard."
+                              : "using " + sourceType + " from " + file)
                               : ".")
                       + (format != null ? "(parsing as '" + format
                               + "' file)" : ""), oom, Desktop.desktop);
index 62e05d0..d4d2054 100644 (file)
@@ -932,7 +932,7 @@ public class AlignViewport extends AlignmentViewport implements
 
     // TODO if we want this (e.g. to enable reload of the alignment from file),
     // we will need to add parameters to the stack.
-    // if (!protocol.equals(AppletFormatAdapter.PASTE))
+    // if (!protocol.equals(DataSourceType.PASTE))
     // {
     // alignFrame.setFileName(file, format);
     // }
index 718e0f0..f20d0e6 100644 (file)
@@ -242,7 +242,7 @@ public class AnnotationChooser extends JPanel
    * type which are in the application scope (all, selected or unselected
    * sequences).
    * 
-   * @param type
+   * @param dataSourceType
    */
   protected void changeShowHide_actionPerformed()
   {
index 5b01b9b..d497488 100755 (executable)
@@ -27,6 +27,7 @@ import jalview.datamodel.Annotation;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
+import jalview.io.FileFormat;
 import jalview.io.FormatAdapter;
 import jalview.util.MessageManager;
 
@@ -944,8 +945,8 @@ public class AnnotationLabels extends JPanel implements MouseListener,
       alignmentStartEnd = av.getAlignment().getVisibleStartAndEndIndex(
               hiddenCols);
     }
-    String output = new FormatAdapter().formatSequences("Fasta", seqs,
-            omitHidden, alignmentStartEnd);
+    String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
+            seqs, omitHidden, alignmentStartEnd);
 
     Toolkit.getDefaultToolkit().getSystemClipboard()
             .setContents(new StringSelection(output), Desktop.instance);
index 1c54a5e..6e520e5 100644 (file)
@@ -25,6 +25,7 @@ import jalview.bin.Cache;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.ext.jmol.JalviewJmolBinding;
+import jalview.io.DataSourceType;
 import jalview.structure.StructureSelectionManager;
 
 import java.awt.Container;
@@ -42,7 +43,7 @@ public class AppJmolBinding extends JalviewJmolBinding
 
   public AppJmolBinding(AppJmol appJmol, StructureSelectionManager sSm,
           PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains,
-          String protocol)
+          DataSourceType protocol)
   {
     super(sSm, pdbentry, sequenceIs, chains, protocol);
     appJmolWindow = appJmol;
@@ -113,6 +114,7 @@ public class AppJmolBinding extends JalviewJmolBinding
     // appJmolWindow.repaint();
     javax.swing.SwingUtilities.invokeLater(new Runnable()
     {
+      @Override
       public void run()
       {
         appJmolWindow.updateTitleAndMenus();
@@ -121,6 +123,7 @@ public class AppJmolBinding extends JalviewJmolBinding
     });
   }
 
+  @Override
   public void updateColours(Object source)
   {
     AlignmentPanel ap = (AlignmentPanel) source;
@@ -144,6 +147,7 @@ public class AppJmolBinding extends JalviewJmolBinding
     // msWalltime);
   }
 
+  @Override
   public void showUrl(String url)
   {
     showUrl(url, "jmol");
index e2637a9..c380e2f 100644 (file)
@@ -23,6 +23,7 @@ package jalview.gui;
 import jalview.api.StructureSelectionManagerProvider;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
+import jalview.io.DataSourceType;
 import jalview.io.StructureFile;
 import jalview.structure.StructureSelectionManager;
 import jalview.util.MessageManager;
@@ -44,7 +45,7 @@ public class AssociatePdbFileWithSeq
    * @param choice
    * @param sequence
    */
-  public PDBEntry associatePdbWithSeq(String choice, String protocol,
+  public PDBEntry associatePdbWithSeq(String choice, DataSourceType file,
           SequenceI sequence, boolean prompt,
           StructureSelectionManagerProvider ssmp)
   {
@@ -52,7 +53,7 @@ public class AssociatePdbFileWithSeq
     StructureFile pdbfile = null;
     pdbfile = StructureSelectionManager.getStructureSelectionManager(ssmp)
             .setMapping(false, new SequenceI[] { sequence }, null, choice,
-                    protocol);
+                    file);
     if (pdbfile == null)
     {
       // stacktrace already thrown so just return
index f2244d5..a114f31 100644 (file)
@@ -28,7 +28,7 @@ import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.ext.rbvi.chimera.JalviewChimeraBinding;
 import jalview.gui.StructureViewer.ViewerType;
-import jalview.io.AppletFormatAdapter;
+import jalview.io.DataSourceType;
 import jalview.io.JalviewFileChooser;
 import jalview.io.JalviewFileView;
 import jalview.schemes.BuriedColourScheme;
@@ -660,12 +660,12 @@ public class ChimeraViewFrame extends StructureViewerBase
             jmb.openFile(pe);
             jmb.addSequence(pos, jmb.getSequence()[pos]);
             File fl = new File(pe.getFile());
-            String protocol = AppletFormatAdapter.URL;
+            DataSourceType protocol = DataSourceType.URL;
             try
             {
               if (fl.exists())
               {
-                protocol = AppletFormatAdapter.FILE;
+                protocol = DataSourceType.FILE;
               }
             } catch (Throwable e)
             {
index 1161340..4e5ef40 100644 (file)
@@ -30,8 +30,11 @@ import jalview.bin.Jalview;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.SequenceI;
+import jalview.io.AlignmentFileI;
 import jalview.io.AppletFormatAdapter;
-import jalview.io.FileParse;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormatException;
+import jalview.io.FileFormatI;
 import jalview.io.FormatAdapter;
 import jalview.io.IdentifyFile;
 import jalview.io.JalviewFileChooser;
@@ -68,7 +71,7 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer
 
   AlignViewportI viewport;
 
-  FileParse source = null;
+  AlignmentFileI source = null;
 
   public CutAndPasteTransfer()
   {
@@ -213,14 +216,21 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer
       return;
     }
 
-    String format = new IdentifyFile().identify(text, "Paste");
-    if (format == null || format.equalsIgnoreCase("EMPTY DATA FILE"))
+    FileFormatI format = null;
+    try
+    {
+      format = new IdentifyFile().identify(text, DataSourceType.PASTE);
+    } catch (FileFormatException e1)
+    {
+      // leave as null
+    }
+    if (format == null)
     {
       System.err.println(MessageManager
               .getString("label.couldnt_read_data"));
       if (!Jalview.isHeadlessMode())
       {
-        javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
+        JOptionPane.showInternalMessageDialog(Desktop.desktop,
                 AppletFormatAdapter.SUPPORTED_FORMATS,
                 MessageManager.getString("label.couldnt_read_data"),
                 JOptionPane.WARNING_MESSAGE);
@@ -231,29 +241,26 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer
     // TODO: identify feature, annotation or tree file and parse appropriately.
     AlignmentI al = null;
 
-    if (FormatAdapter.isValidFormat(format))
+    try
     {
-      try
-      {
-        FormatAdapter fa = new FormatAdapter(alignpanel);
-        al = fa.readFile(getText(), "Paste", format);
-        source = fa.getAlignFile();
+      FormatAdapter fa = new FormatAdapter(alignpanel);
+      al = fa.readFile(getText(), DataSourceType.PASTE, format);
+      source = fa.getAlignFile();
 
-      } catch (java.io.IOException ex)
-      {
-        JOptionPane.showInternalMessageDialog(Desktop.desktop,
-                MessageManager.formatMessage(
-                        "label.couldnt_read_pasted_text",
-                        new String[] { ex.toString() }), MessageManager
-                        .getString("label.error_parsing_text"),
-                JOptionPane.WARNING_MESSAGE);
-      }
+    } catch (java.io.IOException ex)
+    {
+      JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
+              .formatMessage("label.couldnt_read_pasted_text", new String[]
+              { ex.toString() }), MessageManager
+              .getString("label.error_parsing_text"),
+              JOptionPane.WARNING_MESSAGE);
     }
 
     if (al != null && al.hasValidSequence())
     {
       String title = MessageManager.formatMessage(
-              "label.input_cut_paste_params", new String[] { format });
+              "label.input_cut_paste_params",
+              new String[] { format.getShortDescription() });
       FeatureSettingsModelI proxyColourScheme = source
               .getFeatureColourScheme();
 
index 7811e41..624054b 100644 (file)
@@ -24,8 +24,11 @@ import jalview.api.AlignViewportI;
 import jalview.api.AlignmentViewPanel;
 import jalview.bin.Cache;
 import jalview.bin.Jalview;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
+import jalview.io.FileFormatException;
+import jalview.io.FileFormatI;
 import jalview.io.FileLoader;
-import jalview.io.FormatAdapter;
 import jalview.io.IdentifyFile;
 import jalview.io.JalviewFileChooser;
 import jalview.io.JalviewFileView;
@@ -443,11 +446,11 @@ public class Desktop extends jalview.jbgui.GDesktop implements
       public void run()
       {
         Cache.log.debug("Filechooser init thread started.");
-        new JalviewFileChooser(
-                jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
-                jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS,
-                jalview.io.AppletFormatAdapter.READABLE_FNAMES,
-                jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
+        String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
+        JalviewFileChooser.forRead(Cache.getProperty("LAST_DIRECTORY"),
+        // jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS,
+        // jalview.io.AppletFormatAdapter.READABLE_FNAMES,
+                fileFormat, true);
         Cache.log.debug("Filechooser init thread finished.");
       }
     }).start();
@@ -667,10 +670,10 @@ public class Desktop extends jalview.jbgui.GDesktop implements
         String file = (String) contents
                 .getTransferData(DataFlavor.stringFlavor);
 
-        String format = new IdentifyFile().identify(file,
-                FormatAdapter.PASTE);
+        FileFormatI format = new IdentifyFile().identify(file,
+                DataSourceType.PASTE);
 
-        new FileLoader().LoadFile(file, FormatAdapter.PASTE, format);
+        new FileLoader().LoadFile(file, DataSourceType.PASTE, format);
 
       }
     } catch (Exception ex)
@@ -953,8 +956,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements
   {
     boolean success = true;
     Transferable t = evt.getTransferable();
-    java.util.List<String> files = new ArrayList<String>();
-    java.util.List<String> protocols = new ArrayList<String>();
+    List<String> files = new ArrayList<String>();
+    List<DataSourceType> protocols = new ArrayList<DataSourceType>();
 
     try
     {
@@ -972,13 +975,13 @@ public class Desktop extends jalview.jbgui.GDesktop implements
         for (int i = 0; i < files.size(); i++)
         {
           String file = files.get(i).toString();
-          String protocol = (protocols == null) ? FormatAdapter.FILE
-                  : (String) protocols.get(i);
-          String format = null;
+          DataSourceType protocol = (protocols == null) ? DataSourceType.FILE
+                  : protocols.get(i);
+          FileFormatI format = null;
 
           if (file.endsWith(".jar"))
           {
-            format = "Jalview";
+            format = FileFormat.Jalview;
 
           }
           else
@@ -1007,11 +1010,12 @@ public class Desktop extends jalview.jbgui.GDesktop implements
   @Override
   public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
   {
-    JalviewFileChooser chooser = new JalviewFileChooser(
-            jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
-            jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS,
-            jalview.io.AppletFormatAdapter.READABLE_FNAMES,
-            jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
+    String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
+    JalviewFileChooser chooser = JalviewFileChooser.forRead(
+            Cache.getProperty("LAST_DIRECTORY"),
+            // AppletFormatAdapter.READABLE_EXTENSIONS,
+            // AppletFormatAdapter.READABLE_FNAMES,
+            fileFormat, true);
 
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager
@@ -1023,28 +1027,34 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     if (value == JalviewFileChooser.APPROVE_OPTION)
     {
       String choice = chooser.getSelectedFile().getPath();
-      jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
+      Cache.setProperty("LAST_DIRECTORY", chooser
               .getSelectedFile().getParent());
 
-      String format = null;
+      FileFormatI format = null;
       if (chooser.getSelectedFormat() != null
-              && chooser.getSelectedFormat().equals("Jalview"))
+              && chooser.getSelectedFormat() == FileFormat.Jalview)
       {
-        format = "Jalview";
+        format = FileFormat.Jalview;
       }
       else
       {
-        format = new IdentifyFile().identify(choice, FormatAdapter.FILE);
+        try
+        {
+          format = new IdentifyFile().identify(choice, DataSourceType.FILE);
+        } catch (FileFormatException e)
+        {
+          // format is null
+        }
       }
 
       if (viewport != null)
       {
-        new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE,
+        new FileLoader().LoadFile(viewport, choice, DataSourceType.FILE,
                 format);
       }
       else
       {
-        new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);
+        new FileLoader().LoadFile(choice, DataSourceType.FILE, format);
       }
     }
   }
@@ -1054,9 +1064,11 @@ public class Desktop extends jalview.jbgui.GDesktop implements
    * 
    * @param e
    *          DOCUMENT ME!
+   * @throws FileFormatException
    */
   @Override
   public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
+  // throws FileFormatException
   {
     // This construct allows us to have a wider textfield
     // for viewing
@@ -1100,19 +1112,28 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     {
       if (viewport != null)
       {
-        new FileLoader().LoadFile(viewport, url, FormatAdapter.URL,
-                "Jalview");
+        new FileLoader().LoadFile(viewport, url, DataSourceType.URL,
+                FileFormat.Jalview);
       }
       else
       {
-        new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview");
+        new FileLoader().LoadFile(url, DataSourceType.URL,
+                FileFormat.Jalview);
       }
     }
     else
     {
-      String format = new IdentifyFile().identify(url, FormatAdapter.URL);
+      FileFormatI format = null;
+      try
+      {
+        format = new IdentifyFile().identify(url, DataSourceType.URL);
+      } catch (FileFormatException e)
+      {
+        // TODO revise error handling, distinguish between
+        // URL not found and response not valid
+      }
 
-      if (format.equals("URL NOT FOUND"))
+      if (format == null)
       {
         JOptionPane.showInternalMessageDialog(Desktop.desktop,
                 MessageManager.formatMessage("label.couldnt_locate",
@@ -1125,11 +1146,12 @@ public class Desktop extends jalview.jbgui.GDesktop implements
 
       if (viewport != null)
       {
-        new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format);
+        new FileLoader()
+                .LoadFile(viewport, url, DataSourceType.URL, format);
       }
       else
       {
-        new FileLoader().LoadFile(url, FormatAdapter.URL, format);
+        new FileLoader().LoadFile(url, DataSourceType.URL, format);
       }
     }
   }
@@ -1512,8 +1534,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
   public void saveState_actionPerformed(ActionEvent e)
   {
     JalviewFileChooser chooser = new JalviewFileChooser(
-            jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
-            new String[] { "jvp" }, new String[] { "Jalview Project" },
+            Cache.getProperty("LAST_DIRECTORY"), "jvp", "Jalview Project",
             "Jalview Project");
 
     chooser.setFileView(new JalviewFileView());
@@ -1584,7 +1605,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
   public void loadState_actionPerformed(ActionEvent e)
   {
     JalviewFileChooser chooser = new JalviewFileChooser(
-            jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] {
+            Cache.getProperty("LAST_DIRECTORY"), new String[] {
                 "jvp", "jar" }, new String[] { "Jalview Project",
                 "Jalview Project (old)" }, "Jalview Project");
     chooser.setFileView(new JalviewFileView());
@@ -1597,7 +1618,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
       final File selectedFile = chooser.getSelectedFile();
       setProjectFile(selectedFile);
       final String choice = selectedFile.getAbsolutePath();
-      jalview.bin.Cache.setProperty("LAST_DIRECTORY",
+      Cache.setProperty("LAST_DIRECTORY",
               selectedFile.getParent());
       new Thread(new Runnable()
       {
@@ -2168,9 +2189,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     if (v_client != null)
     {
       JalviewFileChooser chooser = new JalviewFileChooser(
-              jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[]
-              { "vdj" }, // TODO: VAMSAS DOCUMENT EXTENSION is VDJ
-              new String[] { "Vamsas Document" }, "Vamsas Document");
+              Cache.getProperty("LAST_DIRECTORY"), "vdj",
+              "Vamsas Document", "Vamsas Document");
 
       chooser.setFileView(new JalviewFileView());
       chooser.setDialogTitle(MessageManager
@@ -2184,7 +2204,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
         JPanel progpanel = addProgressPanel(MessageManager.formatMessage(
                 "label.saving_vamsas_doc",
                 new Object[] { choice.getName() }));
-        jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
+        Cache.setProperty("LAST_DIRECTORY", choice.getParent());
         String warnmsg = null;
         String warnttl = null;
         try
@@ -3179,7 +3199,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements
   }
 
   public static void transferFromDropTarget(List<String> files,
-          List<String> protocols, DropTargetDropEvent evt, Transferable t)
+          List<DataSourceType> protocols, DropTargetDropEvent evt,
+          Transferable t)
           throws Exception
   {
 
@@ -3194,7 +3215,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
               .getTransferData(DataFlavor.javaFileListFlavor))
       {
         files.add(((File)file).toString());
-        protocols.add(FormatAdapter.FILE);
+        protocols.add(DataSourceType.FILE);
       }
     }
     else
@@ -3225,7 +3246,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
       {
         Cache.log.debug("Adding missing FILE protocol for "
                 + files.get(protocols.size()));
-        protocols.add(FormatAdapter.FILE);
+        protocols.add(DataSourceType.FILE);
       }
       for (java.util.StringTokenizer st = new java.util.StringTokenizer(
               data, "\r\n"); st.hasMoreTokens();)
@@ -3240,14 +3261,14 @@ public class Desktop extends jalview.jbgui.GDesktop implements
         java.net.URI uri = new java.net.URI(s);
         if (uri.getScheme().toLowerCase().startsWith("http"))
         {
-          protocols.add(FormatAdapter.URL);
+          protocols.add(DataSourceType.URL);
           files.add(uri.toString());
         }
         else
         {
           // otherwise preserve old behaviour: catch all for file objects
           java.io.File file = new java.io.File(uri);
-          protocols.add(FormatAdapter.FILE);
+          protocols.add(DataSourceType.FILE);
           files.add(file.toString());
         }
       }
index 3b8ce37..6dc5cb3 100644 (file)
@@ -750,10 +750,8 @@ public class FeatureSettings extends JPanel implements
   void load()
   {
     JalviewFileChooser chooser = new JalviewFileChooser(
-            jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
-            new String[] { "fc" },
-            new String[] { "Sequence Feature Colours" },
-            "Sequence Feature Colours");
+            Cache.getProperty("LAST_DIRECTORY"), "fc",
+            "Sequence Feature Colours", "Sequence Feature Colours");
     chooser.setFileView(new jalview.io.JalviewFileView());
     chooser.setDialogTitle(MessageManager
             .getString("label.load_feature_colours"));
@@ -845,10 +843,8 @@ public class FeatureSettings extends JPanel implements
   void save()
   {
     JalviewFileChooser chooser = new JalviewFileChooser(
-            Cache.getProperty("LAST_DIRECTORY"),
-            new String[] { "fc" },
-            new String[] { "Sequence Feature Colours" },
-            "Sequence Feature Colours");
+            Cache.getProperty("LAST_DIRECTORY"), "fc",
+            "Sequence Feature Colours", "Sequence Feature Colours");
     chooser.setFileView(new jalview.io.JalviewFileView());
     chooser.setDialogTitle(MessageManager
             .getString("label.save_feature_colours"));
index 68245b6..35d4685 100644 (file)
@@ -36,6 +36,8 @@ import jalview.datamodel.StructureViewerModel;
 import jalview.datamodel.StructureViewerModel.StructureData;
 import jalview.ext.varna.RnaModel;
 import jalview.gui.StructureViewer.ViewerType;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
 import jalview.schemabinding.version2.AlcodMap;
 import jalview.schemabinding.version2.AlcodonFrame;
 import jalview.schemabinding.version2.Annotation;
@@ -974,14 +976,14 @@ public class Jalview2XML
           if (entry.getProperty() != null && !entry.getProperty().isEmpty())
           {
             PdbentryItem item = new PdbentryItem();
-            Hashtable properties = entry.getProperty();
-            Enumeration en2 = properties.keys();
+            Hashtable<String, String> properties = entry.getProperty();
+            Enumeration<String> en2 = properties.keys();
             while (en2.hasMoreElements())
             {
               Property prop = new Property();
-              String key = en2.nextElement().toString();
+              String key = en2.nextElement();
               prop.setName(key);
-              prop.setValue(properties.get(key).toString());
+              prop.setValue(properties.get(key));
               item.addProperty(prop);
             }
             pdb.addPdbentryItem(item);
@@ -4144,8 +4146,7 @@ public class Jalview2XML
       StructureData filedat = oldFiles.get(id);
       String pdbFile = filedat.getFilePath();
       SequenceI[] seq = filedat.getSeqList().toArray(new SequenceI[0]);
-      binding.getSsm().setMapping(seq, null, pdbFile,
-              jalview.io.AppletFormatAdapter.FILE);
+      binding.getSsm().setMapping(seq, null, pdbFile, DataSourceType.FILE);
       binding.addSequenceForStructFile(pdbFile, seq);
     }
     // and add the AlignmentPanel's reference to the view panel
@@ -4260,7 +4261,7 @@ public class Jalview2XML
     af = new AlignFrame(al, view.getWidth(), view.getHeight(),
             uniqueSeqSetId, viewId);
 
-    af.setFileName(file, "Jalview");
+    af.setFileName(file, FileFormat.Jalview);
 
     for (int i = 0; i < JSEQ.length; i++)
     {
index 61e20fa..4a582de 100755 (executable)
@@ -35,6 +35,7 @@ import jalview.binding.Tree;
 import jalview.binding.UserColours;
 import jalview.binding.Viewport;
 import jalview.datamodel.PDBEntry;
+import jalview.io.FileFormat;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ColourSchemeProperty;
 import jalview.schemes.ResidueProperties;
@@ -305,7 +306,7 @@ public class Jalview2XML_V1
 
     AlignFrame af = new AlignFrame(al, view.getWidth(), view.getHeight());
 
-    af.setFileName(file, "Jalview");
+    af.setFileName(file, FileFormat.Jalview);
 
     for (int i = 0; i < JSEQ.length; i++)
     {
index 7a54732..76d2703 100644 (file)
@@ -24,6 +24,7 @@ import jalview.api.AlignmentViewPanel;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.ext.rbvi.chimera.JalviewChimeraBinding;
+import jalview.io.DataSourceType;
 import jalview.structure.StructureSelectionManager;
 
 public class JalviewChimeraBindingModel extends JalviewChimeraBinding
@@ -34,7 +35,8 @@ public class JalviewChimeraBindingModel extends JalviewChimeraBinding
 
   public JalviewChimeraBindingModel(ChimeraViewFrame chimeraViewFrame,
           StructureSelectionManager ssm, PDBEntry[] pdbentry,
-          SequenceI[][] sequenceIs, String[][] chains, String protocol)
+          SequenceI[][] sequenceIs, String[][] chains,
+          DataSourceType protocol)
   {
     super(ssm, pdbentry, sequenceIs, chains, protocol);
     cvf = chimeraViewFrame;
@@ -72,6 +74,7 @@ public class JalviewChimeraBindingModel extends JalviewChimeraBinding
   {
     javax.swing.SwingUtilities.invokeLater(new Runnable()
     {
+      @Override
       public void run()
       {
         cvf.updateTitleAndMenus();
@@ -80,6 +83,7 @@ public class JalviewChimeraBindingModel extends JalviewChimeraBinding
     });
   }
 
+  @Override
   public void updateColours(Object source)
   {
     AlignmentPanel ap = (AlignmentPanel) source;
@@ -113,6 +117,7 @@ public class JalviewChimeraBindingModel extends JalviewChimeraBinding
    * Send an asynchronous command to Chimera, in a new thread, optionally with
    * an 'in progress' message in a progress bar somewhere
    */
+  @Override
   protected void sendAsynchronousCommand(final String command,
           final String progressMsg)
   {
index d28dc60..52a0d41 100644 (file)
@@ -38,6 +38,8 @@ import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
+import jalview.io.FileFormat;
+import jalview.io.FileFormatI;
 import jalview.io.FormatAdapter;
 import jalview.io.SequenceAnnotationReport;
 import jalview.schemes.AnnotationColourGradient;
@@ -2334,8 +2336,8 @@ public class PopupMenu extends JPopupMenu
     // or we simply trust the user wants
     // wysiwig behaviour
 
-    cap.setText(new FormatAdapter(ap).formatSequences(e.getActionCommand(),
-            ap, true));
+    FileFormatI fileFormat = FileFormat.forName(e.getActionCommand());
+    cap.setText(new FormatAdapter(ap).formatSequences(fileFormat, ap, true));
   }
 
   public void sequenceFeature_actionPerformed()
index afc93e0..1ac17e4 100755 (executable)
@@ -683,12 +683,14 @@ public class Preferences extends GPreferences
   @Override
   public void startupFileTextfield_mouseClicked()
   {
-    JalviewFileChooser chooser = new JalviewFileChooser(
-            jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] {
-                "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",
-                "jar" }, new String[] { "Fasta", "Clustal", "PFAM", "MSF",
-                "PIR", "BLC", "Jalview" },
-            jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
+    String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
+    JalviewFileChooser chooser = JalviewFileChooser.forRead(
+            Cache.getProperty("LAST_DIRECTORY"), fileFormat, true);
+    // new String[] {
+    // "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",
+    // "jar" }, new String[] { "Fasta", "Clustal", "PFAM", "MSF",
+    // "PIR", "BLC", "Jalview" },
+    // fileFormat);
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager
             .getString("label.select_startup_file"));
@@ -697,8 +699,9 @@ public class Preferences extends GPreferences
 
     if (value == JalviewFileChooser.APPROVE_OPTION)
     {
-      jalview.bin.Cache.applicationProperties.setProperty(
-              "DEFAULT_FILE_FORMAT", chooser.getSelectedFormat());
+      Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
+              chooser
+                      .getSelectedFormat().toString());
       startupFileTextfield.setText(chooser.getSelectedFile()
               .getAbsolutePath());
     }
index 828a2aa..fca130b 100755 (executable)
@@ -28,6 +28,7 @@ import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.fts.service.pdb.PDBFTSPanel;
 import jalview.fts.service.uniprot.UniprotFTSPanel;
+import jalview.io.FileFormatI;
 import jalview.io.gff.SequenceOntologyI;
 import jalview.util.DBRefUtils;
 import jalview.util.MessageManager;
@@ -894,7 +895,7 @@ public class SequenceFetcher extends JPanel implements Runnable
   }
 
   AlignmentI parseResult(AlignmentI al, String title,
-          String currentFileFormat,
+          FileFormatI currentFileFormat,
           FeatureSettingsModelI preferredFeatureColours)
   {
 
index 13fa460..3581cf9 100644 (file)
@@ -32,6 +32,7 @@ import jalview.fts.api.FTSRestClientI;
 import jalview.fts.core.FTSRestRequest;
 import jalview.fts.core.FTSRestResponse;
 import jalview.fts.service.pdb.PDBFTSRestClient;
+import jalview.io.DataSourceType;
 import jalview.jbgui.GStructureChooser;
 import jalview.structure.StructureSelectionManager;
 import jalview.util.MessageManager;
@@ -828,7 +829,7 @@ public class StructureChooser extends GStructureChooser implements
       }
       PDBEntry fileEntry = new AssociatePdbFileWithSeq()
               .associatePdbWithSeq(selectedPdbFileName,
-                      jalview.io.AppletFormatAdapter.FILE,
+                          DataSourceType.FILE,
                       selectedSequence, true, Desktop.instance);
 
           launchStructureViewer(ssm, new PDBEntry[] { fileEntry }, ap,
index 7df42fd..e295dfb 100644 (file)
@@ -24,7 +24,7 @@ import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.gui.StructureViewer.ViewerType;
 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
-import jalview.io.AppletFormatAdapter;
+import jalview.io.DataSourceType;
 import jalview.jbgui.GStructureViewer;
 import jalview.structures.models.AAStructureBindingModel;
 import jalview.util.MessageManager;
@@ -152,6 +152,7 @@ public abstract class StructureViewerBase extends GStructureViewer
     this.ap = alp;
   }
 
+  @Override
   public AlignmentPanel[] getAllAlignmentPanels()
   {
     AlignmentPanel[] t, list = new AlignmentPanel[0];
@@ -291,6 +292,7 @@ public abstract class StructureViewerBase extends GStructureViewer
         // queue.
         new Thread(new Runnable()
         {
+          @Override
           public void run()
           {
             while (worker != null && worker.isAlive() && _started)
@@ -411,7 +413,7 @@ public abstract class StructureViewerBase extends GStructureViewer
      * create the mappings
      */
     apanel.getStructureSelectionManager().setMapping(seq, chains,
-            pdbFilename, AppletFormatAdapter.FILE);
+            pdbFilename, DataSourceType.FILE);
 
     /*
      * alert the FeatureRenderer to show new (PDB RESNUM) features
index fafa610..af84dbc 100755 (executable)
@@ -42,6 +42,7 @@ import jalview.io.JalviewFileView;
 import jalview.io.NewickFile;
 import jalview.jbgui.GTreePanel;
 import jalview.schemes.ResidueProperties;
+import jalview.util.ImageMaker;
 import jalview.util.MessageManager;
 import jalview.viewmodel.AlignmentViewport;
 
@@ -747,24 +748,24 @@ public class TreePanel extends GTreePanel
 
     try
     {
-      jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
-              jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[]
-              { "eps" }, new String[] { "Encapsulated Postscript" },
-              "Encapsulated Postscript");
-      chooser.setFileView(new jalview.io.JalviewFileView());
+      JalviewFileChooser chooser = new JalviewFileChooser(
+              Cache.getProperty("LAST_DIRECTORY"),
+              ImageMaker.EPS_EXTENSION, ImageMaker.EPS_EXTENSION,
+              ImageMaker.EPS_EXTENSION);
+      chooser.setFileView(new JalviewFileView());
       chooser.setDialogTitle(MessageManager
               .getString("label.create_eps_from_tree"));
       chooser.setToolTipText(MessageManager.getString("action.save"));
 
       int value = chooser.showSaveDialog(this);
 
-      if (value != jalview.io.JalviewFileChooser.APPROVE_OPTION)
+      if (value != JalviewFileChooser.APPROVE_OPTION)
       {
         return;
       }
 
-      jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
-              .getSelectedFile().getParent());
+      Cache.setProperty("LAST_DIRECTORY", chooser.getSelectedFile()
+              .getParent());
 
       FileOutputStream out = new FileOutputStream(chooser.getSelectedFile());
       EpsGraphics2D pg = new EpsGraphics2D("Tree", out, 0, 0, width, height);
@@ -795,10 +796,10 @@ public class TreePanel extends GTreePanel
 
     try
     {
-      jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
-              jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[]
-              { "png" }, new String[] { "Portable network graphics" },
-              "Portable network graphics");
+      JalviewFileChooser chooser = new JalviewFileChooser(
+              Cache.getProperty("LAST_DIRECTORY"),
+              ImageMaker.PNG_EXTENSION, ImageMaker.PNG_DESCRIPTION,
+              ImageMaker.PNG_DESCRIPTION);
 
       chooser.setFileView(new jalview.io.JalviewFileView());
       chooser.setDialogTitle(MessageManager
index c9c1531..80fd5f6 100755 (executable)
@@ -21,6 +21,7 @@
 package jalview.gui;
 
 import jalview.api.structures.JalviewStructureDisplayI;
+import jalview.bin.Cache;
 import jalview.datamodel.SequenceGroup;
 import jalview.io.JalviewFileChooser;
 import jalview.jbgui.GUserDefinedColours;
@@ -597,9 +598,8 @@ public class UserDefinedColours extends GUserDefinedColours implements
     lowerCaseButtons = new ArrayList<JButton>();
 
     JalviewFileChooser chooser = new JalviewFileChooser(
-            jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
-            new String[] { "jc" }, new String[] { "Jalview User Colours" },
-            "Jalview User Colours");
+            Cache.getProperty("LAST_DIRECTORY"), "jc",
+            "Jalview User Colours", "Jalview User Colours");
     chooser.setFileView(new jalview.io.JalviewFileView());
     chooser.setDialogTitle(MessageManager
             .getString("label.load_colour_scheme"));
@@ -833,9 +833,8 @@ public class UserDefinedColours extends GUserDefinedColours implements
       userColourSchemes.remove(schemeName.getText());
     }
     JalviewFileChooser chooser = new JalviewFileChooser(
-            jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
-            new String[] { "jc" }, new String[] { "Jalview User Colours" },
-            "Jalview User Colours");
+            Cache.getProperty("LAST_DIRECTORY"), "jc",
+            "Jalview User Colours", "Jalview User Colours");
 
     chooser.setFileView(new jalview.io.JalviewFileView());
     chooser.setDialogTitle(MessageManager
index b6a7672..aec79e4 100644 (file)
@@ -22,6 +22,7 @@ package jalview.gui;
 
 import jalview.bin.Cache;
 import jalview.io.JalviewFileChooser;
+import jalview.io.JalviewFileView;
 import jalview.util.MessageManager;
 import jalview.ws.params.ParamDatastoreI;
 import jalview.ws.params.ParamManager;
@@ -185,11 +186,9 @@ public class WsParamSetManager implements ParamManager
     if (filename == null)
     {
       JalviewFileChooser chooser = new JalviewFileChooser(
-              jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[]
-              { "wsparams" },
-              new String[] { "Web Service Parameter File" },
-              "Web Service Parameter File");
-      chooser.setFileView(new jalview.io.JalviewFileView());
+              Cache.getProperty("LAST_DIRECTORY"), "wsparams",
+              "Web Service Parameter File", "Web Service Parameter File");
+      chooser.setFileView(new JalviewFileView());
       chooser.setDialogTitle(MessageManager
               .getString("label.choose_filename_for_param_file"));
       chooser.setToolTipText(MessageManager.getString("action.save"));
index f82407e..798249f 100644 (file)
@@ -22,6 +22,7 @@ package jalview.io;
 
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SequenceI;
 
 public class AMSAFile extends jalview.io.FastaFile
 {
@@ -41,9 +42,9 @@ public class AMSAFile extends jalview.io.FastaFile
    * 
    * @return DOCUMENT ME!
    */
-  public String print()
+  public String print(SequenceI[] sqs, boolean jvsuffix)
   {
-    super.print(getSeqsAsArray());
+    super.print(sqs, jvsuffix);
 
     AlignmentAnnotation aa;
     if (al.getAlignmentAnnotation() != null)
index 5760fbe..d333c64 100755 (executable)
@@ -40,7 +40,7 @@ import java.util.Vector;
  * @author $author$
  * @version $Revision$
  */
-public abstract class AlignFile extends FileParse
+public abstract class AlignFile extends FileParse implements AlignmentFileI
 {
   int noSeqs = 0;
 
@@ -71,8 +71,6 @@ public abstract class AlignFile extends FileParse
 
   long end;
 
-  boolean jvSuffix = true;
-
   private boolean parseCalled;
 
   /**
@@ -86,17 +84,24 @@ public abstract class AlignFile extends FileParse
     initData();
   }
 
+  public AlignFile(SequenceI[] seqs)
+  {
+    this();
+    setSeqs(seqs);
+  }
+
   /**
    * Constructor which parses the data from a file of some specified type.
    * 
    * @param dataObject
    *          Filename, URL or Pasted String to read from.
-   * @param type
+   * @param sourceType
    *          What type of file to read from (File, URL, Pasted String)
    */
-  public AlignFile(String dataObject, String type) throws IOException
+  public AlignFile(String dataObject, DataSourceType sourceType)
+          throws IOException
   {
-    this(true, dataObject, type);
+    this(true, dataObject, sourceType);
   }
 
   /**
@@ -107,14 +112,15 @@ public abstract class AlignFile extends FileParse
    *          if false, need to call 'doParse()' to begin parsing data
    * @param dataObject
    *          Filename, URL or Pasted String to read from.
-   * @param type
+   * @param sourceType
    *          What type of file to read from (File, URL)
    * @throws IOException
    */
-  public AlignFile(boolean parseImmediately, String dataObject, String type)
+  public AlignFile(boolean parseImmediately, String dataObject,
+          DataSourceType sourceType)
           throws IOException
   {
-    super(dataObject, type);
+    super(dataObject, sourceType);
     initData();
     if (parseImmediately)
     {
@@ -191,6 +197,7 @@ public abstract class AlignFile extends FileParse
   /**
    * Return the Sequences in the seqs Vector as an array of Sequences
    */
+  @Override
   public SequenceI[] getSeqsAsArray()
   {
     SequenceI[] s = new SequenceI[seqs.size()];
@@ -209,6 +216,7 @@ public abstract class AlignFile extends FileParse
    * 
    * @param al
    */
+  @Override
   public void addAnnotations(AlignmentI al)
   {
     addProperties(al);
@@ -314,7 +322,8 @@ public abstract class AlignFile extends FileParse
    * @param s
    *          DOCUMENT ME!
    */
-  protected void setSeqs(SequenceI[] s)
+  @Override
+  public void setSeqs(SequenceI[] s)
   {
     seqs = new Vector<SequenceI>();
 
@@ -330,16 +339,6 @@ public abstract class AlignFile extends FileParse
   public abstract void parse() throws IOException;
 
   /**
-   * Print out in alignment file format the Sequences in the seqs Vector.
-   */
-  public abstract String print();
-
-  public void addJVSuffix(boolean b)
-  {
-    jvSuffix = b;
-  }
-
-  /**
    * A general parser for ids.
    * 
    * @String id Id to be parsed
@@ -371,14 +370,21 @@ public abstract class AlignFile extends FileParse
   }
 
   /**
-   * Creates the output id. Adds prefix Uniprot format source|id And suffix
-   * Jalview /start-end
+   * Creates the output id. Adds prefix Uniprot format source|id and optionally
+   * suffix Jalview /start-end
+   * 
+   * @param jvsuffix
    * 
    * @String id Id to be parsed
    */
+  String printId(SequenceI seq, boolean jvsuffix)
+  {
+    return seq.getDisplayId(jvsuffix);
+  }
+
   String printId(SequenceI seq)
   {
-    return seq.getDisplayId(jvSuffix);
+    return printId(seq, true);
   }
 
   /**
@@ -400,6 +406,7 @@ public abstract class AlignFile extends FileParse
     return newickStrings == null ? 0 : newickStrings.size();
   }
 
+  @Override
   public void addGroups(AlignmentI al)
   {
 
diff --git a/src/jalview/io/AlignmentFileI.java b/src/jalview/io/AlignmentFileI.java
new file mode 100644 (file)
index 0000000..1a000a3
--- /dev/null
@@ -0,0 +1,38 @@
+package jalview.io;
+
+import jalview.api.AlignExportSettingI;
+import jalview.api.AlignmentViewPanel;
+import jalview.api.FeatureSettingsModelI;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SequenceI;
+
+public interface AlignmentFileI
+{
+
+  SequenceI[] getSeqsAsArray();
+
+  void addAnnotations(AlignmentI al);
+
+  void addGroups(AlignmentI al);
+
+  void setNewlineString(String newline);
+
+  void setExportSettings(AlignExportSettingI exportSettings);
+
+  void configureForView(AlignmentViewPanel viewpanel);
+
+  void setSeqs(SequenceI[] sequencesArray);
+
+  String print(SequenceI[] seqs, boolean jvsuffix);
+
+  boolean hasWarningMessage();
+
+  String getWarningMessage();
+
+  String getInFile();
+
+  DataSourceType getDataSourceType();
+
+  FeatureSettingsModelI getFeatureColourScheme();
+
+}
index d738882..6e121b3 100755 (executable)
@@ -661,7 +661,7 @@ public class AnnotationFile
   String refSeqId = null;
 
   public boolean annotateAlignmentView(AlignViewportI viewport,
-          String file, String protocol)
+          String file, DataSourceType protocol)
   {
     ColumnSelection colSel = viewport.getColumnSelection();
     if (colSel == null)
@@ -679,31 +679,31 @@ public class AnnotationFile
   }
 
   public boolean readAnnotationFile(AlignmentI al, String file,
-          String protocol)
+          DataSourceType sourceType)
   {
-    return readAnnotationFile(al, null, file, protocol);
+    return readAnnotationFile(al, null, file, sourceType);
   }
 
   public boolean readAnnotationFile(AlignmentI al, ColumnSelection colSel,
-          String file, String protocol)
+          String file, DataSourceType sourceType)
   {
     BufferedReader in = null;
     try
     {
-      if (protocol.equals(AppletFormatAdapter.FILE))
+      if (sourceType == DataSourceType.FILE)
       {
         in = new BufferedReader(new FileReader(file));
       }
-      else if (protocol.equals(AppletFormatAdapter.URL))
+      else if (sourceType == DataSourceType.URL)
       {
         URL url = new URL(file);
         in = new BufferedReader(new InputStreamReader(url.openStream()));
       }
-      else if (protocol.equals(AppletFormatAdapter.PASTE))
+      else if (sourceType == DataSourceType.PASTE)
       {
         in = new BufferedReader(new StringReader(file));
       }
-      else if (protocol.equals(AppletFormatAdapter.CLASSLOADER))
+      else if (sourceType == DataSourceType.CLASSLOADER)
       {
         java.io.InputStream is = getClass().getResourceAsStream("/" + file);
         if (is != null)
index 55bb03d..04d68e8 100755 (executable)
@@ -27,8 +27,9 @@ import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.AlignmentView;
 import jalview.datamodel.PDBEntry.Type;
+import jalview.datamodel.SequenceI;
+import jalview.ext.jmol.JmolParser;
 import jalview.structure.StructureImportSettings;
-import jalview.util.MessageManager;
 
 import java.io.File;
 import java.io.IOException;
@@ -48,14 +49,6 @@ public class AppletFormatAdapter
 {
   private AlignmentViewPanel viewpanel;
 
-  public static String FILE = "File";
-
-  public static String URL = "URL";
-
-  public static String PASTE = "Paste";
-
-  public static String CLASSLOADER = "ClassLoader";
-
   /**
    * add jalview-derived non-secondary structure annotation from PDB structure
    */
@@ -71,7 +64,7 @@ public class AppletFormatAdapter
    */
   boolean serviceSecondaryStruct = false;
 
-  private AlignFile alignFile = null;
+  private AlignmentFileI alignFile = null;
 
   String inFile;
 
@@ -87,7 +80,7 @@ public class AppletFormatAdapter
    */
   public static final String[] READABLE_FORMATS = new String[] { "BLC",
       "CLUSTAL", "FASTA", "MSF", "PileUp", "PIR", "PFAM", "STH", "PDB",
-      "JnetFile", "RNAML", PhylipFile.FILE_DESC, JSONFile.FILE_DESC,
+      "JnetFile", "RNAML", "PHYLIP", "JSON",
       IdentifyFile.FeaturesFile, "HTML", "mmCIF" };
 
   /**
@@ -96,8 +89,8 @@ public class AppletFormatAdapter
    */
   public static final String[] READABLE_EXTENSIONS = new String[] {
       "fa, fasta, mfa, fastq", "aln", "pfam", "msf", "pir", "blc", "amsa",
-      "sto,stk", "xml,rnaml", PhylipFile.FILE_EXT, JSONFile.FILE_EXT,
-      ".gff2,gff3", "jar,jvp", HtmlFile.FILE_EXT, "cif" };
+      "sto,stk", "xml,rnaml", "phy", "json",
+      ".gff2,gff3", "jar,jvp", "html", "cif" };
 
   /**
    * List of readable formats by application in order corresponding to
@@ -105,7 +98,7 @@ public class AppletFormatAdapter
    */
   public static final String[] READABLE_FNAMES = new String[] { "Fasta",
       "Clustal", "PFAM", "MSF", "PIR", "BLC", "AMSA", "Stockholm", "RNAML",
-      PhylipFile.FILE_DESC, JSONFile.FILE_DESC, IdentifyFile.FeaturesFile,
+      "PHYLIP", "JSON", IdentifyFile.FeaturesFile,
       "Jalview", HtmlFile.FILE_DESC, "mmCIF" };
 
   /**
@@ -114,7 +107,7 @@ public class AppletFormatAdapter
    */
   public static final String[] WRITEABLE_FORMATS = new String[] { "BLC",
       "CLUSTAL", "FASTA", "MSF", "PileUp", "PIR", "PFAM", "AMSA", "STH",
-      PhylipFile.FILE_DESC, JSONFile.FILE_DESC };
+      "PHYLIP", "JSON" };
 
   /**
    * List of extensions corresponding to file format types in WRITABLE_FNAMES
@@ -122,7 +115,7 @@ public class AppletFormatAdapter
    */
   public static final String[] WRITABLE_EXTENSIONS = new String[] {
       "fa, fasta, mfa, fastq", "aln", "pfam", "msf", "pir", "blc", "amsa",
-      "sto,stk", PhylipFile.FILE_EXT, JSONFile.FILE_EXT, "jvp" };
+      "sto,stk", "phy", "json", "jvp" };
 
   /**
    * List of writable formats by the application. Order must correspond with the
@@ -130,7 +123,7 @@ public class AppletFormatAdapter
    */
   public static final String[] WRITABLE_FNAMES = new String[] { "Fasta",
       "Clustal", "PFAM", "MSF", "PIR", "BLC", "AMSA", "STH",
-      PhylipFile.FILE_DESC, JSONFile.FILE_DESC, "Jalview" };
+      "PHYLIP", "JSON", "Jalview" };
 
   public static String INVALID_CHARACTERS = "Contains invalid characters";
 
@@ -182,102 +175,23 @@ public class AppletFormatAdapter
   }
 
   /**
-   * check that this format is valid for reading
-   *
-   * @param format
-   *          a format string to be compared with READABLE_FORMATS
-   * @return true if format is readable
-   */
-  public static final boolean isValidFormat(String format)
-  {
-    return isValidFormat(format, false);
-  }
-
-  /**
-   * validate format is valid for IO
-   *
-   * @param format
-   *          a format string to be compared with either READABLE_FORMATS or
-   *          WRITEABLE_FORMATS
-   * @param forwriting
-   *          when true, format is checked for containment in WRITEABLE_FORMATS
-   * @return true if format is valid
-   */
-  public static final boolean isValidFormat(String format,
-          boolean forwriting)
-  {
-    if (format == null)
-    {
-      return false;
-    }
-    boolean valid = false;
-    String[] format_list = (forwriting) ? WRITEABLE_FORMATS
-            : READABLE_FORMATS;
-    for (String element : format_list)
-    {
-      if (element.equalsIgnoreCase(format))
-      {
-        return true;
-      }
-    }
-
-    return valid;
-  }
-
-  /**
    * Constructs the correct filetype parser for a characterised datasource
    *
    * @param inFile
    *          data/data location
-   * @param type
+   * @param sourceType
    *          type of datasource
-   * @param format
-   *          File format of data provided by datasource
+   * @param fileFormat
    *
-   * @return DOCUMENT ME!
+   * @return
    */
-  public AlignmentI readFile(String inFile, String type, String format)
-          throws java.io.IOException
+  public AlignmentI readFile(String file, DataSourceType sourceType,
+          FileFormatI fileFormat) throws IOException
   {
-    // TODO: generalise mapping between format string and io. class instances
-    // using Constructor.invoke reflection
-    this.inFile = inFile;
+    this.inFile = file;
     try
     {
-      if (format.equals("FASTA"))
-      {
-        alignFile = new FastaFile(inFile, type);
-      }
-      else if (format.equals("MSF"))
-      {
-        alignFile = new MSFfile(inFile, type);
-      }
-      else if (format.equals("PileUp"))
-      {
-        alignFile = new PileUpfile(inFile, type);
-      }
-      else if (format.equals("CLUSTAL"))
-      {
-        alignFile = new ClustalFile(inFile, type);
-      }
-      else if (format.equals("BLC"))
-      {
-        alignFile = new BLCFile(inFile, type);
-      }
-      else if (format.equals("PIR"))
-      {
-        alignFile = new PIRFile(inFile, type);
-      }
-      else if (format.equals("PFAM"))
-      {
-        alignFile = new PfamFile(inFile, type);
-      }
-      else if (format.equals("JnetFile"))
-      {
-        alignFile = new JPredFile(inFile, type);
-        ((JPredFile) alignFile).removeNonSequences();
-      }
-      else if (format.equals("PDB"))
+      if (fileFormat == FileFormat.PDB || fileFormat == FileFormat.MMCif)
       {
         // TODO obtain config value from preference settings.
         // Set value to 'true' to test PDB processing with Jmol: JAL-1213
@@ -289,9 +203,9 @@ public class AppletFormatAdapter
         {
           StructureImportSettings.addSettings(annotFromStructure,
                   localSecondaryStruct, serviceSecondaryStruct);
-          alignFile = new jalview.ext.jmol.JmolParser(annotFromStructure,
+          alignFile = new JmolParser(annotFromStructure,
                   localSecondaryStruct, serviceSecondaryStruct, inFile,
-                  type);
+                  sourceType);
         }
         else
         {
@@ -300,85 +214,72 @@ public class AppletFormatAdapter
           StructureImportSettings.setShowSeqFeatures(true);
           alignFile = new MCview.PDBfile(annotFromStructure,
                   localSecondaryStruct, serviceSecondaryStruct, inFile,
-                  type);
+                  sourceType);
         }
-        ((StructureFile) alignFile).setDbRefType(format);
-      }
-      else if (format.equalsIgnoreCase("mmCIF"))
-      {
-        StructureImportSettings.addSettings(annotFromStructure,
-                localSecondaryStruct, serviceSecondaryStruct);
-        alignFile = new jalview.ext.jmol.JmolParser(annotFromStructure,
-                localSecondaryStruct, serviceSecondaryStruct, inFile, type);
-        ((StructureFile) alignFile).setDbRefType(format);
-      }
-      else if (format.equals("STH"))
-      {
-        alignFile = new StockholmFile(inFile, type);
+        ((StructureFile) alignFile)
+                .setDbRefType(fileFormat == FileFormat.PDB ? Type.PDB
+                        : Type.MMCIF);
       }
-      else if (format.equals("SimpleBLAST"))
-      {
-        alignFile = new SimpleBlastFile(inFile, type);
-      }
-      else if (format.equals(PhylipFile.FILE_DESC))
-      {
-        alignFile = new PhylipFile(inFile, type);
-      }
-      else if (format.equals(JSONFile.FILE_DESC))
-      {
-        alignFile = new JSONFile(inFile, type);
-      }
-      else if (format.equals(HtmlFile.FILE_DESC))
-      {
-        alignFile = new HtmlFile(inFile, type);
-      }
-      else if (format.equals("RNAML"))
-      {
-        alignFile = new RnamlFile(inFile, type);
-      }
-      else if (format.equals(IdentifyFile.FeaturesFile))
+      else
       {
-        alignFile = new FeaturesFile(true, inFile, type);
-      }
-      return buildAlignmentFrom(alignFile);
+        alignFile = fileFormat.getAlignmentFile(inFile, sourceType);
+      }
+        // new FastaFile(inFile, sourceType);
+        // new MSFfile(inFile, sourceType);
+        // new PileUpfile(inFile, sourceType);
+        // new ClustalFile(inFile, sourceType);
+        // new BLCFile(inFile, sourceType);
+        // new PIRFile(inFile, sourceType);
+        // new PfamFile(inFile, sourceType);
+        // alignFile = new JPredFile(inFile, sourceType);
+        // ((JPredFile) alignFile).removeNonSequences();
+        // new StockholmFile(inFile, sourceType);
+        // new SimpleBlastFile(inFile, sourceType);
+        // new PhylipFile(inFile, sourceType);
+        // new JSONFile(inFile, sourceType);
+        // new HtmlFile(inFile, sourceType);
+        // new RnamlFile(inFile, sourceType);
+//        alignFile = new FeaturesFile(true, inFile, sourceType);
+      return buildAlignmentFromFile();
     } catch (Exception e)
     {
       e.printStackTrace();
-      System.err.println("Failed to read alignment using the '" + format
+      System.err.println("Failed to read alignment using the '"
+              + fileFormat
               + "' reader.\n" + e);
 
       if (e.getMessage() != null
               && e.getMessage().startsWith(INVALID_CHARACTERS))
       {
-        throw new java.io.IOException(e.getMessage());
+        throw new IOException(e.getMessage());
       }
 
       // Finally test if the user has pasted just the sequence, no id
-      if (type.equalsIgnoreCase("Paste"))
+      if (sourceType == DataSourceType.PASTE)
       {
         try
         {
           // Possible sequence is just residues with no label
-          alignFile = new FastaFile(">UNKNOWN\n" + inFile, "Paste");
-          return buildAlignmentFrom(alignFile);
+          alignFile = new FastaFile(">UNKNOWN\n" + inFile,
+                  DataSourceType.PASTE);
+          return buildAlignmentFromFile();
 
         } catch (Exception ex)
         {
           if (ex.toString().startsWith(INVALID_CHARACTERS))
           {
-            throw new java.io.IOException(e.getMessage());
+            throw new IOException(e.getMessage());
           }
 
           ex.printStackTrace();
         }
       }
-      if (format.equalsIgnoreCase("HTML"))
+      if (fileFormat == FileFormat.Html)
       {
         throw new IOException(e.getMessage());
       }
-      // If we get to this stage, the format was not supported
-      throw new java.io.IOException(SUPPORTED_FORMATS);
     }
+    throw new FileFormatException(SUPPORTED_FORMATS);
   }
 
   /**
@@ -389,53 +290,16 @@ public class AppletFormatAdapter
    * @param format
    *          File format of data that will be provided by datasource
    *
-   * @return DOCUMENT ME!
+   * @return
    */
-  public AlignmentI readFromFile(FileParse source, String format)
-          throws java.io.IOException
+  public AlignmentI readFromFile(FileParse source, FileFormatI format)
+          throws IOException
   {
-    // TODO: generalise mapping between format string and io. class instances
-    // using Constructor.invoke reflection
-    // This is exactly the same as the readFile method except we substitute
-    // 'inFile, type' with 'source'
     this.inFile = source.getInFile();
-    String type = source.type;
+    DataSourceType type = source.dataSourceType;
     try
     {
-      if (format.equals("FASTA"))
-      {
-        alignFile = new FastaFile(source);
-      }
-      else if (format.equals("MSF"))
-      {
-        alignFile = new MSFfile(source);
-      }
-      else if (format.equals("PileUp"))
-      {
-        alignFile = new PileUpfile(source);
-      }
-      else if (format.equals("CLUSTAL"))
-      {
-        alignFile = new ClustalFile(source);
-      }
-      else if (format.equals("BLC"))
-      {
-        alignFile = new BLCFile(source);
-      }
-      else if (format.equals("PIR"))
-      {
-        alignFile = new PIRFile(source);
-      }
-      else if (format.equals("PFAM"))
-      {
-        alignFile = new PfamFile(source);
-      }
-      else if (format.equals("JnetFile"))
-      {
-        alignFile = new JPredFile(source);
-        ((JPredFile) alignFile).removeNonSequences();
-      }
-      else if (format.equals("PDB"))
+      if (format == FileFormat.PDB || format == FileFormat.MMCif)
       {
         // TODO obtain config value from preference settings
         boolean isParseWithJMOL = false;
@@ -443,7 +307,7 @@ public class AppletFormatAdapter
         {
           StructureImportSettings.addSettings(annotFromStructure,
                   localSecondaryStruct, serviceSecondaryStruct);
-          alignFile = new jalview.ext.jmol.JmolParser(annotFromStructure,
+          alignFile = new JmolParser(annotFromStructure,
                   localSecondaryStruct, serviceSecondaryStruct, source);
         }
         else
@@ -454,44 +318,12 @@ public class AppletFormatAdapter
         }
         ((StructureFile) alignFile).setDbRefType(Type.PDB);
       }
-      else if (format.equalsIgnoreCase("mmCIF"))
-      {
-        StructureImportSettings.addSettings(annotFromStructure,
-                localSecondaryStruct, serviceSecondaryStruct);
-        alignFile = new jalview.ext.jmol.JmolParser(annotFromStructure,
-                localSecondaryStruct, serviceSecondaryStruct, source);
-        ((StructureFile) alignFile).setDbRefType(Type.MMCIF);
-      }
-      else if (format.equals("STH"))
-      {
-        alignFile = new StockholmFile(source);
-      }
-      else if (format.equals("RNAML"))
-      {
-        alignFile = new RnamlFile(source);
-      }
-      else if (format.equals("SimpleBLAST"))
-      {
-        alignFile = new SimpleBlastFile(source);
-      }
-      else if (format.equals(PhylipFile.FILE_DESC))
-      {
-        alignFile = new PhylipFile(source);
-      }
-      else if (format.equals(IdentifyFile.FeaturesFile))
-      {
-        alignFile = new FeaturesFile(inFile, type);
-      }
-      else if (format.equals(JSONFile.FILE_DESC))
-      {
-        alignFile = new JSONFile(source);
-      }
-      else if (format.equals(HtmlFile.FILE_DESC))
+      else
       {
-        alignFile = new HtmlFile(source);
+        alignFile = format.getAlignmentFile(source);
       }
 
-      return buildAlignmentFrom(alignFile);
+      return buildAlignmentFromFile();
 
     } catch (Exception e)
     {
@@ -502,23 +334,24 @@ public class AppletFormatAdapter
       if (e.getMessage() != null
               && e.getMessage().startsWith(INVALID_CHARACTERS))
       {
-        throw new java.io.IOException(e.getMessage());
+        throw new FileFormatException(e.getMessage());
       }
 
       // Finally test if the user has pasted just the sequence, no id
-      if (type.equalsIgnoreCase("Paste"))
+      if (type == DataSourceType.PASTE)
       {
         try
         {
           // Possible sequence is just residues with no label
-          alignFile = new FastaFile(">UNKNOWN\n" + inFile, "Paste");
-          return buildAlignmentFrom(alignFile);
+          alignFile = new FastaFile(">UNKNOWN\n" + inFile,
+                  DataSourceType.PASTE);
+          return buildAlignmentFromFile();
 
         } catch (Exception ex)
         {
           if (ex.toString().startsWith(INVALID_CHARACTERS))
           {
-            throw new java.io.IOException(e.getMessage());
+            throw new IOException(e.getMessage());
           }
 
           ex.printStackTrace();
@@ -526,7 +359,7 @@ public class AppletFormatAdapter
       }
 
       // If we get to this stage, the format was not supported
-      throw new java.io.IOException(SUPPORTED_FORMATS);
+      throw new FileFormatException(SUPPORTED_FORMATS);
     }
   }
 
@@ -534,10 +367,9 @@ public class AppletFormatAdapter
    * boilerplate method to handle data from an AlignFile and construct a new
    * alignment or import to an existing alignment
    * 
-   * @param alignFile2
    * @return AlignmentI instance ready to pass to a UI constructor
    */
-  private AlignmentI buildAlignmentFrom(AlignFile alignFile2)
+  private AlignmentI buildAlignmentFromFile()
   {
     // Standard boilerplate for creating alignment from parser
     // alignFile.configureForView(viewpanel);
@@ -560,7 +392,7 @@ public class AppletFormatAdapter
    * @param selectedOnly
    * @return flatfile in a string
    */
-  public String formatSequences(String format, boolean jvsuffix,
+  public String formatSequences(FileFormatI format, boolean jvsuffix,
           AlignmentViewPanel ap, boolean selectedOnly)
   {
 
@@ -596,86 +428,31 @@ public class AppletFormatAdapter
    *
    * @return alignment flat file contents
    */
-  public String formatSequences(String format, AlignmentI alignment,
+  public String formatSequences(FileFormatI format, AlignmentI alignment,
           boolean jvsuffix)
   {
     try
     {
-      AlignFile afile = null;
-      if (format.equalsIgnoreCase("FASTA"))
-      {
-        afile = new FastaFile();
-      }
-      else if (format.equalsIgnoreCase("MSF"))
-      {
-        afile = new MSFfile();
-      }
-      else if (format.equalsIgnoreCase("PileUp"))
-      {
-        afile = new PileUpfile();
-      }
-      else if (format.equalsIgnoreCase("CLUSTAL"))
-      {
-        afile = new ClustalFile();
-      }
-      else if (format.equalsIgnoreCase("BLC"))
-      {
-        afile = new BLCFile();
-      }
-      else if (format.equalsIgnoreCase("PIR"))
-      {
-        afile = new PIRFile();
-      }
-      else if (format.equalsIgnoreCase("PFAM"))
-      {
-        afile = new PfamFile();
-      }
-      else if (format.equalsIgnoreCase("STH"))
-      {
-        afile = new StockholmFile(alignment);
-      }
-      else if (format.equalsIgnoreCase("AMSA"))
-      {
-        afile = new AMSAFile(alignment);
-      }
-      else if (format.equalsIgnoreCase(PhylipFile.FILE_DESC))
-      {
-        afile = new PhylipFile();
-      }
-      else if (format.equalsIgnoreCase(JSONFile.FILE_DESC))
-      {
-        afile = new JSONFile();
-      }
-      else if (format.equalsIgnoreCase("RNAML"))
-      {
-        afile = new RnamlFile();
-      }
-
-      else
-      {
-        throw new Exception(
-                MessageManager
-                        .getString("error.implementation_error_unknown_file_format_string"));
-      }
+      AlignmentFileI afile = format.getAlignmentFile();
 
       afile.setNewlineString(newline);
-      afile.addJVSuffix(jvsuffix);
       afile.setExportSettings(exportSettings);
       afile.configureForView(viewpanel);
 
       // check whether we were given a specific alignment to export, rather than
       // the one in the viewpanel
+      SequenceI[] seqs = null;
       if (viewpanel == null || viewpanel.getAlignment() == null
               || viewpanel.getAlignment() != alignment)
       {
-        afile.setSeqs(alignment.getSequencesArray());
+        seqs = alignment.getSequencesArray();
       }
       else
       {
-        afile.setSeqs(viewpanel.getAlignment().getSequencesArray());
+        seqs = viewpanel.getAlignment().getSequencesArray();
       }
 
-      String afileresp = afile.print();
+      String afileresp = afile.print(seqs, jvsuffix);
       if (afile.hasWarningMessage())
       {
         System.err.println("Warning raised when writing as " + format
@@ -692,14 +469,14 @@ public class AppletFormatAdapter
     return null;
   }
 
-  public static String checkProtocol(String file)
+  public static DataSourceType checkProtocol(String file)
   {
-    String protocol = FILE;
+    DataSourceType protocol = DataSourceType.FILE;
     String ft = file.toLowerCase().trim();
     if (ft.indexOf("http:") == 0 || ft.indexOf("https:") == 0
             || ft.indexOf("file:") == 0)
     {
-      protocol = URL;
+      protocol = DataSourceType.URL;
     }
     return protocol;
   }
@@ -720,8 +497,10 @@ public class AppletFormatAdapter
           System.gc();
           long memf = -r.totalMemory() + r.freeMemory();
           long t1 = -System.currentTimeMillis();
-          AlignmentI al = afa.readFile(args[i], FILE,
-                  new IdentifyFile().identify(args[i], FILE));
+          AlignmentI al = afa
+                  .readFile(args[i], DataSourceType.FILE,
+                          new IdentifyFile().identify(args[i],
+                                  DataSourceType.FILE));
           t1 += System.currentTimeMillis();
           System.gc();
           memf += r.totalMemory() - r.freeMemory();
@@ -732,7 +511,7 @@ public class AppletFormatAdapter
             try
             {
               System.out.println(new AppletFormatAdapter().formatSequences(
-                      "FASTA", al, true));
+                      FileFormat.Fasta, al, true));
             } catch (Exception e)
             {
               System.err
@@ -771,16 +550,17 @@ public class AppletFormatAdapter
    * @param format
    * @return protocol that yields the data parsable as the given type
    */
-  public static String resolveProtocol(String file, String format)
+  public static DataSourceType resolveProtocol(String file,
+          FileFormatI format)
   {
     return resolveProtocol(file, format, false);
   }
 
-  public static String resolveProtocol(String file, String format,
-          boolean debug)
+  public static DataSourceType resolveProtocol(String file,
+          FileFormatI format, boolean debug)
   {
     // TODO: test thoroughly!
-    String protocol = null;
+    DataSourceType protocol = null;
     if (debug)
     {
       System.out.println("resolving datasource started with:\n>>file\n"
@@ -804,10 +584,9 @@ public class AppletFormatAdapter
         System.err.println("Resource '" + file + "' was "
                 + (rtn ? "" : "not") + " located by classloader.");
       }
-      ;
       if (rtn)
       {
-        protocol = AppletFormatAdapter.CLASSLOADER;
+        protocol = DataSourceType.CLASSLOADER;
       }
 
     } catch (Exception ex)
@@ -818,12 +597,12 @@ public class AppletFormatAdapter
 
     if (file.indexOf("://") > -1)
     {
-      protocol = AppletFormatAdapter.URL;
+      protocol = DataSourceType.URL;
     }
     else
     {
       // skipping codebase prepend check.
-      protocol = AppletFormatAdapter.FILE;
+      protocol = DataSourceType.FILE;
     }
     FileParse fp = null;
     try
@@ -859,7 +638,7 @@ public class AppletFormatAdapter
       {
         System.out.println("Accessing as paste.");
       }
-      protocol = AppletFormatAdapter.PASTE;
+      protocol = DataSourceType.PASTE;
       fp = null;
       try
       {
@@ -879,7 +658,7 @@ public class AppletFormatAdapter
     {
       return null;
     }
-    if (format == null || format.length() == 0)
+    if (format == null)
     {
       return protocol;
     }
@@ -887,7 +666,7 @@ public class AppletFormatAdapter
     {
       try
       {
-        String idformat = new jalview.io.IdentifyFile().identify(file,
+        FileFormatI idformat = new IdentifyFile().identify(file,
                 protocol);
         if (idformat == null)
         {
@@ -927,20 +706,13 @@ public class AppletFormatAdapter
           System.err.println("File deemed not accessible via " + protocol);
           e.printStackTrace();
         }
-        ;
-
       }
     }
     return null;
   }
 
-  public AlignFile getAlignFile()
+  public AlignmentFileI getAlignFile()
   {
     return alignFile;
   }
-
-  public void setAlignFile(AlignFile alignFile)
-  {
-    this.alignFile = alignFile;
-  }
 }
index a499f75..6317e83 100755 (executable)
@@ -48,15 +48,16 @@ public class BLCFile extends AlignFile
    * 
    * @param inFile
    *          DOCUMENT ME!
-   * @param type
+   * @param sourceType
    *          DOCUMENT ME!
    * 
    * @throws IOException
    *           DOCUMENT ME!
    */
-  public BLCFile(String inFile, String type) throws IOException
+  public BLCFile(String inFile, DataSourceType sourceType)
+          throws IOException
   {
-    super(inFile, type);
+    super(inFile, sourceType);
   }
 
   public BLCFile(FileParse source) throws IOException
@@ -67,6 +68,7 @@ public class BLCFile extends AlignFile
   /**
    * DOCUMENT ME!
    */
+  @Override
   public void initData()
   {
     super.initData();
@@ -89,6 +91,7 @@ public class BLCFile extends AlignFile
   /**
    * DOCUMENT ME!
    */
+  @Override
   public void parse() throws IOException
   {
     StringBuffer headerLines = new StringBuffer();
@@ -215,22 +218,13 @@ public class BLCFile extends AlignFile
   /**
    * DOCUMENT ME!
    * 
-   * @return DOCUMENT ME!
-   */
-  public String print()
-  {
-    return print(getSeqsAsArray());
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
    * @param s
    *          DOCUMENT ME!
    * 
    * @return DOCUMENT ME!
    */
-  public String print(SequenceI[] s)
+  @Override
+  public String print(SequenceI[] s, boolean jvsuffix)
   {
     StringBuffer out = new StringBuffer();
     /**
@@ -244,7 +238,7 @@ public class BLCFile extends AlignFile
 
     while ((i < s.length) && (s[i] != null))
     {
-      out.append(">" + printId(s[i]));
+      out.append(">" + printId(s[i], jvsuffix));
       if (s[i].getDescription() != null)
       {
         out.append(" " + s[i].getDescription());
index f8fa1f5..80df097 100644 (file)
@@ -22,12 +22,15 @@ package jalview.io;
 
 import jalview.api.AlignExportSettingI;
 import jalview.api.AlignmentViewPanel;
+import jalview.bin.Cache;
 import jalview.datamodel.AlignmentExportData;
 import jalview.exceptions.NoFileSelectedException;
+import jalview.gui.AlignFrame;
 import jalview.gui.IProgressIndicator;
 import jalview.gui.OOMWarning;
 import jalview.json.binding.biojs.BioJSReleasePojo;
 import jalview.json.binding.biojs.BioJSRepositoryPojo;
+import jalview.util.ImageMaker;
 import jalview.util.MessageManager;
 
 import java.io.BufferedInputStream;
@@ -125,11 +128,11 @@ public class BioJsHTMLOutput
         }
 
       };
-      AlignmentExportData exportData = jalview.gui.AlignFrame
-              .getAlignmentForExport(JSONFile.FILE_DESC,
+      AlignmentExportData exportData = AlignFrame
+              .getAlignmentForExport(FileFormat.Json,
                       ap.getAlignViewport(), exportSettings);
       String bioJSON = new FormatAdapter(ap, exportData.getSettings())
-              .formatSequences(JSONFile.FILE_DESC, exportData
+              .formatSequences(FileFormat.Json, exportData
                       .getAlignment(), exportData.getOmitHidden(),
                       exportData.getStartEndPostions(), ap
                               .getAlignViewport().getColumnSelection());
@@ -176,9 +179,8 @@ public class BioJsHTMLOutput
     }
 
     JalviewFileChooser jvFileChooser = new JalviewFileChooser(
-            jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
-            new String[] { "html" }, new String[] { "HTML files" },
-            "HTML files");
+            Cache.getProperty("LAST_DIRECTORY"), ImageMaker.HTML_EXTENSION,
+            ImageMaker.HTML_EXTENSION, ImageMaker.HTML_EXTENSION);
     jvFileChooser.setFileView(new JalviewFileView());
 
     jvFileChooser.setDialogTitle(MessageManager
@@ -188,7 +190,7 @@ public class BioJsHTMLOutput
     int fileChooserOpt = jvFileChooser.showSaveDialog(null);
     if (fileChooserOpt == JalviewFileChooser.APPROVE_OPTION)
     {
-      jalview.bin.Cache.setProperty("LAST_DIRECTORY", jvFileChooser
+      Cache.setProperty("LAST_DIRECTORY", jvFileChooser
               .getSelectedFile().getParent());
       selectedFile = jvFileChooser.getSelectedFile().getPath();
     }
index f7a45de..5d58d42 100755 (executable)
@@ -37,9 +37,10 @@ public class ClustalFile extends AlignFile
   {
   }
 
-  public ClustalFile(String inFile, String type) throws IOException
+  public ClustalFile(String inFile, DataSourceType sourceType)
+          throws IOException
   {
-    super(inFile, type);
+    super(inFile, sourceType);
   }
 
   public ClustalFile(FileParse source) throws IOException
@@ -196,13 +197,7 @@ public class ClustalFile extends AlignFile
   }
 
   @Override
-  public String print()
-  {
-    return print(getSeqsAsArray());
-    // TODO: locaRNA style aln output
-  }
-
-  public String print(SequenceI[] s)
+  public String print(SequenceI[] s, boolean jvsuffix)
   {
     StringBuffer out = new StringBuffer("CLUSTAL" + newline + newline);
 
@@ -213,7 +208,7 @@ public class ClustalFile extends AlignFile
 
     while ((i < s.length) && (s[i] != null))
     {
-      String tmp = printId(s[i]);
+      String tmp = printId(s[i], jvsuffix);
 
       if (s[i].getSequence().length > max)
       {
@@ -244,7 +239,8 @@ public class ClustalFile extends AlignFile
 
       while ((j < s.length) && (s[j] != null))
       {
-        out.append(new Format("%-" + maxid + "s").form(printId(s[j]) + " "));
+        out.append(new Format("%-" + maxid + "s").form(printId(s[j],
+                jvsuffix) + " "));
 
         int start = i * len;
         int end = start + len;
index 769f8b9..11cb4bf 100644 (file)
@@ -20,6 +20,8 @@
  */
 package jalview.io;
 
+import jalview.datamodel.SequenceI;
+
 import java.io.IOException;
 
 /**
@@ -32,13 +34,15 @@ import java.io.IOException;
 public class DBRefFile extends AlignFile
 {
 
+  @Override
   public void parse() throws IOException
   {
     // TODO Auto-generated method stub
 
   }
 
-  public String print()
+  @Override
+  public String print(SequenceI[] sqs, boolean jvsuffix)
   {
     // TODO Auto-generated method stub
     return null;
diff --git a/src/jalview/io/DataSourceType.java b/src/jalview/io/DataSourceType.java
new file mode 100644 (file)
index 0000000..e2808e8
--- /dev/null
@@ -0,0 +1,6 @@
+package jalview.io;
+
+public enum DataSourceType
+{
+  FILE, URL, PASTE, CLASSLOADER;
+}
index 4c2265c..9c8cdf6 100755 (executable)
@@ -55,15 +55,16 @@ public class FastaFile extends AlignFile
    * 
    * @param inFile
    *          DOCUMENT ME!
-   * @param type
+   * @param sourceType
    *          DOCUMENT ME!
    * 
    * @throws IOException
    *           DOCUMENT ME!
    */
-  public FastaFile(String inFile, String type) throws IOException
+  public FastaFile(String inFile, DataSourceType sourceType)
+          throws IOException
   {
-    super(inFile, type);
+    super(inFile, sourceType);
   }
 
   public FastaFile(FileParse source) throws IOException
@@ -71,6 +72,11 @@ public class FastaFile extends AlignFile
     super(source);
   }
 
+  public FastaFile(SequenceI[] seqs)
+  {
+    super(seqs);
+  }
+
   /**
    * DOCUMENT ME!
    * 
@@ -181,28 +187,15 @@ public class FastaFile extends AlignFile
     }
   }
 
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param s
-   *          DOCUMENT ME!
-   * @param len
-   *          DOCUMENT ME!
-   * @param gaps
-   *          DOCUMENT ME!
-   * @param displayId
-   *          DOCUMENT ME!
-   * 
-   * @return DOCUMENT ME!
-   */
-  public String print(SequenceI[] s)
+  @Override
+  public String print(SequenceI[] s, boolean jvsuffix)
   {
     out = new StringBuffer();
     int i = 0;
 
     while ((i < s.length) && (s[i] != null))
     {
-      out.append(">" + printId(s[i]));
+      out.append(">" + printId(s[i], jvsuffix));
       if (s[i].getDescription() != null)
       {
         out.append(" " + s[i].getDescription());
@@ -234,15 +227,4 @@ public class FastaFile extends AlignFile
 
     return out.toString();
   }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @return DOCUMENT ME!
-   */
-  @Override
-  public String print()
-  {
-    return print(getSeqsAsArray());
-  }
 }
index aa38540..20c44bc 100755 (executable)
@@ -94,12 +94,13 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
    * Constructor which does not parse the file immediately
    * 
    * @param inFile
-   * @param type
+   * @param paste
    * @throws IOException
    */
-  public FeaturesFile(String inFile, String type) throws IOException
+  public FeaturesFile(String inFile, DataSourceType paste)
+          throws IOException
   {
-    super(false, inFile, type);
+    super(false, inFile, paste);
   }
 
   /**
@@ -119,7 +120,8 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
    * @param type
    * @throws IOException
    */
-  public FeaturesFile(boolean parseImmediately, String inFile, String type)
+  public FeaturesFile(boolean parseImmediately, String inFile,
+          DataSourceType type)
           throws IOException
   {
     super(parseImmediately, inFile, type);
@@ -731,9 +733,10 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
    * @return error message
    */
   @Override
-  public String print()
+  public String print(SequenceI[] sqs, boolean jvsuffix)
   {
-    return "Use printGffFormat() or printJalviewFormat()";
+    System.out.println("Use printGffFormat() or printJalviewFormat()");
+    return null;
   }
 
   /**
diff --git a/src/jalview/io/FileFormat.java b/src/jalview/io/FileFormat.java
new file mode 100644 (file)
index 0000000..a7113f6
--- /dev/null
@@ -0,0 +1,530 @@
+package jalview.io;
+
+import jalview.datamodel.PDBEntry;
+import jalview.ext.jmol.JmolParser;
+import jalview.structure.StructureImportSettings;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+public enum FileFormat implements FileFormatI
+{
+  Fasta("FASTA", "fa, fasta, mfa, fastq", true, true)
+  {
+    @Override
+    public AlignmentFileI getAlignmentFile(String inFile,
+            DataSourceType sourceType) throws IOException
+    {
+      return new FastaFile(inFile, sourceType);
+    }
+
+    @Override
+    public AlignmentFileI getAlignmentFile(FileParse source)
+            throws IOException
+    {
+      return new FastaFile(source);
+    }
+
+    @Override
+    public AlignmentFileI getAlignmentFile()
+    {
+      return new FastaFile();
+    }
+  },
+  Pfam("PFAM", "pfam", true, true)
+  {
+    @Override
+    public AlignmentFileI getAlignmentFile(String inFile,
+            DataSourceType sourceType) throws IOException
+    {
+      return new PfamFile(inFile, sourceType);
+    }
+
+    @Override
+    public AlignmentFileI getAlignmentFile(FileParse source)
+            throws IOException
+    {
+      return new PfamFile(source);
+    }
+
+    @Override
+    public AlignmentFileI getAlignmentFile()
+    {
+      return new PfamFile();
+    }
+  },
+  Stockholm("STH", "sto,stk", true, true)
+  {
+    @Override
+    public AlignmentFileI getAlignmentFile(String inFile,
+            DataSourceType sourceType) throws IOException
+    {
+      return new StockholmFile(inFile, sourceType);
+    }
+    @Override
+    public AlignmentFileI getAlignmentFile(FileParse source)
+            throws IOException
+    {
+      return new StockholmFile(source);
+    }
+
+    @Override
+    public AlignmentFileI getAlignmentFile()
+    {
+      return new StockholmFile();
+    }
+
+  },
+
+  PIR("PIR", "pir", true, true)
+  {
+    @Override
+    public AlignmentFileI getAlignmentFile(String inFile,
+            DataSourceType sourceType) throws IOException
+    {
+      return new PIRFile(inFile, sourceType);
+    }
+    @Override
+    public AlignmentFileI getAlignmentFile(FileParse source)
+            throws IOException
+    {
+      return new PIRFile(source);
+    }
+
+    @Override
+    public AlignmentFileI getAlignmentFile()
+    {
+      return new PIRFile();
+    }
+  },
+  BLC("BLC", "BLC", true, true)
+  {
+    @Override
+    public AlignmentFileI getAlignmentFile(String inFile,
+            DataSourceType sourceType) throws IOException
+    {
+      return new BLCFile(inFile, sourceType);
+    }    @Override
+    public AlignmentFileI getAlignmentFile(FileParse source)
+            throws IOException
+    {
+      return new BLCFile(source);
+    }
+
+    @Override
+    public AlignmentFileI getAlignmentFile()
+    {
+      return new BLCFile();
+    }
+  },
+  Html("HTML", "html", true, false)
+  {
+    @Override
+    public AlignmentFileI getAlignmentFile(String inFile,
+            DataSourceType sourceType) throws IOException
+    {
+      return new HtmlFile(inFile, sourceType);
+    }    @Override
+    public AlignmentFileI getAlignmentFile(FileParse source)
+            throws IOException
+    {
+      return new HtmlFile(source);
+    }
+
+    @Override
+    public AlignmentFileI getAlignmentFile()
+    {
+      return new HtmlFile();
+    }
+
+    @Override
+    public boolean isComplexAlignFile()
+    {
+      return true;
+    }
+
+  },
+  Rnaml("RNAML", "xml,rnaml", true, false)
+  {
+    @Override
+    public AlignmentFileI getAlignmentFile(String inFile,
+            DataSourceType sourceType) throws IOException
+    {
+      return new RnamlFile(inFile, sourceType);
+    }    @Override
+    public AlignmentFileI getAlignmentFile(FileParse source)
+            throws IOException
+    {
+      return new RnamlFile(source);
+    }
+
+    @Override
+    public AlignmentFileI getAlignmentFile()
+    {
+      return new RnamlFile();
+    }
+
+  },
+  Json("JSON","json", true, true)
+  {
+    @Override
+    public AlignmentFileI getAlignmentFile(String inFile,
+            DataSourceType sourceType) throws IOException
+    {
+      return new JSONFile(inFile, sourceType);
+    }    @Override
+    public AlignmentFileI getAlignmentFile(FileParse source)
+            throws IOException
+    {
+      return new JSONFile(source);
+    }
+
+    @Override
+    public AlignmentFileI getAlignmentFile()
+    {
+      return new JSONFile();
+    }
+
+    @Override
+    public boolean isComplexAlignFile()
+    {
+      return true;
+    }
+
+  },
+  Pileup("PileUp", "?", false, false)
+  {
+    @Override
+    public AlignmentFileI getAlignmentFile(String inFile,
+            DataSourceType sourceType) throws IOException
+    {
+      return new PileUpfile(inFile, sourceType);
+    }    @Override
+    public AlignmentFileI getAlignmentFile(FileParse source)
+            throws IOException
+    {
+      return new PileUpfile(source);
+    }
+
+    @Override
+    public AlignmentFileI getAlignmentFile()
+    {
+      return new PileUpfile();
+    }
+
+  },
+  MSF("MSF", "msf", true, true)
+  {
+    @Override
+    public AlignmentFileI getAlignmentFile(String inFile,
+            DataSourceType sourceType) throws IOException
+    {
+      return new MSFfile(inFile, sourceType);
+    }    @Override
+    public AlignmentFileI getAlignmentFile(FileParse source)
+            throws IOException
+    {
+      return new MSFfile(source);
+    }
+
+    @Override
+    public AlignmentFileI getAlignmentFile()
+    {
+      return new MSFfile();
+    }
+
+  },
+  Clustal("CLUSTAL", "aln", true, true)
+  {
+    @Override
+    public AlignmentFileI getAlignmentFile(String inFile,
+            DataSourceType sourceType) throws IOException
+    {
+      return new ClustalFile(inFile, sourceType);
+    }    @Override
+    public AlignmentFileI getAlignmentFile(FileParse source)
+            throws IOException
+    {
+      return new ClustalFile(source);
+    }
+
+    @Override
+    public AlignmentFileI getAlignmentFile()
+    {
+      return new ClustalFile();
+    }
+  },
+  Phylip("PHYLIP", "phy", true, true)
+  {
+    @Override
+    public AlignmentFileI getAlignmentFile(String inFile,
+            DataSourceType sourceType) throws IOException
+    {
+      return new PhylipFile(inFile, sourceType);
+    }
+
+    @Override
+    public AlignmentFileI getAlignmentFile(FileParse source)
+            throws IOException
+    {
+      return new PhylipFile(source);
+    }
+
+    @Override
+    public AlignmentFileI getAlignmentFile()
+    {
+      return new PhylipFile();
+    }
+  },
+  Jnet("JnetFile", "", false, false)
+  {
+    @Override
+    public AlignmentFileI getAlignmentFile(String inFile,
+            DataSourceType sourceType) throws IOException
+    {
+      JPredFile af = new JPredFile(inFile, sourceType);
+      af.removeNonSequences();
+      return af;
+    }
+
+    @Override
+    public AlignmentFileI getAlignmentFile(FileParse source)
+            throws IOException
+    {
+      JPredFile af = new JPredFile(source);
+      af.removeNonSequences();
+      return af;
+    }
+
+    @Override
+    public AlignmentFileI getAlignmentFile()
+    {
+      return null; // todo is this called?
+    }
+
+  },
+  Features("GFF or Jalview features", "gff2,gff3", false, false)
+  {
+    @Override
+    public AlignmentFileI getAlignmentFile(String inFile,
+            DataSourceType sourceType) throws IOException
+    {
+      return new FeaturesFile(true, inFile, sourceType);
+    }
+
+    @Override
+    public AlignmentFileI getAlignmentFile(FileParse source)
+            throws IOException
+    {
+      return new FeaturesFile(source);
+    }
+
+    @Override
+    public AlignmentFileI getAlignmentFile()
+    {
+      return new FeaturesFile();
+    }
+  },
+  PDB("PDB", "", false, false)
+  {
+
+    @Override
+    public AlignmentFileI getAlignmentFile(String inFile,
+            DataSourceType sourceType) throws IOException
+    {
+      // TODO obtain config value from preference settings.
+      // Set value to 'true' to test PDB processing with Jmol: JAL-1213
+      boolean isParseWithJMOL = StructureImportSettings
+              .getDefaultStructureFileFormat() != PDBEntry.Type.PDB;
+      if (isParseWithJMOL)
+      {
+        return new JmolParser(
+                StructureImportSettings.isVisibleChainAnnotation(),
+                StructureImportSettings.isProcessSecondaryStructure(),
+                StructureImportSettings.isExternalSecondaryStructure(),
+                inFile,
+                sourceType);
+      }
+      else
+      {
+        StructureImportSettings.setShowSeqFeatures(true);
+        return new MCview.PDBfile(
+                StructureImportSettings.isVisibleChainAnnotation(),
+                StructureImportSettings.isProcessSecondaryStructure(),
+                StructureImportSettings.isExternalSecondaryStructure(),
+                inFile,
+                sourceType);
+      }
+    }
+
+    @Override
+    public AlignmentFileI getAlignmentFile(FileParse source)
+            throws IOException
+    {
+      boolean isParseWithJMOL = StructureImportSettings
+              .getDefaultStructureFileFormat() != PDBEntry.Type.PDB;
+      if (isParseWithJMOL)
+      {
+        return new JmolParser(
+                StructureImportSettings.isVisibleChainAnnotation(),
+                StructureImportSettings.isProcessSecondaryStructure(),
+                StructureImportSettings.isExternalSecondaryStructure(),
+                source);
+      }
+      else
+      {
+        StructureImportSettings.setShowSeqFeatures(true);
+        return new MCview.PDBfile(
+                StructureImportSettings.isVisibleChainAnnotation(),
+                StructureImportSettings.isProcessSecondaryStructure(),
+                StructureImportSettings.isExternalSecondaryStructure(),
+                source);
+      }
+    }
+
+    @Override
+    public AlignmentFileI getAlignmentFile()
+    {
+      return new JmolParser(); // todo or null?
+    }
+  },
+  MMCif("mmCIF", "cif", false, false)
+  {
+
+    @Override
+    public AlignmentFileI getAlignmentFile(String inFile,
+            DataSourceType sourceType) throws IOException
+    {
+      return new JmolParser(
+              StructureImportSettings.isVisibleChainAnnotation(),
+              StructureImportSettings.isProcessSecondaryStructure(),
+              StructureImportSettings.isExternalSecondaryStructure(),
+              inFile, sourceType);
+    }
+
+    @Override
+    public AlignmentFileI getAlignmentFile(FileParse source)
+            throws IOException
+    {
+      return new JmolParser(
+              StructureImportSettings.isVisibleChainAnnotation(),
+              StructureImportSettings.isProcessSecondaryStructure(),
+              StructureImportSettings.isExternalSecondaryStructure(),
+              source);
+    }
+
+    @Override
+    public AlignmentFileI getAlignmentFile()
+    {
+      return new JmolParser(); // todo or null?
+    }
+  },
+  Jalview("Jalview", "jar,jvp", true, false)
+  {
+
+    @Override
+    public AlignmentFileI getAlignmentFile(String inFile,
+            DataSourceType sourceType) throws IOException
+    {
+      return null;
+    }
+
+    @Override
+    public AlignmentFileI getAlignmentFile(FileParse source)
+            throws IOException
+    {
+      return null;
+    }
+
+    @Override
+    public AlignmentFileI getAlignmentFile()
+    {
+      return null;
+    }
+  };
+
+  /**
+   * A lookup map of enums by upper-cased name
+   */
+  private static Map<String, FileFormat> names;
+  static
+  {
+    names = new HashMap<String, FileFormat>();
+    for (FileFormat format : FileFormat.values())
+    {
+      names.put(format.toString().toUpperCase(), format);
+    }
+  }
+
+  private boolean writable;
+
+  private boolean readable;
+
+  private String extensions;
+
+  private String name;
+
+  @Override
+  public boolean isComplexAlignFile()
+  {
+    return false;
+  }
+
+  @Override
+  public String getShortDescription()
+  {
+    return toString();
+  }
+
+  /**
+   * Returns the file format with the given name, or null if format is null or
+   * invalid. Unlike valueOf(), this is not case-sensitive, to be kind to
+   * writers of javascript.
+   * 
+   * @param format
+   * @return
+   */
+  public static FileFormatI forName(String format)
+  {
+    // or could store format.getShortDescription().toUpperCase()
+    // in order to decouple 'given name' from enum name
+    return format == null ? null : names.get(format.toUpperCase());
+  }
+
+  @Override
+  public boolean isReadable()
+  {
+    return readable;
+  }
+
+  @Override
+  public boolean isWritable()
+  {
+    return writable;
+  }
+
+  /**
+   * Constructor
+   * 
+   * @param shortName
+   * @param extensions
+   *          comma-separated list of file extensions associated with the format
+   * @param isReadable
+   * @param isWritable
+   */
+  private FileFormat(String shortName, String extensions,
+          boolean isReadable, boolean isWritable)
+  {
+    this.name = shortName;
+    this.extensions = extensions;
+    this.readable = isReadable;
+    this.writable = isWritable;
+  }
+
+  @Override
+  public String getExtensions()
+  {
+    return extensions;
+  }
+}
diff --git a/src/jalview/io/FileFormatException.java b/src/jalview/io/FileFormatException.java
new file mode 100644 (file)
index 0000000..c037cf2
--- /dev/null
@@ -0,0 +1,13 @@
+package jalview.io;
+
+import java.io.IOException;
+
+public class FileFormatException extends IOException
+{
+
+  public FileFormatException(String msg)
+  {
+    super(msg);
+  }
+
+}
diff --git a/src/jalview/io/FileFormatI.java b/src/jalview/io/FileFormatI.java
new file mode 100644 (file)
index 0000000..f594a36
--- /dev/null
@@ -0,0 +1,30 @@
+package jalview.io;
+
+import java.io.IOException;
+
+public interface FileFormatI
+{
+
+  AlignmentFileI getAlignmentFile(String inFile, DataSourceType sourceType)
+          throws IOException;
+
+  AlignmentFileI getAlignmentFile(FileParse source) throws IOException;
+
+  AlignmentFileI getAlignmentFile();
+
+  boolean isComplexAlignFile();
+
+  String getShortDescription();
+
+  /**
+   * Returns a comma-separated list of file extensions associated with the
+   * format
+   * 
+   * @return
+   */
+  String getExtensions();
+
+  boolean isReadable();
+
+  boolean isWritable();
+}
index b449d19..88f9ae5 100755 (executable)
@@ -24,6 +24,7 @@ import jalview.api.ComplexAlignFile;
 import jalview.api.FeatureSettingsModelI;
 import jalview.api.FeaturesDisplayedI;
 import jalview.api.FeaturesSourceI;
+import jalview.bin.Cache;
 import jalview.bin.Jalview;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.ColumnSelection;
@@ -48,11 +49,11 @@ public class FileLoader implements Runnable
 {
   String file;
 
-  String protocol;
+  DataSourceType protocol;
 
-  String format;
+  FileFormatI format;
 
-  FileParse source = null; // alternative specification of where data comes
+  AlignmentFileI source = null; // alternative specification of where data comes
 
   // from
 
@@ -86,13 +87,14 @@ public class FileLoader implements Runnable
   }
 
   public void LoadFile(AlignViewport viewport, String file,
-          String protocol, String format)
+          DataSourceType protocol, FileFormatI format)
   {
     this.viewport = viewport;
     LoadFile(file, protocol, format);
   }
 
-  public void LoadFile(String file, String protocol, String format)
+  public void LoadFile(String file, DataSourceType protocol,
+          FileFormatI format)
   {
     this.file = file;
     this.protocol = protocol;
@@ -116,7 +118,7 @@ public class FileLoader implements Runnable
    * @param file
    * @param protocol
    */
-  public void LoadFile(String file, String protocol)
+  public void LoadFile(String file, DataSourceType protocol)
   {
     LoadFile(file, protocol, null);
   }
@@ -125,27 +127,28 @@ public class FileLoader implements Runnable
    * Load alignment from (file, protocol) and wait till loaded
    * 
    * @param file
-   * @param protocol
+   * @param sourceType
    * @return alignFrame constructed from file contents
    */
-  public AlignFrame LoadFileWaitTillLoaded(String file, String protocol)
+  public AlignFrame LoadFileWaitTillLoaded(String file,
+          DataSourceType sourceType)
   {
-    return LoadFileWaitTillLoaded(file, protocol, null);
+    return LoadFileWaitTillLoaded(file, sourceType, null);
   }
 
   /**
    * Load alignment from (file, protocol) of type format and wait till loaded
    * 
    * @param file
-   * @param protocol
+   * @param sourceType
    * @param format
    * @return alignFrame constructed from file contents
    */
-  public AlignFrame LoadFileWaitTillLoaded(String file, String protocol,
-          String format)
+  public AlignFrame LoadFileWaitTillLoaded(String file,
+          DataSourceType sourceType, FileFormatI format)
   {
     this.file = file;
-    this.protocol = protocol;
+    this.protocol = sourceType;
     this.format = format;
     return _LoadFileWaitTillLoaded();
   }
@@ -157,12 +160,13 @@ public class FileLoader implements Runnable
    * @param format
    * @return alignFrame constructed from file contents
    */
-  public AlignFrame LoadFileWaitTillLoaded(FileParse source, String format)
+  public AlignFrame LoadFileWaitTillLoaded(AlignmentFileI source,
+          FileFormatI format)
   {
     this.source = source;
 
     file = source.getInFile();
-    protocol = source.type;
+    protocol = source.getDataSourceType();
     this.format = format;
     return _LoadFileWaitTillLoaded();
   }
@@ -194,13 +198,13 @@ public class FileLoader implements Runnable
   public void updateRecentlyOpened()
   {
     Vector recent = new Vector();
-    if (protocol.equals(FormatAdapter.PASTE))
+    if (protocol == DataSourceType.PASTE)
     {
       // do nothing if the file was pasted in as text... there is no filename to
       // refer to it as.
       return;
     }
-    String type = protocol.equals(FormatAdapter.FILE) ? "RECENT_FILE"
+    String type = protocol == DataSourceType.FILE ? "RECENT_FILE"
             : "RECENT_URL";
 
     String historyItems = jalview.bin.Cache.getProperty(type);
@@ -229,18 +233,18 @@ public class FileLoader implements Runnable
       newHistory.append(recent.elementAt(i));
     }
 
-    jalview.bin.Cache.setProperty(type, newHistory.toString());
+    Cache.setProperty(type, newHistory.toString());
 
-    if (protocol.equals(FormatAdapter.FILE))
+    if (protocol == DataSourceType.FILE)
     {
-      jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", format);
+      Cache.setProperty("DEFAULT_FILE_FORMAT", format.toString());
     }
   }
 
   @Override
   public void run()
   {
-    String title = protocol.equals(AppletFormatAdapter.PASTE) ? "Copied From Clipboard"
+    String title = protocol == DataSourceType.PASTE ? "Copied From Clipboard"
             : file;
     Runtime rt = Runtime.getRuntime();
     try
@@ -254,10 +258,8 @@ public class FileLoader implements Runnable
         // just in case the caller didn't identify the file for us
         if (source != null)
         {
-          format = new IdentifyFile().identify(source, false); // identify
-          // stream and
-          // rewind rather
-          // than close
+          format = new IdentifyFile().identify(source, false);
+          // identify stream and rewind rather than close
         }
         else
         {
@@ -266,7 +268,7 @@ public class FileLoader implements Runnable
 
       }
 
-      if (format == null || format.equalsIgnoreCase("EMPTY DATA FILE"))
+      if (format == null)
       {
         Desktop.instance.stopLoading();
         System.err.println("The input file \"" + file
@@ -296,7 +298,7 @@ public class FileLoader implements Runnable
       loadtime = -System.currentTimeMillis();
       AlignmentI al = null;
 
-      if (format.equalsIgnoreCase("Jalview"))
+      if (format == FileFormat.Jalview)
       {
         if (source != null)
         {
@@ -310,8 +312,6 @@ public class FileLoader implements Runnable
       else
       {
         String error = AppletFormatAdapter.SUPPORTED_FORMATS;
-        if (FormatAdapter.isValidFormat(format))
-        {
           try
           {
             if (source != null)
@@ -332,15 +332,6 @@ public class FileLoader implements Runnable
           {
             error = ex.getMessage();
           }
-        }
-        else
-        {
-          if (format != null && format.length() > 7)
-          {
-            // ad hoc message in format.
-            error = format + "\n" + error;
-          }
-        }
 
         if ((al != null) && (al.getHeight() > 0) && al.hasValidSequence())
         {
@@ -410,7 +401,7 @@ public class FileLoader implements Runnable
               }
             }
             // add metadata and update ui
-            if (!protocol.equals(AppletFormatAdapter.PASTE))
+            if (!(protocol == DataSourceType.PASTE))
             {
               alignFrame.setFileName(file, format);
             }
index fddb565..dc0418f 100755 (executable)
@@ -95,7 +95,7 @@ public class FileParse
    */
   protected String suffix = null;
 
-  protected String type = null;
+  protected DataSourceType dataSourceType = null;
 
   protected BufferedReader dataIn = null;
 
@@ -139,7 +139,7 @@ public class FileParse
     suffix = from.suffix;
     errormessage = from.errormessage; // inherit potential error messages
     error = false; // reset any error condition.
-    type = from.type;
+    dataSourceType = from.dataSourceType;
     dataIn = from.dataIn;
     if (dataIn != null)
     {
@@ -279,9 +279,9 @@ public class FileParse
    * configurable values for the origin and the type of the source
    */
   public FileParse(BufferedReader source, String originString,
-          String typeString)
+          DataSourceType sourceType)
   {
-    type = typeString;
+    dataSourceType = sourceType;
     error = false;
     inFile = null;
     dataName = originString;
@@ -304,18 +304,18 @@ public class FileParse
    * 
    * @param fileStr
    *          - datasource locator/content
-   * @param type
+   * @param sourceType
    *          - protocol of source
    * @throws MalformedURLException
    * @throws IOException
    */
-  public FileParse(String fileStr, String type)
+  public FileParse(String fileStr, DataSourceType sourceType)
           throws MalformedURLException, IOException
   {
-    this.type = type;
+    this.dataSourceType = sourceType;
     error = false;
 
-    if (type.equals(AppletFormatAdapter.FILE))
+    if (sourceType == DataSourceType.FILE)
     {
       if (checkFileSource(fileStr))
       {
@@ -338,7 +338,7 @@ public class FileParse
         }
       }
     }
-    else if (type.equals(AppletFormatAdapter.URL))
+    else if (sourceType == DataSourceType.URL)
     {
       try
       {
@@ -375,13 +375,13 @@ public class FileParse
         error = true;
       }
     }
-    else if (type.equals(AppletFormatAdapter.PASTE))
+    else if (sourceType == DataSourceType.PASTE)
     {
       errormessage = "PASTE INACCESSIBLE!";
       dataIn = new BufferedReader(new StringReader(fileStr));
       dataName = "Paste";
     }
-    else if (type.equals(AppletFormatAdapter.CLASSLOADER))
+    else if (sourceType == DataSourceType.CLASSLOADER)
     {
       errormessage = "RESOURCE CANNOT BE LOCATED";
       java.io.InputStream is = getClass()
@@ -407,7 +407,7 @@ public class FileParse
     else
     {
       errormessage = "PROBABLE IMPLEMENTATION ERROR : Datasource Type given as '"
-              + (type != null ? type : "null") + "'";
+              + (sourceType != null ? sourceType : "null") + "'";
       error = true;
     }
     if (dataIn == null || error)
@@ -625,4 +625,9 @@ public class FileParse
   {
     return null;
   }
+
+  public DataSourceType getDataSourceType()
+  {
+    return dataSourceType;
+  }
 }
index 6d94616..1408cd1 100755 (executable)
@@ -22,6 +22,7 @@ package jalview.io;
 
 import jalview.api.AlignExportSettingI;
 import jalview.api.AlignmentViewPanel;
+import jalview.bin.Cache;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
@@ -29,6 +30,9 @@ import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
+import jalview.util.Comparison;
+
+import java.io.IOException;
 
 /**
  * Additional formatting methods used by the application in a number of places.
@@ -76,7 +80,7 @@ public class FormatAdapter extends AppletFormatAdapter
     }
   }
 
-  public String formatSequences(String format, SequenceI[] seqs,
+  public String formatSequences(FileFormatI format, SequenceI[] seqs,
           String[] omitHiddenColumns, int[] exportRange)
   {
 
@@ -112,14 +116,14 @@ public class FormatAdapter extends AppletFormatAdapter
           startIndex = startEnd[0];
           endIndex = startEnd[1];
           // get first non-gaped residue start position
-          while (jalview.util.Comparison.isGap(seqs[i]
+          while (Comparison.isGap(seqs[i]
                   .getCharAt(startIndex)) && startIndex < endIndex)
           {
             startIndex++;
           }
 
           // get last non-gaped residue end position
-          while (jalview.util.Comparison.isGap(seqs[i].getCharAt(endIndex))
+          while (Comparison.isGap(seqs[i].getCharAt(endIndex))
                   && endIndex > startIndex)
           {
             endIndex--;
@@ -144,105 +148,101 @@ public class FormatAdapter extends AppletFormatAdapter
    * 
    * 
    * @param format
-   *          Format string as givien in the AppletFormatAdaptor list (exact
-   *          match to name of class implementing file io for that format)
    * @param seqs
    *          vector of sequences to write
    * 
    * @return String containing sequences in desired format
    */
-  public String formatSequences(String format, SequenceI[] seqs)
+  public String formatSequences(FileFormatI format, SequenceI[] seqs)
   {
+    //
+    // try
+    // {
+      boolean withSuffix = getCacheSuffixDefault(format);
+    return format.getAlignmentFile().print(seqs, withSuffix);
+      // null;
+      //
+      // if (format.equalsIgnoreCase("FASTA"))
+      // {
+      // afile = new FastaFile();
+      // afile.addJVSuffix(jalview.bin.Cache.getDefault("FASTA_JVSUFFIX",
+      // true));
+      // }
+      // else if (format.equalsIgnoreCase("MSF"))
+      // {
+      // afile = new MSFfile();
+      // afile.addJVSuffix(jalview.bin.Cache
+      // .getDefault("MSF_JVSUFFIX", true));
+      // }
+      // else if (format.equalsIgnoreCase("PileUp"))
+      // {
+      // afile = new PileUpfile();
+      // afile.addJVSuffix(jalview.bin.Cache.getDefault("PILEUP_JVSUFFIX",
+      // true));
+      // }
+      // else if (format.equalsIgnoreCase("CLUSTAL"))
+      // {
+      // afile = new ClustalFile();
+      // afile.addJVSuffix(jalview.bin.Cache.getDefault("CLUSTAL_JVSUFFIX",
+      // true));
+      // }
+      // else if (format.equalsIgnoreCase("BLC"))
+      // {
+      // afile = new BLCFile();
+      // afile.addJVSuffix(jalview.bin.Cache
+      // .getDefault("BLC_JVSUFFIX", true));
+      // }
+      // else if (format.equalsIgnoreCase("PIR"))
+      // {
+      // afile = new PIRFile();
+      // afile.addJVSuffix(jalview.bin.Cache
+      // .getDefault("PIR_JVSUFFIX", true));
+      // }
+      // else if (format.equalsIgnoreCase("PFAM"))
+      // {
+      // afile = new PfamFile();
+      // afile.addJVSuffix(jalview.bin.Cache.getDefault("PFAM_JVSUFFIX",
+      // true));
+      // }
+      // /*
+      // * amsa is not supported by this function - it requires an alignment
+      // * rather than a sequence vector else if
+      // (format.equalsIgnoreCase("AMSA"))
+      // * { afile = new AMSAFile(); afile.addJVSuffix(
+      // * jalview.bin.Cache.getDefault("AMSA_JVSUFFIX", true)); }
+      // */
 
-    try
-    {
-      AlignFile afile = null;
-
-      if (format.equalsIgnoreCase("FASTA"))
-      {
-        afile = new FastaFile();
-        afile.addJVSuffix(jalview.bin.Cache.getDefault("FASTA_JVSUFFIX",
-                true));
-      }
-      else if (format.equalsIgnoreCase("MSF"))
-      {
-        afile = new MSFfile();
-        afile.addJVSuffix(jalview.bin.Cache
-                .getDefault("MSF_JVSUFFIX", true));
-      }
-      else if (format.equalsIgnoreCase("PileUp"))
-      {
-        afile = new PileUpfile();
-        afile.addJVSuffix(jalview.bin.Cache.getDefault("PILEUP_JVSUFFIX",
-                true));
-      }
-      else if (format.equalsIgnoreCase("CLUSTAL"))
-      {
-        afile = new ClustalFile();
-        afile.addJVSuffix(jalview.bin.Cache.getDefault("CLUSTAL_JVSUFFIX",
-                true));
-      }
-      else if (format.equalsIgnoreCase("BLC"))
-      {
-        afile = new BLCFile();
-        afile.addJVSuffix(jalview.bin.Cache
-                .getDefault("BLC_JVSUFFIX", true));
-      }
-      else if (format.equalsIgnoreCase("PIR"))
-      {
-        afile = new PIRFile();
-        afile.addJVSuffix(jalview.bin.Cache
-                .getDefault("PIR_JVSUFFIX", true));
-      }
-      else if (format.equalsIgnoreCase("PFAM"))
-      {
-        afile = new PfamFile();
-        afile.addJVSuffix(jalview.bin.Cache.getDefault("PFAM_JVSUFFIX",
-                true));
-      }
-      /*
-       * amsa is not supported by this function - it requires an alignment
-       * rather than a sequence vector else if (format.equalsIgnoreCase("AMSA"))
-       * { afile = new AMSAFile(); afile.addJVSuffix(
-       * jalview.bin.Cache.getDefault("AMSA_JVSUFFIX", true)); }
-       */
-
-      afile.setSeqs(seqs);
-      String afileresp = afile.print();
-      if (afile.hasWarningMessage())
-      {
-        System.err.println("Warning raised when writing as " + format
-                + " : " + afile.getWarningMessage());
-      }
-      return afileresp;
-    } catch (Exception e)
-    {
-      System.err.println("Failed to write alignment as a '" + format
-              + "' file\n");
-      e.printStackTrace();
-    }
-
-    return null;
+//      afile.setSeqs(seqs);
+//      String afileresp = afile.print();
+//      if (afile.hasWarningMessage())
+//      {
+//        System.err.println("Warning raised when writing as " + format
+//                + " : " + afile.getWarningMessage());
+//      }
+//      return afileresp;
+//    } catch (Exception e)
+//    {
+//      System.err.println("Failed to write alignment as a '" + format
+//              + "' file\n");
+//      e.printStackTrace();
+//    }
+//
+//    return null;
   }
 
-  public boolean getCacheSuffixDefault(String format)
+  public boolean getCacheSuffixDefault(FileFormatI format)
   {
-    if (isValidFormat(format))
-    {
-      return jalview.bin.Cache.getDefault(format.toUpperCase()
-              + "_JVSUFFIX", true);
-    }
-    return false;
+    return Cache.getDefault(format.toString() + "_JVSUFFIX", true);
   }
 
-  public String formatSequences(String format, AlignmentI alignment,
+  public String formatSequences(FileFormatI format, AlignmentI alignment,
           String[] omitHidden, int[] exportRange, ColumnSelection colSel)
   {
     return formatSequences(format, alignment, omitHidden, exportRange,
             getCacheSuffixDefault(format), colSel, null);
   }
 
-  public String formatSequences(String format, AlignmentI alignment,
+  public String formatSequences(FileFormatI format, AlignmentI alignment,
           String[] omitHidden, int[] exportRange, ColumnSelection colSel,
           SequenceGroup sgp)
   {
@@ -262,7 +262,7 @@ public class FormatAdapter extends AppletFormatAdapter
    *          defines hidden columns that are edited out of annotation
    * @return string representation of the alignment formatted as format
    */
-  public String formatSequences(String format, AlignmentI alignment,
+  public String formatSequences(FileFormatI format, AlignmentI alignment,
           String[] omitHidden, int[] exportRange, boolean suffix,
           ColumnSelection colSel)
   {
@@ -270,9 +270,9 @@ public class FormatAdapter extends AppletFormatAdapter
             suffix, colSel, null);
   }
 
-  public String formatSequences(String format, AlignmentI alignment,
+  public String formatSequences(FileFormatI format, AlignmentI alignment,
           String[] omitHidden, int[] exportRange, boolean suffix,
-          ColumnSelection colSel, jalview.datamodel.SequenceGroup selgp)
+          ColumnSelection colSel, SequenceGroup selgp)
   {
     if (omitHidden != null)
     {
@@ -305,26 +305,20 @@ public class FormatAdapter extends AppletFormatAdapter
     return this.formatSequences(format, alignment, suffix);
   }
 
-  /**
-   * validate format is valid for IO in Application. This is basically the
-   * AppletFormatAdapter.isValidFormat call with additional checks for
-   * Application only formats like 'Jalview'.
-   * 
-   * @param format
-   *          a format string to be compared with list of readable or writable
-   *          formats (READABLE_FORMATS or WRITABLE_FORMATS)
-   * @param forwriting
-   *          when true, format is checked against list of writable formats.
-   * @return true if format is valid
-   */
-  public static final boolean isValidIOFormat(String format,
-          boolean forwriting)
+  @Override
+  public AlignmentI readFile(String file, DataSourceType sourceType,
+          FileFormatI fileFormat) throws IOException
   {
-    if (format.equalsIgnoreCase("jalview"))
-    {
-      return true;
-    }
-    return AppletFormatAdapter.isValidFormat(format, forwriting);
+    AlignmentI al = super.readFile(file, sourceType, fileFormat);
+    return al;
+  }
+
+  @Override
+  public AlignmentI readFromFile(FileParse source, FileFormatI format)
+          throws IOException
+  {
+    AlignmentI al = super.readFromFile(source, format);
+    return al;
   }
 
   /**
@@ -336,7 +330,7 @@ public class FormatAdapter extends AppletFormatAdapter
    *          alignment panel originating the view
    * @return String containing flat file
    */
-  public String formatSequences(String format, AlignmentViewPanel ap,
+  public String formatSequences(FileFormatI format, AlignmentViewPanel ap,
           boolean selectedOnly)
   {
     return formatSequences(format, getCacheSuffixDefault(format), ap,
index df0dc06..2e4a781 100755 (executable)
  */
 package jalview.io;
 
+import jalview.bin.Cache;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignViewport;
 import jalview.gui.AlignmentPanel;
 import jalview.gui.FeatureRenderer;
 import jalview.gui.SequenceRenderer;
+import jalview.util.BrowserLauncher;
+import jalview.util.ImageMaker;
 import jalview.util.MessageManager;
 
 import java.awt.Color;
 import java.awt.Font;
+import java.io.FileWriter;
 import java.io.PrintWriter;
 
 public class HTMLOutput
@@ -52,9 +56,8 @@ public class HTMLOutput
     fr.transferSettings(fr1);
 
     JalviewFileChooser chooser = new JalviewFileChooser(
-            jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
-            new String[] { "html" }, new String[] { "HTML files" },
-            "HTML files");
+            Cache.getProperty("LAST_DIRECTORY"), ImageMaker.HTML_EXTENSION,
+            "HTML files", "HTML files");
 
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager.getString("label.save_as_html"));
@@ -65,13 +68,12 @@ public class HTMLOutput
     if (value == JalviewFileChooser.APPROVE_OPTION)
     {
       String choice = chooser.getSelectedFile().getPath();
-      jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
+      Cache.setProperty("LAST_DIRECTORY", chooser
               .getSelectedFile().getParent());
 
       try
       {
-        PrintWriter out = new java.io.PrintWriter(new java.io.FileWriter(
-                choice));
+        PrintWriter out = new PrintWriter(new FileWriter(choice));
         out.println("<HTML>");
         out.println("<style type=\"text/css\">");
         out.println("<!--");
@@ -106,7 +108,7 @@ public class HTMLOutput
 
         out.println("\n</body>\n</html>");
         out.close();
-        jalview.util.BrowserLauncher.openURL("file:///" + choice);
+        BrowserLauncher.openURL("file:///" + choice);
       } catch (Exception ex)
       {
         ex.printStackTrace();
index e31e78d..af3fb5d 100644 (file)
@@ -60,9 +60,10 @@ public class HtmlFile extends AlignFile implements ComplexAlignFile
     super(source);
   }
 
-  public HtmlFile(String inFile, String type) throws IOException
+  public HtmlFile(String inFile, DataSourceType sourceType)
+          throws IOException
   {
-    super(inFile, type);
+    super(inFile, sourceType);
   }
 
   @Override
@@ -119,7 +120,7 @@ public class HtmlFile extends AlignFile implements ComplexAlignFile
   }
 
   @Override
-  public String print()
+  public String print(SequenceI[] sqs, boolean jvsuffix)
   {
     throw new UnsupportedOperationException(
             "Print method of HtmlFile is not supported!");
index 4e1b261..0acddfd 100644 (file)
@@ -22,6 +22,7 @@ package jalview.io;
 
 import jalview.api.AlignExportSettingI;
 import jalview.api.FeatureRenderer;
+import jalview.bin.Cache;
 import jalview.datamodel.AlignmentExportData;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignViewport;
@@ -30,6 +31,7 @@ import jalview.gui.HTMLOptions;
 import jalview.gui.IProgressIndicator;
 import jalview.gui.OOMWarning;
 import jalview.math.AlignmentDimension;
+import jalview.util.ImageMaker;
 import jalview.util.MessageManager;
 
 import java.awt.Color;
@@ -114,8 +116,7 @@ public class HtmlSvgOutput
         try
         {
           setProgressMessage(null);
-          setProgressMessage(MessageManager
-.formatMessage(
+          setProgressMessage(MessageManager.formatMessage(
                   "status.exporting_alignment_as_x_file", "HTML"));
           AlignmentDimension aDimension = ap.getAlignmentDimension();
           SVGGraphics2D g1 = new SVGGraphics2D(aDimension.getWidth(),
@@ -200,10 +201,10 @@ public class HtmlSvgOutput
 
             };
             AlignmentExportData exportData = jalview.gui.AlignFrame
-                    .getAlignmentForExport(JSONFile.FILE_DESC, av,
+                    .getAlignmentForExport(FileFormat.Json, av,
                             exportSettings);
             jsonData = new FormatAdapter(ap, exportData.getSettings())
-                    .formatSequences(JSONFile.FILE_DESC,
+                    .formatSequences(FileFormat.Json,
                             exportData.getAlignment(),
                             exportData.getOmitHidden(),
                             exportData.getStartEndPostions(),
@@ -252,11 +253,9 @@ public class HtmlSvgOutput
 
   static JalviewFileChooser getHTMLChooser()
   {
-    return new jalview.io.JalviewFileChooser(
-            jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
-            new String[] { "html" },
-            new String[] { "Hypertext Markup Language" },
-            "Hypertext Markup Language");
+    return new JalviewFileChooser(Cache.getProperty("LAST_DIRECTORY"),
+            ImageMaker.HTML_EXTENSION, ImageMaker.HTML_EXTENSION,
+            ImageMaker.HTML_EXTENSION);
   }
 
   public int printUnwrapped(int pwidth, int pheight, int pi, Graphics... pg)
index 889359f..89fc3cd 100755 (executable)
@@ -39,18 +39,18 @@ public class IdentifyFile
    *       instead.
    *
    * @param file
-   *          DOCUMENT ME!
-   * @param protocol
-   *          DOCUMENT ME!
-   * @return ID String
+   * @param sourceType
+   * @return
+   * @throws FileFormatException
    */
-  public String identify(String file, String protocol)
+  public FileFormatI identify(String file, DataSourceType sourceType)
+          throws FileFormatException
   {
     String emessage = "UNIDENTIFIED FILE PARSING ERROR";
     FileParse parser = null;
     try
     {
-      parser = new FileParse(file, protocol);
+      parser = new FileParse(file, sourceType);
       if (parser.isValid())
       {
         return identify(parser);
@@ -63,15 +63,15 @@ public class IdentifyFile
     }
     if (parser != null)
     {
-      return parser.errormessage;
+      throw new FileFormatException(parser.errormessage);
     }
-    return emessage;
+    throw new FileFormatException(emessage);
   }
 
-  public String identify(FileParse source)
+  public FileFormatI identify(FileParse source) throws FileFormatException
   {
-    return identify(source, true); // preserves original behaviour prior to
-    // version 2.3
+    return identify(source, true);
+    // preserves original behaviour prior to version 2.3
   }
 
   /**
@@ -80,11 +80,13 @@ public class IdentifyFile
    *
    * @param source
    * @param closeSource
-   * @return filetype string
+   * @return (best guess at) file format
+   * @throws FileFormatException
    */
-  public String identify(FileParse source, boolean closeSource)
+  public FileFormatI identify(FileParse source, boolean closeSource)
+          throws FileFormatException
   {
-    String reply = "PFAM";
+    FileFormatI reply = FileFormat.Pfam;
     String data;
     int bytesRead = 0;
     int trimmedLength = 0;
@@ -123,12 +125,12 @@ public class IdentifyFile
             if (fileStr.lastIndexOf(".jar") > -1
                     || fileStr.lastIndexOf(".zip") > -1)
             {
-              reply = "Jalview";
+              reply = FileFormat.Jalview;
             }
           }
           if (!lineswereskipped && data.startsWith("PK"))
           {
-            reply = "Jalview"; // archive.
+            reply = FileFormat.Jalview; // archive.
             break;
           }
         }
@@ -137,24 +139,24 @@ public class IdentifyFile
         if (data.startsWith("##GFF-VERSION"))
         {
           // GFF - possibly embedded in a Jalview features file!
-          reply = FeaturesFile;
+          reply = FileFormat.Features;
           break;
         }
         if (looksLikeFeatureData(data))
         {
-          reply = FeaturesFile;
+          reply = FileFormat.Features;
           break;
         }
         if (data.indexOf("# STOCKHOLM") > -1)
         {
-          reply = "STH";
+          reply = FileFormat.Stockholm;
           break;
         }
         if (data.indexOf("_ENTRY.ID") > -1
                 || data.indexOf("_AUDIT_AUTHOR.NAME") > -1
                 || data.indexOf("_ATOM_SITE.") > -1)
         {
-          reply = "mmCIF";
+          reply = FileFormat.MMCif;
           break;
         }
         // if (data.indexOf(">") > -1)
@@ -166,14 +168,14 @@ public class IdentifyFile
           {
             // watch for PIR file attributes
             checkPIR = true;
-            reply = "PIR";
+            reply = FileFormat.PIR;
           }
           // could also be BLC file, read next line to confirm
           data = source.nextLine();
 
           if (data.indexOf(">") > -1)
           {
-            reply = "BLC";
+            reply = FileFormat.BLC;
           }
           else
           {
@@ -190,18 +192,19 @@ public class IdentifyFile
             {
               if (c1 == 0 && c1 == data2.indexOf("*"))
               {
-                reply = "BLC";
+                reply = FileFormat.BLC;
               }
               else
               {
-                reply = "FASTA"; // possibly a bad choice - may be recognised as
+                reply = FileFormat.Fasta; // possibly a bad choice - may be
+                                          // recognised as
                 // PIR
               }
               // otherwise can still possibly be a PIR file
             }
             else
             {
-              reply = "FASTA";
+              reply = FileFormat.Fasta;
               // TODO : AMSA File is indicated if there is annotation in the
               // FASTA file - but FASTA will automatically generate this at the
               // mo.
@@ -238,12 +241,12 @@ public class IdentifyFile
             }
             if (starterm)
             {
-              reply = "PIR";
+              reply = FileFormat.PIR;
               break;
             }
             else
             {
-              reply = "FASTA"; // probably a bad choice!
+              reply = FileFormat.Fasta; // probably a bad choice!
             }
           }
           // read as a FASTA (probably)
@@ -256,19 +259,19 @@ public class IdentifyFile
           String upper = data.toUpperCase();
           if (upper.substring(lessThan).startsWith("<HTML"))
           {
-            reply = HtmlFile.FILE_DESC;
+            reply = FileFormat.Html;
             break;
           }
           if (upper.substring(lessThan).startsWith("<RNAML"))
           {
-            reply = "RNAML";
+            reply = FileFormat.Rnaml;
             break;
           }
         }
 
         if (data.indexOf("{\"") > -1)
         {
-          reply = JSONFile.FILE_DESC;
+          reply = FileFormat.Json;
           break;
         }
         if ((data.length() < 1) || (data.indexOf("#") == 0))
@@ -279,7 +282,7 @@ public class IdentifyFile
 
         if (data.indexOf("PILEUP") > -1)
         {
-          reply = "PileUp";
+          reply = FileFormat.Pileup;
 
           break;
         }
@@ -288,32 +291,32 @@ public class IdentifyFile
                 || ((data.indexOf("!!") > -1) && (data.indexOf("!!") < data
                         .indexOf("_MULTIPLE_ALIGNMENT "))))
         {
-          reply = "MSF";
+          reply = FileFormat.MSF;
 
           break;
         }
         else if (data.indexOf("CLUSTAL") > -1)
         {
-          reply = "CLUSTAL";
+          reply = FileFormat.Clustal;
 
           break;
         }
 
         else if (data.indexOf("HEADER") == 0 || data.indexOf("ATOM") == 0)
         {
-          reply = "PDB";
+          reply = FileFormat.PDB;
           break;
         }
         else if (data.matches("\\s*\\d+\\s+\\d+\\s*"))
         {
-          reply = PhylipFile.FILE_DESC;
+          reply = FileFormat.Phylip;
           break;
         }
         else
         {
           if (!lineswereskipped && looksLikeJnetData(data))
           {
-            reply = "JnetFile";
+            reply = FileFormat.Jnet;
             break;
           }
         }
@@ -332,13 +335,13 @@ public class IdentifyFile
     } catch (Exception ex)
     {
       System.err.println("File Identification failed!\n" + ex);
-      return source.errormessage;
+      throw new FileFormatException(source.errormessage);
     }
     if (trimmedLength == 0)
     {
       System.err
               .println("File Identification failed! - Empty file was read.");
-      return "EMPTY DATA FILE";
+      throw new FileFormatException("EMPTY DATA FILE");
     }
     return reply;
   }
@@ -389,11 +392,19 @@ public class IdentifyFile
 
   public static void main(String[] args)
   {
-
     for (int i = 0; args != null && i < args.length; i++)
     {
       IdentifyFile ider = new IdentifyFile();
-      String type = ider.identify(args[i], AppletFormatAdapter.FILE);
+      FileFormatI type = null;
+      try
+      {
+        type = ider.identify(args[i], DataSourceType.FILE);
+      } catch (FileFormatException e)
+      {
+        System.err.println(String.format(
+                "Error '%s' identifying file type for %s", args[i],
+                e.getMessage()));
+      }
       System.out.println("Type of " + args[i] + " is " + type);
     }
     if (args == null || args.length == 0)
index ddb2ddc..fd971fd 100755 (executable)
@@ -70,15 +70,16 @@ public class JPredFile extends AlignFile
    * 
    * @param inFile
    *          DOCUMENT ME!
-   * @param type
+   * @param sourceType
    *          DOCUMENT ME!
    * 
    * @throws IOException
    *           DOCUMENT ME!
    */
-  public JPredFile(String inFile, String type) throws IOException
+  public JPredFile(String inFile, DataSourceType sourceType)
+          throws IOException
   {
-    super(inFile, type);
+    super(inFile, sourceType);
   }
 
   public JPredFile(FileParse source) throws IOException
@@ -130,6 +131,7 @@ public class JPredFile extends AlignFile
   /**
    * DOCUMENT ME!
    */
+  @Override
   public void initData()
   {
     super.initData();
@@ -141,6 +143,7 @@ public class JPredFile extends AlignFile
   /**
    * parse a JPred concise file into a sequence-alignment like object.
    */
+  @Override
   public void parse() throws IOException
   {
     // JBPNote log.System.out.println("all read in ");
@@ -205,7 +208,7 @@ public class JPredFile extends AlignFile
             ascore = symbols.nextToken();
 
             Float score = new Float(ascore);
-            scores.addElement((Object) score);
+            scores.addElement(score);
           }
 
           Scores.put(id, scores);
@@ -217,15 +220,15 @@ public class JPredFile extends AlignFile
           for (int j = 0; j < i; j++)
           {
             scores.setElementAt(
-                    (Object) ((Float) scores.elementAt(j)).toString(), j);
+                    ((Float) scores.elementAt(j)).toString(), j);
           }
 
-          scores.addElement((Object) ascore);
+          scores.addElement(ascore);
 
           while (symbols.hasMoreTokens())
           {
             ascore = symbols.nextToken();
-            scores.addElement((Object) ascore);
+            scores.addElement(ascore);
           }
 
           Scores.put(id, scores);
@@ -265,7 +268,9 @@ public class JPredFile extends AlignFile
           }
 
           if (QuerySeqPosition == -1)
+          {
             QuerySeqPosition = ids.size();
+          }
           ids.addElement(name);
           noSeqs++;
         }
@@ -278,7 +283,7 @@ public class JPredFile extends AlignFile
 
           seq_entries.addElement(newseq.toString());
           ids.addElement(id);
-          Symscores.put((Object) id, (Object) new Integer(ids.size() - 1));
+          Symscores.put(id, new Integer(ids.size() - 1));
         }
       }
     }
@@ -350,7 +355,8 @@ public class JPredFile extends AlignFile
    * 
    * @return String
    */
-  public String print()
+  @Override
+  public String print(SequenceI[] sqs, boolean jvsuffix)
   {
     return "Not Supported";
   }
@@ -365,13 +371,13 @@ public class JPredFile extends AlignFile
   {
     try
     {
-      JPredFile blc = new JPredFile(args[0], "File");
+      JPredFile jpred = new JPredFile(args[0], DataSourceType.FILE);
 
-      for (int i = 0; i < blc.seqs.size(); i++)
+      for (int i = 0; i < jpred.seqs.size(); i++)
       {
-        System.out.println(((Sequence) blc.seqs.elementAt(i)).getName()
+        System.out.println(((Sequence) jpred.seqs.elementAt(i)).getName()
                 + "\n"
-                + ((Sequence) blc.seqs.elementAt(i)).getSequenceAsString()
+                + ((Sequence) jpred.seqs.elementAt(i)).getSequenceAsString()
                 + "\n");
       }
     } catch (java.io.IOException e)
@@ -402,7 +408,7 @@ public class JPredFile extends AlignFile
     }
     // check that no stray annotations have been added at the end.
     {
-      SequenceI sq = (SequenceI) seqs.elementAt(j - 1);
+      SequenceI sq = seqs.elementAt(j - 1);
       if (sq.getName().toUpperCase().startsWith("JPRED"))
       {
         annotSeqs.addElement(sq);
index 653c071..7a12076 100644 (file)
@@ -71,10 +71,6 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
 
   private String application = "Jalview";
 
-  public static final String FILE_EXT = "json";
-
-  public static final String FILE_DESC = "JSON";
-
   private String globalColourScheme;
 
   private boolean showSeqFeatures;
@@ -105,9 +101,10 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
     super(source);
   }
 
-  public JSONFile(String inFile, String type) throws IOException
+  public JSONFile(String inFile, DataSourceType sourceType)
+          throws IOException
   {
-    super(inFile, type);
+    super(inFile, sourceType);
   }
 
   @Override
@@ -118,7 +115,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
   }
 
   @Override
-  public String print()
+  public String print(SequenceI[] sqs, boolean jvsuffix)
   {
     String jsonOutput = null;
     try
@@ -171,7 +168,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
       }
 
       int count = 0;
-      for (SequenceI seq : seqs)
+      for (SequenceI seq : sqs)
       {
         StringBuilder name = new StringBuilder();
         name.append(seq.getName()).append("/").append(seq.getStart())
@@ -228,7 +225,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
       if (exportSettings.isExportFeatures())
       {
         jsonAlignmentPojo
-                .setSeqFeatures(sequenceFeatureToJsonPojo(seqs, fr));
+                .setSeqFeatures(sequenceFeatureToJsonPojo(sqs, fr));
       }
 
       if (exportSettings.isExportGroups() && seqGroups != null
@@ -318,11 +315,16 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
   }
 
   public List<SequenceFeaturesPojo> sequenceFeatureToJsonPojo(
-          List<SequenceI> seqs, FeatureRenderer fr)
+          SequenceI[] sqs, FeatureRenderer fr)
   {
     displayedFeatures = (fr == null) ? null : fr.getFeaturesDisplayed();
     List<SequenceFeaturesPojo> sequenceFeaturesPojo = new ArrayList<SequenceFeaturesPojo>();
-    for (SequenceI seq : seqs)
+    if (sqs == null)
+    {
+      return sequenceFeaturesPojo;
+    }
+
+    for (SequenceI seq : sqs)
     {
       SequenceI dataSetSequence = seq.getDatasetSequence();
       SequenceFeature[] seqFeatures = (dataSetSequence == null) ? null
index 1ea6795..a4362dc 100755 (executable)
@@ -31,6 +31,9 @@ import java.awt.HeadlessException;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 import java.util.StringTokenizer;
 import java.util.Vector;
 
@@ -41,6 +44,7 @@ import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.SpringLayout;
+import javax.swing.plaf.basic.BasicFileChooserUI;
 
 /**
  * Enhanced file chooser dialog box.
@@ -53,12 +57,97 @@ import javax.swing.SpringLayout;
  */
 public class JalviewFileChooser extends JFileChooser
 {
+  /**
+   * Factory method to return a file chooser that offers readable alignment file
+   * formats
+   * 
+   * @param directory
+   * @param selected
+   * @param selectAll
+   * @return
+   */
+  public static JalviewFileChooser forRead(String directory,
+          String selected, boolean selectAll)
+  {
+    List<String> extensions = new ArrayList<String>();
+    List<String> descs = new ArrayList<String>();
+    for (FileFormatI format : FileFormat.values())
+    {
+      if (format.isReadable())
+      {
+        extensions.add(format.getExtensions());
+        descs.add(format.getShortDescription());
+      }
+    }
+    return new JalviewFileChooser(directory,
+            extensions.toArray(new String[extensions.size()]),
+            descs.toArray(new String[descs.size()]),
+            selected);
+  }
+
+  /**
+   * Factory method to return a file chooser that offers writable alignment file
+   * formats
+   * 
+   * @param directory
+   * @param selected
+   * @param selectAll
+   * @return
+   */
+  public static JalviewFileChooser forWrite(String directory,
+          String selected, boolean selectAll)
+  {
+    // TODO in Java 8, forRead and forWrite can be a single method
+    // with a lambda expression parameter for isReadable/isWritable
+    List<String> extensions = new ArrayList<String>();
+    List<String> descs = new ArrayList<String>();
+    for (FileFormatI format : FileFormat.values())
+    {
+      if (format.isWritable())
+      {
+        extensions.add(format.getExtensions());
+        descs.add(format.getShortDescription());
+      }
+    }
+    return new JalviewFileChooser(directory,
+            extensions.toArray(new String[extensions.size()]),
+            descs.toArray(new String[descs.size()]), selected);
+  }
+
   public JalviewFileChooser(String dir)
   {
     super(safePath(dir));
     setAccessory(new RecentlyOpened());
   }
 
+  public JalviewFileChooser(String dir, String extension, String desc,
+          String selected)
+  {
+    super(safePath(dir));
+    init(Collections.singletonList(new String[] { extension, desc }),
+            selected);
+  }
+
+  public JalviewFileChooser(String dir, String[] extensions, String[] descs,
+          String selected)
+  {
+    super(safePath(dir));
+    if (extensions.length == descs.length)
+    {
+      List<String[]> formats = new ArrayList<String[]>();
+      for (int i = 0; i < extensions.length; i++)
+      {
+        formats.add(new String[] { extensions[i], descs[i] });
+      }
+      init(formats, selected);
+    }
+    else
+    {
+      System.err.println("JalviewFileChooser arguments mismatch: "
+              + extensions + ", " + descs);
+    }
+  }
+
   private static File safePath(String dir)
   {
     if (dir == null)
@@ -74,35 +163,26 @@ public class JalviewFileChooser extends JFileChooser
     return f;
   }
 
-  public JalviewFileChooser(String dir, String[] suffix, String[] desc,
-          String selected, boolean selectAll)
-  {
-    super(safePath(dir));
-    init(suffix, desc, selected, selectAll);
-  }
-
-  public JalviewFileChooser(String dir, String[] suffix, String[] desc,
-          String selected)
-  {
-    super(safePath(dir));
-    init(suffix, desc, selected, true);
-  }
-
-  void init(String[] suffix, String[] desc, String selected,
-          boolean selectAll)
+  /**
+   * 
+   * @param formats
+   *          a list of {extensions, description} for each file format
+   * @param selected
+   */
+  void init(List<String[]> formats, String selected)
   {
 
     JalviewFileFilter chosen = null;
 
     // SelectAllFilter needs to be set first before adding further
     // file filters to fix bug on Mac OSX
-    setAcceptAllFileFilterUsed(selectAll);
+    setAcceptAllFileFilterUsed(true);
 
-    for (int i = 0; i < suffix.length; i++)
+    for (String[] format : formats)
     {
-      JalviewFileFilter jvf = new JalviewFileFilter(suffix[i], desc[i]);
+      JalviewFileFilter jvf = new JalviewFileFilter(format[0], format[1]);
       addChoosableFileFilter(jvf);
-      if ((selected != null) && selected.equalsIgnoreCase(desc[i]))
+      if ((selected != null) && selected.equalsIgnoreCase(format[1]))
       {
         chosen = jvf;
       }
@@ -123,10 +203,10 @@ public class JalviewFileChooser extends JFileChooser
 
     try
     {
-      if (getUI() instanceof javax.swing.plaf.basic.BasicFileChooserUI)
+      if (getUI() instanceof BasicFileChooserUI)
       {
-        final javax.swing.plaf.basic.BasicFileChooserUI ui = (javax.swing.plaf.basic.BasicFileChooserUI) getUI();
-        final String name = ui.getFileName().trim();
+        final BasicFileChooserUI fcui = (BasicFileChooserUI) getUI();
+        final String name = fcui.getFileName().trim();
 
         if ((name == null) || (name.length() == 0))
         {
@@ -138,10 +218,10 @@ public class JalviewFileChooser extends JFileChooser
           @Override
           public void run()
           {
-            String currentName = ui.getFileName();
+            String currentName = fcui.getFileName();
             if ((currentName == null) || (currentName.length() == 0))
             {
-              ui.setFileName(name);
+              fcui.setFileName(name);
             }
           }
         });
@@ -153,7 +233,7 @@ public class JalviewFileChooser extends JFileChooser
     }
   }
 
-  public String getSelectedFormat()
+  public FileFormatI getSelectedFormat()
   {
     if (getFileFilter() == null)
     {
@@ -161,41 +241,7 @@ public class JalviewFileChooser extends JFileChooser
     }
 
     String format = getFileFilter().getDescription();
-
-    if (format.toUpperCase().startsWith("JALVIEW"))
-    {
-      format = "Jalview";
-    }
-    else if (format.toUpperCase().startsWith("FASTA"))
-    {
-      format = "FASTA";
-    }
-    else if (format.toUpperCase().startsWith("MSF"))
-    {
-      format = "MSF";
-    }
-    else if (format.toUpperCase().startsWith("CLUSTAL"))
-    {
-      format = "CLUSTAL";
-    }
-    else if (format.toUpperCase().startsWith("BLC"))
-    {
-      format = "BLC";
-    }
-    else if (format.toUpperCase().startsWith("PIR"))
-    {
-      format = "PIR";
-    }
-    else if (format.toUpperCase().startsWith("PFAM"))
-    {
-      format = "PFAM";
-    }
-    else if (format.toUpperCase().startsWith(PhylipFile.FILE_DESC))
-    {
-      format = PhylipFile.FILE_DESC;
-    }
-
-    return format;
+    return FileFormat.valueOf(format);
   }
 
   @Override
index ab510d5..aa8e406 100755 (executable)
@@ -58,7 +58,7 @@ public class MSFfile extends AlignFile
    * @throws IOException
    *           DOCUMENT ME!
    */
-  public MSFfile(String inFile, String type) throws IOException
+  public MSFfile(String inFile, DataSourceType type) throws IOException
   {
     super(inFile, type);
   }
@@ -216,7 +216,8 @@ public class MSFfile extends AlignFile
    * 
    * @return DOCUMENT ME!
    */
-  public String print(SequenceI[] sqs)
+  @Override
+  public String print(SequenceI[] sqs, boolean jvSuffix)
   {
 
     boolean is_NA = Comparison.isNucleotide(sqs);
@@ -308,7 +309,7 @@ public class MSFfile extends AlignFile
     while ((i < s.length) && (s[i] != null))
     {
 
-      nameBlock[i] = new String("  Name: " + printId(s[i]) + " ");
+      nameBlock[i] = new String("  Name: " + printId(s[i], jvSuffix) + " ");
 
       idBlock[i] = new String("Len: "
               + maxLenpad.form(s[i].getSequence().length) + "  Check: "
@@ -360,7 +361,7 @@ public class MSFfile extends AlignFile
 
       while ((j < s.length) && (s[j] != null))
       {
-        String name = printId(s[j]);
+        String name = printId(s[j], jvSuffix);
 
         out.append(new Format("%-" + maxid + "s").form(name + " "));
 
@@ -408,15 +409,4 @@ public class MSFfile extends AlignFile
 
     return out.toString();
   }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @return DOCUMENT ME!
-   */
-  @Override
-  public String print()
-  {
-    return print(getSeqsAsArray());
-  }
 }
index ab3c37c..765ea95 100755 (executable)
@@ -110,7 +110,7 @@ public class NewickFile extends FileParse
    */
   public NewickFile(String inStr) throws IOException
   {
-    super(inStr, "Paste");
+    super(inStr, DataSourceType.PASTE);
   }
 
   /**
@@ -118,15 +118,16 @@ public class NewickFile extends FileParse
    * 
    * @param inFile
    *          DOCUMENT ME!
-   * @param type
+   * @param protocol
    *          DOCUMENT ME!
    * 
    * @throws IOException
    *           DOCUMENT ME!
    */
-  public NewickFile(String inFile, String type) throws IOException
+  public NewickFile(String inFile, DataSourceType protocol)
+          throws IOException
   {
-    super(inFile, type);
+    super(inFile, protocol);
   }
 
   public NewickFile(FileParse source) throws IOException
@@ -966,7 +967,7 @@ public class NewickFile extends FileParse
       treefile.close();
       System.out.println("Read file :\n");
 
-      NewickFile trf = new NewickFile(args[0], "File");
+      NewickFile trf = new NewickFile(args[0], DataSourceType.FILE);
       trf.parse();
       System.out.println("Original file :\n");
 
index 5f5c23c..d9ed516 100755 (executable)
@@ -22,6 +22,7 @@ package jalview.io;
 
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceI;
+import jalview.util.Comparison;
 
 import java.io.IOException;
 import java.util.Vector;
@@ -36,9 +37,10 @@ public class PIRFile extends AlignFile
   {
   }
 
-  public PIRFile(String inFile, String type) throws IOException
+  public PIRFile(String inFile, DataSourceType sourceType)
+          throws IOException
   {
-    super(inFile, type);
+    super(inFile, sourceType);
   }
 
   public PIRFile(FileParse source) throws IOException
@@ -102,14 +104,9 @@ public class PIRFile extends AlignFile
   }
 
   @Override
-  public String print()
+  public String print(SequenceI[] s, boolean jvsuffix)
   {
-    return print(getSeqsAsArray());
-  }
-
-  public String print(SequenceI[] s)
-  {
-    boolean is_NA = jalview.util.Comparison.isNucleotide(s);
+    boolean is_NA = Comparison.isNucleotide(s);
     int len = 72;
     StringBuffer out = new StringBuffer();
     int i = 0;
@@ -161,7 +158,7 @@ public class PIRFile extends AlignFile
         }
         else
         {
-          out.append(">P1;" + printId(s[i]));
+          out.append(">P1;" + printId(s[i], jvsuffix));
           out.append(newline);
           if (s[i].getDescription() != null)
           {
index 667da9f..05adb0e 100755 (executable)
@@ -36,9 +36,10 @@ public class PfamFile extends AlignFile
   {
   }
 
-  public PfamFile(String inFile, String type) throws IOException
+  public PfamFile(String inFile, DataSourceType sourceType)
+          throws IOException
   {
-    super(inFile, type);
+    super(inFile, sourceType);
   }
 
   public PfamFile(FileParse source) throws IOException
@@ -143,7 +144,8 @@ public class PfamFile extends AlignFile
     }
   }
 
-  public String print(SequenceI[] s)
+  @Override
+  public String print(SequenceI[] s, boolean jvsuffix)
   {
     StringBuffer out = new StringBuffer("");
 
@@ -154,7 +156,7 @@ public class PfamFile extends AlignFile
 
     while ((i < s.length) && (s[i] != null))
     {
-      String tmp = printId(s[i]);
+      String tmp = printId(s[i], jvsuffix);
 
       if (s[i].getSequence().length > max)
       {
@@ -178,7 +180,8 @@ public class PfamFile extends AlignFile
 
     while ((j < s.length) && (s[j] != null))
     {
-      out.append(new Format("%-" + maxid + "s").form(printId(s[j]) + " "));
+      out.append(new Format("%-" + maxid + "s")
+              .form(printId(s[j], jvsuffix) + " "));
 
       out.append(s[j].getSequenceAsString());
       out.append(newline);
@@ -189,10 +192,4 @@ public class PfamFile extends AlignFile
 
     return out.toString();
   }
-
-  @Override
-  public String print()
-  {
-    return print(getSeqsAsArray());
-  }
 }
index 8e01c88..e8fe7e9 100644 (file)
@@ -59,9 +59,6 @@ import java.io.IOException;
 public class PhylipFile extends AlignFile
 {
 
-  // Define file extension and description to save repeating it elsewhere
-  public static final String FILE_EXT = "phy";
-
   public static final String FILE_DESC = "PHYLIP";
 
   /**
@@ -85,13 +82,14 @@ public class PhylipFile extends AlignFile
 
   /**
    * @param inFile
-   * @param type
+   * @param sourceType
    * @throws IOException
    * @see {@link AlignFile#AlignFile(FileParse)}
    */
-  public PhylipFile(String inFile, String type) throws IOException
+  public PhylipFile(String inFile, DataSourceType sourceType)
+          throws IOException
   {
-    super(inFile, type);
+    super(inFile, sourceType);
   }
 
   /**
@@ -242,15 +240,15 @@ public class PhylipFile extends AlignFile
    * @see {@link AlignFile#print()}
    */
   @Override
-  public String print()
+  public String print(SequenceI[] sqs, boolean jvsuffix)
   {
 
-    StringBuffer sb = new StringBuffer(Integer.toString(seqs.size()));
+    StringBuffer sb = new StringBuffer(Integer.toString(sqs.length));
     sb.append(" ");
     // if there are no sequences, then define the number of characters as 0
     sb.append(
-            (seqs.size() > 0) ? Integer
-                    .toString(seqs.get(0).getSequence().length) : "0")
+            (sqs.length > 0) ? Integer.toString(sqs[0].getSequence().length)
+                    : "0")
             .append(newline);
 
     // Due to how IO is handled, there doesn't appear to be a way to store
@@ -262,7 +260,7 @@ public class PhylipFile extends AlignFile
     int numInterleavedColumns = 60;
 
     int sequenceLength = 0;
-    for (SequenceI s : seqs)
+    for (SequenceI s : sqs)
     {
 
       // ensure name is only 10 characters
@@ -313,7 +311,7 @@ public class PhylipFile extends AlignFile
         // add blank line to separate this matrix from previous
         sb.append(newline);
         int start = i * numInterleavedColumns;
-        for (SequenceI s : seqs)
+        for (SequenceI s : sqs)
         {
           sb.append(
                   s.getSequence(start, Math.min(start
index 79c6531..84be72c 100755 (executable)
@@ -55,15 +55,16 @@ public class PileUpfile extends MSFfile
    * 
    * @param inFile
    *          DOCUMENT ME!
-   * @param type
+   * @param sourceType
    *          DOCUMENT ME!
    * 
    * @throws IOException
    *           DOCUMENT ME!
    */
-  public PileUpfile(String inFile, String type) throws IOException
+  public PileUpfile(String inFile, DataSourceType sourceType)
+          throws IOException
   {
-    super(inFile, type);
+    super(inFile, sourceType);
   }
 
   public PileUpfile(FileParse source) throws IOException
@@ -71,19 +72,8 @@ public class PileUpfile extends MSFfile
     super(source);
   }
 
-  /**
-   * DOCUMENT ME!
-   * 
-   * @return DOCUMENT ME!
-   */
-  @Override
-  public String print()
-  {
-    return print(getSeqsAsArray());
-  }
-
   @Override
-  public String print(SequenceI[] s)
+  public String print(SequenceI[] s, boolean jvsuffix)
   {
     StringBuffer out = new StringBuffer("PileUp");
     out.append(newline);
@@ -112,7 +102,8 @@ public class PileUpfile extends MSFfile
     while ((i < s.length) && (s[i] != null))
     {
       String seq = s[i].getSequenceAsString();
-      out.append(" Name: " + printId(s[i]) + " oo  Len:  " + seq.length()
+      out.append(" Name: " + printId(s[i], jvsuffix) + " oo  Len:  "
+              + seq.length()
               + "  Check:  " + checksums[i] + "  Weight:  1.00");
       out.append(newline);
 
@@ -151,7 +142,7 @@ public class PileUpfile extends MSFfile
 
       while ((j < s.length) && (s[j] != null))
       {
-        String name = printId(s[j]);
+        String name = printId(s[j], jvsuffix);
 
         out.append(new Format("%-" + maxid + "s").form(name + " "));
 
index f48f825..eb623d3 100644 (file)
@@ -54,7 +54,7 @@ public class RnamlFile extends AlignFile
 
   }
 
-  public RnamlFile(String inFile, String type) throws IOException
+  public RnamlFile(String inFile, DataSourceType type) throws IOException
   {
     super(inFile, type);
 
@@ -195,16 +195,10 @@ public class RnamlFile extends AlignFile
     setSeqs(sqs);
   }
 
-  public static String print(SequenceI[] s)
-  {
-    return "not yet implemented";
-  }
-
   @Override
-  public String print()
+  public String print(SequenceI[] s, boolean jvSuffix)
   {
-    System.out.print("print :");
-    return print(getSeqsAsArray());
+    return "not yet implemented";
   }
 
   public List<RNA> getRNA()
index f4dc5a2..1b72545 100644 (file)
@@ -51,9 +51,10 @@ public class SimpleBlastFile extends AlignFile
   {
   }
 
-  public SimpleBlastFile(String inFile, String type) throws IOException
+  public SimpleBlastFile(String inFile, DataSourceType sourceType)
+          throws IOException
   {
-    super(inFile, type);
+    super(inFile, sourceType);
   }
 
   public SimpleBlastFile(FileParse source) throws IOException
@@ -61,6 +62,7 @@ public class SimpleBlastFile extends AlignFile
     super(source);
   }
 
+  @Override
   public void initData()
   {
     super.initData();
@@ -69,6 +71,7 @@ public class SimpleBlastFile extends AlignFile
     seqids = new Vector();
   }
 
+  @Override
   public void parse() throws IOException
   {
     String line;
@@ -286,13 +289,9 @@ public class SimpleBlastFile extends AlignFile
     }
   }
 
-  public String print(SequenceI[] s)
+  @Override
+  public String print(SequenceI[] sqs, boolean jvsuffix)
   {
     return new String("Not Implemented.");
   }
-
-  public String print()
-  {
-    return print(getSeqsAsArray());
-  }
 }
index bec7d82..3fd0505 100644 (file)
@@ -97,7 +97,8 @@ public class StockholmFile extends AlignFile
     this.al = al;
   }
 
-  public StockholmFile(String inFile, String type) throws IOException
+  public StockholmFile(String inFile, DataSourceType type)
+          throws IOException
   {
     super(inFile, type);
   }
@@ -881,8 +882,13 @@ public class StockholmFile extends AlignFile
     return annot;
   }
 
-  public String print(SequenceI[] s)
+  @Override
+  public String print(SequenceI[] s, boolean jvSuffix)
   {
+    out = new StringBuffer();
+    out.append("# STOCKHOLM 1.0");
+    out.append(newline);
+
     // find max length of id
     int max = 0;
     int maxid = 0;
@@ -890,7 +896,7 @@ public class StockholmFile extends AlignFile
     Hashtable dataRef = null;
     while ((in < s.length) && (s[in] != null))
     {
-      String tmp = printId(s[in]);
+      String tmp = printId(s[in], jvSuffix);
       if (s[in].getSequence().length > max)
       {
         max = s[in].getSequence().length;
@@ -987,7 +993,7 @@ public class StockholmFile extends AlignFile
 
             // out.append("#=GR ");
             out.append(new Format("%-" + maxid + "s").form("#=GR "
-                    + printId(s[i]) + " " + key + " "));
+                    + printId(s[i], jvSuffix) + " " + key + " "));
             ann = alAnot[j].annotations;
             boolean isrna = alAnot[j].isValidStruc();
             String seq = "";
@@ -1001,7 +1007,8 @@ public class StockholmFile extends AlignFile
         }
       }
 
-      out.append(new Format("%-" + maxid + "s").form(printId(s[i]) + " "));
+      out.append(new Format("%-" + maxid + "s")
+              .form(printId(s[i], jvSuffix) + " "));
       out.append(s[i].getSequenceAsString());
       out.append(newline);
       i++;
@@ -1054,6 +1061,10 @@ public class StockholmFile extends AlignFile
         out.append(newline);
       }
     }
+
+    out.append("//");
+    out.append(newline);
+
     return out.toString();
   }
 
@@ -1106,13 +1117,12 @@ public class StockholmFile extends AlignFile
     return seq;
   }
 
-  @Override
   public String print()
   {
     out = new StringBuffer();
     out.append("# STOCKHOLM 1.0");
     out.append(newline);
-    print(getSeqsAsArray());
+    print(getSeqsAsArray(), false);
 
     out.append("//");
     out.append(newline);
index fc0e207..152a2c0 100644 (file)
@@ -48,9 +48,10 @@ public abstract class StructureFile extends AlignFile
 
   private Vector<PDBChain> chains;
 
-  public StructureFile(String inFile, String type) throws IOException
+  public StructureFile(String inFile, DataSourceType sourceType)
+          throws IOException
   {
-    super(inFile, type);
+    super(inFile, sourceType);
   }
 
   public StructureFile(FileParse fp) throws IOException
@@ -77,10 +78,10 @@ public abstract class StructureFile extends AlignFile
 
   }
 
-  public StructureFile(boolean parseImmediately, String dataObject, String type)
-          throws IOException
+  public StructureFile(boolean parseImmediately, String dataObject,
+          DataSourceType sourceType) throws IOException
   {
-    super(parseImmediately, dataObject, type);
+    super(parseImmediately, dataObject, sourceType);
   }
 
   public StructureFile(boolean a, FileParse fp) throws IOException
@@ -154,7 +155,7 @@ public abstract class StructureFile extends AlignFile
                 new Object[] {});
         AlignmentI al = ((AlignmentI) cl.getMethod("getRNAMLFor",
                 new Class[] { FileParse.class }).invoke(annotate3d,
-                new Object[] { new FileParse(getDataName(), type) }));
+                new Object[] { new FileParse(getDataName(), dataSourceType) }));
         for (SequenceI sq : al.getSequences())
         {
           if (sq.getDatasetSequence() != null)
@@ -267,7 +268,7 @@ public abstract class StructureFile extends AlignFile
             boolean.class, boolean.class, boolean.class, FileParse.class });
         final Object[] args = new Object[] { visibleChainAnnotation,
             predictSecondaryStructure, externalSecondaryStructure,
-            new FileParse(getDataName(), type) };
+            new FileParse(getDataName(), dataSourceType) };
 
         StructureImportSettings.setShowSeqFeatures(false);
         StructureImportSettings.setVisibleChainAnnotation(false);
index 07d7be4..c3ec951 100644 (file)
@@ -91,9 +91,10 @@ import java.util.regex.Pattern;
  */
 public class TCoffeeScoreFile extends AlignFile
 {
-  public TCoffeeScoreFile(String inFile, String type) throws IOException
+  public TCoffeeScoreFile(String inFile, DataSourceType fileSourceType)
+          throws IOException
   {
-    super(inFile, type);
+    super(inFile, fileSourceType);
 
   }
 
@@ -213,6 +214,7 @@ public class TCoffeeScoreFile extends AlignFile
     return result;
   }
 
+  @Override
   public void parse() throws IOException
   {
     /*
@@ -643,7 +645,7 @@ public class TCoffeeScoreFile extends AlignFile
   }
 
   @Override
-  public String print()
+  public String print(SequenceI[] sqs, boolean jvsuffix)
   {
     // TODO Auto-generated method stub
     return "Not valid.";
index 71999f0..138fef7 100644 (file)
@@ -23,6 +23,7 @@ package jalview.io.packed;
 import jalview.api.FeatureColourI;
 import jalview.datamodel.AlignmentI;
 import jalview.io.AppletFormatAdapter;
+import jalview.io.FileFormatI;
 import jalview.io.FileParse;
 import jalview.io.FormatAdapter;
 import jalview.io.IdentifyFile;
@@ -64,7 +65,7 @@ public class ParsePackedSet
       FileParse src = dta.getDataSource();
       if (dta.getType().equals(DataProvider.JvDataType.ALIGNMENT))
       {
-        String fmt = null;
+        FileFormatI fmt = null;
         try
         {
           fmt = new IdentifyFile().identify(src, false);
@@ -76,32 +77,24 @@ public class ParsePackedSet
 
         if (fmt != null)
         {
-          if (!FormatAdapter.isValidIOFormat(fmt, false))
+          // parse the alignment
+          AlignmentI al = null;
+          try
           {
-            errmsg = fmt;
-            exerror = null;
+            al = new FormatAdapter().readFromFile(src, fmt);
+          } catch (Exception e)
+          {
+            errmsg = "Failed to parse alignment from result set";
+            exerror = e;
           }
-          else
+          if (al != null)
           {
-            // parse the alignment
-            AlignmentI al = null;
-            try
-            {
-              al = new FormatAdapter().readFromFile(src, fmt);
-            } catch (Exception e)
-            {
-              errmsg = "Failed to parse alignment from result set";
-              exerror = e;
-            }
-            if (al != null)
-            {
-              // deuniquify and construct/merge additional dataset entries if
-              // necessary.
-              context.addAlignment(al);
-              context.updateSetModified(true);
-              rslt.add(al);
-              deuniquify = true;
-            }
+            // deuniquify and construct/merge additional dataset entries if
+            // necessary.
+            context.addAlignment(al);
+            context.updateSetModified(true);
+            rslt.add(al);
+            deuniquify = true;
           }
         }
       }
index bf02e9e..072754e 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.jbgui;
 
+import jalview.io.FileFormatI;
 import jalview.util.MessageManager;
 
 import java.awt.BorderLayout;
@@ -69,20 +70,11 @@ public abstract class GAlignExportSettings extends JPanel
           showDialog;
 
   public GAlignExportSettings(boolean hasHiddenSeq, boolean hasHiddenCols,
-          String alignFileFormat)
+          FileFormatI format)
   {
     this.hasHiddenSeq = hasHiddenSeq;
     this.hasHiddenCols = hasHiddenCols;
-    String[] complexFormats = { "JSON", "HTML" };
-
-    for (String format : complexFormats)
-    {
-      if (format.equalsIgnoreCase(alignFileFormat))
-      {
-        this.isComplexAlignFile = true;
-        break;
-      }
-    }
+    this.isComplexAlignFile = format.isComplexAlignFile();
     if (this.hasHiddenCols || this.hasHiddenSeq || this.isComplexAlignFile)
     {
       this.showDialog = true;
@@ -111,6 +103,7 @@ public abstract class GAlignExportSettings extends JPanel
 
     chkAll.addItemListener(new ItemListener()
     {
+      @Override
       public void itemStateChanged(ItemEvent e)
       {
         checkAllAction();
@@ -119,6 +112,7 @@ public abstract class GAlignExportSettings extends JPanel
 
     btnOk.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         ok_actionPerformed(e);
@@ -127,6 +121,7 @@ public abstract class GAlignExportSettings extends JPanel
 
     btnCancel.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         cancel_actionPerformed(e);
index d22fd88..63ecdaf 100755 (executable)
@@ -21,6 +21,7 @@
 package jalview.jbgui;
 
 import jalview.api.AlignmentViewPanel;
+import jalview.io.FileFormatException;
 import jalview.util.MessageManager;
 
 import java.awt.FlowLayout;
@@ -157,6 +158,7 @@ public class GDesktop extends JFrame
     inputLocalFileMenuItem
             .addActionListener(new java.awt.event.ActionListener()
             {
+              @Override
               public void actionPerformed(ActionEvent e)
               {
                 inputLocalFileMenuItem_actionPerformed(null);
@@ -165,9 +167,16 @@ public class GDesktop extends JFrame
     inputURLMenuItem.setText(MessageManager.getString("label.from_url"));
     inputURLMenuItem.addActionListener(new java.awt.event.ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
-        inputURLMenuItem_actionPerformed(null);
+        try
+        {
+          inputURLMenuItem_actionPerformed(null);
+        } catch (FileFormatException e1)
+        {
+          System.err.println("Error loading from URL: " + e1.getMessage());
+        }
       }
     });
     inputTextboxMenuItem.setText(MessageManager
@@ -175,6 +184,7 @@ public class GDesktop extends JFrame
     inputTextboxMenuItem
             .addActionListener(new java.awt.event.ActionListener()
             {
+              @Override
               public void actionPerformed(ActionEvent e)
               {
                 inputTextboxMenuItem_actionPerformed(null);
@@ -183,6 +193,7 @@ public class GDesktop extends JFrame
     quit.setText(MessageManager.getString("action.quit"));
     quit.addActionListener(new java.awt.event.ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         quit();
@@ -191,6 +202,7 @@ public class GDesktop extends JFrame
     aboutMenuItem.setText(MessageManager.getString("label.about"));
     aboutMenuItem.addActionListener(new java.awt.event.ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         aboutMenuItem_actionPerformed(e);
@@ -203,6 +215,7 @@ public class GDesktop extends JFrame
     documentationMenuItem
             .addActionListener(new java.awt.event.ActionListener()
             {
+              @Override
               public void actionPerformed(ActionEvent e)
               {
                 documentationMenuItem_actionPerformed(e);
@@ -213,6 +226,7 @@ public class GDesktop extends JFrame
     preferences.setText(MessageManager.getString("label.preferences"));
     preferences.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         preferences_actionPerformed(e);
@@ -222,6 +236,7 @@ public class GDesktop extends JFrame
     saveState.setText(MessageManager.getString("action.save_project"));
     saveState.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         saveState_actionPerformed(e);
@@ -230,6 +245,7 @@ public class GDesktop extends JFrame
     loadState.setText(MessageManager.getString("action.load_project"));
     loadState.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         loadState_actionPerformed(e);
@@ -241,6 +257,7 @@ public class GDesktop extends JFrame
     vamsasStart.setVisible(false);
     vamsasStart.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         vamsasStart_actionPerformed(e);
@@ -251,6 +268,7 @@ public class GDesktop extends JFrame
     vamsasImport.setVisible(false);
     vamsasImport.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         vamsasImport_actionPerformed(e);
@@ -261,6 +279,7 @@ public class GDesktop extends JFrame
     vamsasSave.setVisible(false);
     vamsasSave.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         vamsasSave_actionPerformed(e);
@@ -270,6 +289,7 @@ public class GDesktop extends JFrame
             .getString("action.fetch_sequences"));
     inputSequence.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         inputSequence_actionPerformed(e);
@@ -280,6 +300,7 @@ public class GDesktop extends JFrame
     vamsasStop.setVisible(false);
     vamsasStop.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         vamsasStop_actionPerformed(e);
@@ -288,6 +309,7 @@ public class GDesktop extends JFrame
     closeAll.setText(MessageManager.getString("action.close_all"));
     closeAll.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         closeAll_actionPerformed(e);
@@ -297,6 +319,7 @@ public class GDesktop extends JFrame
             .getString("action.raise_associated_windows"));
     raiseRelated.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         raiseRelated_actionPerformed(e);
@@ -306,6 +329,7 @@ public class GDesktop extends JFrame
             .getString("action.minimize_associated_windows"));
     minimizeAssociated.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         minimizeAssociated_actionPerformed(e);
@@ -315,6 +339,7 @@ public class GDesktop extends JFrame
             .getString("label.collect_garbage"));
     garbageCollect.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         garbageCollect_actionPerformed(e);
@@ -324,6 +349,7 @@ public class GDesktop extends JFrame
             .getString("label.show_memory_usage"));
     showMemusage.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         showMemusage_actionPerformed(e);
@@ -333,6 +359,7 @@ public class GDesktop extends JFrame
             .setText(MessageManager.getString("label.show_java_console"));
     showConsole.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         showConsole_actionPerformed(e);
@@ -341,6 +368,7 @@ public class GDesktop extends JFrame
     showNews.setText(MessageManager.getString("label.show_jalview_news"));
     showNews.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         showNews_actionPerformed(e);
@@ -349,6 +377,7 @@ public class GDesktop extends JFrame
     snapShotWindow.setText(MessageManager.getString("label.take_snapshot"));
     snapShotWindow.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         snapShotWindow_actionPerformed(e);
@@ -446,9 +475,10 @@ public class GDesktop extends JFrame
    * 
    * @param e
    *          DOCUMENT ME!
+   * @throws FileFormatException
    */
   protected void inputURLMenuItem_actionPerformed(
-          jalview.gui.AlignViewport av)
+          jalview.gui.AlignViewport av) throws FileFormatException
   {
   }
 
index df09a61..fef4568 100755 (executable)
@@ -21,6 +21,8 @@
 package jalview.jbgui;
 
 import jalview.datamodel.AlignmentI;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
 import jalview.io.FormatAdapter;
 import jalview.util.MessageManager;
 
@@ -99,6 +101,7 @@ public class GFinder extends JPanel
     findAll.setText(MessageManager.getString("action.find_all"));
     findAll.addActionListener(new java.awt.event.ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         findAll_actionPerformed(e);
@@ -108,6 +111,7 @@ public class GFinder extends JPanel
     findNext.setText(MessageManager.getString("action.find_next"));
     findNext.addActionListener(new java.awt.event.ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         findNext_actionPerformed(e);
@@ -123,6 +127,7 @@ public class GFinder extends JPanel
     createNewGroup.setText(MessageManager.getString("label.new_feature"));
     createNewGroup.addActionListener(new java.awt.event.ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         createNewGroup_actionPerformed(e);
@@ -133,6 +138,7 @@ public class GFinder extends JPanel
     textfield.setLineWrap(true);
     textfield.addCaretListener(new CaretListener()
     {
+      @Override
       public void caretUpdate(CaretEvent e)
       {
         textfield_caretUpdate(e);
@@ -140,6 +146,7 @@ public class GFinder extends JPanel
     });
     textfield.addKeyListener(new java.awt.event.KeyAdapter()
     {
+      @Override
       public void keyPressed(KeyEvent e)
       {
         textfield_keyPressed(e);
@@ -207,13 +214,15 @@ public class GFinder extends JPanel
     {
       SwingUtilities.invokeLater(new Runnable()
       {
+        @Override
         public void run()
         {
           String str = textfield.getText();
           AlignmentI al = null;
           try
           {
-            al = new FormatAdapter().readFile(str, "Paste", "FASTA");
+            al = new FormatAdapter().readFile(str, DataSourceType.PASTE,
+                    FileFormat.Fasta);
           } catch (Exception ex)
           {
           }
index 82b5f69..f5963de 100644 (file)
@@ -101,9 +101,9 @@ public class StructureImportSettings
     StructureImportSettings.showSeqFeatures = showSeqFeatures;
   }
 
-  public static String getDefaultStructureFileFormat()
+  public static PDBEntry.Type getDefaultStructureFileFormat()
   {
-    return defaultStructureFileFormat.toString();
+    return defaultStructureFileFormat;
   }
 
   public static void setDefaultStructureFileFormat(
index be042e6..1738f99 100644 (file)
@@ -32,8 +32,9 @@ import jalview.datamodel.Annotation;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SearchResults;
 import jalview.datamodel.SequenceI;
+import jalview.ext.jmol.JmolParser;
 import jalview.gui.IProgressIndicator;
-import jalview.io.AppletFormatAdapter;
+import jalview.io.DataSourceType;
 import jalview.io.StructureFile;
 import jalview.util.MappingUtils;
 import jalview.util.MessageManager;
@@ -316,14 +317,14 @@ public class StructureSelectionManager
    *          (may be nill, individual elements may be nill)
    * @param pdbFile
    *          - structure data resource
-   * @param protocol
+   * @param paste
    *          - how to resolve data from resource
    * @return null or the structure data parsed as a pdb file
    */
   synchronized public StructureFile setMapping(SequenceI[] sequence,
-          String[] targetChains, String pdbFile, String protocol)
+          String[] targetChains, String pdbFile, DataSourceType paste)
   {
-    return setMapping(true, sequence, targetChains, pdbFile, protocol);
+    return setMapping(true, sequence, targetChains, pdbFile, paste);
   }
 
 
@@ -341,14 +342,14 @@ public class StructureSelectionManager
    *          (may be nill, individual elements may be nill)
    * @param pdbFile
    *          - structure data resource
-   * @param protocol
+   * @param sourceType
    *          - how to resolve data from resource
    * @return null or the structure data parsed as a pdb file
    */
   synchronized public StructureFile setMapping(boolean forStructureView,
           SequenceI[] sequenceArray, String[] targetChainIds,
           String pdbFile,
-          String protocol)
+ DataSourceType sourceType)
   {
     /*
      * There will be better ways of doing this in the future, for now we'll use
@@ -391,17 +392,17 @@ public class StructureSelectionManager
                               .toString());
       if (isParseWithJMOL || (pdbFile != null && isCIFFile(pdbFile)))
       {
-        pdb = new jalview.ext.jmol.JmolParser(addTempFacAnnot, parseSecStr,
-                secStructServices, pdbFile, protocol);
+        pdb = new JmolParser(addTempFacAnnot, parseSecStr,
+                secStructServices, pdbFile, sourceType);
       }
       else
       {
         pdb = new PDBfile(addTempFacAnnot, parseSecStr, secStructServices,
-                pdbFile, protocol);
+                pdbFile, sourceType);
       }
 
       if (pdb.getId() != null && pdb.getId().trim().length() > 0
-              && AppletFormatAdapter.FILE.equals(protocol))
+              && sourceType == DataSourceType.FILE)
       {
         registerPDBFile(pdb.getId().trim(), pdbFile);
       }
@@ -496,7 +497,7 @@ public class StructureSelectionManager
         continue;
       }
 
-      if (protocol.equals(jalview.io.AppletFormatAdapter.PASTE))
+      if (sourceType == DataSourceType.PASTE)
       {
         pdbFile = "INLINE" + pdb.getId();
       }
index dc42315..70fe609 100644 (file)
@@ -24,6 +24,7 @@ import jalview.api.StructureSelectionManagerProvider;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
+import jalview.io.DataSourceType;
 import jalview.structure.AtomSpec;
 import jalview.structure.StructureListener;
 import jalview.structure.StructureMapping;
@@ -66,7 +67,7 @@ public abstract class AAStructureBindingModel extends
   /*
    * datasource protocol for access to PDBEntrylatest
    */
-  String protocol = null;
+  DataSourceType protocol = null;
 
   protected boolean colourBySequence = true;
 
@@ -123,18 +124,18 @@ public abstract class AAStructureBindingModel extends
    * @param pdbentry
    * @param sequenceIs
    * @param chains
-   * @param protocol
+   * @param protocol2
    */
   public AAStructureBindingModel(StructureSelectionManager ssm,
           PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains,
-          String protocol)
+          DataSourceType protocol2)
   {
     this.ssm = ssm;
     this.sequence = sequenceIs;
     this.nucleotide = Comparison.isNucleotide(sequenceIs);
     this.chains = chains;
     this.pdbEntry = pdbentry;
-    this.protocol = protocol;
+    this.protocol = protocol2;
     if (chains == null)
     {
       this.chains = new String[pdbentry.length][];
@@ -198,7 +199,7 @@ public abstract class AAStructureBindingModel extends
     return chains;
   }
 
-  public String getProtocol()
+  public DataSourceType getProtocol()
   {
     return protocol;
   }
index fcea21d..d8b6a7b 100755 (executable)
@@ -20,6 +20,7 @@
  */
 package jalview.util;
 
+import jalview.bin.Cache;
 import jalview.bin.Jalview;
 import jalview.gui.EPSOptions;
 import jalview.gui.IProgressIndicator;
@@ -42,6 +43,22 @@ import org.jibble.epsgraphics.EpsGraphics2D;
 
 public class ImageMaker
 {
+  public static final String SVG_DESCRIPTION = "Scalable Vector Graphics";
+
+  public static final String SVG_EXTENSION = "svg";
+
+  public static final String EPS_DESCRIPTION = "Encapsulated Postscript";
+
+  public static final String EPS_EXTENSION = "eps";
+
+  public static final String PNG_EXTENSION = "png";
+
+  public static final String PNG_DESCRIPTION = "Portable  network graphics";
+
+  public static final String HTML_EXTENSION = "html";
+
+  public static final String HTML_DESCRIPTION = "Hypertext Markup Language";
+
   EpsGraphics2D pg;
 
   SVGGraphics2D g2;
@@ -181,7 +198,7 @@ public class ImageMaker
         out.close();
         break;
       case PNG:
-        ImageIO.write(bi, "png", out);
+        ImageIO.write(bi, PNG_EXTENSION, out);
         out.flush();
         out.close();
         break;
@@ -293,11 +310,8 @@ public class ImageMaker
     {
       return null;
     }
-    return new jalview.io.JalviewFileChooser(
-            jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
-            new String[] { "png" },
-            new String[] { "Portable network graphics" },
-            "Portable network graphics");
+    return new JalviewFileChooser(Cache.getProperty("LAST_DIRECTORY"),
+            PNG_EXTENSION, PNG_DESCRIPTION, PNG_DESCRIPTION);
   }
 
   static JalviewFileChooser getEPSChooser()
@@ -306,11 +320,8 @@ public class ImageMaker
     {
       return null;
     }
-    return new jalview.io.JalviewFileChooser(
-            jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
-            new String[] { "eps" },
-            new String[] { "Encapsulated Postscript" },
-            "Encapsulated Postscript");
+    return new JalviewFileChooser(Cache.getProperty("LAST_DIRECTORY"),
+            EPS_EXTENSION, EPS_DESCRIPTION, EPS_DESCRIPTION);
   }
 
   private void setProgressMessage(String message)
@@ -327,10 +338,7 @@ public class ImageMaker
     {
       return null;
     }
-    return new jalview.io.JalviewFileChooser(
-            jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
-            new String[] { "svg" },
-            new String[] { "Scalable Vector Graphics" },
-            "Scalable Vector Graphics");
+    return new JalviewFileChooser(Cache.getProperty("LAST_DIRECTORY"),
+            SVG_EXTENSION, SVG_DESCRIPTION, SVG_DESCRIPTION);
   }
 }
index 61c5c04..757ab83 100644 (file)
@@ -29,6 +29,9 @@ import jalview.datamodel.DBRefSource;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.PDBEntry.Type;
 import jalview.datamodel.SequenceI;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
+import jalview.io.FileFormatI;
 import jalview.io.FormatAdapter;
 import jalview.io.PDBFeatureSettings;
 import jalview.structure.StructureImportSettings;
@@ -133,12 +136,11 @@ public class Pdb extends EbiFileRetrievedProxy
       stopQuery();
       return null;
     }
-    String ext = StructureImportSettings.getDefaultStructureFileFormat()
-            .equalsIgnoreCase(Type.MMCIF.toString()) ? ".cif" : ".xml";
+    Type pdbFileFormat = StructureImportSettings
+            .getDefaultStructureFileFormat();
+    String ext = "." + pdbFileFormat.getExtension();
     EBIFetchClient ebi = new EBIFetchClient();
-    file = ebi.fetchDataAsFile("pdb:" + id,
-            StructureImportSettings.getDefaultStructureFileFormat().toLowerCase(),
-            ext)
+    file = ebi.fetchDataAsFile("pdb:" + id, pdbFileFormat.getFormat(), ext)
             .getAbsolutePath();
     stopQuery();
     if (file == null)
@@ -147,10 +149,11 @@ public class Pdb extends EbiFileRetrievedProxy
     }
     try
     {
-
+      // convert Type.PDB/MMCIF to FileFormat.PDB/MMCIF
+      // todo get rid of Type?
+      FileFormatI fileFormat = FileFormat.valueOf(pdbFileFormat.toString());
       pdbAlignment = new FormatAdapter().readFile(file,
-              jalview.io.AppletFormatAdapter.FILE,
-              StructureImportSettings.getDefaultStructureFileFormat());
+              DataSourceType.FILE, fileFormat);
       if (pdbAlignment != null)
       {
         List<SequenceI> toremove = new ArrayList<SequenceI>();
index 4f081ee..5b8a3ae 100644 (file)
@@ -23,6 +23,8 @@ package jalview.ws.dbsources;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.DBRefEntry;
 import jalview.datamodel.DBRefSource;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
 import jalview.io.FormatAdapter;
 
 import com.stevesoft.pat.Regex;
@@ -119,8 +121,8 @@ abstract public class Pfam extends Xfam
     // retrieved.
     startQuery();
     AlignmentI rcds = new FormatAdapter().readFile(getXFAMURL()
-            + queries.trim().toUpperCase(), jalview.io.FormatAdapter.URL,
-            "STH");
+            + queries.trim().toUpperCase(), DataSourceType.URL,
+            FileFormat.Stockholm);
     for (int s = 0, sNum = rcds.getHeight(); s < sNum; s++)
     {
       rcds.getSequenceAt(s).addDBRef(
index 508047d..3554f01 100644 (file)
@@ -22,6 +22,8 @@ package jalview.ws.dbsources;
 
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.DBRefEntry;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
 import jalview.io.FormatAdapter;
 import jalview.ws.seqfetcher.DbSourceProxyImpl;
 
@@ -56,8 +58,7 @@ public abstract class Xfam extends DbSourceProxyImpl
     // TODO: trap HTTP 404 exceptions and return null
     AlignmentI rcds = new FormatAdapter().readFile(getXFAMURL()
             + queries.trim().toUpperCase() + getXFAMURLSUFFIX(),
-            jalview.io.FormatAdapter.URL,
-            "STH");
+            DataSourceType.URL, FileFormat.Stockholm);
     for (int s = 0, sNum = rcds.getHeight(); s < sNum; s++)
     {
       rcds.getSequenceAt(s).addDBRef(new DBRefEntry(getXfamSource(),
index 8c30c69..bae0357 100644 (file)
@@ -21,6 +21,7 @@
 package jalview.ws.jws1;
 
 import jalview.datamodel.AlignmentI;
+import jalview.io.FileFormat;
 import jalview.io.FileParse;
 import jalview.io.FormatAdapter;
 import jalview.io.InputStreamParser;
@@ -86,7 +87,8 @@ public class Annotate3D
       while (r.hasNext())
       {
         FileParse fp = new InputStreamParser(r.next(), source.getDataName());
-        AlignmentI nal = new FormatAdapter().readFromFile(fp, "RNAML");
+        AlignmentI nal = new FormatAdapter().readFromFile(fp,
+                FileFormat.Rnaml);
         if (al == null)
         {
           al = nal;
index 8299e3c..4e5cadc 100644 (file)
@@ -21,6 +21,7 @@
 package jalview.ws.jws1;
 
 import jalview.analysis.AlignSeq;
+import jalview.analysis.SeqsetUtils;
 import jalview.bin.Cache;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentAnnotation;
@@ -31,7 +32,13 @@ import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
 import jalview.gui.Desktop;
 import jalview.gui.WebserviceInfo;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormatI;
 import jalview.io.FormatAdapter;
+import jalview.io.IdentifyFile;
+import jalview.io.JPredFile;
+import jalview.io.JnetAnnotationMaker;
+import jalview.io.PileUpfile;
 import jalview.util.Comparison;
 import jalview.util.MessageManager;
 import jalview.ws.AWsJob;
@@ -71,6 +78,7 @@ class JPredThread extends JWS1Thread implements WSClientI
      * @return true if getResultSet will return a valid alignment and prediction
      *         result.
      */
+    @Override
     public boolean hasResults()
     {
       if (subjobComplete && result != null && result.isFinished()
@@ -82,6 +90,7 @@ class JPredThread extends JWS1Thread implements WSClientI
       return false;
     }
 
+    @Override
     public boolean hasValidInput()
     {
       if (sequence != null)
@@ -110,23 +119,23 @@ class JPredThread extends JWS1Thread implements WSClientI
 
       JpredResult result = (JpredResult) this.result;
 
-      jalview.bin.Cache.log.debug("Parsing output from JNet job.");
+      Cache.log.debug("Parsing output from JNet job.");
       // JPredFile prediction = new JPredFile("C:/JalviewX/files/jpred.txt",
       // "File");
-      jalview.io.JPredFile prediction = new jalview.io.JPredFile(
-              result.getPredfile(), "Paste");
+      JPredFile prediction = new JPredFile(
+              result.getPredfile(), DataSourceType.PASTE);
       SequenceI[] preds = prediction.getSeqsAsArray();
-      jalview.bin.Cache.log.debug("Got prediction profile.");
+      Cache.log.debug("Got prediction profile.");
 
       if ((this.msa != null) && (result.getAligfile() != null))
       {
-        jalview.bin.Cache.log.debug("Getting associated alignment.");
+        Cache.log.debug("Getting associated alignment.");
         // we ignore the returned alignment if we only predicted on a single
         // sequence
-        String format = new jalview.io.IdentifyFile().identify(
-                result.getAligfile(), "Paste");
+        FileFormatI format = new IdentifyFile().identify(
+                result.getAligfile(), DataSourceType.PASTE);
 
-        if (jalview.io.FormatAdapter.isValidFormat(format))
+        if (format != null)
         {
           SequenceI sqs[];
           if (predMap != null)
@@ -140,14 +149,14 @@ class JPredThread extends JWS1Thread implements WSClientI
           else
           {
             al = new FormatAdapter().readFile(result.getAligfile(),
-                    "Paste", format);
+                    DataSourceType.PASTE, format);
             sqs = new SequenceI[al.getHeight()];
 
             for (int i = 0, j = al.getHeight(); i < j; i++)
             {
               sqs[i] = al.getSequenceAt(i);
             }
-            if (!jalview.analysis.SeqsetUtils.deuniquify(SequenceInfo, sqs))
+            if (!SeqsetUtils.deuniquify(SequenceInfo, sqs))
             {
               throw (new Exception(
                       MessageManager
@@ -164,7 +173,7 @@ class JPredThread extends JWS1Thread implements WSClientI
           {
             al.setDataset(null);
           }
-          jalview.io.JnetAnnotationMaker.add_annotation(prediction, al,
+          JnetAnnotationMaker.add_annotation(prediction, al,
                   FirstSeq, false, predMap);
 
         }
@@ -172,7 +181,7 @@ class JPredThread extends JWS1Thread implements WSClientI
         {
           throw (new Exception(MessageManager.formatMessage(
                   "exception.unknown_format_for_file", new String[] {
-                      format, result.getAligfile() })));
+                      format.toString(), result.getAligfile() })));
         }
       }
       else
@@ -355,8 +364,8 @@ class JPredThread extends JWS1Thread implements WSClientI
         if (msf.length > 1)
         {
           msa = new vamsas.objects.simple.Msfalignment();
-          jalview.io.PileUpfile pileup = new jalview.io.PileUpfile();
-          msa.setMsf(pileup.print(msf));
+          PileUpfile pileup = new PileUpfile();
+          msa.setMsf(pileup.print(msf, true));
         }
       }
     }
@@ -420,6 +429,7 @@ class JPredThread extends JWS1Thread implements WSClientI
     }
   }
 
+  @Override
   public void StartJob(AWsJob j)
   {
     if (!(j instanceof JPredJob))
@@ -502,6 +512,7 @@ class JPredThread extends JWS1Thread implements WSClientI
     }
   }
 
+  @Override
   public void parseResult()
   {
     int results = 0; // number of result sets received
@@ -529,6 +540,7 @@ class JPredThread extends JWS1Thread implements WSClientI
       wsInfo.showResultsNewFrame
               .addActionListener(new java.awt.event.ActionListener()
               {
+                @Override
                 public void actionPerformed(java.awt.event.ActionEvent evt)
                 {
                   displayResults(true);
@@ -537,6 +549,7 @@ class JPredThread extends JWS1Thread implements WSClientI
       wsInfo.mergeResults
               .addActionListener(new java.awt.event.ActionListener()
               {
+                @Override
                 public void actionPerformed(java.awt.event.ActionEvent evt)
                 {
                   displayResults(false);
@@ -652,21 +665,25 @@ class JPredThread extends JWS1Thread implements WSClientI
     }
   }
 
+  @Override
   public void pollJob(AWsJob job) throws Exception
   {
     ((JPredJob) job).result = server.getresult(job.getJobId());
   }
 
+  @Override
   public boolean isCancellable()
   {
     return false;
   }
 
+  @Override
   public void cancelJob()
   {
     throw new Error(MessageManager.getString("error.implementation_error"));
   }
 
+  @Override
   public boolean canMergeResults()
   {
     return false;
index 70056a6..b14917e 100644 (file)
@@ -209,7 +209,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
           if (inFile != null && inFile.length() > 0)
           {
             new jalview.io.AnnotationFile().readAnnotationFile(al, inFile,
-                    jalview.io.AppletFormatAdapter.PASTE);
+                    jalview.io.DataSourceType.PASTE);
           }
         } catch (Exception e)
         {
@@ -225,7 +225,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
           if (inFile != null && inFile.length() > 0)
           {
             jalview.io.FeaturesFile ff = new jalview.io.FeaturesFile(
-                    inFile, jalview.io.AppletFormatAdapter.PASTE);
+                    inFile, jalview.io.DataSourceType.PASTE);
             ff.parse(al, featureColours, false);
           }
         } catch (Exception e)
@@ -242,7 +242,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
           if (inFile != null && inFile.length() > 0)
           {
             nf = new jalview.io.NewickFile(inFile,
-                    jalview.io.AppletFormatAdapter.PASTE);
+                    jalview.io.DataSourceType.PASTE);
             if (!nf.isValid())
             {
               nf.close();
index 18c1ad0..c78bced 100644 (file)
@@ -21,6 +21,9 @@
 package jalview.ws.rest.params;
 
 import jalview.datamodel.AlignmentI;
+import jalview.io.FileFormat;
+import jalview.io.FileFormatI;
+import jalview.io.FormatAdapter;
 import jalview.ws.params.OptionI;
 import jalview.ws.params.simple.BooleanOption;
 import jalview.ws.params.simple.Option;
@@ -55,7 +58,7 @@ public class Alignment extends InputType
     super(new Class[] { AlignmentI.class });
   }
 
-  String format = "FASTA";
+  FileFormatI format = FileFormat.Fasta;
 
   molType type;
 
@@ -79,7 +82,7 @@ public class Alignment extends InputType
         PrintWriter pw = new PrintWriter(
                 new OutputStreamWriter(new BufferedOutputStream(
                         new FileOutputStream(fa)), "UTF-8"));
-        pw.append(new jalview.io.FormatAdapter().formatSequences(format,
+        pw.append(new FormatAdapter().formatSequences(format,
                 alignment, jvsuffix));
         pw.close();
         return new FileBody(fa, "text/plain");
@@ -91,7 +94,7 @@ public class Alignment extends InputType
     }
     else
     {
-      jalview.io.FormatAdapter fa = new jalview.io.FormatAdapter();
+      FormatAdapter fa = new FormatAdapter();
       fa.setNewlineString("\r\n");
       return new StringBody(
               (fa.formatSequences(format, alignment, jvsuffix)));
@@ -115,12 +118,10 @@ public class Alignment extends InputType
     {
       prms.add("jvsuffix");
     }
-    ;
     if (writeAsFile)
     {
       prms.add("writeasfile");
     }
-    ;
     return prms;
   }
 
@@ -147,9 +148,9 @@ public class Alignment extends InputType
 
     if (tok.startsWith("format"))
     {
-      for (String fmt : jalview.io.FormatAdapter.WRITEABLE_FORMATS)
+      for (FileFormatI fmt : FileFormat.values())
       {
-        if (val.equalsIgnoreCase(fmt))
+        if (fmt.isWritable() && val.equalsIgnoreCase(fmt.toString()))
         {
           format = fmt;
           return true;
@@ -157,9 +158,12 @@ public class Alignment extends InputType
       }
       warnings.append("Invalid alignment format '" + val
               + "'. Must be one of (");
-      for (String fmt : jalview.io.FormatAdapter.WRITEABLE_FORMATS)
+      for (FileFormatI fmt : FileFormat.values())
       {
-        warnings.append(" " + fmt);
+        if (fmt.isWritable())
+        {
+          warnings.append(" " + fmt).toString();
+        }
       }
       warnings.append(")\n");
     }
@@ -194,8 +198,9 @@ public class Alignment extends InputType
             "Append jalview style /start-end suffix to ID", false, false,
             writeAsFile, null));
 
-    lst.add(new Option("format", "Alignment upload format", true, "FASTA",
-            format, Arrays
+    lst.add(new Option("format", "Alignment upload format", true,
+            FileFormat.Fasta.toString(),
+ format.toString(), Arrays
                     .asList(jalview.io.FormatAdapter.WRITEABLE_FORMATS),
             null));
     lst.add(createMolTypeOption("type", "Sequence type", false, type, null));
index 5bed720..2fcf501 100644 (file)
@@ -22,6 +22,8 @@ package jalview.ws.seqfetcher;
 
 import jalview.api.FeatureSettingsModelI;
 import jalview.datamodel.AlignmentI;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormatI;
 import jalview.io.FormatAdapter;
 import jalview.io.IdentifyFile;
 
@@ -92,10 +94,12 @@ public abstract class DbSourceProxyImpl implements DbSourceProxy
   protected AlignmentI parseResult(String result) throws Exception
   {
     AlignmentI sequences = null;
-    String format = new IdentifyFile().identify(result, "Paste");
-    if (FormatAdapter.isValidFormat(format))
+    FileFormatI format = new IdentifyFile().identify(result,
+            DataSourceType.PASTE);
+    if (format != null)
     {
-      sequences = new FormatAdapter().readFile(result.toString(), "Paste",
+      sequences = new FormatAdapter().readFile(result.toString(),
+              DataSourceType.PASTE,
               format);
     }
     return sequences;
index a6a1de4..54576c6 100644 (file)
@@ -32,7 +32,7 @@ import jalview.datamodel.AlignmentI;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceI;
-import jalview.io.AppletFormatAdapter;
+import jalview.io.DataSourceType;
 
 import java.io.IOException;
 import java.util.List;
@@ -70,7 +70,7 @@ public class PDBfileTest
      * Constructor with file path performs parse()
      */
     PDBfile pf = new PDBfile(false, false, false, "examples/3W5V.pdb",
-            AppletFormatAdapter.FILE);
+            DataSourceType.FILE);
 
     assertEquals("3W5V", pf.getId());
     // verify no alignment annotations created
@@ -146,7 +146,7 @@ public class PDBfileTest
   public void testParse_withAnnotations_noSS() throws IOException
   {
     PDBfile pf = new PDBfile(true, false, false, "examples/3W5V.pdb",
-            AppletFormatAdapter.FILE);
+            DataSourceType.FILE);
 
     AlignmentAnnotation[] anns = getAlignmentAnnotations(pf);
     assertEquals(4, anns.length);
@@ -204,7 +204,7 @@ public class PDBfileTest
   public void testParse_withJmol_noAnnotations() throws IOException
   {
     PDBfile pf = new PDBfile(false, true, false, "examples/3W5V.pdb",
-            AppletFormatAdapter.FILE);
+            DataSourceType.FILE);
 
     /*
      * alignment annotations _are_ created anyway (in
@@ -234,7 +234,7 @@ public class PDBfileTest
           throws IOException
   {
     PDBfile pf = new PDBfile(true, true, false, "examples/3W5V.pdb",
-            AppletFormatAdapter.FILE);
+            DataSourceType.FILE);
 
     /*
      * Alignment annotations for TempFactor, SecStruct, per sequence (chain)
@@ -292,7 +292,7 @@ public class PDBfileTest
     // TODO requires a mock for Annotate3D processing
     // and/or run as an integration test
     PDBfile pf = new PDBfile(true, true, true, "examples/2GIS.pdb",
-            AppletFormatAdapter.FILE);
+            DataSourceType.FILE);
   }
 
   /**
index c3191e8..5367d7f 100644 (file)
@@ -28,7 +28,8 @@ import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.Annotation;
 import jalview.datamodel.SequenceI;
-import jalview.io.AppletFormatAdapter;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -142,7 +143,7 @@ public class AlignmentAnnotationUtilsTest
   public void setUp() throws IOException
   {
     alignment = new jalview.io.FormatAdapter().readFile(TEST_DATA,
-            AppletFormatAdapter.PASTE, "FASTA");
+            DataSourceType.PASTE, FileFormat.Fasta);
 
     AlignmentAnnotation[] anns = new AlignmentAnnotation[SEQ_ANN_COUNT];
     for (int i = 0; i < anns.length; i++)
index a856231..f74e456 100644 (file)
@@ -41,6 +41,9 @@ import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.io.AppletFormatAdapter;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
+import jalview.io.FileFormatI;
 import jalview.io.FormatAdapter;
 import jalview.util.MapList;
 import jalview.util.MappingUtils;
@@ -69,14 +72,15 @@ public class AlignmentUtilsTests
       SequenceI s1 = ts.deriveSequence().getSubSequence(i, i + 7);
       al.addSequence(s1);
     }
-    System.out.println(new AppletFormatAdapter().formatSequences("Clustal",
+    System.out.println(new AppletFormatAdapter().formatSequences(
+            FileFormat.Clustal,
             al, true));
     for (int flnk = -1; flnk < 25; flnk++)
     {
       AlignmentI exp = AlignmentUtils.expandContext(al, flnk);
       System.out.println("\nFlank size: " + flnk);
       System.out.println(new AppletFormatAdapter().formatSequences(
-              "Clustal", exp, true));
+              FileFormat.Clustal, exp, true));
       if (flnk == -1)
       {
         /*
@@ -209,7 +213,7 @@ public class AlignmentUtilsTests
   {
     final String data = ">Seq1Name\nKQYL\n" + ">Seq2Name\nRFPW\n"
             + ">Seq1Name\nABCD\n";
-    AlignmentI al = loadAlignment(data, "FASTA");
+    AlignmentI al = loadAlignment(data, FileFormat.Fasta);
     Map<String, List<SequenceI>> map = AlignmentUtils
             .getSequencesByName(al);
     assertEquals(2, map.keySet().size());
@@ -229,11 +233,11 @@ public class AlignmentUtilsTests
    * @return
    * @throws IOException
    */
-  protected AlignmentI loadAlignment(final String data, String format)
+  protected AlignmentI loadAlignment(final String data, FileFormatI format)
           throws IOException
   {
     AlignmentI a = new FormatAdapter().readFile(data,
-            AppletFormatAdapter.PASTE, format);
+            DataSourceType.PASTE, format);
     a.setDataset(null);
     return a;
   }
index 69e5c23..9b7fec1 100644 (file)
@@ -83,7 +83,7 @@ public class DnaAlignmentGenerator
             + " bases with " + gapPercentage + "% gaps and "
             + changePercentage + "% mutations (random seed = " + randomSeed
             + ")");
-    System.out.println(new FastaFile().print(al.getSequencesArray()));
+    System.out.println(new FastaFile().print(al.getSequencesArray(), true));
   }
 
   /**
index 0142ab5..31c9839 100644 (file)
@@ -32,6 +32,8 @@ import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignViewport;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
 import jalview.io.FormatAdapter;
 
 import java.io.IOException;
@@ -120,8 +122,8 @@ public class DnaTest
           throws IOException
   {
     AlignmentI alf = new FormatAdapter().readFile(
-            JAL_1312_example_align_fasta, jalview.io.FormatAdapter.PASTE,
-            "FASTA");
+            JAL_1312_example_align_fasta, DataSourceType.PASTE,
+            FileFormat.Fasta);
     ColumnSelection cs = new ColumnSelection();
     AlignViewportI av = new AlignViewport(alf, cs);
     Dna dna = new Dna(av, new int[] { 0, alf.getWidth() - 1 });
@@ -141,8 +143,8 @@ public class DnaTest
           throws IOException
   {
     AlignmentI alf = new FormatAdapter().readFile(
-            JAL_1312_example_align_fasta, jalview.io.FormatAdapter.PASTE,
-            "FASTA");
+            JAL_1312_example_align_fasta, DataSourceType.PASTE,
+            FileFormat.Fasta);
     int vwidth = 15;
     for (int ipos = 0; ipos + vwidth < alf.getWidth(); ipos += vwidth)
     {
@@ -176,7 +178,7 @@ public class DnaTest
   public void testTranslateCdna_simple() throws IOException
   {
     AlignmentI alf = new FormatAdapter().readFile(fasta,
-            FormatAdapter.PASTE, "FASTA");
+            DataSourceType.PASTE, FileFormat.Fasta);
     ColumnSelection cs = new ColumnSelection();
     AlignViewportI av = new AlignViewport(alf, cs);
     Dna dna = new Dna(av, new int[] { 0, alf.getWidth() - 1 });
@@ -196,8 +198,8 @@ public class DnaTest
   public void testTranslateCdna_hiddenColumns() throws IOException
   {
     AlignmentI alf = new FormatAdapter().readFile(fasta,
-            FormatAdapter.PASTE, "FASTA");
-    ColumnSelection cs = new jalview.datamodel.ColumnSelection();
+            DataSourceType.PASTE, FileFormat.Fasta);
+    ColumnSelection cs = new ColumnSelection();
     cs.hideColumns(6, 14); // hide codons 3/4/5
     cs.hideColumns(24, 35); // hide codons 9-12
     cs.hideColumns(177, 191); // hide codons 60-64
index 029483f..1a95081 100644 (file)
@@ -24,8 +24,8 @@ import jalview.datamodel.AlignmentI;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
+import jalview.io.DataSourceType;
 import jalview.io.FileLoader;
-import jalview.io.FormatAdapter;
 
 import org.testng.Assert;
 import org.testng.annotations.Test;
@@ -43,7 +43,7 @@ public class FeatureScoreModelTest
   public AlignFrame getTestAlignmentFrame()
   {
     AlignFrame alf = new FileLoader(false).LoadFileWaitTillLoaded(
-            alntestFile, FormatAdapter.PASTE);
+            alntestFile, DataSourceType.PASTE);
     AlignmentI al = alf.getViewport().getAlignment();
     Assert.assertEquals(al.getHeight(), 4);
     Assert.assertEquals(al.getWidth(), 5);
index 1aff519..fb02166 100644 (file)
@@ -25,6 +25,7 @@ import static org.testng.AssertJUnit.assertNull;
 
 import jalview.analysis.AlignSeq;
 import jalview.io.AppletFormatAdapter;
+import jalview.io.FileFormat;
 
 import org.testng.annotations.Test;
 
@@ -119,7 +120,8 @@ public class AlignmentAnnotationTests
     alSeq2.setEnd(sqTo.getStart() + align.getSeq2End() - 1);
     alSeq2.setDatasetSequence(sqTo);
     System.out.println(new AppletFormatAdapter()
-            .formatSequences("STH", new Alignment(new SequenceI[] { sqFrom,
+.formatSequences(
+            FileFormat.Stockholm, new Alignment(new SequenceI[] { sqFrom,
                 alSeq1, sqTo, alSeq2 }), true));
 
     Mapping mp = align.getMappingFromS1(false);
@@ -143,7 +145,8 @@ public class AlignmentAnnotationTests
     AlignmentI all = new Alignment(new SequenceI[] { alSeq1, alSeq2 });
     all.addAnnotation(almap1);
     all.addAnnotation(almap2);
-    System.out.println(new AppletFormatAdapter().formatSequences("STH",
+    System.out.println(new AppletFormatAdapter().formatSequences(
+            FileFormat.Stockholm,
             all, true));
 
     for (int p = 0; p < alSeq1.getLength(); p++)
@@ -280,4 +283,4 @@ public class AlignmentAnnotationTests
               ann.getDefaultRnaHelixSymbol(i));
     }
   }
-}
\ No newline at end of file
+}
index b75ef50..756bf71 100644 (file)
@@ -27,7 +27,9 @@ import static org.testng.AssertJUnit.assertNull;
 import static org.testng.AssertJUnit.assertSame;
 import static org.testng.AssertJUnit.assertTrue;
 
-import jalview.io.AppletFormatAdapter;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
+import jalview.io.FileFormatI;
 import jalview.io.FormatAdapter;
 import jalview.util.MapList;
 
@@ -92,11 +94,11 @@ public class AlignmentTest
    * @return
    * @throws IOException
    */
-  protected AlignmentI loadAlignment(final String data, String format)
+  protected AlignmentI loadAlignment(final String data, FileFormatI format)
           throws IOException
   {
-    AlignmentI a = new FormatAdapter().readFile(data,
-            AppletFormatAdapter.PASTE, format);
+    AlignmentI a = new FormatAdapter().readFile(data, DataSourceType.PASTE,
+            format);
     a.setDataset(null);
     return a;
   }
@@ -108,7 +110,7 @@ public class AlignmentTest
   @BeforeMethod(alwaysRun = true)
   public void setUp() throws IOException
   {
-    al = loadAlignment(TEST_DATA, "STH");
+    al = loadAlignment(TEST_DATA, FileFormat.Stockholm);
     int i = 0;
     for (AlignmentAnnotation ann : al.getAlignmentAnnotation())
     {
@@ -174,9 +176,9 @@ public class AlignmentTest
   public void testAlignAs_dnaAsDna() throws IOException
   {
     // aligned cDNA:
-    AlignmentI al1 = loadAlignment(CDNA_SEQS_1, "FASTA");
+    AlignmentI al1 = loadAlignment(CDNA_SEQS_1, FileFormat.Fasta);
     // unaligned cDNA:
-    AlignmentI al2 = loadAlignment(CDNA_SEQS_2, "FASTA");
+    AlignmentI al2 = loadAlignment(CDNA_SEQS_2, FileFormat.Fasta);
 
     /*
      * Make mappings between sequences. The 'aligned cDNA' is playing the role
@@ -200,8 +202,8 @@ public class AlignmentTest
   public void testAlignAs_proteinAsCdna() throws IOException
   {
     // see also AlignmentUtilsTests
-    AlignmentI al1 = loadAlignment(CDNA_SEQS_1, "FASTA");
-    AlignmentI al2 = loadAlignment(AA_SEQS_1, "FASTA");
+    AlignmentI al1 = loadAlignment(CDNA_SEQS_1, FileFormat.Fasta);
+    AlignmentI al2 = loadAlignment(AA_SEQS_1, FileFormat.Fasta);
     makeMappings(al1, al2);
 
     // Fudge - alignProteinAsCdna expects mappings to be on protein
@@ -224,8 +226,8 @@ public class AlignmentTest
     /*
      * Load alignments and add mappings for cDNA to protein
      */
-    AlignmentI al1 = loadAlignment(CDNA_SEQS_1, "FASTA");
-    AlignmentI al2 = loadAlignment(AA_SEQS_1, "FASTA");
+    AlignmentI al1 = loadAlignment(CDNA_SEQS_1, FileFormat.Fasta);
+    AlignmentI al2 = loadAlignment(AA_SEQS_1, FileFormat.Fasta);
     makeMappings(al1, al2);
 
     /*
@@ -281,8 +283,8 @@ public class AlignmentTest
      * Load alignments and add mappings from nucleotide to protein (or from
      * first to second if both the same type)
      */
-    AlignmentI al1 = loadAlignment(fromSeqs, "FASTA");
-    AlignmentI al2 = loadAlignment(toSeqs, "FASTA");
+    AlignmentI al1 = loadAlignment(fromSeqs, FileFormat.Fasta);
+    AlignmentI al2 = loadAlignment(toSeqs, FileFormat.Fasta);
     makeMappings(al1, al2);
 
     /*
@@ -339,9 +341,9 @@ public class AlignmentTest
     String dna1 = "A-Aa-gG-GCC-cT-TT";
     String dna2 = "c--CCGgg-TT--T-AA-A";
     AlignmentI al1 = loadAlignment(">Dna1/6-17\n" + dna1
-            + "\n>Dna2/20-31\n" + dna2 + "\n", "FASTA");
+            + "\n>Dna2/20-31\n" + dna2 + "\n", FileFormat.Fasta);
     AlignmentI al2 = loadAlignment(
-            ">Pep1/7-9\n-P--YK\n>Pep2/11-13\nG-T--F\n", "FASTA");
+            ">Pep1/7-9\n-P--YK\n>Pep2/11-13\nG-T--F\n", FileFormat.Fasta);
     AlignedCodonFrame acf = new AlignedCodonFrame();
     // Seq1 has intron at dna positions 3,4,9 so splice is AAG GCC TTT
     // Seq2 has intron at dna positions 1,5,6 so splice is CCG TTT AAA
@@ -381,7 +383,7 @@ public class AlignmentTest
   @Test(groups = "Functional")
   public void testCopyConstructor() throws IOException
   {
-    AlignmentI protein = loadAlignment(AA_SEQS_1, FormatAdapter.PASTE);
+    AlignmentI protein = loadAlignment(AA_SEQS_1, FileFormat.Fasta);
     // create sequence and alignment datasets
     protein.setDataset(null);
     AlignedCodonFrame acf = new AlignedCodonFrame();
@@ -418,7 +420,7 @@ public class AlignmentTest
   public void testCreateDatasetAlignment() throws IOException
   {
     AlignmentI protein = new FormatAdapter().readFile(AA_SEQS_1,
-            AppletFormatAdapter.PASTE, "FASTA");
+            DataSourceType.PASTE, FileFormat.Fasta);
     /*
      * create a dataset sequence on first sequence
      * leave the second without one
index 2d3948f..b1ebdf8 100644 (file)
@@ -8,7 +8,7 @@ import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
-import jalview.io.AppletFormatAdapter;
+import jalview.io.DataSourceType;
 import jalview.io.FastaFile;
 import jalview.io.FileParse;
 import jalview.io.gff.SequenceOntologyFactory;
@@ -132,7 +132,7 @@ public class EnsemblSeqProxyTest
             .asList(new String[]
     { sq }));
     SequenceI[] sqs = new FastaFile(fp).getSeqsAsArray();
-    FastaFile trueRes = new FastaFile(fastasq, AppletFormatAdapter.PASTE);
+    FastaFile trueRes = new FastaFile(fastasq, DataSourceType.PASTE);
     SequenceI[] trueSqs = trueRes.getSeqsAsArray();
     Assert.assertEquals(sqs.length, trueSqs.length,
             "Different number of sequences retrieved for query " + sq);
index 7ab058e..f2b32c6 100644 (file)
@@ -28,7 +28,7 @@ import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
-import jalview.io.AppletFormatAdapter;
+import jalview.io.DataSourceType;
 import jalview.io.FileLoader;
 import jalview.structure.StructureImportSettings;
 import jalview.structure.StructureImportSettings.StructureParser;
@@ -101,8 +101,7 @@ public class JmolParserTest
     for (String f : testFile)
     {
       FileLoader fl = new jalview.io.FileLoader(false);
-      AlignFrame af = fl
-              .LoadFileWaitTillLoaded(f, AppletFormatAdapter.FILE);
+      AlignFrame af = fl.LoadFileWaitTillLoaded(f, DataSourceType.FILE);
       validateSecStrRows(af.getViewport().getAlignment());
     }
   }
@@ -113,9 +112,9 @@ public class JmolParserTest
     for (String pdbStr : testFile)
     {
       PDBfile mctest = new PDBfile(false, false, false, pdbStr,
-              AppletFormatAdapter.FILE);
+              DataSourceType.FILE);
       JmolParser jtest = new JmolParser(false, false, false, pdbStr,
-              jalview.io.AppletFormatAdapter.FILE);
+              DataSourceType.FILE);
       Vector<SequenceI> seqs = jtest.getSeqs(), mcseqs = mctest.getSeqs();
 
       assertTrue(
@@ -180,15 +179,13 @@ public class JmolParserTest
   public void testParse_missingResidues() throws Exception
   {
     PDBfile mctest = new PDBfile(false, false, false,
-            pastePDBDataWithChainBreak,
-            AppletFormatAdapter.PASTE);
+            pastePDBDataWithChainBreak, DataSourceType.PASTE);
     boolean annotFromStructure = false;
     boolean localSecondaryStruct = false;
     boolean serviceSecondaryStruct = false;
     JmolParser jtest = new JmolParser(annotFromStructure,
             localSecondaryStruct, serviceSecondaryStruct,
-            pastePDBDataWithChainBreak,
-            jalview.io.AppletFormatAdapter.PASTE);
+            pastePDBDataWithChainBreak, DataSourceType.PASTE);
     Vector<SequenceI> seqs = jtest.getSeqs();
     Vector<SequenceI> mcseqs = mctest.getSeqs();
 
@@ -209,13 +206,13 @@ public class JmolParserTest
   public void testParse_alternativeResidues() throws Exception
   {
     PDBfile mctest = new PDBfile(false, false, false, pdbWithAltLoc,
-            AppletFormatAdapter.PASTE);
+            DataSourceType.PASTE);
     boolean annotFromStructure = false;
     boolean localSecondaryStruct = false;
     boolean serviceSecondaryStruct = false;
     JmolParser jtest = new JmolParser(annotFromStructure,
             localSecondaryStruct, serviceSecondaryStruct, pdbWithAltLoc,
-            jalview.io.AppletFormatAdapter.PASTE);
+            DataSourceType.PASTE);
     Vector<SequenceI> seqs = jtest.getSeqs();
     Vector<SequenceI> mcseqs = mctest.getSeqs();
   
index 10224fa..1100000 100644 (file)
@@ -29,7 +29,7 @@ import jalview.gui.AlignFrame;
 import jalview.gui.Preferences;
 import jalview.gui.StructureViewer;
 import jalview.gui.StructureViewer.ViewerType;
-import jalview.io.FormatAdapter;
+import jalview.io.DataSourceType;
 
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
@@ -65,7 +65,7 @@ public class JmolViewerTest
     Cache.setProperty(Preferences.STRUCTURE_DISPLAY, ViewerType.JMOL.name());
     String inFile = "examples/1gaq.txt";
     AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
-            inFile, FormatAdapter.FILE);
+            inFile, DataSourceType.FILE);
     assertTrue("Didn't read input file " + inFile, af != null);
     for (SequenceI sq : af.getViewport().getAlignment().getSequences())
     {
index 8a89830..01b4adf 100644 (file)
@@ -1,7 +1,7 @@
 package jalview.ext.jmol;
 
 import jalview.datamodel.SequenceI;
-import jalview.io.AppletFormatAdapter;
+import jalview.io.DataSourceType;
 
 import java.io.File;
 import java.io.IOException;
@@ -52,9 +52,9 @@ public class JmolVsJalviewPDBParserEndToEndTest
       try
       {
         mctest = new PDBfile(false, false, false, testFile,
-                AppletFormatAdapter.FILE);
+                DataSourceType.FILE);
         jtest = new JmolParser(false, false, false, testFile,
-                jalview.io.AppletFormatAdapter.FILE);
+                DataSourceType.FILE);
       } catch (IOException e)
       {
         System.err.println("Exception thrown while parsing : " + pdbStr);
index 4110863..3a3b4c2 100644 (file)
@@ -24,7 +24,9 @@ import static org.testng.AssertJUnit.assertTrue;
 
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.SequenceI;
+import jalview.io.DataSourceType;
 import jalview.io.FastaFile;
+import jalview.io.FileFormat;
 import jalview.io.FormatAdapter;
 
 import java.io.BufferedReader;
@@ -101,7 +103,7 @@ public class TestAnnotate3D
   public void testPDBfileVsRNAML() throws Exception
   {
     PDBfile pdbf = new PDBfile(true, false, true, "examples/2GIS.pdb",
-            FormatAdapter.FILE);
+            DataSourceType.FILE);
     Assert.assertTrue(pdbf.isValid());
     // Comment - should add new FileParse constructor like new FileParse(Reader
     // ..). for direct reading
@@ -128,7 +130,7 @@ public class TestAnnotate3D
       assertTrue("No data returned by Annotate3D", sb.length() > 0);
       final String lines = sb.toString();
       AlignmentI al = new FormatAdapter().readFile(lines,
-              FormatAdapter.PASTE, "RNAML");
+              DataSourceType.PASTE, FileFormat.Rnaml);
       if (al == null || al.getHeight() == 0)
       {
         System.out.println(lines);
@@ -156,11 +158,11 @@ public class TestAnnotate3D
             {
               AssertJUnit
                       .fail("Couldn't find this sequence in original input:\n"
-                              + new FastaFile()
-                                      .print(new SequenceI[] { sq })
+                              + new FastaFile().print(
+                                      new SequenceI[] { sq }, true)
                               + "\n\nOriginal input:\n"
-                              + new FastaFile().print(pdbf.getSeqsAsArray())
-                              + "\n");
+                              + new FastaFile().print(
+                                      pdbf.getSeqsAsArray(), true) + "\n");
             }
           }
         }
index 93a98b8..2a6dc73 100644 (file)
@@ -30,7 +30,7 @@ import jalview.gui.AlignFrame;
 import jalview.gui.Preferences;
 import jalview.gui.StructureViewer;
 import jalview.gui.StructureViewer.ViewerType;
-import jalview.io.FormatAdapter;
+import jalview.io.DataSourceType;
 
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
@@ -67,7 +67,7 @@ public class JalviewChimeraView
             ViewerType.CHIMERA.name());
     String inFile = "examples/1gaq.txt";
     AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
-            inFile, FormatAdapter.FILE);
+            inFile, DataSourceType.FILE);
     assertTrue("Didn't read input file " + inFile, af != null);
     for (SequenceI sq : af.getViewport().getAlignment().getSequences())
     {
index 2b72914..8c540b0 100644 (file)
@@ -33,8 +33,8 @@ import jalview.datamodel.PDBEntry;
 import jalview.datamodel.PDBEntry.Type;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceI;
+import jalview.io.DataSourceType;
 import jalview.io.FileLoader;
-import jalview.io.FormatAdapter;
 import jalview.structure.StructureSelectionManager;
 import jalview.util.MapList;
 
@@ -132,7 +132,7 @@ public class AlignViewportTest
      * alignment with reference to mappings
      */
     AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
-            ">Seq1\nCAGT\n", FormatAdapter.PASTE);
+            ">Seq1\nCAGT\n", DataSourceType.PASTE);
 
     SequenceI s1 = af1.getViewport().getAlignment().getSequenceAt(0);
     AlignedCodonFrame acf1 = new AlignedCodonFrame();
@@ -181,9 +181,9 @@ public class AlignViewportTest
     ssm.resetAll();
 
     AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
-            ">Seq1\nRSVQ\n", FormatAdapter.PASTE);
+            ">Seq1\nRSVQ\n", DataSourceType.PASTE);
     AlignFrame af2 = new FileLoader().LoadFileWaitTillLoaded(
-            ">Seq2\nDGEL\n", FormatAdapter.PASTE);
+            ">Seq2\nDGEL\n", DataSourceType.PASTE);
     SequenceI cs1 = new Sequence("cseq1", "CCCGGGTTTAAA");
     SequenceI cs2 = new Sequence("cseq2", "CTTGAGTCTAGA");
     SequenceI s1 = af1.getViewport().getAlignment().getSequenceAt(0);
@@ -244,9 +244,9 @@ public class AlignViewportTest
     ssm.resetAll();
 
     AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
-            ">Seq1\nRSVQ\n", FormatAdapter.PASTE);
+            ">Seq1\nRSVQ\n", DataSourceType.PASTE);
     AlignFrame af2 = new FileLoader().LoadFileWaitTillLoaded(
-            ">Seq2\nDGEL\n", FormatAdapter.PASTE);
+            ">Seq2\nDGEL\n", DataSourceType.PASTE);
     SequenceI cs1 = new Sequence("cseq1", "CCCGGGTTTAAA");
     SequenceI cs2 = new Sequence("cseq2", "CTTGAGTCTAGA");
     SequenceI s1 = af1.getViewport().getAlignment().getSequenceAt(0);
index f08fa8d..1a61c3e 100644 (file)
@@ -31,7 +31,9 @@ import jalview.datamodel.AlignmentI;
 import jalview.datamodel.Annotation;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
-import jalview.io.AppletFormatAdapter;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
+import jalview.io.FormatAdapter;
 import jalview.util.MessageManager;
 
 import java.awt.BorderLayout;
@@ -85,8 +87,8 @@ public class AnnotationChooserTest
     Cache.applicationProperties.setProperty("SHOW_CONSERVATION", TRUE);
     Cache.applicationProperties.setProperty("SHOW_IDENTITY", TRUE);
 
-    AlignmentI al = new jalview.io.FormatAdapter().readFile(TEST_DATA,
-            AppletFormatAdapter.PASTE, "FASTA");
+    AlignmentI al = new FormatAdapter().readFile(TEST_DATA,
+            DataSourceType.PASTE, FileFormat.Fasta);
     af = new AlignFrame(al, 700, 500);
     parentPanel = new AlignmentPanel(af, af.getViewport());
     addAnnotations();
index edf3202..0ad75e8 100644 (file)
@@ -28,7 +28,8 @@ import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.Annotation;
 import jalview.datamodel.SequenceI;
-import jalview.io.AppletFormatAdapter;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
 import jalview.io.FormatAdapter;
 import jalview.util.MessageManager;
 
@@ -66,7 +67,7 @@ public class PopupMenuTest
   public void setUp() throws IOException
   {
     alignment = new FormatAdapter().readFile(TEST_DATA,
-            AppletFormatAdapter.PASTE, "FASTA");
+            DataSourceType.PASTE, FileFormat.Fasta);
     AlignFrame af = new AlignFrame(alignment, 700, 500);
     parentPanel = new AlignmentPanel(af, af.getViewport());
     testee = new PopupMenu(parentPanel, null, null);
index d3d9ff8..9a07ef7 100644 (file)
@@ -63,7 +63,7 @@ public class AnnotatedPDBFileInputTest
             Boolean.TRUE.toString());
     FileLoader loader = new FileLoader(false);
     AlignFrame af = loader.LoadFileWaitTillLoaded("examples/1gaq.txt",
-            FormatAdapter.FILE);
+            DataSourceType.FILE);
     al = af.getViewport().getAlignment();
     pdbId = al.getSequenceAt(0).getDatasetSequence().getAllPDBEntries()
             .get(0).getId();
@@ -204,14 +204,14 @@ public class AnnotatedPDBFileInputTest
     String tfile = File.createTempFile("JalviewTest", ".jvp")
             .getAbsolutePath();
     AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
-            inFile, FormatAdapter.FILE);
+            inFile, DataSourceType.FILE);
     assertTrue("Didn't read input file " + inFile, af != null);
     assertTrue("Failed to store as a project.",
-            af.saveAlignment(tfile, "Jalview"));
+            af.saveAlignment(tfile, FileFormat.Jalview));
     af.closeMenuItem_actionPerformed(true);
     af = null;
     af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
-            FormatAdapter.FILE);
+            DataSourceType.FILE);
     assertTrue("Failed to import new project", af != null);
     for (SequenceI asq : af.getViewport().getAlignment().getSequences())
     {
index 625244d..c39cc4a 100644 (file)
@@ -69,8 +69,8 @@ public class AnnotationFileIOTest
     {
       FormatAdapter rf = new FormatAdapter();
 
-      AlignmentI al = rf.readFile(ff, AppletFormatAdapter.FILE,
-              new IdentifyFile().identify(ff, AppletFormatAdapter.FILE));
+      AlignmentI al = rf.readFile(ff, DataSourceType.FILE,
+              new IdentifyFile().identify(ff, DataSourceType.FILE));
 
       // make sure dataset is initialised ? not sure about this
       for (int i = 0; i < al.getSequencesArray().length; ++i)
@@ -115,7 +115,7 @@ public class AnnotationFileIOTest
                       + testname
                       + "\nAlignment was not annotated - annotation file not imported.",
               new AnnotationFile().readAnnotationFile(al, cs, af,
-                      FormatAdapter.FILE));
+                      DataSourceType.FILE));
 
       AnnotationFile aff = new AnnotationFile();
       ViewDef v = aff.new ViewDef(null, al.getHiddenSequences(), cs,
@@ -143,7 +143,7 @@ public class AnnotationFileIOTest
                       + testname
                       + "\nregenerated annotation file did not annotate alignment.",
               new AnnotationFile().readAnnotationFile(al_new, anfileout,
-                      FormatAdapter.PASTE));
+                      DataSourceType.PASTE));
 
       // test for consistency in io
       StockholmFileTest.testAlignmentEquivalence(al, al_new, false);
index 2f5d0c5..0cfe46a 100644 (file)
@@ -56,7 +56,7 @@ public class FeaturesFileTest
     Map<String, FeatureColourI> colours = af.getFeatureRenderer()
             .getFeatureColours();
     FeaturesFile featuresFile = new FeaturesFile(
-            "examples/exampleFeatures.txt", FormatAdapter.FILE);
+            "examples/exampleFeatures.txt", DataSourceType.FILE);
     assertTrue("Test " + "Features file test"
             + "\nFailed to parse features file.",
             featuresFile.parse(al.getDataset(), colours, true));
@@ -157,7 +157,7 @@ public class FeaturesFileTest
             + "FER_CAPAA\tuniprot\tMETAL\t44\t45\t4.0\t.\t.\tNote Iron-sulfur; Note 2Fe-2S\n"
             + "FER1_SOLLC\tuniprot\tPfam\t55\t130\t2.0\t.\t.";
     FeaturesFile featuresFile = new FeaturesFile(gffData,
-            FormatAdapter.PASTE);
+            DataSourceType.PASTE);
     assertTrue("Failed to parse features file",
             featuresFile.parse(al.getDataset(), colours, true));
 
@@ -196,8 +196,8 @@ public class FeaturesFileTest
     String ff = f.getPath();
     FormatAdapter rf = new FormatAdapter();
 
-    AlignmentI al = rf.readFile(ff, FormatAdapter.FILE,
-            new IdentifyFile().identify(ff, FormatAdapter.FILE));
+    AlignmentI al = rf.readFile(ff, DataSourceType.FILE,
+            new IdentifyFile().identify(ff, DataSourceType.FILE));
 
     al.setDataset(null); // creates dataset sequences
     assertNotNull("Couldn't read supplied alignment data.", al);
@@ -223,7 +223,7 @@ public class FeaturesFileTest
             + "Note=Iron-sulfur (2Fe-2S);Note=another note;evidence=ECO:0000255|PROSITE-ProRule:PRU00465\n"
             + "FER1_SOLLC\tuniprot\tPfam\t55\t130\t3.0\t.\t.\tID=$23";
     FeaturesFile featuresFile = new FeaturesFile(gffData,
-            FormatAdapter.PASTE);
+            DataSourceType.PASTE);
     assertTrue("Failed to parse features file",
             featuresFile.parse(al.getDataset(), colours, true));
 
@@ -276,7 +276,7 @@ public class FeaturesFileTest
     String featureData = "Iron-sulfur (2Fe-2S)\tFER_CAPAA\t-1\t39\t39\tMETAL\n"
             + "Iron-phosphorus (2Fe-P)\tID_NOT_SPECIFIED\t2\t86\t87\tMETALLIC\n";
     FeaturesFile featuresFile = new FeaturesFile(featureData,
-            FormatAdapter.PASTE);
+            DataSourceType.PASTE);
     assertTrue("Failed to parse features file",
             featuresFile.parse(al.getDataset(), colours, true));
 
@@ -342,7 +342,7 @@ public class FeaturesFileTest
   public void readGff3File() throws IOException
   {
     FeaturesFile gffreader = new FeaturesFile(true, simpleGffFile,
-            FormatAdapter.FILE);
+            DataSourceType.FILE);
     Alignment dataset = new Alignment(gffreader.getSeqsAsArray());
     gffreader.addProperties(dataset);
     checkDatasetfromSimpleGff3(dataset);
@@ -353,7 +353,7 @@ public class FeaturesFileTest
   {
     AlignmentI dataset = new Alignment(new SequenceI[] {});
     FeaturesFile ffile = new FeaturesFile(simpleGffFile,
-            FormatAdapter.FILE);
+            DataSourceType.FILE);
   
     boolean parseResult = ffile.parse(dataset, null, false, false);
     assertTrue("return result should be true", parseResult);
@@ -364,7 +364,7 @@ public class FeaturesFileTest
   public void simpleGff3FileLoader() throws IOException
   {
     AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded(
-            simpleGffFile, FormatAdapter.FILE);
+            simpleGffFile, DataSourceType.FILE);
     assertTrue(
             "Didn't read the alignment into an alignframe from Gff3 File",
             af != null);
@@ -376,7 +376,7 @@ public class FeaturesFileTest
   {
     AlignmentI dataset = new Alignment(new SequenceI[] {});
     FeaturesFile ffile = new FeaturesFile(simpleGffFile,
-            FormatAdapter.FILE);
+            DataSourceType.FILE);
   
     boolean parseResult = ffile.parse(dataset, null, false, true);
     assertTrue("return result (relaxedID matching) should be true",
@@ -401,7 +401,7 @@ public class FeaturesFileTest
             + "<html>Pfam domain<a href=\"http://pfam.xfam.org/family/PF00111\">Pfam_3_4</a></html>\tFER_CAPAA\t-1\t20\t20\tPfam\n"
             + "ENDGROUP\tuniprot\n";
     FeaturesFile featuresFile = new FeaturesFile(features,
-            FormatAdapter.PASTE);
+            DataSourceType.PASTE);
     featuresFile.parse(al.getDataset(), colours, false);
 
     /*
index 2eb3703..4fb2ee6 100644 (file)
@@ -65,13 +65,14 @@ public class FileIOTester
   final static File STARS_FA_FILE2 = new File(
           "test/jalview/io/test_fasta_stars2.fa");
 
-  private void assertValidFormat(String fmt, String src, FileParse fp)
+  private void assertValidFormat(FileFormatI fmt, String src, FileParse fp)
+          throws FileFormatException
   {
     AssertJUnit.assertTrue("Couldn't resolve " + src + " as a valid file",
             fp.isValid());
-    String type = new IdentifyFile().identify(fp);
-    AssertJUnit.assertTrue("Data from '" + src + "' Expected to be '" + fmt
-            + "' identified as '" + type + "'", type.equalsIgnoreCase(fmt));
+    FileFormatI type = new IdentifyFile().identify(fp);
+    AssertJUnit.assertSame("Data from '" + src + "' Expected to be '" + fmt
+            + "' identified as '" + type + "'", type, fmt);
   }
 
   @Test(groups = { "Functional" })
@@ -79,8 +80,8 @@ public class FileIOTester
   {
     String uri;
     FileParse fp = new FileParse(uri = STARS_FA_FILE1.getAbsoluteFile()
-            .toString(), AppletFormatAdapter.FILE);
-    assertValidFormat("FASTA", uri, fp);
+            .toString(), DataSourceType.FILE);
+    assertValidFormat(FileFormat.Fasta, uri, fp);
   }
 
   @Test(groups = { "Functional" })
@@ -88,8 +89,8 @@ public class FileIOTester
   {
     String uri;
     FileParse fp = new FileParse(uri = STARS_FA_FILE2.getAbsoluteFile()
-            .toString(), AppletFormatAdapter.FILE);
-    assertValidFormat("FASTA", uri, fp);
+            .toString(), DataSourceType.FILE);
+    assertValidFormat(FileFormat.Fasta, uri, fp);
   }
 
   @Test(groups = { "Functional" })
@@ -97,8 +98,8 @@ public class FileIOTester
   {
     String uri;
     FileParse fp = new FileParse(uri = ALIGN_FILE.getAbsoluteFile().toURI()
-            .toString(), AppletFormatAdapter.URL);
-    assertValidFormat("FASTA", uri, fp);
+            .toString(), DataSourceType.URL);
+    assertValidFormat(FileFormat.Fasta, uri, fp);
   }
 
   @Test(groups = { "Functional" })
@@ -106,8 +107,8 @@ public class FileIOTester
   {
     String filepath;
     FileParse fp = new FileParse(filepath = ALIGN_FILE.getAbsoluteFile()
-            .toString(), AppletFormatAdapter.FILE);
-    assertValidFormat("FASTA", filepath, fp);
+            .toString(), DataSourceType.FILE);
+    assertValidFormat(FileFormat.Fasta, filepath, fp);
   }
 
   @Test(groups = { "Functional" })
@@ -115,8 +116,8 @@ public class FileIOTester
   {
     String uri;
     FileParse fp = new FileParse(uri = NOTGZALIGN_FILE.getAbsoluteFile()
-            .toURI().toString(), AppletFormatAdapter.URL);
-    assertValidFormat("FASTA", uri, fp);
+            .toURI().toString(), DataSourceType.URL);
+    assertValidFormat(FileFormat.Fasta, uri, fp);
   }
 
   @Test(groups = { "Functional" })
@@ -124,7 +125,7 @@ public class FileIOTester
   {
     String filepath;
     FileParse fp = new FileParse(filepath = NOTGZALIGN_FILE
-            .getAbsoluteFile().toString(), AppletFormatAdapter.FILE);
-    assertValidFormat("FASTA", filepath, fp);
+            .getAbsoluteFile().toString(), DataSourceType.FILE);
+    assertValidFormat(FileFormat.Fasta, filepath, fp);
   }
 }
index 81e336e..6bf954a 100644 (file)
@@ -9,7 +9,6 @@ import jalview.datamodel.SequenceI;
 
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 
 import org.testng.annotations.DataProvider;
@@ -24,12 +23,12 @@ public class FormatAdapterTest
    * @throws IOException
    */
   @Test(groups = { "Functional" }, dataProvider = "formats")
-  public void testRoundTrip(String format) throws IOException
+  public void testRoundTrip(FileFormatI format) throws IOException
   {
     try
     {
       AlignmentI al = new FormatAdapter().readFile("examples/uniref50.fa",
-              FormatAdapter.FILE, "FASTA");
+              DataSourceType.FILE, FileFormat.Fasta);
 
       /*
        * 'gap' is the gap character used in the alignment data file here,
@@ -43,7 +42,7 @@ public class FormatAdapterTest
               false);
 
       AlignmentI reloaded = new FormatAdapter().readFile(formatted,
-              FormatAdapter.PASTE, format);
+              DataSourceType.PASTE, format);
       List<SequenceI> reread = reloaded.getSequences();
       assertEquals("Wrong number of reloaded sequences", seqs.length,
               reread.size());
@@ -82,9 +81,9 @@ public class FormatAdapterTest
    * @return
    */
   String adjustForGapTreatment(String sequenceString, char gap,
-          String format)
+          FileFormatI format)
   {
-    if ("MSF".equals(format))
+    if (format == FileFormat.MSF)
     {
       /*
        * MSF forces gap character to '.', so change it back
@@ -104,20 +103,18 @@ public class FormatAdapterTest
   @DataProvider(name = "formats")
   static Object[][] getFormats()
   {
-    List<String> both = new ArrayList<String>();
-    String[] readable = FormatAdapter.READABLE_FORMATS;
-    List<String> writeable = Arrays.asList(FormatAdapter.WRITEABLE_FORMATS);
-    for (String r : readable)
+    List<FileFormatI> both = new ArrayList<FileFormatI>();
+    for (FileFormat format : FileFormat.values())
     {
-      if (writeable.contains(r))
+      if (format.isReadable() && format.isWritable())
       {
-        both.add(r);
+        both.add(format);
       }
     }
 
     Object[][] formats = new Object[both.size()][];
     int i = 0;
-    for (String format : both)
+    for (FileFormatI format : both)
     {
       formats[i] = new Object[] { format };
       i++;
@@ -133,6 +130,6 @@ public class FormatAdapterTest
   @Test(groups = { "Functional" }, enabled = false)
   public void testOneFormatRoundTrip() throws IOException
   {
-    testRoundTrip("JSON");
+    testRoundTrip(FileFormat.Json);
   }
 }
index c00cf06..d693a6c 100644 (file)
@@ -33,19 +33,22 @@ public class IdentifyFileTest
 
   @Test(groups = { "Functional" }, dataProvider = "identifyFiles")
   public void testIdentify(String data, String expectedFileType)
+          throws FileFormatException
   {
-    String protocol = AppletFormatAdapter.FILE;
+    DataSourceType protocol = DataSourceType.FILE;
     IdentifyFile ider = new IdentifyFile();
-    String actualFiletype = ider.identify(data, protocol);
+    String actualFiletype = ider.identify(data, protocol).toString();
     Assert.assertEquals(actualFiletype, expectedFileType,
             "File identification Failed!");
   }
 
   /**
    * Additional tests for Jalview features file
+   * 
+   * @throws FileFormatException
    */
   @Test(groups = "Functional")
-  public void testIdentify_featureFile()
+  public void testIdentify_featureFile() throws FileFormatException
   {
     IdentifyFile ider = new IdentifyFile();
 
@@ -55,7 +58,7 @@ public class IdentifyFileTest
     String data = "Iron-sulfur (2Fe-2S)\tFER_CAPAA\t-1\t39\t39\tMETAL\n"
             + "Iron-phosphorus (2Fe-P)\tID_NOT_SPECIFIED\t2\t86\t87\tMETALLIC\n";
     assertEquals(IdentifyFile.FeaturesFile,
-            ider.identify(data, AppletFormatAdapter.PASTE));
+            ider.identify(data, DataSourceType.PASTE));
 
     /*
      * Jalview feature colour followed by GFF format feature data
@@ -63,14 +66,14 @@ public class IdentifyFileTest
     data = "METAL\tcc9900\n" + "GFF\n"
             + "FER_CAPAA\tuniprot\tMETAL\t44\t45\t4.0\t.\t.\n";
     assertEquals(IdentifyFile.FeaturesFile,
-            ider.identify(data, AppletFormatAdapter.PASTE));
+            ider.identify(data, DataSourceType.PASTE));
 
     /*
      * Feature with '<' in the name (JAL-2098)
      */
     data = "kD < 3\tred\n" + "Low kD\tFER_CAPAA\t-1\t39\t39\tkD < 3\n";
     assertEquals(IdentifyFile.FeaturesFile,
-            ider.identify(data, AppletFormatAdapter.PASTE));
+            ider.identify(data, DataSourceType.PASTE));
   }
 
   @DataProvider(name = "identifyFiles")
index 93fb12b..cd40bab 100644 (file)
@@ -227,7 +227,7 @@ public class JSONFileTest
     try
     {
       alignment = (Alignment) formatAdapter.readFile(TEST_JSON_FILE,
-              AppletFormatAdapter.FILE, JSONFile.FILE_DESC);
+              DataSourceType.FILE, FileFormat.Json);
       jf = (JSONFile) formatAdapter.getAlignFile();
 
       AlignFrame af = new AlignFrame(alignment, jf.getHiddenSequences(),
@@ -241,12 +241,12 @@ public class JSONFileTest
       af.getViewport().setFeaturesDisplayed(jf.getDisplayedFeatures());
 
       formatAdapter = new AppletFormatAdapter(af.alignPanel, exportSettings);
-      String jsonOutput = formatAdapter.formatSequences(JSONFile.FILE_DESC,
+      String jsonOutput = formatAdapter.formatSequences(FileFormat.Json,
               af.alignPanel.getAlignment(), false);
 
       formatAdapter = new AppletFormatAdapter();
       testAlignment = formatAdapter.readFile(jsonOutput,
-              AppletFormatAdapter.PASTE, JSONFile.FILE_DESC);
+              DataSourceType.PASTE, FileFormat.Json);
       testJsonFile = (JSONFile) formatAdapter.getAlignFile();
       // System.out.println(jsonOutput);
     } catch (IOException e)
index 784f3dd..266b0f8 100644 (file)
@@ -120,7 +120,7 @@ public class Jalview2xmlTests
     String tfile = File.createTempFile("JalviewTest", ".jvp")
             .getAbsolutePath();
     AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
-            inFile, FormatAdapter.FILE);
+            inFile, DataSourceType.FILE);
     assertTrue("Didn't read input file " + inFile, af != null);
     int olddsann = countDsAnn(af.getViewport());
     assertTrue("Didn't find any dataset annotations", olddsann > 0);
@@ -129,11 +129,11 @@ public class Jalview2xmlTests
             "Couldn't apply RNA helices colourscheme",
             af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
     assertTrue("Failed to store as a project.",
-            af.saveAlignment(tfile, "Jalview"));
+            af.saveAlignment(tfile, FileFormat.Jalview));
     af.closeMenuItem_actionPerformed(true);
     af = null;
     af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
-            FormatAdapter.FILE);
+            DataSourceType.FILE);
     assertTrue("Failed to import new project", af != null);
     int newdsann = countDsAnn(af.getViewport());
     assertTrue(
@@ -155,9 +155,9 @@ public class Jalview2xmlTests
     String tfile = File.createTempFile("JalviewTest", ".jvp")
             .getAbsolutePath();
     AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
-            inFile, FormatAdapter.FILE);
+            inFile, DataSourceType.FILE);
     assertTrue("Didn't read input file " + inFile, af != null);
-    af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null, null);
+    af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
     assertTrue(
             "Didn't set T-coffee colourscheme",
             af.getViewport().getGlobalColourScheme().getClass()
@@ -170,11 +170,11 @@ public class Jalview2xmlTests
                             .getViewport().getGlobalColourScheme())) != null);
 
     assertTrue("Failed to store as a project.",
-            af.saveAlignment(tfile, "Jalview"));
+            af.saveAlignment(tfile, FileFormat.Jalview));
     af.closeMenuItem_actionPerformed(true);
     af = null;
     af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
-            FormatAdapter.FILE);
+            DataSourceType.FILE);
     assertTrue("Failed to import new project", af != null);
     assertTrue(
             "Didn't set T-coffee colourscheme for imported project.",
@@ -191,9 +191,9 @@ public class Jalview2xmlTests
     String tfile = File.createTempFile("JalviewTest", ".jvp")
             .getAbsolutePath();
     AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
-            inFile, FormatAdapter.FILE);
+            inFile, DataSourceType.FILE);
     assertTrue("Didn't read input file " + inFile, af != null);
-    af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null, null);
+    af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
     AlignmentAnnotation[] aa = af.getViewport().getAlignment()
             .getSequenceAt(0).getAnnotation("IUPredWS (Short)");
     assertTrue(
@@ -215,11 +215,11 @@ public class Jalview2xmlTests
     sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true);
     af.alignPanel.alignmentChanged();
     assertTrue("Failed to store as a project.",
-            af.saveAlignment(tfile, "Jalview"));
+            af.saveAlignment(tfile, FileFormat.Jalview));
     af.closeMenuItem_actionPerformed(true);
     af = null;
     af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
-            FormatAdapter.FILE);
+            DataSourceType.FILE);
     assertTrue("Failed to import new project", af != null);
 
     // check for group and alignment colourschemes
@@ -276,7 +276,7 @@ public class Jalview2xmlTests
     int origCount = Desktop.getAlignFrames() == null ? 0 : Desktop
             .getAlignFrames().length;
     AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
-            "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
+            "examples/exampleFile_2_7.jar", DataSourceType.FILE);
     assertTrue("Didn't read in the example file correctly.", af != null);
     assertTrue("Didn't gather the views in the example file.",
             Desktop.getAlignFrames().length == 1 + origCount);
@@ -292,7 +292,7 @@ public class Jalview2xmlTests
     StructureImportSettings.setProcessSecondaryStructure(true);
     StructureImportSettings.setVisibleChainAnnotation(true);
     AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
-            "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
+            "examples/exampleFile_2_7.jar", DataSourceType.FILE);
     assertTrue("Didn't read in the example file correctly.", af != null);
     AlignmentViewPanel sps = null;
     for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
@@ -351,7 +351,7 @@ public class Jalview2xmlTests
   public void testCopyViewSettings() throws Exception
   {
     AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
-            "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
+            "examples/exampleFile_2_7.jar", DataSourceType.FILE);
     assertTrue("Didn't read in the example file correctly.", af != null);
     AlignmentViewPanel sps = null, groups = null;
     for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
@@ -391,7 +391,7 @@ public class Jalview2xmlTests
     Desktop.instance.closeAll_actionPerformed(null);
 
     AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
-            "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
+            "examples/exampleFile_2_7.jar", DataSourceType.FILE);
     assertTrue("Didn't read in the example file correctly.", af != null);
     Assert.assertEquals(Desktop.getAlignFrames().length, 1);
     String afid = af.getViewport().getSequenceSetId();
@@ -424,7 +424,7 @@ public class Jalview2xmlTests
       Assert.assertEquals(Desktop.getAlignFrames().length, 0);
     }
     af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
-            tfile.getAbsolutePath(), FormatAdapter.FILE);
+            tfile.getAbsolutePath(), DataSourceType.FILE);
     Assert.assertNotNull(af);
     Assert.assertEquals(
             Desktop.getAlignFrames().length,
@@ -445,7 +445,7 @@ public class Jalview2xmlTests
   {
     Desktop.instance.closeAll_actionPerformed(null);
     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
-            "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
+            "examples/exampleFile_2_7.jar", DataSourceType.FILE);
     assertTrue("Didn't read in the example file correctly.", af != null);
     String afid = af.getViewport().getSequenceSetId();
 
@@ -489,7 +489,7 @@ public class Jalview2xmlTests
     }
 
     af = new FileLoader().LoadFileWaitTillLoaded(
-            tfile.getAbsolutePath(), FormatAdapter.FILE);
+            tfile.getAbsolutePath(), DataSourceType.FILE);
     afid = af.getViewport().getSequenceSetId();
 
     for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
@@ -578,7 +578,7 @@ public class Jalview2xmlTests
   {
     Desktop.instance.closeAll_actionPerformed(null);
     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
-            "examples/uniref50.fa", FormatAdapter.FILE);
+            "examples/uniref50.fa", DataSourceType.FILE);
     assertTrue("Didn't read in the example file correctly.", af != null);
     String afid = af.getViewport().getSequenceSetId();
     // make a second view of the alignment
@@ -658,7 +658,7 @@ public class Jalview2xmlTests
     }
   
     af = new FileLoader().LoadFileWaitTillLoaded(
-            tfile.getAbsolutePath(), FormatAdapter.FILE);
+            tfile.getAbsolutePath(), DataSourceType.FILE);
     afid = af.getViewport().getSequenceSetId();
   
     for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
@@ -700,7 +700,7 @@ public class Jalview2xmlTests
     Desktop.instance.closeAll_actionPerformed(null);
     String exampleFile = "examples/3W5V.pdb";
     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile,
-            FormatAdapter.FILE);
+            DataSourceType.FILE);
     assertTrue("Didn't read in the example file correctly.", af != null);
     String afid = af.getViewport().getSequenceSetId();
 
@@ -749,7 +749,7 @@ public class Jalview2xmlTests
     }
 
     AlignFrame restoredFrame = new FileLoader().LoadFileWaitTillLoaded(
-            tfile.getAbsolutePath(), FormatAdapter.FILE);
+            tfile.getAbsolutePath(), DataSourceType.FILE);
     String rfid = restoredFrame.getViewport().getSequenceSetId();
     AlignmentPanel[] rAlignPanels = Desktop.getAlignmentPanels(rfid);
     AlignmentViewPanel rap = rAlignPanels[0];
index 164c259..b13f9d1 100644 (file)
@@ -66,7 +66,7 @@ public class JalviewExportPropertiesTests
     assertTrue("Couldn't set gap character to '.'",
             ".".equals("" + jalview.bin.Cache.getProperty("GAP_SYMBOL")));
     AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
-            "examples/uniref50.fa", FormatAdapter.FILE);
+            "examples/uniref50.fa", DataSourceType.FILE);
     assertTrue("Didn't read in the example file correctly.", af != null);
     assertTrue("Didn't set the gap character correctly", af.getViewport()
             .getAlignment().getSequenceAt(0).getCharAt(5) == '.');
@@ -78,7 +78,7 @@ public class JalviewExportPropertiesTests
     sg.setEndRes(7);
     af.getViewport().setSelectionGroup(sg);
     String fseqs = new FormatAdapter(af.alignPanel).formatSequences(
-            "FASTA", af.alignPanel, true);
+            FileFormat.Fasta, af.alignPanel, true);
     assertTrue("Couldn't find '.' in the exported region\n" + fseqs,
             fseqs.indexOf(".") > -1);
   }
index f89f58b..7acc37d 100644 (file)
@@ -93,7 +93,7 @@ public class NewickFileTests
     {
       stage = "Parsing testTree " + treename;
       System.out.println(treename + "\n" + testTree);
-      NewickFile nf = new NewickFile(testTree, FormatAdapter.PASTE);
+      NewickFile nf = new NewickFile(testTree, DataSourceType.PASTE);
       nf.parse();
       AssertJUnit.assertTrue(
               stage + "Invalid Tree '" + nf.getWarningMessage() + "'",
@@ -106,7 +106,7 @@ public class NewickFileTests
       AssertJUnit.assertTrue(stage + "Empty string generated",
               gentree != null && gentree.trim().length() > 0);
       stage = "Parsing regenerated testTree " + treename;
-      NewickFile nf_regen = new NewickFile(gentree, FormatAdapter.PASTE);
+      NewickFile nf_regen = new NewickFile(gentree, DataSourceType.PASTE);
       nf_regen.parse();
       AssertJUnit.assertTrue(
               stage + "Newick file is invalid ('"
index 5dd4ecb..8eb3c60 100644 (file)
@@ -13,7 +13,8 @@ public class PfamFormatInputTest
   public void testPfamFormatNoLimits() throws IOException
   {
     AlignmentI al = new jalview.io.AppletFormatAdapter().readFile("ASEQ"
-            + '\t' + "...--FFAFAFF--", AppletFormatAdapter.PASTE, "PFAM");
+            + '\t' + "...--FFAFAFF--", DataSourceType.PASTE,
+            FileFormat.Pfam);
     Assert.assertEquals(1, al.getHeight(), "Wrong number of sequences");
     Assert.assertTrue(al.hasValidSequence(),
             "Didn't extract limits from PFAM ID");
@@ -24,7 +25,8 @@ public class PfamFormatInputTest
   {
     AlignmentI al = new jalview.io.AppletFormatAdapter().readFile(
             "ASEQ/15-25" + '\t' + "...--FFAFAFF--",
-            AppletFormatAdapter.PASTE, "PFAM");
+ DataSourceType.PASTE,
+            FileFormat.Pfam);
     Assert.assertEquals(1, al.getHeight(), "Wrong number of sequences");
     Assert.assertTrue(al.hasValidSequence(),
             "Didn't extract limits from PFAM ID");
index fa57c3d..e0f1f68 100644 (file)
@@ -126,8 +126,8 @@ public class PhylipFileTests
   private void testDataExtraction(String file) throws IOException
   {
     AppletFormatAdapter rf = new AppletFormatAdapter();
-    AlignmentI al = rf.readFile(file, AppletFormatAdapter.FILE,
-            PhylipFile.FILE_DESC);
+    AlignmentI al = rf.readFile(file, DataSourceType.FILE,
+            FileFormat.Phylip);
     assertNotNull("Couldn't read supplied alignment data.", al);
 
     Map<String, String> data = PhylipFileTests.getTestData();
@@ -171,14 +171,14 @@ public class PhylipFileTests
   public void testIO(String file) throws IOException
   {
     AppletFormatAdapter rf = new AppletFormatAdapter();
-    AlignmentI al = rf.readFile(file, AppletFormatAdapter.FILE,
-            PhylipFile.FILE_DESC);
+    AlignmentI al = rf.readFile(file, DataSourceType.FILE,
+            FileFormat.Phylip);
     assertNotNull("Couldn't read supplied alignment data.", al);
 
-    String outputfile = rf.formatSequences(PhylipFile.FILE_DESC, al, true);
+    String outputfile = rf.formatSequences(FileFormat.Phylip, al, true);
 
     AlignmentI al_input = new AppletFormatAdapter().readFile(outputfile,
-            AppletFormatAdapter.PASTE, PhylipFile.FILE_DESC);
+            DataSourceType.PASTE, FileFormat.Phylip);
     assertNotNull("Couldn't parse reimported alignment data.", al_input);
 
     StockholmFileTest.testAlignmentEquivalence(al, al_input, false);
index c084792..feda619 100644 (file)
@@ -43,7 +43,8 @@ public class RNAMLfileTest
   public void testRnamlToStockholmIO()
   {
     StockholmFileTest.testFileIOwithFormat(new File(
-            "examples/testdata/rna-alignment.xml"), "STH", -1, -1);
+            "examples/testdata/rna-alignment.xml"), FileFormat.Stockholm,
+            -1, -1);
 
   }
 
index b034fb0..bdd311b 100644 (file)
@@ -47,15 +47,15 @@ public class StockholmFileTest
   @Test(groups = { "Functional" })
   public void pfamFileIO() throws Exception
   {
-    testFileIOwithFormat(new File(PfamFile), "STH", -1, 0);
+    testFileIOwithFormat(new File(PfamFile), FileFormat.Stockholm, -1, 0);
   }
 
   @Test(groups = { "Functional" })
   public void pfamFileDataExtraction() throws Exception
   {
     AppletFormatAdapter af = new AppletFormatAdapter();
-    AlignmentI al = af.readFile(PfamFile, af.FILE,
-            new IdentifyFile().identify(PfamFile, af.FILE));
+    AlignmentI al = af.readFile(PfamFile, DataSourceType.FILE,
+            new IdentifyFile().identify(PfamFile, DataSourceType.FILE));
     int numpdb = 0;
     for (SequenceI sq : al.getSequences())
     {
@@ -72,7 +72,7 @@ public class StockholmFileTest
   @Test(groups = { "Functional" })
   public void rfamFileIO() throws Exception
   {
-    testFileIOwithFormat(new File(RfamFile), "STH", 2, 1);
+    testFileIOwithFormat(new File(RfamFile), FileFormat.Stockholm, 2, 1);
   }
 
   /**
@@ -86,7 +86,7 @@ public class StockholmFileTest
    *          f
    */
 
-  public static void testFileIOwithFormat(File f, String ioformat,
+  public static void testFileIOwithFormat(File f, FileFormatI ioformat,
           int naliannot, int nminseqann)
   {
     System.out.println("Reading file: " + f);
@@ -95,8 +95,8 @@ public class StockholmFileTest
     {
       AppletFormatAdapter rf = new AppletFormatAdapter();
 
-      AlignmentI al = rf.readFile(ff, AppletFormatAdapter.FILE,
-              new IdentifyFile().identify(ff, AppletFormatAdapter.FILE));
+      AlignmentI al = rf.readFile(ff, DataSourceType.FILE,
+              new IdentifyFile().identify(ff, DataSourceType.FILE));
 
       assertNotNull("Couldn't read supplied alignment data.", al);
 
@@ -110,11 +110,11 @@ public class StockholmFileTest
               + outputfile + "\n<<EOF\n");
       // test for consistency in io
       AlignmentI al_input = new AppletFormatAdapter().readFile(outputfile,
-              AppletFormatAdapter.PASTE, ioformat);
+              DataSourceType.PASTE, ioformat);
       assertNotNull("Couldn't parse reimported alignment data.", al_input);
 
-      String identifyoutput = new IdentifyFile().identify(outputfile,
-              AppletFormatAdapter.PASTE);
+      FileFormatI identifyoutput = new IdentifyFile().identify(outputfile,
+              DataSourceType.PASTE);
       assertNotNull("Identify routine failed for outputformat " + ioformat,
               identifyoutput);
       assertTrue(
index 181aabd..a46591c 100644 (file)
@@ -45,7 +45,7 @@ public class TCoffeeScoreFileTest
   {
 
     TCoffeeScoreFile scoreFile = new TCoffeeScoreFile(SCORE_FILE.getPath(),
-            AppletFormatAdapter.FILE);
+            DataSourceType.FILE);
     AssertJUnit.assertTrue(scoreFile.getWarningMessage(),
             scoreFile.isValid());
 
@@ -73,7 +73,7 @@ public class TCoffeeScoreFileTest
     try
     {
       TCoffeeScoreFile result = new TCoffeeScoreFile(ALIGN_FILE.getPath(),
-              FormatAdapter.FILE);
+              DataSourceType.FILE);
       AssertJUnit.assertFalse(result.isValid());
     } catch (IOException x)
     {
@@ -86,7 +86,7 @@ public class TCoffeeScoreFileTest
   public void testHeightAndWidth() throws IOException
   {
     TCoffeeScoreFile result = new TCoffeeScoreFile(SCORE_FILE.getPath(),
-            FormatAdapter.FILE);
+            DataSourceType.FILE);
     AssertJUnit.assertTrue(result.isValid());
     AssertJUnit.assertEquals(8, result.getHeight());
     AssertJUnit.assertEquals(83, result.getWidth());
@@ -107,7 +107,7 @@ public class TCoffeeScoreFileTest
             + "1QCF   99999999999999999999999999974-------2---------24\n"
             + "cons   999999999999999999999999999851000110321100001134\n"
             + "\n" + "\n";
-    FileParse source = new FileParse(BLOCK, FormatAdapter.PASTE);
+    FileParse source = new FileParse(BLOCK, DataSourceType.PASTE);
     Block block = TCoffeeScoreFile.readBlock(source, 0);
 
     AssertJUnit.assertNotNull(block);
@@ -145,7 +145,7 @@ public class TCoffeeScoreFileTest
   {
 
     TCoffeeScoreFile parser = new TCoffeeScoreFile(SCORE_FILE.getPath(),
-            FormatAdapter.FILE);
+            DataSourceType.FILE);
 
     AssertJUnit
             .assertEquals(
@@ -190,7 +190,7 @@ public class TCoffeeScoreFileTest
   {
 
     TCoffeeScoreFile parser = new TCoffeeScoreFile(SCORE_FILE.getPath(),
-            FormatAdapter.FILE);
+            DataSourceType.FILE);
     AssertJUnit.assertTrue(parser.getWarningMessage(), parser.isValid());
     List<String> scores = parser.getScoresList();
     AssertJUnit
@@ -237,7 +237,7 @@ public class TCoffeeScoreFileTest
   {
 
     TCoffeeScoreFile parser = new TCoffeeScoreFile(SCORE_FILE.getPath(),
-            FormatAdapter.FILE);
+            DataSourceType.FILE);
     AssertJUnit.assertTrue(parser.getWarningMessage(), parser.isValid());
     byte[][] scores = parser.getScoresArray();
 
@@ -267,7 +267,7 @@ public class TCoffeeScoreFileTest
   public void testHeightAndWidthWithResidueNumbers() throws Exception
   {
     String file = "test/jalview/io/tcoffee.score_ascii_with_residue_numbers";
-    TCoffeeScoreFile result = new TCoffeeScoreFile(file, FormatAdapter.FILE);
+    TCoffeeScoreFile result = new TCoffeeScoreFile(file, DataSourceType.FILE);
     AssertJUnit.assertTrue(result.isValid());
     AssertJUnit.assertEquals(5, result.getHeight());
     AssertJUnit.assertEquals(84, result.getWidth());
index 54d6eb2..28036b2 100644 (file)
@@ -15,8 +15,8 @@ import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceDummy;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
+import jalview.io.DataSourceType;
 import jalview.io.FileLoader;
-import jalview.io.FormatAdapter;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -239,10 +239,10 @@ public class ExonerateHelperTest
     FileLoader loader = new FileLoader(false);
     AlignFrame af = loader.LoadFileWaitTillLoaded(
             "examples/testdata/exonerateseqs.fa",
-            FormatAdapter.FILE);
+            DataSourceType.FILE);
   
     af.loadJalviewDataFile("examples/testdata/exonerateoutput.gff",
-            FormatAdapter.FILE, null, null);
+            DataSourceType.FILE, null, null);
   
     /*
      * verify one mapping to a dummy sequence, one to a real one
index 2ee4eac..72ea7e2 100644 (file)
@@ -13,8 +13,8 @@ import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceDummy;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
+import jalview.io.DataSourceType;
 import jalview.io.FileLoader;
-import jalview.io.FormatAdapter;
 
 import java.util.List;
 
@@ -37,7 +37,7 @@ public class GffTests
   {
     String proteinSeq = ">prot1/10-16\nYCWRSGA";
     AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded(
-            proteinSeq, FormatAdapter.PASTE);
+            proteinSeq, DataSourceType.PASTE);
 
     /*
      * exonerate GFF output mapping residues 11-15 (CWRSG) 
@@ -45,7 +45,7 @@ public class GffTests
      */
     String exonerateGff = "##gff-version 2\n"
             + "prot1\tprotein2genome\tsimilarity\t11\t15\t99\t-\t.\talignment_id 0 ; Target dna1 ; Align 11 24 5";
-    af.loadJalviewDataFile(exonerateGff, FormatAdapter.PASTE, null, null);
+    af.loadJalviewDataFile(exonerateGff, DataSourceType.PASTE, null, null);
 
     /*
      * check we have a mapping from prot1 to SequenceDummy 'dna1'
index 5ab43b5..13387db 100644 (file)
@@ -28,8 +28,9 @@ import jalview.datamodel.Annotation;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
 import jalview.io.FileLoader;
-import jalview.io.FormatAdapter;
 import jalview.io.StructureFile;
 
 import org.testng.Assert;
@@ -68,7 +69,7 @@ public class Mapping
       StructureSelectionManager ssm = new jalview.structure.StructureSelectionManager();
       StructureFile pmap = ssm.setMapping(true, new SequenceI[] { uprot },
               new String[] { "A" }, "test/jalview/ext/jmol/1QCF.pdb",
-              jalview.io.FormatAdapter.FILE);
+              jalview.io.DataSourceType.FILE);
       assertTrue(pmap != null);
       SequenceI protseq = pmap.getSeqsAsArray()[0];
       AlignmentAnnotation pstra = protseq
@@ -139,7 +140,7 @@ public class Mapping
     // source
     StructureFile pde = ssm.setMapping(true, new SequenceI[] { sq },
             new String[]
-    { "A" }, inFile = "examples/1gaq.txt", jalview.io.FormatAdapter.FILE);
+    { "A" }, inFile = "examples/1gaq.txt", jalview.io.DataSourceType.FILE);
     assertTrue("PDB File couldn't be found", pde != null);
     StructureMapping[] mp = ssm.getMapping(inFile);
     assertTrue("No mappings made.", mp != null && mp.length > 0);
@@ -231,12 +232,12 @@ public class Mapping
     AlignFrame seqf = new FileLoader(false)
             .LoadFileWaitTillLoaded(
                     ">FER1_MAIZE/1-150 Ferredoxin-1, chloroplast precursor\nMATVLGSPRAPAFFFSSSSLRAAPAPTAVALPAAKVGIMGRSASSRRRLRAQATYNVKLITPEGEVELQVPD\nDVYILDQAEEDGIDLPYSCRAGSCSSCAGKVVSGSVDQSDQSYLDDGQIADGWVLTCHAYPTSDVVIETHKE\nEELTGA",
-                    FormatAdapter.PASTE, "FASTA");
+                    DataSourceType.PASTE, FileFormat.Fasta);
     SequenceI newseq = seqf.getViewport().getAlignment().getSequenceAt(0);
     StructureSelectionManager ssm = new jalview.structure.StructureSelectionManager();
     StructureFile pmap = ssm.setMapping(true, new SequenceI[] { newseq },
             new String[] { null }, "examples/3W5V.pdb",
-            jalview.io.FormatAdapter.FILE);
+            jalview.io.DataSourceType.FILE);
     if (pmap == null)
     {
       AssertJUnit.fail("Couldn't make a mapping for 3W5V to FER1_MAIZE");
@@ -253,7 +254,7 @@ public class Mapping
     StructureImportSettings.setShowSeqFeatures(true);
     AlignFrame ref = new FileLoader(false)
             .LoadFileWaitTillLoaded("test/jalview/ext/jmol/1QCF.pdb",
-                    jalview.io.FormatAdapter.FILE);
+                    jalview.io.DataSourceType.FILE);
     SequenceI refseq = ref.getViewport().getAlignment().getSequenceAt(0);
     SequenceI newseq = new Sequence(refseq.getName() + "Copy",
             refseq.getSequenceAsString());
@@ -265,7 +266,7 @@ public class Mapping
     ssm.setAddTempFacAnnot(true);
     StructureFile pmap = ssm.setMapping(true, new SequenceI[] { newseq },
             new String[] { null }, "test/jalview/ext/jmol/1QCF.pdb",
-            jalview.io.FormatAdapter.FILE);
+            jalview.io.DataSourceType.FILE);
     assertTrue(pmap != null);
     assertEquals("Original and copied sequence of different lengths.",
             refseq.getLength(), newseq.getLength());
index baaa96b..aecdbf9 100644 (file)
@@ -27,7 +27,7 @@ import jalview.datamodel.AlignedCodonFrame;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
-import jalview.io.FormatAdapter;
+import jalview.io.DataSourceType;
 import jalview.io.StructureFile;
 import jalview.util.MapList;
 
@@ -124,7 +124,7 @@ public class StructureSelectionManagerTest
     sm.setProcessSecondaryStructure(true);
     sm.setAddTempFacAnnot(true);
     StructureFile pmap = sm.setMapping(true, new SequenceI[] { seq },
-            new String[] { null }, "examples/1gaq.txt", FormatAdapter.FILE);
+            new String[] { null }, "examples/1gaq.txt", DataSourceType.FILE);
     assertTrue(pmap != null);
 
     assertEquals(3, pmap.getSeqs().size());
index bb81992..2e0692e 100644 (file)
@@ -30,7 +30,7 @@ import jalview.datamodel.PDBEntry;
 import jalview.datamodel.PDBEntry.Type;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceI;
-import jalview.io.AppletFormatAdapter;
+import jalview.io.DataSourceType;
 import jalview.structure.AtomSpec;
 import jalview.structure.StructureSelectionManager;
 import jalview.structures.models.AAStructureBindingModel.SuperposeData;
@@ -98,11 +98,11 @@ public class AAStructureBindingModelTest
     StructureSelectionManager ssm = new StructureSelectionManager();
 
     ssm.setMapping(new SequenceI[] { seq1 }, null, PDB_1,
-            AppletFormatAdapter.PASTE);
+            DataSourceType.PASTE);
     ssm.setMapping(new SequenceI[] { seq2 }, null, PDB_2,
-            AppletFormatAdapter.PASTE);
+            DataSourceType.PASTE);
     ssm.setMapping(new SequenceI[] { seq3 }, null, PDB_3,
-            AppletFormatAdapter.PASTE);
+            DataSourceType.PASTE);
 
     testee = new AAStructureBindingModel(ssm, pdbFiles, seqs, chains, null)
     {
index 7e28579..6ba69b0 100644 (file)
@@ -39,7 +39,9 @@ import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignViewport;
-import jalview.io.AppletFormatAdapter;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
+import jalview.io.FileFormatI;
 import jalview.io.FormatAdapter;
 
 import java.awt.Color;
@@ -197,10 +199,10 @@ public class MappingUtilsTest
      * viewport).
      */
     AlignmentI cdna = loadAlignment(">Seq1\nACG\n>Seq2\nTGA\n>Seq3\nTAC\n",
-            "FASTA");
+            FileFormat.Fasta);
     cdna.setDataset(null);
     AlignmentI protein = loadAlignment(">Seq1\nK\n>Seq2\nL\n>Seq3\nQ\n",
-            "FASTA");
+            FileFormat.Fasta);
     protein.setDataset(null);
     AlignedCodonFrame acf = new AlignedCodonFrame();
     MapList map = new MapList(new int[] { 1, 3 }, new int[] { 1, 1 }, 3, 1);
@@ -268,11 +270,11 @@ public class MappingUtilsTest
    * @return
    * @throws IOException
    */
-  protected AlignmentI loadAlignment(final String data, String format)
+  protected AlignmentI loadAlignment(final String data, FileFormatI format)
           throws IOException
   {
     AlignmentI a = new FormatAdapter().readFile(data,
-            AppletFormatAdapter.PASTE, format);
+            DataSourceType.PASTE, format);
     a.setDataset(null);
     return a;
   }
@@ -351,11 +353,11 @@ public class MappingUtilsTest
      */
     AlignmentI cdna = loadAlignment(">Seq1/10-18\nAC-GctGtC-T\n"
             + ">Seq2/20-27\nTc-GA-G-T-Tc\n" + ">Seq3/30-38\nTtTT-AaCGg-\n",
-            "FASTA");
+            FileFormat.Fasta);
     cdna.setDataset(null);
     AlignmentI protein = loadAlignment(
             ">Seq1/40-41\n-K-P\n>Seq2/50-51\nL--Q\n>Seq3/60-61\nG--S\n",
-            "FASTA");
+            FileFormat.Fasta);
     protein.setDataset(null);
 
     // map first dna to first protein seq
@@ -466,10 +468,11 @@ public class MappingUtilsTest
      * viewport).
      */
     AlignmentI cdna = loadAlignment(
-            ">Seq1\nACGGCA\n>Seq2\nTGACAG\n>Seq3\nTACGTA\n", "FASTA");
+            ">Seq1\nACGGCA\n>Seq2\nTGACAG\n>Seq3\nTACGTA\n",
+            FileFormat.Fasta);
     cdna.setDataset(null);
     AlignmentI protein = loadAlignment(">Seq1\nKA\n>Seq2\nLQ\n>Seq3\nQV\n",
-            "FASTA");
+            FileFormat.Fasta);
     protein.setDataset(null);
     AlignedCodonFrame acf = new AlignedCodonFrame();
     MapList map = new MapList(new int[] { 1, 6 }, new int[] { 1, 2 }, 3, 1);
@@ -549,10 +552,10 @@ public class MappingUtilsTest
      */
     AlignmentI cdna = loadAlignment(
             ">Seq1\nA-CG-GC--AT-CA\n>Seq2\n-TG-AC-AG-T-AT\n>Seq3\n-T--ACG-TAAT-G\n",
-            "FASTA");
+            FileFormat.Fasta);
     cdna.setDataset(null);
     AlignmentI protein = loadAlignment(
-            ">Seq1\n-KA-S\n>Seq2\n--L-QY\n>Seq3\nQ-V-M\n", "FASTA");
+            ">Seq1\n-KA-S\n>Seq2\n--L-QY\n>Seq3\nQ-V-M\n", FileFormat.Fasta);
     protein.setDataset(null);
     AlignedCodonFrame acf = new AlignedCodonFrame();
     MapList map = new MapList(new int[] { 1, 9 }, new int[] { 1, 3 }, 3, 1);
index 9f62481..85c075b 100644 (file)
@@ -27,6 +27,8 @@ import jalview.bin.Cache;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.io.AnnotationFile;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
 import jalview.io.FormatAdapter;
 import jalview.io.StockholmFileTest;
 import jalview.ws.jws2.AADisorderClient;
@@ -71,7 +73,7 @@ public class DisorderAnnotExportImport
     assertTrue("Couldn't discover any IUPred services to use to test.",
             iupreds.size() > 0);
     jalview.io.FileLoader fl = new jalview.io.FileLoader(false);
-    af = fl.LoadFileWaitTillLoaded(testseqs, jalview.io.FormatAdapter.FILE);
+    af = fl.LoadFileWaitTillLoaded(testseqs, jalview.io.DataSourceType.FILE);
     assertNotNull("Couldn't load test data ('" + testseqs + "')", af);
   }
 
@@ -127,8 +129,8 @@ public class DisorderAnnotExportImport
   {
     try
     {
-      String aligfileout = new FormatAdapter().formatSequences("PFAM",
-              al.getSequencesArray());
+      String aligfileout = FileFormat.Pfam.getAlignmentFile().print(
+              al.getSequencesArray(), true);
       String anfileout = new AnnotationFile()
               .printAnnotationsForAlignment(al);
       assertTrue(
@@ -146,13 +148,13 @@ public class DisorderAnnotExportImport
               + "\n<<EOF\n");
 
       AlignmentI al_new = new FormatAdapter().readFile(aligfileout,
-              FormatAdapter.PASTE, "PFAM");
+              DataSourceType.PASTE, FileFormat.Pfam);
       assertTrue(
               "Test "
                       + testname
                       + "\nregenerated annotation file did not annotate alignment.",
               new AnnotationFile().readAnnotationFile(al_new, anfileout,
-                      FormatAdapter.PASTE));
+                      DataSourceType.PASTE));
 
       // test for consistency in io
       StockholmFileTest.testAlignmentEquivalence(al, al_new, true);
index 7f94b6b..28fb052 100644 (file)
@@ -27,6 +27,8 @@ import jalview.bin.Cache;
 import jalview.datamodel.AlignmentI;
 import jalview.gui.Jalview2XML;
 import jalview.io.AnnotationFile;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
 import jalview.io.FormatAdapter;
 import jalview.io.StockholmFileTest;
 import jalview.ws.jws2.JPred301Client;
@@ -81,7 +83,7 @@ public class JpredJabaStructExportImport
     System.out.println("State of jpredws: " + jpredws);
     Assert.assertNotNull(jpredws, "jpredws is null!");
     jalview.io.FileLoader fl = new jalview.io.FileLoader(false);
-    af = fl.LoadFileWaitTillLoaded(testseqs, jalview.io.FormatAdapter.FILE);
+    af = fl.LoadFileWaitTillLoaded(testseqs, jalview.io.DataSourceType.FILE);
     assertNotNull("Couldn't load test data ('" + testseqs + "')", af);
   }
 
@@ -177,8 +179,8 @@ public class JpredJabaStructExportImport
     try
     {
       // what format would be appropriate for RNAalifold annotations?
-      String aligfileout = new FormatAdapter().formatSequences("PFAM",
-              al.getSequencesArray());
+      String aligfileout = FileFormat.Pfam.getAlignmentFile().print(
+              al.getSequencesArray(), true);
 
       String anfileout = new AnnotationFile()
               .printAnnotationsForAlignment(al);
@@ -198,13 +200,13 @@ public class JpredJabaStructExportImport
 
       // again what format would be appropriate?
       AlignmentI al_new = new FormatAdapter().readFile(aligfileout,
-              FormatAdapter.PASTE, "PFAM");
+              DataSourceType.PASTE, FileFormat.Fasta);
       assertTrue(
               "Test "
                       + testname
                       + "\nregenerated annotation file did not annotate alignment.",
               new AnnotationFile().readAnnotationFile(al_new, anfileout,
-                      FormatAdapter.PASTE));
+                      DataSourceType.PASTE));
 
       // test for consistency in io
       StockholmFileTest.testAlignmentEquivalence(al, al_new, false);
index 2a111ee..fbee3a7 100644 (file)
@@ -28,7 +28,8 @@ import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.gui.Jalview2XML;
 import jalview.io.AnnotationFile;
-import jalview.io.FileLoader;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
 import jalview.io.FormatAdapter;
 import jalview.io.StockholmFileTest;
 import jalview.ws.jws2.Jws2Discoverer;
@@ -90,9 +91,9 @@ public class RNAStructExportImport
       Assert.fail("no web service");
     }
 
-    FileLoader fl = new FileLoader(false);
+    jalview.io.FileLoader fl = new jalview.io.FileLoader(false);
 
-    af = fl.LoadFileWaitTillLoaded(testseqs, FormatAdapter.FILE);
+    af = fl.LoadFileWaitTillLoaded(testseqs, jalview.io.DataSourceType.FILE);
 
     assertNotNull("Couldn't load test data ('" + testseqs + "')", af);
 
@@ -191,8 +192,8 @@ public class RNAStructExportImport
     try
     {
       // what format would be appropriate for RNAalifold annotations?
-      String aligfileout = new FormatAdapter().formatSequences("PFAM",
-              al.getSequencesArray());
+      String aligfileout = FileFormat.Pfam.getAlignmentFile().print(
+              al.getSequencesArray(), true);
 
       String anfileout = new AnnotationFile()
               .printAnnotationsForAlignment(al);
@@ -212,13 +213,13 @@ public class RNAStructExportImport
 
       // again what format would be appropriate?
       AlignmentI al_new = new FormatAdapter().readFile(aligfileout,
-              FormatAdapter.PASTE, "PFAM");
+              DataSourceType.PASTE, FileFormat.Pfam);
       assertTrue(
               "Test "
                       + testname
                       + "\nregenerated annotation file did not annotate alignment.",
               new AnnotationFile().readAnnotationFile(al_new, anfileout,
-                      FormatAdapter.PASTE));
+                      DataSourceType.PASTE));
 
       // test for consistency in io
       StockholmFileTest.testAlignmentEquivalence(al, al_new, false);
index 30383f7..d04e8c8 100644 (file)
@@ -53,10 +53,10 @@ public class ShmmrRSBSService
     assertNotNull(_rc);
     AlignFrame alf = new jalview.io.FileLoader(false)
             .LoadFileWaitTillLoaded("examples/testdata/smad.fa",
-                    jalview.io.FormatAdapter.FILE);
+                    jalview.io.DataSourceType.FILE);
     assertNotNull("Couldn't find test data.", alf);
     alf.loadJalviewDataFile("examples/testdata/smad_groups.jva",
-            jalview.io.FormatAdapter.FILE, null, null);
+            jalview.io.DataSourceType.FILE, null, null);
     assertTrue(
             "Couldn't load the test data's annotation file (should be 5 groups but found "
                     + alf.getViewport().getAlignment().getGroups().size()
index 6f9a864..9d59b78 100644 (file)
@@ -25,7 +25,7 @@ import jalview.datamodel.DBRefEntry;
 import jalview.datamodel.DBRefSource;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceI;
-import jalview.io.AppletFormatAdapter;
+import jalview.io.DataSourceType;
 import jalview.structure.StructureMapping;
 import jalview.xml.binding.sifts.Entry.Entity;
 
@@ -182,7 +182,7 @@ public class SiftsClientTest
     try
     {
       pdbFile = new PDBfile(false, false, false, "test/jalview/io/"
-              + testPDBId + ".pdb", AppletFormatAdapter.FILE);
+              + testPDBId + ".pdb", DataSourceType.FILE);
       siftsClient = new SiftsClient(pdbFile);
     } catch (Exception e)
     {
@@ -455,7 +455,7 @@ public class SiftsClientTest
     try
     {
       pdbFile = new PDBfile(false, false, false, "test/jalview/io/2nq2"
-              + ".pdb", AppletFormatAdapter.FILE);
+              + ".pdb", DataSourceType.FILE);
       siftsClientX = new SiftsClient(pdbFile);
     } catch (Exception e)
     {