Merge branch 'develop' into trialMerge
[jalview.git] / src / jalview / bin / Jalview.java
index 2595c4d..857bd84 100755 (executable)
@@ -41,8 +41,6 @@ import jalview.util.MessageManager;
 import jalview.util.Platform;
 import jalview.ws.jws2.Jws2Discoverer;
 
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileOutputStream;
@@ -67,9 +65,10 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.swing.LookAndFeel;
-import javax.swing.Timer;
 import javax.swing.UIManager;
 
+import com.threerings.getdown.util.LaunchUtil;
+
 import groovy.lang.Binding;
 import groovy.util.GroovyScriptEngine;
 
@@ -90,32 +89,13 @@ import groovy.util.GroovyScriptEngine;
  */
 public class Jalview
 {
-       /**
-        * @j2sNative
-        * 
-        *  // find first query parameter (if any) that doesn't start with j2s
-        *  // and set as space-delimited arguments to Jalview main
-        *      hr = decodeURI(document.location.href);
-        *  pos = hr.indexOf("?");
-        *  if (pos > 0)
-        *  {
-        *     q = hr.substring(pos+1);
-        *     args = q.split("&");
-        *     for (i = 0 ; i < args.length; i++)
-        *     {
-        *      arg1 = args[i];
-        *      if (!arg1.startsWith("j2s"))
-        *      {
-        *       thisApplet.__Info.args = arg1.split(" ");
-        *       break;
-        *      }
-        *     }
-        *  }
-        */
-
-  /*
-   * singleton instance of this class
-   */
+  static
+  {
+    Platform.getURLCommandArguments();
+  }
+
+  // singleton instance of this class
+
   private static Jalview instance;
 
   private Desktop desktop;
@@ -125,8 +105,13 @@ public class Jalview
   static
   {
     if (!Platform.isJS())
-    { // BH 2018
-           // grab all the rights we can for the JVM
+    /**
+     * Java only
+     * 
+     * @j2sIgnore
+     */
+    {
+      // grab all the rights we can for the JVM
            Policy.setPolicy(new Policy()
            {
              @Override
@@ -235,8 +220,22 @@ public class Jalview
   @SuppressWarnings("unused")
   private static void setLogging() 
   {
+
+    /**
+     * @j2sIgnore
+     * 
+     */
+    {
+      System.out.println("not in js");
+    }
+
          // BH - for event debugging in JavaScript (Java mode only)
-       if (!(/** @j2sNative true ||*/false)) 
+    if (!Platform.isJS())
+    /**
+     * Java only
+     * 
+     * @j2sIgnore
+     */
        {
                Logger.getLogger("").setLevel(Level.ALL);
         logClass("java.awt.EventDispatchThread");
@@ -268,6 +267,23 @@ public class Jalview
             + System.getProperty("os.name") + " "
             + System.getProperty("os.version"));
 
+    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();
+
+    }
     ArgsParser aparser = new ArgsParser(args);
     boolean headless = false;
 
@@ -279,10 +295,11 @@ public class Jalview
               "CMD [-props " + usrPropsFile + "] executed successfully!");
     }
 
+    if (!Platform.isJS())
     /**
-     * BH 2018 ignoring this section for JS
+     * Java only
      * 
-     * @j2sNative
+     * @j2sIgnore
      */
     {
       if (aparser.contains("help") || aparser.contains("h"))
@@ -419,13 +436,27 @@ public class Jalview
 //       }
       ;
       desktop.setInBatchMode(true); // indicate we are starting up
+
+      try
+      {
+        JalviewTaskbar.setTaskbar(this);
+      } catch (Exception e)
+      {
+        System.out.println("Cannot set Taskbar");
+        // e.printStackTrace();
+      } catch (Throwable t)
+      {
+        System.out.println("Cannot set Taskbar");
+        // t.printStackTrace();
+      }
+
       desktop.setVisible(true);
 
+      if (!Platform.isJS())
       /**
-       * BH 2018 JS bypass this section
-       * 
-       * @j2sNative
+       * Java only
        * 
+       * @j2sIgnore
        */
       {
         desktop.startServiceDiscovery();
@@ -595,14 +626,23 @@ public class Jalview
       }
       System.out.println("CMD [-open " + file + "] executed successfully!");
 
-      if (!Platform.isJS() && !file.startsWith("http://"))
+      if (!Platform.isJS())
+        /**
+         * ignore in JavaScript -- can't just file existence - could load it?
+         * 
+         * @j2sIgnore
+         */
       {
-        if (!(new File(file)).exists())
+        if (!file.startsWith("http://") && !file.startsWith("https://"))
+        // BH 2019 added https check for Java
         {
-          System.out.println("Can't find " + file);
-          if (headless)
+          if (!(new File(file)).exists())
           {
-            System.exit(1);
+            System.out.println("Can't find " + file);
+            if (headless)
+            {
+              System.exit(1);
+            }
           }
         }
       }
@@ -819,9 +859,14 @@ public class Jalview
     // And the user
     // ////////////////////
 
-    if (/** @j2sNative false && */ // BH 2018
-    !headless && file == null && vamsasImport == null
+    if (!Platform.isJS() && !headless && file == null
+            && vamsasImport == null
             && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
+    /**
+     * Java only
+     * 
+     * @j2sIgnore
+     */
     {
       file = jalview.bin.Cache.getDefault("STARTUP_FILE",
               jalview.bin.Cache.getDefault("www.jalview.org",
@@ -1059,7 +1104,7 @@ public class Jalview
     }
     try
     {
-      Map<String, Object> vbinding = new HashMap<>();
+      Map<String, java.lang.Object> vbinding = new HashMap<>();
       vbinding.put("Jalview", this);
       if (af != null)
       {