JAL-3626 from JAL-3253-applet Jalview.java
authorBobHanson <hansonr@stolaf.edu>
Tue, 2 Jun 2020 03:13:03 +0000 (22:13 -0500)
committerBobHanson <hansonr@stolaf.edu>
Tue, 2 Jun 2020 03:13:03 +0000 (22:13 -0500)
adds JalviewLite interface; removes deprecated AppletContext interface

src/jalview/api/JalviewApp.java
src/jalview/bin/Jalview.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/AlignViewport.java
src/jalview/gui/Preferences.java

index 0548c85..e488d6e 100644 (file)
@@ -12,7 +12,7 @@ import jalview.javascript.MouseOverStructureListener;
 import jalview.structure.SelectionSource;
 import jalview.structure.VamsasSource;
 
-import java.applet.AppletContext;
+//import java.applet.AppletContext;
 import java.io.IOException;
 import java.net.URL;
 import java.util.Hashtable;
@@ -54,7 +54,7 @@ public interface JalviewApp
 
   public Vector<Runnable> getJsExecQueue(JSFunctionExec jsFunctionExec);
 
-  public AppletContext getAppletContext();
+// deprecated  public AppletContext getAppletContext();
 
   public boolean isJsfallbackEnabled();
 
index 98dc039..e98ea63 100755 (executable)
  */
 package jalview.bin;
 
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.security.AllPermission;
+import java.security.CodeSource;
+import java.security.PermissionCollection;
+import java.security.Permissions;
+import java.security.Policy;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Vector;
+
+import javax.swing.LookAndFeel;
+import javax.swing.UIManager;
+
+import com.threerings.getdown.util.LaunchUtil;
+
+import groovy.lang.Binding;
+import groovy.util.GroovyScriptEngine;
 import jalview.api.AlignCalcWorkerI;
 import jalview.api.AlignViewportI;
 import jalview.api.JalviewApp;
@@ -31,9 +59,11 @@ import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.ext.so.SequenceOntology;
 import jalview.gui.AlignFrame;
+import jalview.gui.AlignViewport;
 import jalview.gui.AlignmentPanel;
 import jalview.gui.CalculationChooser;
 import jalview.gui.Desktop;
+import jalview.gui.Preferences;
 import jalview.gui.PromptUserConfig;
 import jalview.gui.StructureViewer;
 import jalview.io.AppletFormatAdapter;
@@ -42,6 +72,7 @@ import jalview.io.DataSourceType;
 import jalview.io.FileFormat;
 import jalview.io.FileFormatException;
 import jalview.io.FileFormatI;
+import jalview.io.FileFormats;
 import jalview.io.FileLoader;
 import jalview.io.HtmlSvgOutput;
 import jalview.io.IdentifyFile;
@@ -59,39 +90,6 @@ import jalview.util.Platform;
 import jalview.ws.jws2.Jws2Discoverer;
 import netscape.javascript.JSObject;
 
-import java.applet.AppletContext;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.security.AllPermission;
-import java.security.CodeSource;
-import java.security.PermissionCollection;
-import java.security.Permissions;
-import java.security.Policy;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Map;
-import java.util.Vector;
-import java.util.logging.ConsoleHandler;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.swing.LookAndFeel;
-import javax.swing.UIManager;
-
-import com.threerings.getdown.util.LaunchUtil;
-
-import groovy.lang.Binding;
-import groovy.util.GroovyScriptEngine;
-
 /**
  * Main class for Jalview Application <br>
  * <br>
@@ -114,6 +112,8 @@ public class Jalview implements JalviewJSApi
     Platform.getURLCommandArguments();
   }
 
+  private boolean headless;
+
   // singleton instance of this class
 
   private static Jalview instance;
@@ -154,7 +154,6 @@ public class Jalview implements JalviewJSApi
     return !noAnnotation;
   }
 
-
   static
   {
     if (!Platform.isJS())
@@ -165,21 +164,21 @@ public class Jalview implements JalviewJSApi
      */
     {
       // grab all the rights we can for the JVM
-           Policy.setPolicy(new Policy()
-           {
-             @Override
-             public PermissionCollection getPermissions(CodeSource codesource)
-             {
-               Permissions perms = new Permissions();
-               perms.add(new AllPermission());
-               return (perms);
-             }
-       
-             @Override
-             public void refresh()
-             {
-             }
-           });
+      Policy.setPolicy(new Policy()
+      {
+        @Override
+        public PermissionCollection getPermissions(CodeSource codesource)
+        {
+          Permissions perms = new Permissions();
+          perms.add(new AllPermission());
+          return (perms);
+        }
+
+        @Override
+        public void refresh()
+        {
+        }
+      });
     }
   }
 
@@ -246,23 +245,26 @@ public class Jalview implements JalviewJSApi
   {
     return instance;
   }
