JAL-3032 Jalview (as JS) parse query params to main arguments
[jalview.git] / src / jalview / bin / Jalview.java
index 37f396e..e528dec 100755 (executable)
@@ -41,6 +41,8 @@ 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;
@@ -60,8 +62,12 @@ import java.security.Policy;
 import java.util.HashMap;
 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.Timer;
 import javax.swing.UIManager;
 
 import groovy.lang.Binding;
@@ -84,8 +90,17 @@ import groovy.util.GroovyScriptEngine;
  */
 public class Jalview
 {
-
-  // BH 6/19/2018 starting to work on JS version - just discovering issues
+       /**
+        * @j2sNative
+        * 
+        *  // set space-delimited query parameters as arguments to Jalview main
+        *      hr = decodeURI(document.location.href);
+        *  pos = hr.indexOf("?");
+        *  if (pos > 0)
+        *  {
+        *     thisApplet.__Info.args = hr.substring(pos+1).split(" ");
+        *  }
+        */
 
   /*
    * singleton instance of this class
@@ -96,21 +111,22 @@ public class Jalview
 
   public static AlignFrame currentAlignFrame;
 
-  /**
-   * Answers true if Jalview is running as Javascript, else false. The value is
-   * set at compile time.
-   * 
-   * @return
-   */
-  public static boolean isJS()
-  {
-    return /** @j2sNative true || */
-    false;
-  }
+//BH 2019.01.25 moved to Platform
+///**
+// * Answers true if Jalview is running as Javascript, else false. The value is
+// * set at compile time.
+// * 
+// * @return
+// */
+//public static boolean isJS()
+//{
+//  return /** @j2sNative true || */
+//  false;
+//}
 
   static
   {
-    if (!isJS())
+    if (!Platform.isJS())
     { // BH 2018
     // grab all the rights we can the JVM
     Policy.setPolicy(new Policy()
@@ -204,9 +220,39 @@ public class Jalview
    */
   public static void main(String[] args)
   {
+//     setLogging(); // BH - for event debugging in JavaScript
     instance = new Jalview();
     instance.doMain(args);
+}
+
+  private static void logClass(String name) 
+  {    
+         // BH - for event debugging in JavaScript
+      ConsoleHandler consoleHandler = new ConsoleHandler();
+      consoleHandler.setLevel(Level.ALL);
+      Logger logger = Logger.getLogger(name);
+      logger.setLevel(Level.ALL);
+      logger.addHandler(consoleHandler);
+  }
+
+  @SuppressWarnings("unused")
+  private static void setLogging() 
+  {
+         // BH - for event debugging in JavaScript (Java mode only)
+       if (!(/** @j2sNative true ||*/false)) 
+       {
+               Logger.getLogger("").setLevel(Level.ALL);
+        logClass("java.awt.EventDispatchThread");
+        logClass("java.awt.EventQueue");
+        logClass("java.awt.Component");
+        logClass("java.awt.focus.Component");
+        logClass("java.awt.focus.DefaultKeyboardFocusManager"); 
+       }       
+
   }
+  
+
+  
 
   /**
    * @param args
@@ -214,7 +260,7 @@ public class Jalview
   void doMain(String[] args)
   {
 
-    if (!isJS())
+    if (!Platform.isJS())
     {
       System.setSecurityManager(null);
     }
@@ -316,7 +362,7 @@ public class Jalview
       System.err.println("Unexpected Look and Feel Exception");
       ex.printStackTrace();
     }
-    if (Platform.isAMac())
+    if (Platform.isAMacAndNotJS())
     {
 
       LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
@@ -364,7 +410,16 @@ public class Jalview
 
     if (!headless)
     {
-      desktop = new Desktop();
+      desktop = new Desktop() 
+//      {
+// // BH testing
+//       @Override
+//       protected void processEvent(AWTEvent e) {
+//               System.out.println("Jalview.java " + e);
+//               super.processEvent(e);
+//       }
+//       }
+      ;
       desktop.setInBatchMode(true); // indicate we are starting up
       desktop.setVisible(true);
 
@@ -545,7 +600,7 @@ public class Jalview
       }
       System.out.println("CMD [-open " + file + "] executed successfully!");
 
-      if (!isJS() && !file.startsWith("http://"))
+      if (!Platform.isJS() && !file.startsWith("http://"))
       {
         if (!(new File(file)).exists())
         {