'Add Rfam database sequence retrieval' merged; JAL-580
[jalview.git] / src / jalview / bin / Jalview.java
index 57fb00a..9383656 100755 (executable)
@@ -36,7 +36,6 @@ import java.util.*;
 import javax.swing.*;
 
 import jalview.gui.*;
-import jalview.io.FileParse;
 import jalview.util.Platform;
 
 /**
@@ -249,7 +248,7 @@ public class Jalview
       {
         try
         {
-          String viprotocol = FileParse.checkProtocol(vamsasImport);
+          String viprotocol = jalview.io.AppletFormatAdapter.checkProtocol(vamsasImport);
           if (viprotocol == jalview.io.FormatAdapter.FILE)
           {
             inSession = desktop.vamsasImport(new File(vamsasImport));
@@ -334,7 +333,7 @@ public class Jalview
         }
       }
 
-      protocol = FileParse.checkProtocol(file);
+      protocol = jalview.io.AppletFormatAdapter.checkProtocol(file);
 
       format = new jalview.io.IdentifyFile().Identify(file, protocol);
 
@@ -370,20 +369,20 @@ public class Jalview
       data = aparser.getValue("groups", true);
       if (data != null)
       {
-        af.parseFeaturesFile(data, FileParse.checkProtocol(data));
+        af.parseFeaturesFile(data, jalview.io.AppletFormatAdapter.checkProtocol(data));
         System.out.println("Added " + data);
       }
       data = aparser.getValue("features", true);
       if (data != null)
       {
-        af.parseFeaturesFile(data, FileParse.checkProtocol(data));
+        af.parseFeaturesFile(data, jalview.io.AppletFormatAdapter.checkProtocol(data));
         System.out.println("Added " + data);
       }
 
       data = aparser.getValue("annotations", true);
       if (data != null)
       {
-        af.loadJalviewDataFile(data);
+        af.loadJalviewDataFile(data, null, null, null);
         System.out.println("Added " + data);
       }
       // set or clear the sortbytree flag.
@@ -401,7 +400,7 @@ public class Jalview
         jalview.io.NewickFile fin = null;
         try
         {
-          fin = new jalview.io.NewickFile(data, FileParse.checkProtocol(data));
+          fin = new jalview.io.NewickFile(data, jalview.io.AppletFormatAdapter.checkProtocol(data));
           if (fin != null)
           {
             af.getViewport().setCurrentTree(
@@ -443,7 +442,7 @@ public class Jalview
         if (jalview.bin.Cache.groovyJarsPresent())
         {
           System.out.println("Executing script " + groovyscript);
-          executeGroovyScript(groovyscript, desktop);
+          executeGroovyScript(groovyscript, new Object[] {desktop,af});
         }
         else
         {
@@ -545,7 +544,7 @@ public class Jalview
       if (jalview.bin.Cache.groovyJarsPresent())
       {
         System.out.println("Executing script " + groovyscript);
-        executeGroovyScript(groovyscript, desktop);
+        executeGroovyScript(groovyscript, new Object[] { desktop, startUpAlframe});
       }
       else
       {
@@ -602,7 +601,7 @@ public class Jalview
    *          'Jalview' object.
    */
   private static void executeGroovyScript(String groovyscript,
-          Object jalviewContext)
+          Object[] jalviewContext)
   {
     if (jalviewContext == null)
     {
@@ -671,15 +670,36 @@ public class Jalview
        * = new Binding(); binding.setVariable("input", "world");
        * gse.run("hello.groovy", binding); </code>
        */
-      ClassLoader cl = jalviewContext.getClass().getClassLoader();
+      Class[] bspec;
+      Object[] binding;
+      int blen=((jalviewContext[0]==null) ? 0 : 1) + ((jalviewContext[1]==null) ? 0 : 1);
+      String cnames[] = new String[] { "Jalview", "currentAlFrame"};
+      bspec=new Class[blen*2];
+      binding=new Object[blen*2];
+      blen=0;
+      ClassLoader cl=null;
+      for (int jc=0;jc<jalviewContext.length;jc++)
+      {
+       if (jalviewContext[jc]!=null) { 
+         if (cl==null)
+         {
+                 cl = jalviewContext[jc].getClass().getClassLoader();
+         }
+               bspec[blen*2] = String.class;
+         bspec[blen*2+1] = Object.class;
+         binding[blen*2]=cnames[jc];
+         binding[blen*2+1]=jalviewContext[jc];
+         blen++;
+        }
+      }
       Class gbindingc = cl.loadClass("groovy.lang.Binding");
       Constructor gbcons = gbindingc.getConstructor(null);
       Object gbinding = gbcons.newInstance(null);
+      
       java.lang.reflect.Method setvar = gbindingc.getMethod("setVariable",
-              new Class[]
-              { String.class, Object.class });
-      setvar.invoke(gbinding, new Object[]
-      { "Jalview", jalviewContext });
+              bspec);
+      
+      setvar.invoke(gbinding, binding);
       Class gsec = cl.loadClass("groovy.util.GroovyScriptEngine");
       Constructor gseccons = gsec.getConstructor(new Class[]
       { URL[].class }); // String[].class });