+  
+  
+  private final static boolean doPlatformLogging = false;
 
   /**
    * main class for Jalview application
    * 
    * @param args
-   *               open <em>filename</em>
+   *          open <em>filename</em>
    */
   public static void main(String[] args)
   {
-    if (false)
+    if (doPlatformLogging)
     {
       Platform.startJavaLogging();
     }
 
     instance = new Jalview();
     instance.doMain(args);
-}
+  }
 
   /**
    * @param args
@@ -270,28 +272,35 @@ public class Jalview implements JalviewJSApi
   void doMain(String[] args)
   {
 
-    if (!Platform.isJS())
+    boolean isJS = Platform.isJS();
+    if (isJS)
+    {
+      Platform.setAppClass(this);
+    }
+    else
     {
       System.setSecurityManager(null);
     }
 
     System.out
-            .println("Java version: "
-                    + System.getProperty("java.version"));
+            .println("Java version: " + System.getProperty("java.version"));
     System.out.println("Java Home: " + System.getProperty("java.home"));
     System.out.println(System.getProperty("os.arch") + " "
             + System.getProperty("os.name") + " "
             + System.getProperty("os.version"));
     String val = System.getProperty("sys.install4jVersion");
-    if (val != null) {
-    System.out.println("Install4j version: " + val);
+    if (val != null)
+    {
+      System.out.println("Install4j version: " + val);
     }
     val = System.getProperty("installer_template_version");
-    if (val != null) {
+    if (val != null)
+    {
       System.out.println("Install4j template version: " + val);
     }
     val = System.getProperty("launcher_version");
-    if (val != null) {
+    if (val != null)
+    {
       System.out.println("Launcher version: " + val);
     }
 
@@ -299,37 +308,55 @@ public class Jalview implements JalviewJSApi
     Cache.loadBuildProperties(true);
 
     ArgsParser aparser = new ArgsParser(args);
-    boolean headless = false;
+    headless = false;
 
     String usrPropsFile = aparser.getValue("props");
+
     Cache.loadProperties(usrPropsFile); // must do this before
-    if (usrPropsFile != null)
+
+    if (isJS)
     {
+      isJavaAppletTag = aparser.isApplet();
+      if (isJavaAppletTag)
+      {
+        Preferences.setAppletDefaults();
+        Cache.loadProperties(usrPropsFile); // again, because we
+        // might be changing defaults here?
+      }
       System.out.println(
-              "CMD [-props " + usrPropsFile + "] executed successfully!");
+              "<Applet> found: " + aparser.getValue("Info.j2sAppletID"));
+      appletResourcePath = aparser.getValue("Info.resourcePath");
     }
-
-    if (!Platform.isJS())
+    else
     /**
      * Java only
      * 
      * @j2sIgnore
      */
     {
+
+      if (usrPropsFile != null)
+      {
+        System.out.println(
+                "CMD [-props " + usrPropsFile + "] executed successfully!");
+      }
       if (aparser.contains("help") || aparser.contains("h"))
       {
         showUsage();
         System.exit(0);
       }
+      // ?>>
       if (aparser.contains("nodisplay") || aparser.contains("nogui")
               || aparser.contains("headless"))
       {
         System.setProperty("java.awt.headless", "true");
         headless = true;
       }
+      // <<?
+
       // anything else!
 
-      final String jabawsUrl = aparser.getValue("jabaws");
+      final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
       if (jabawsUrl != null)
       {
         try
@@ -345,7 +372,7 @@ public class Jalview implements JalviewJSApi
       }
 
     }
