Merge branch 'develop' into bug/JAL-2255_seq-fetcher-broken-on-linux
[jalview.git] / src / jalview / bin / JalviewLite.java
index b30ad41..7fa5147 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.FileFormatI;
+import jalview.io.FileFormats;
 import jalview.io.FileParse;
 import jalview.io.IdentifyFile;
 import jalview.io.JPredFile;
@@ -48,6 +51,7 @@ import jalview.javascript.JsCallBack;
 import jalview.javascript.MouseOverStructureListener;
 import jalview.structure.SelectionListener;
 import jalview.structure.StructureSelectionManager;
+import jalview.util.ColorUtils;
 import jalview.util.HttpUtils;
 import jalview.util.MessageManager;
 
@@ -63,6 +67,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 +518,23 @@ public class JalviewLite extends Applet implements
   {
     try
     {
+      FileFormatI theFormat = FileFormats.getInstance().forName(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 +716,15 @@ public class JalviewLite extends Applet implements
     {
       boolean seqlimits = suffix.equalsIgnoreCase(TRUE);
 
-      String reply = new AppletFormatAdapter().formatSequences(format,
+      FileFormatI theFormat = FileFormats.getInstance().forName(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 +750,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 +783,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 +891,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 +1827,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 +1857,7 @@ public class JalviewLite extends Applet implements
        */
       if (path.startsWith("PASTE"))
       {
-        protocol = AppletFormatAdapter.PASTE;
+        protocol = DataSourceType.PASTE;
         return path.substring(5);
       }
 
@@ -1857,7 +1866,7 @@ public class JalviewLite extends Applet implements
        */
       if (path.indexOf("://") != -1)
       {
-        protocol = AppletFormatAdapter.URL;
+        protocol = DataSourceType.URL;
         return path;
       }
 
@@ -1873,7 +1882,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 +1895,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 +1910,7 @@ public class JalviewLite extends Applet implements
        */
       if (inArchive(path))
       {
-        protocol = AppletFormatAdapter.CLASSLOADER;
+        protocol = DataSourceType.CLASSLOADER;
       }
       return path;
     }
@@ -2015,11 +2024,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 +2046,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 +2217,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 });
             }
           }
         }
@@ -2247,6 +2256,11 @@ public class JalviewLite extends Applet implements
     {
       boolean result = false;
       String param = applet.getParameter("jnetfile");
+      if (param == null)
+      {
+        // jnet became jpred around 2016
+        param = applet.getParameter("jpredfile");
+      }
       if (param != null)
       {
         try
@@ -2875,22 +2889,13 @@ public class JalviewLite extends Applet implements
     {
       return defcolour;
     }
-    Color col = jalview.schemes.ColourSchemeProperty
-            .getAWTColorFromName(colprop);
+    Color col = ColorUtils.parseColourString(colprop);
     if (col == null)
     {
-      try
-      {
-        col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
-      } catch (Exception ex)
-      {
-        System.err.println("Couldn't parse '" + colprop
-                + "' as a colour for " + colparam);
-        col = null;
-      }
+      System.err.println("Couldn't parse '" + colprop
+              + "' as a colour for " + colparam);
     }
     return (col == null) ? defcolour : col;
-
   }
 
   public void openJalviewHelpUrl()