JAL-4305 Isolate and unify the Jalview object from all the gubbins in jalview.bin...
[jalview.git] / src / jalview / bin / Jalview.java
index 7518fce..783f533 100755 (executable)
@@ -73,6 +73,8 @@ import jalview.bin.argparser.Arg.Opt;
 import jalview.bin.argparser.Arg.Type;
 import jalview.bin.argparser.ArgParser;
 import jalview.bin.argparser.BootstrapArgs;
+import jalview.bin.groovy.JalviewObject;
+import jalview.bin.groovy.JalviewObjectI;
 import jalview.ext.so.SequenceOntology;
 import jalview.gui.AlignFrame;
 import jalview.gui.Desktop;
@@ -118,7 +120,7 @@ import jalview.ws.jws2.Jws2Discoverer;
  * @author $author$
  * @version $Revision$
  */
-public class Jalview
+public class Jalview implements JalviewObjectI
 {
   static
   {
@@ -138,7 +140,7 @@ public class Jalview
 
   protected Commands cmds;
 
-  public static AlignFrame currentAlignFrame;
+  public AlignFrame currentAlignFrame = null;
 
   private ArgParser argparser = null;
 
@@ -1749,12 +1751,11 @@ public class Jalview
     }
     try
     {
+      JalviewObjectI j = new JalviewObject(this);
       Map<String, java.lang.Object> vbinding = new HashMap<>();
-      vbinding.put("Jalview", this);
-      if (af != null)
-      {
-        vbinding.put("currentAlFrame", af);
-      }
+      vbinding.put("Jalview", j);
+      vbinding.put("currentAlFrame",
+              af != null ? af : getCurrentAlignFrame());
       Binding gbinding = new Binding(vbinding);
       GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
       gse.run(sfile.toString(), gbinding);
@@ -1770,7 +1771,6 @@ public class Jalview
               .errPrintln("Exception Whilst trying to execute file " + sfile
                       + " as a groovy script.");
       e.printStackTrace(System.err);
-
     }
   }
 
@@ -1784,30 +1784,32 @@ public class Jalview
     return false;
   }
 
+  @Override
   public AlignFrame[] getAlignFrames()
   {
     return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
-            : Desktop.getAlignFrames();
-
+            : Desktop.getDesktopAlignFrames();
   }
 
   /**
    * jalview.bin.Jalview.quit() will just run the non-GUI shutdownHook and exit
    */
+  @Override
   public void quit()
   {
     // System.exit will run the shutdownHook first
     Jalview.exit("Quitting now. Bye!", ExitCode.OK);
   }
 
-  public static AlignFrame getCurrentAlignFrame()
+  @Override
+  public AlignFrame getCurrentAlignFrame()
   {
-    return Jalview.currentAlignFrame;
+    return currentAlignFrame;
   }
 
-  public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
+  public void setCurrentAlignFrame(AlignFrame af)
   {
-    Jalview.currentAlignFrame = currentAlignFrame;
+    this.currentAlignFrame = af;
   }
 
   public Commands getCommands()
@@ -1859,7 +1861,7 @@ public class Jalview
     // only add new ones to the end of the list (to preserve ordinal values)
     OK, FILE_NOT_FOUND, FILE_NOT_READABLE, NO_FILES, INVALID_FORMAT,
     INVALID_ARGUMENT, INVALID_VALUE, MIXED_CLI_ARGUMENTS,
-    ERROR_RUNNING_COMMANDS, NO_LOGGING;
+    ERROR_RUNNING_COMMANDS, NO_LOGGING, GROOVY_ERROR;
   }
 
   /******************************