-    String defs = aparser.getValue("setprop");
+    String defs = aparser.getValue(ArgsParser.SETPROP);
     while (defs != null)
     {
       int p = defs.indexOf('=');
@@ -356,9 +383,9 @@ public class Jalview implements JalviewJSApi
       else
       {
         System.out.println("Executing setprop argument: " + defs);
-        if (Platform.isJS())
+        if (isJS)
         {
-          Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
+          Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
         }
       }
       defs = aparser.getValue("setprop");
@@ -383,52 +410,56 @@ public class Jalview implements JalviewJSApi
 
     desktop = null;
 
-    try
-    {
-      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
-    } catch (Exception ex)
-    {
-      System.err.println("Unexpected Look and Feel Exception");
-      ex.printStackTrace();
-    }
-    if (Platform.isAMacAndNotJS())
+    if (!isJS)
+    /** @j2sIgnore */
     {
-
-      LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
-              .getLookAndFeel();
-      System.setProperty("com.apple.mrj.application.apple.menu.about.name",
-              "Jalview");
-      System.setProperty("apple.laf.useScreenMenuBar", "true");
-      if (lookAndFeel != null)
+      try
       {
-        try
-        {
-          UIManager.setLookAndFeel(lookAndFeel);
-        } catch (Throwable e)
-        {
-          System.err.println(
-                  "Failed to set QuaQua look and feel: " + e.toString());
-        }
+        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+      } catch (Exception ex)
+      {
+        System.err.println("Unexpected Look and Feel Exception");
+        ex.printStackTrace();
       }
-      if (lookAndFeel == null
-              || !(lookAndFeel.getClass().isAssignableFrom(
-                      UIManager.getLookAndFeel().getClass()))
-              || !UIManager.getLookAndFeel().getClass().toString()
-                      .toLowerCase().contains("quaqua"))
+      if (Platform.isMac())
       {
-        try
+
+        LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
+                .getLookAndFeel();
+        System.setProperty(
+                "com.apple.mrj.application.apple.menu.about.name",
+                "Jalview");
+        System.setProperty("apple.laf.useScreenMenuBar", "true");
+        if (lookAndFeel != null)
         {
-          System.err.println(
-                  "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
-          UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
-        } catch (Throwable e)
+          try
+          {
+            UIManager.setLookAndFeel(lookAndFeel);
+          } catch (Throwable e)
+          {
+            System.err.println(
+                    "Failed to set QuaQua look and feel: " + e.toString());
+          }
+        }
+        if (lookAndFeel == null
+                || !(lookAndFeel.getClass().isAssignableFrom(
+                        UIManager.getLookAndFeel().getClass()))
+                || !UIManager.getLookAndFeel().getClass().toString()
+                        .toLowerCase().contains("quaqua"))
         {
-          System.err.println(
-                  "Failed to reset look and feel: " + e.toString());
+          try
+          {
+            System.err.println(
+                    "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
+            UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
+          } catch (Throwable e)
+          {
+            System.err.println(
+                    "Failed to reset look and feel: " + e.toString());
+          }
         }
       }
     }
-
     /*
      * configure 'full' SO model if preferences say to, else use the default (full SO)
      * - as JS currently doesn't have OBO parsing, it must use 'Lite' version
@@ -514,42 +545,80 @@ public class Jalview implements JalviewJSApi
       }
     }
 
-    // Move any new getdown-launcher-new.jar into place over old
-    // getdown-launcher.jar
-    String appdirString = System.getProperty("getdownappdir");
-    if (appdirString != null && appdirString.length() > 0)
+    parseArguments(aparser, true);
+  }
+
+  /**
+   * Allow an outside entity to initiate the second half of argument parsing
+   * (only).
+   * 
+   * @param args
+   * @return null is good
+   */
+  @Override
+  public Object parseArguments(String[] args)
+  {
+
+    try
     {
-      final File appdir = new File(appdirString);
-      new Thread()
-      {
-        @Override
-        public void run()
-        {
-          LaunchUtil.upgradeGetdown(
-                  new File(appdir, "getdown-launcher-old.jar"),
-                  new File(appdir, "getdown-launcher.jar"),
-                  new File(appdir, "getdown-launcher-new.jar"));
-        }
-      }.start();
+      parseArguments(new ArgsParser(args), false);
+      return null;
+    } catch (Throwable t)
+    {
+      return t;
     }
+  }
 
-    String file = null, data = null;
-    FileFormatI format = null;
-    DataSourceType protocol = null;
-    FileLoader fileLoader = new FileLoader(!headless);
+  /**
+   * 
+   * @param aparser
+   * @param isStartup
+   */
+  private void parseArguments(ArgsParser aparser, boolean isStartup)
+  {
 
     String groovyscript = null; // script to execute after all loading is
-    // completed one way or another
-    // extract groovy argument and execute if necessary
-    groovyscript = aparser.getValue("groovy", true);
-    file = aparser.getValue("open", true);
+    boolean isJS = Platform.isJS();
+    if (!isJS)
+    /** @j2sIgnore */
+    {
+      // Move any new getdown-launcher-new.jar into place over old
+      // getdown-launcher.jar
+      String appdirString = System.getProperty("getdownappdir");
+      if (appdirString != null && appdirString.length() > 0)
+      {
+        final File appdir = new File(appdirString);
+        new Thread()
+        {
+          @Override
+          public void run()
+          {
+            LaunchUtil.upgradeGetdown(
+                    new File(appdir, "getdown-launcher-old.jar"),
+                    new File(appdir, "getdown-launcher.jar"),
+                    new File(appdir, "getdown-launcher-new.jar"));
+          }
+        }.start();
+      }
+
+      // completed one way or another
+      // extract groovy argument and execute if necessary
+      groovyscript = aparser.getValue("groovy", true);
+
+    }
+
+    String file = aparser.getValue("open", true);
 
     if (file == null && desktop == null)
     {
       System.out.println("No files to open!");
       System.exit(1);
     }
+
     long progress = -1;
+    DataSourceType protocol = null;
+    FileLoader fileLoader = new FileLoader(!headless);
+    FileFormatI format = null;
     // Finally, deal with the remaining input data.
     if (file != null)
     {
@@ -563,11 +632,11 @@ public class Jalview implements JalviewJSApi
       System.out.println("CMD [-open " + file + "] executed successfully!");
 
       if (!Platform.isJS())
-        /**
-         * ignore in JavaScript -- can't just file existence - could load it?
-         * 
-         * @j2sIgnore
-         */
+      /**
+       * ignore in JavaScript -- can't just file existence - could load it?
+       * 
+       * @j2sIgnore
+       */
       {
         if (!file.startsWith("http://") && !file.startsWith("https://"))
         // BH 2019 added https check for Java
@@ -582,27 +651,89 @@ public class Jalview implements JalviewJSApi
           }
         }
       }
-
-        protocol = AppletFormatAdapter.checkProtocol(file);
-
+      String fileFormat = (isJavaAppletTag
+              ? aparser.getAppletValue("format", null)
+              : null);
+      protocol = AppletFormatAdapter.checkProtocol(file);
       try
       {
+        format = (isJavaAppletTag && fileFormat != null
+                ? FileFormats.getInstance().forName(fileFormat)
+                : null);
+        if (format == null)
+        {
+          format = new IdentifyFile().identify(file, protocol);
+        }
         format = new IdentifyFile().identify(file, protocol);
       } catch (FileFormatException e1)
       {
         // TODO ?
       }
 
-      AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
-              format);
+      if (aparser.contains(ArgsParser.NOMENUBAR))
+      {
+        noMenuBar = true;
+        System.out.println("CMD [nomenu] executed successfully!");
+      }
+
+      if (aparser.contains(ArgsParser.NOSTATUS))
+      {
+        noStatus = true;
+        System.out.println("CMD [nostatus] executed successfully!");
+      }
+
+      if (aparser.contains(ArgsParser.NOANNOTATION)
+              || aparser.contains(ArgsParser.NOANNOTATION2))
+      {
+        noAnnotation = true;
+        System.out.println("CMD no-annotation executed successfully!");
+      }
+      if (aparser.contains(ArgsParser.NOCALCULATION))
+      {
+        noCalculation = true;
+        System.out.println("CMD [nocalculation] executed successfully!");
+      }
+
+      AlignFrame af = new FileLoader(!headless).LoadFileWaitTillLoaded(file,
+              protocol, format);
       if (af == null)
       {
         System.out.println("error");
       }
       else
       {
+
+        // JalviewLite interface for JavaScript allows second file open
+        String file2 = aparser.getValue(ArgsParser.OPEN2, true);
+        if (file2 != null)
+        {
+          protocol = AppletFormatAdapter.checkProtocol(file2);
+          try
+          {
+            format = new IdentifyFile().identify(file2, protocol);
+          } catch (FileFormatException e1)
+          {
+            // TODO ?
+          }
+          AlignFrame af2 = new FileLoader(!headless)
+                  .LoadFileWaitTillLoaded(file2, protocol, format);
+          if (af2 == null)
+          {
+            System.out.println("error");
+          }
+          else
+          {
+            AlignViewport.openLinkedAlignmentAs(af,
+                    af.getViewport().getAlignment(),
+                    af2.getViewport().getAlignment(), "",
+                    AlignViewport.SPLIT_FRAME);
+            System.out.println(
+                    "CMD [-open2 " + file2 + "] executed successfully!");
+          }
+        }
         setCurrentAlignFrame(af);
-        data = aparser.getValue("colour", true);
+
+        String data = aparser.getValue(ArgsParser.COLOUR, true);
         if (data != null)
         {
           data.replaceAll("%20", " ");
@@ -619,7 +750,7 @@ public class Jalview implements JalviewJSApi
         }
 
         // Must maintain ability to use the groups flag
-        data = aparser.getValue("groups", true);
+        data = aparser.getValue(ArgsParser.GROUPS, true);
         if (data != null)
         {
           af.parseFeaturesFile(data,
@@ -628,7 +759,7 @@ public class Jalview implements JalviewJSApi
           System.out.println(
                   "CMD groups[-" + data + "]  executed successfully!");
         }
-        data = aparser.getValue("features", true);
+        data = aparser.getValue(ArgsParser.FEATURES, true);
         if (data != null)
         {
           af.parseFeaturesFile(data,
@@ -637,8 +768,7 @@ public class Jalview implements JalviewJSApi
           System.out.println(
                   "CMD [-features " + data + "]  executed successfully!");
         }
-
-        data = aparser.getValue("annotations", true);
+        data = aparser.getValue(ArgsParser.ANNOTATIONS, true);
         if (data != null)
         {
           af.loadJalviewDataFile(data, null, null, null);
@@ -646,8 +776,17 @@ public class Jalview implements JalviewJSApi
           System.out.println(
                   "CMD [-annotations " + data + "] executed successfully!");
         }
+
+        // JavaScript feature
+
+        if (aparser.contains(ArgsParser.SHOWOVERVIEW))
+        {
+          af.overviewMenuItem_actionPerformed(null);
+          System.out.println("CMD [showoverview] executed successfully!");
+        }
+
         // set or clear the sortbytree flag.
-        if (aparser.contains("sortbytree"))
+        if (aparser.contains(ArgsParser.SORTBYTREE))
         {
           af.getViewport().setSortByTree(true);
           if (af.getViewport().getSortByTree())
@@ -655,24 +794,50 @@ public class Jalview implements JalviewJSApi
             System.out.println("CMD [-sortbytree] executed successfully!");
           }
         }
-        if (aparser.contains("no-annotation"))
+
+        boolean doUpdateAnnotation = false;
+        /**
+         * we do this earlier in JalviewJS because of a complication with
+         * SHOWOVERVIEW
+         * 
+         * For now, just fixing this in JalviewJS.
+         *
+         * 
+         * @j2sIgnore
+         * 
+         */
         {
-          af.getViewport().setShowAnnotation(false);
-          if (!af.getViewport().isShowAnnotation())
+          if (aparser.contains(ArgsParser.NOANNOTATION)
+                  || aparser.contains(ArgsParser.NOANNOTATION2))
           {
-            System.out.println("CMD no-annotation executed successfully!");
+            af.getViewport().setShowAnnotation(false);
+            if (!af.getViewport().isShowAnnotation())
+            {
+              doUpdateAnnotation = true;
+              System.out
+                      .println("CMD no-annotation executed successfully!");
+            }
           }
         }
-        if (aparser.contains("nosortbytree"))
+        
+        
+        if (aparser.contains(ArgsParser.NOSORTBYTREE))
         {
           af.getViewport().setSortByTree(false);
           if (!af.getViewport().getSortByTree())
           {
+            doUpdateAnnotation = true;
             System.out
                     .println("CMD [-nosortbytree] executed successfully!");
           }
         }
-        data = aparser.getValue("tree", true);
+        if (doUpdateAnnotation)
+        { // BH 2019.07.24
+          af.setMenusForViewport();
+          af.alignPanel.updateLayout();
+        }
+
+        data = aparser.getValue(ArgsParser.TREE, true);
         if (data != null)
         {
           try
@@ -692,109 +857,44 @@ public class Jalview implements JalviewJSApi
         // TODO - load PDB structure(s) to alignment JAL-629
         // (associate with identical sequence in alignment, or a specified
         // sequence)
-        if (groovyscript != null)
+        if (isJavaAppletTag)
         {
-          // Execute the groovy script after we've done all the rendering stuff
-          // and before any images or figures are generated.
-          System.out.println("Executing script " + groovyscript);
-          executeGroovyScript(groovyscript, af);
-          System.out.println("CMD groovy[" + groovyscript
-                  + "] executed successfully!");
-          groovyscript = null;
+          loadAppletParams(aparser, af);
         }
-        String imageName = "unnamed.png";
-        while (aparser.getSize() > 1)
+        else if (!isJS)
+        /**
+         * Java only
+         * 
+         * @j2sIgnore
+         */
         {
-          String outputFormat = aparser.nextValue();
-          file = aparser.nextValue();
-
-          if (outputFormat.equalsIgnoreCase("png"))
-          {
-            af.createPNG(new File(file));
-            imageName = (new File(file)).getName();
-            System.out.println("Creating PNG image: " + file);
-            continue;
-          }
-          else if (outputFormat.equalsIgnoreCase("svg"))
-          {
-            File imageFile = new File(file);
-            imageName = imageFile.getName();
-            af.createSVG(imageFile);
-            System.out.println("Creating SVG image: " + file);
-            continue;
-          }
-          else if (outputFormat.equalsIgnoreCase("html"))
-          {
-            File imageFile = new File(file);
-            imageName = imageFile.getName();
-            HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
-            htmlSVG.exportHTML(file);
-
-            System.out.println("Creating HTML image: " + file);
-            continue;
-          }
-          else if (outputFormat.equalsIgnoreCase("biojsmsa"))
-          {
-            if (file == null)
-            {
-              System.err.println("The output html file must not be null");
-              return;
-            }
-            try
-            {
-              BioJsHTMLOutput.refreshVersionInfo(
-                      BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
-            } catch (URISyntaxException e)
-            {
-              e.printStackTrace();
-            }
-            BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
-            bjs.exportHTML(file);
-            System.out
-                    .println("Creating BioJS MSA Viwer HTML file: " + file);
-            continue;
-          }
-          else if (outputFormat.equalsIgnoreCase("imgMap"))
-          {
-            af.createImageMap(new File(file), imageName);
-            System.out.println("Creating image map: " + file);
-            continue;
-          }
-          else if (outputFormat.equalsIgnoreCase("eps"))
-          {
-            File outputFile = new File(file);
-            System.out.println(
-                    "Creating EPS file: " + outputFile.getAbsolutePath());
-            af.createEPS(outputFile);
-            continue;
-          }
-
-          af.saveAlignment(file, format);
-          if (af.isSaveAlignmentSuccessful())
-          {
-            System.out.println("Written alignment in " + format
-                    + " format to " + file);
-          }
-          else
+          if (groovyscript != null)
           {
-            System.out.println("Error writing file " + file + " in "
-                    + format + " format!!");
+            // Execute the groovy script after we've done all the rendering
+            // stuff
+            // and before any images or figures are generated.
+            System.out.println("Executing script " + groovyscript);
+            executeGroovyScript(groovyscript, af);
+            System.out.println("CMD groovy[" + groovyscript
+                    + "] executed successfully!");
+            groovyscript = null;
           }
-
         }
-
+        createOutputFiles(aparser, af, format);
         while (aparser.getSize() > 0)
         {
           System.out.println("Unknown arg: " + aparser.nextValue());
         }
       }
     }
+    
+    
     AlignFrame startUpAlframe = null;
     // We'll only open the default file if the desktop is visible.
     // And the user
     // ////////////////////
 
-    if (!Platform.isJS() && !headless && file == null
+    if (!isJS && !headless && file == null
             && Cache.getDefault("SHOW_STARTUP_FILE", true))
     /**
      * Java only
@@ -803,8 +903,7 @@ public class Jalview implements JalviewJSApi
      */
     {
       file = Cache.getDefault("STARTUP_FILE",
-              Cache.getDefault("www.jalview.org",
-                      "http://www.jalview.org")
+              Cache.getDefault("www.jalview.org", "http://www.jalview.org")
                       + "/examples/exampleFile_2_7.jar");
       if (file.equals(
               "http://www.jalview.org/examples/exampleFile_2_3.jar"))
@@ -839,9 +938,10 @@ public class Jalview implements JalviewJSApi
 
       startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
               format);
-      // extract groovy arguments before anything else.
-    }
 
+    }
+    
+    // extract groovy arguments before anything else.
     // Once all other stuff is done, execute any groovy scripts (in order)
     if (groovyscript != null)
     {
@@ -857,6 +957,7 @@ public class Jalview implements JalviewJSApi
                         + groovyscript);
       }
     }
+
     // and finally, turn off batch mode indicator - if the desktop still exists
     if (desktop != null)
     {
@@ -868,6 +969,109 @@ public class Jalview implements JalviewJSApi
     }
   }
 
+  /**
+   * Writes an output file for each format (if any) specified in the
+   * command-line arguments. Supported formats are currently
+   * <ul>
+   * <li>png</li>
+   * <li>svg</li>
+   * <li>html</li>
+   * <li>biojsmsa</li>
+   * <li>imgMap</li>
+   * <li>eps</li>
+   * </ul>
+   * A format parameter should be followed by a parameter specifying the output
+   * file name. {@code imgMap} parameters should follow those for the
+   * corresponding alignment image output.
+   * 
+   * @param aparser
+   * @param af
+   * @param format
+   */
+  private void createOutputFiles(ArgsParser aparser, AlignFrame af,
+          FileFormatI format)
+  {
+    String imageName = "unnamed.png";
+    while (aparser.getSize() > 1)
+    {
+      String outputFormat = aparser.nextValue();
+      String file = aparser.nextValue();
+
+      if (outputFormat.equalsIgnoreCase("png"))
+      {
+        af.createPNG(new File(file));
+        imageName = (new File(file)).getName();
+        System.out.println("Creating PNG image: " + file);
+        continue;
+      }
+      else if (outputFormat.equalsIgnoreCase("svg"))
+      {
+        File imageFile = new File(file);
+        imageName = imageFile.getName();
+        af.createSVG(imageFile);
+        System.out.println("Creating SVG image: " + file);
+        continue;
+      }
+      else if (outputFormat.equalsIgnoreCase("html"))
+      {
+        File imageFile = new File(file);
+        imageName = imageFile.getName();
+        HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
+        htmlSVG.exportHTML(file);
+        System.out.println("Creating HTML image: " + file);
+        continue;
+      }
+      else if (outputFormat.equalsIgnoreCase("biojsmsa"))
+      {
+        if (file == null)
+        {
+          System.err.println("The output html file must not be null");
+          return;
+        }
+        try
+        {
+          BioJsHTMLOutput.refreshVersionInfo(
+                  BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
+        } catch (URISyntaxException e)
+        {
+          e.printStackTrace();
+        }
+        BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
+        bjs.exportHTML(file);
+        System.out.println("Creating BioJS MSA Viwer HTML file: " + file);
+        continue;
+      }
+      else if (outputFormat.equalsIgnoreCase("imgMap"))
+      {
+        af.createImageMap(new File(file), imageName);
+        System.out.println("Creating image map: " + file);
+        continue;
+      }
+      else if (outputFormat.equalsIgnoreCase("eps"))
+      {
+        File outputFile = new File(file);
+        System.out.println(
+                "Creating EPS file: " + outputFile.getAbsolutePath());
+        af.createEPS(outputFile);
+        continue;
+      }
+
+      af.saveAlignment(file, format);
+      if (af.isSaveAlignmentSuccessful())
+      {
+        System.out.println(
+                "Written alignment in " + format + " format to " + file);
+      }
+      else
+      {
+        System.out.println("Error writing file " + file + " in " + format
+                + " format!!");
+      }
+
+    }
+
+  }
+
   private static void showUsage()
   {
     System.out.println(
@@ -944,10 +1148,10 @@ public class Jalview implements JalviewJSApi
    * Locate the given string as a file and pass it to the groovy interpreter.
    * 
    * @param groovyscript
-   *                         the script to execute
+   *          the script to execute
    * @param jalviewContext
-   *                         the Jalview Desktop object passed in to the groovy
-   *                         binding as the 'Jalview' object.
+   *          the Jalview Desktop object passed in to the groovy binding as the
+   *          'Jalview' object.
    */
   private void executeGroovyScript(String groovyscript, AlignFrame af)
   {
@@ -1076,8 +1280,8 @@ public class Jalview implements JalviewJSApi
   }
 
   /**
-   * Quit method delegates to Desktop.quit - unless running in headless mode when
-   * it just ends the JVM
+   * Quit method delegates to Desktop.quit - unless running in headless mode
+   * when it just ends the JVM
    */
   public void quit()
   {
@@ -1100,7 +1304,7 @@ public class Jalview implements JalviewJSApi
   {
     Jalview.currentAlignFrame = currentAlignFrame;
   }
-  
+
   /**
    * Get the SwingJS applet ID and combine that with the frameType
    * 
@@ -1267,13 +1471,15 @@ public class Jalview implements JalviewJSApi
                 : jsExecQueue);
       }
 
-      @Override
-      public AppletContext getAppletContext()
-      {
-        // TODO Auto-generated method stub
-        return null;
-      }
-
+// AppletContext deprecated 
+//
+//      @Override
+//      public AppletContext getAppletContext()
+//      {
+//        // TODO Auto-generated method stub
+//        return null;
+//      }
+//
       @Override
       public boolean isJsfallbackEnabled()
       {
@@ -1422,8 +1628,7 @@ public class Jalview implements JalviewJSApi
   public void highlight(String sequenceId, String position,
           String alignedPosition)
   {
-    highlightIn(null, sequenceId, position,
-            alignedPosition);
+    highlightIn(null, sequenceId, position, alignedPosition);
   }
 
   @Override
@@ -1470,8 +1675,7 @@ public class Jalview implements JalviewJSApi
   public String getSelectedSequencesAsAlignment(String format,
           String suffix)
   {
-    return getSelectedSequencesAsAlignmentFrom(null,
-            format, suffix);
+    return getSelectedSequencesAsAlignmentFrom(null, format, suffix);
   }
 
   @Override
@@ -1620,33 +1824,33 @@ public class Jalview implements JalviewJSApi
     return appLoader.getAnnotationFrom(alf);
   }
 
-//  @Override
-//  public AlignFrame newView()
-//  {
-//    return newViewFrom(null, null);
-//  }
-//
-//  @Override
-//  public AlignFrame newView(String name)
-//  {
-//    return newViewFrom(null, name);
-//  }
-//
-//  @Override
-//  public AlignFrame newViewFrom(AlignFrame alf)
-//  {
-//    return newViewFrom(alf, null);
-//  }
-//
-//  @Override
-//  public AlignFrame newViewFrom(AlignFrame alf, String name)
-//  {
-//    if (alf == null)
-//    {
-//      alf = getCurrentAlignFrame();
-//    }
-//    return appLoader.newViewFrom(alf, name);
-//  }
+  // @Override
+  // public AlignFrame newView()
+  // {
+  // return newViewFrom(null, null);
+  // }
+  //
+  // @Override
+  // public AlignFrame newView(String name)
+  // {
+  // return newViewFrom(null, name);
+  // }
+  //
+  // @Override
+  // public AlignFrame newViewFrom(AlignFrame alf)
+  // {
+  // return newViewFrom(alf, null);
+  // }
+  //
+  // @Override
+  // public AlignFrame newViewFrom(AlignFrame alf, String name)
+  // {
+  // if (alf == null)
+  // {
+  // alf = getCurrentAlignFrame();
+  // }
+  // return appLoader.newViewFrom(alf, name);
+  // }
 
   @Override
   public AlignFrame loadAlignment(String text, String title)
@@ -1810,8 +2014,7 @@ public class Jalview implements JalviewJSApi
   public String getSelectedSequencesAsAlignment(String format,
           boolean suffix)
   {
-    return getSelectedSequencesAsAlignmentFrom(null,
-            format, suffix);
+    return getSelectedSequencesAsAlignmentFrom(null, format, suffix);
   }
 
   @Override
@@ -1903,14 +2106,4 @@ public class Jalview implements JalviewJSApi
     // + " " + status);
   }
 
-  @Override
-  public Object parseArguments(String[] args)
-  {
-    // TODO Auto-generated method stub
-    return null;
-  }
-
-
-  
-  
 }
index ba2c1d3..29f6a2e 100644 (file)
@@ -4471,7 +4471,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
       {
         final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
-        viewport.openSplitFrame(af, new Alignment(seqs));
+        AlignViewport.openSplitFrame(this, af, new Alignment(seqs));
       }
       else
       {
index 140f77e..1849447 100644 (file)
@@ -73,6 +73,14 @@ import javax.swing.JInternalFrame;
 public class AlignViewport extends AlignmentViewport
         implements SelectionSource
 {
+
+  public final static int NO_SPLIT = 0;
+
+  public final static int SPLIT_FRAME = 1;
+
+  public final static int NEW_WINDOW = 2;
+
+
   Font font;
 
   boolean cursorMode = false;
@@ -162,7 +170,7 @@ public class AlignViewport extends AlignmentViewport
    * @param hiddenColumns
    * @param seqsetid
    *          (may be null)
-   */
+f   */
   public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns,
           String seqsetid)
   {
@@ -773,47 +781,54 @@ public class AlignViewport extends AlignmentViewport
      * in reverse order)
      */
     JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.desktop)
-            .setResponseHandler(0, new Runnable()
+            .setResponseHandler(NO_SPLIT, new Runnable()
             {
               @Override
               public void run()
               {
                   addDataToAlignment(al);
               }
-            }).setResponseHandler(1, new Runnable()
+            }).setResponseHandler(SPLIT_FRAME, new Runnable()
             {
               @Override
               public void run()
               {
-                us.openLinkedAlignmentAs(al, title, true);
+                openLinkedAlignmentAs(getAlignPanel().alignFrame,
+                        new Alignment(getAlignment()), al, title,
+                        SPLIT_FRAME);
+//                us.openLinkedAlignmentAs(al, title, true);
               }
-            }).setResponseHandler(2, new Runnable()
+            }).setResponseHandler(NEW_WINDOW, new Runnable()
             {
               @Override
               public void run()
               {
-                us.openLinkedAlignmentAs(al, title, false);
+                openLinkedAlignmentAs(null, getAlignment(), al, title,
+                        NEW_WINDOW);
               }
             });
-       dialog.showDialog(question,
+      dialog.showDialog(question,
             MessageManager.getString("label.open_split_window"),
             JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
             options, options[0]);
   }
-
-  protected void openLinkedAlignmentAs(AlignmentI al, String title,
-          boolean newWindowOrSplitPane)
-    {
+  /**
+   * Open a split frame or a new window
+   * 
+   * @param al
+   * @param title
+   * @param mode
+   *          SPLIT_FRAME or NEW_WINDOW
+   */
+  public static void openLinkedAlignmentAs(AlignFrame thisFrame,
+          AlignmentI thisAlignment, AlignmentI al, String title, int mode)
+  {
     /*
      * Identify protein and dna alignments. Make a copy of this one if opening
      * in a new split pane.
      */
-    AlignmentI thisAlignment = newWindowOrSplitPane
-            ? new Alignment(getAlignment())
-            : getAlignment();
     AlignmentI protein = al.isNucleotide() ? thisAlignment : al;
-    final AlignmentI cdna = al.isNucleotide() ? al : thisAlignment;
-
+    AlignmentI cdna = al.isNucleotide() ? al : thisAlignment;
     /*
      * Map sequences. At least one should get mapped as we have already passed
      * the test for 'mappability'. Any mappings made will be added to the
@@ -841,7 +856,7 @@ public class AlignViewport extends AlignmentViewport
     // alignFrame.setFileName(file, format);
     // }
 
-    if (!newWindowOrSplitPane)
+    if (mode == NEW_WINDOW)
     {
       Desktop.addInternalFrame(newAlignFrame, title,
               AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
@@ -855,10 +870,10 @@ public class AlignViewport extends AlignmentViewport
     {
     }
 
-    if (newWindowOrSplitPane)
+    if (mode == SPLIT_FRAME)
     {
       al.alignAs(thisAlignment);
-      protein = openSplitFrame(newAlignFrame, thisAlignment);
+      openSplitFrame(thisFrame, newAlignFrame, thisAlignment);
     }
   }
 
@@ -872,8 +887,8 @@ public class AlignViewport extends AlignmentViewport
    *          cdna/protein complement alignment to show in the other split half
    * @return the protein alignment in the split frame
    */
-  protected AlignmentI openSplitFrame(AlignFrame newAlignFrame,
-          AlignmentI complement)
+  static protected AlignmentI openSplitFrame(AlignFrame thisFrame,
+          AlignFrame newAlignFrame, AlignmentI complement)
   {
     /*
      * Make a new frame with a copy of the alignment we are adding to. If this
@@ -882,7 +897,8 @@ public class AlignViewport extends AlignmentViewport
      */
     AlignFrame copyMe = new AlignFrame(complement, AlignFrame.DEFAULT_WIDTH,
             AlignFrame.DEFAULT_HEIGHT);
-    copyMe.setTitle(getAlignPanel().alignFrame.getTitle());
+    copyMe.setTitle(thisFrame.getTitle());
+
 
     AlignmentI al = newAlignFrame.viewport.getAlignment();
     final AlignFrame proteinFrame = al.isNucleotide() ? copyMe
index 646bf61..de67768 100755 (executable)
  */
 package jalview.gui;
 
-import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
-import jalview.bin.Cache;
-import jalview.gui.Help.HelpId;
-import jalview.gui.StructureViewer.ViewerType;
-import jalview.io.BackupFiles;
-import jalview.io.BackupFilesPresetEntry;
-import jalview.io.FileFormatI;
-import jalview.io.JalviewFileChooser;
-import jalview.io.JalviewFileView;
-import jalview.jbgui.GPreferences;
-import jalview.jbgui.GSequenceLink;
-import jalview.schemes.ColourSchemeI;
-import jalview.schemes.ColourSchemes;
-import jalview.schemes.ResidueColourScheme;
-import jalview.urls.UrlLinkTableModel;
-import jalview.urls.api.UrlProviderFactoryI;
-import jalview.urls.api.UrlProviderI;
-import jalview.urls.desktop.DesktopUrlProviderFactory;
-import jalview.util.MessageManager;
-import jalview.util.Platform;
-import jalview.util.UrlConstants;
-import jalview.ws.sifts.SiftsSettings;
-
 import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Component;
@@ -74,6 +51,28 @@ import javax.swing.table.TableModel;
 import javax.swing.table.TableRowSorter;
 
 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
+import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
+import jalview.bin.Cache;
+import jalview.gui.Help.HelpId;
+import jalview.gui.StructureViewer.ViewerType;
+import jalview.io.BackupFiles;
+import jalview.io.BackupFilesPresetEntry;
+import jalview.io.FileFormatI;
+import jalview.io.JalviewFileChooser;
+import jalview.io.JalviewFileView;
+import jalview.jbgui.GPreferences;
+import jalview.jbgui.GSequenceLink;
+import jalview.schemes.ColourSchemeI;
+import jalview.schemes.ColourSchemes;
+import jalview.schemes.ResidueColourScheme;
+import jalview.urls.UrlLinkTableModel;
+import jalview.urls.api.UrlProviderFactoryI;
+import jalview.urls.api.UrlProviderI;
+import jalview.urls.desktop.DesktopUrlProviderFactory;
+import jalview.util.MessageManager;
+import jalview.util.Platform;
+import jalview.util.UrlConstants;
+import jalview.ws.sifts.SiftsSettings;
 
 /**
  * DOCUMENT ME!
@@ -833,7 +832,7 @@ public class Preferences extends GPreferences
     String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
     if (menuLinks.isEmpty())
     {
-      Cache.removeNoSave("SEQUENCE_LINKS");
+      Cache.removePropertyNoSave("SEQUENCE_LINKS");
     }
     else
     {
@@ -844,7 +843,7 @@ public class Preferences extends GPreferences
     String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
     if (nonMenuLinks.isEmpty())
     {
-      Cache.removeNoSave("STORED_LINKS");
+      Cache.removePropertyNoSave("STORED_LINKS");
     }
     else
     {
@@ -948,8 +947,7 @@ public class Preferences extends GPreferences
       BackupFilesPresetEntry customBFPE = getBackupfilesCurrentEntry();
       BackupFilesPresetEntry.backupfilesPresetEntriesValues.put(
               BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM, customBFPE);
-      Cache.applicationProperties
-              .setProperty(BackupFilesPresetEntry.CUSTOMCONFIG,
+      Cache.setPropertyNoSave(BackupFilesPresetEntry.CUSTOMCONFIG,
                       customBFPE.toString());
     }
 
@@ -968,7 +966,43 @@ public class Preferences extends GPreferences
     }
   }
 
-  /**
+  public static void setAppletDefaults()
+  {
+
+    // http://www.jalview.org/old/v2_8/examples/appletParameters.html
+
+    // showConservation true or false Default is true.
+    // showQuality true or false Default is true.
+    // showConsensus true or false Default is true.
+    // showFeatureSettings true or false Shows the feature settings window when
+    // startin
+    // showTreeBootstraps true or false (default is true) show or hide branch
+    // bootstraps
+    // showTreeDistances true or false (default is true) show or hide branch
+    // lengths
+    // showUnlinkedTreeNodes true or false (default is false) indicate if
+    // unassociated nodes should be highlighted in the tree view
+    // showUnconserved true of false (default is false) When true, only gaps and
+    // symbols different to the consensus sequence ions of the alignment
+    // showGroupConsensus true of false (default is false) When true, shows
+    // consensus annotation row for any groups on the alignment. (since 2.7)
+    // showGroupConservation true of false (default is false) When true, shows
+    // amino-acid property conservation annotation row for any groups on the
+    // showConsensusHistogram true of false (default is true) When true, shows
+    // the percentage occurence of the consensus symbol for each column as a
+    // showSequenceLogo true of false (default is false) When true, shows a
+    // sequence logo above the consensus sequence (overlaid above the Consensus
+
+    Cache.setPropertyNoSave(SHOW_CONSERVATION, "true");
+    Cache.setPropertyNoSave(SHOW_QUALITY, "false");
+    Cache.setPropertyNoSave(SHOW_CONSENSUS, "true");
+    Cache.setPropertyNoSave(SHOW_UNCONSERVED, "false");
+    Cache.setPropertyNoSave(SHOW_GROUP_CONSERVATION, "false");
+    Cache.setPropertyNoSave(SHOW_GROUP_CONSENSUS, "false");
+
+    // TODO -- just a start here
+  }
+ /**
    * Do any necessary validation before saving settings. Return focus to the
    * first tab which fails validation.
    *