JAL-4059 Send bespoke Info hash parameters into jalview.bin.Jalview instance. Set...
authorBen Soares <b.soares@dundee.ac.uk>
Wed, 22 Nov 2023 20:11:43 +0000 (20:11 +0000)
committerBen Soares <b.soares@dundee.ac.uk>
Wed, 22 Nov 2023 20:11:43 +0000 (20:11 +0000)
src/jalview/bin/Jalview.java
src/jalview/gui/Desktop.java
src/jalview/util/Platform.java
utils/jalviewjs/_j2sclasslist.txt
utils/jalviewjs/site-resources/images/jalview_logo_small.svg [new file with mode: 0644]
utils/jalviewjs/site-resources/jalview_bin_Jalview-corenamespace.html [new file with mode: 0644]
utils/jalviewjs/site-resources/jalview_bin_Jalview-namespace.html

index 65ffcab..4eed72f 100755 (executable)
@@ -40,6 +40,7 @@ import java.security.PermissionCollection;
 import java.security.Permissions;
 import java.security.Policy;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
@@ -311,7 +312,7 @@ public class Jalview implements JalviewObjectI
     }
     else
     {
-      setJSNamespace();
+      setJSInfo();
     }
 
     if (args == null || args.length == 0 || (args.length == 1
@@ -2099,52 +2100,76 @@ public class Jalview implements JalviewObjectI
   }
 
   /**
-   * Namespace (if set) by JalviewJS
+   * Info dict set by instantiating JalviewJS
    */
-  private String JSNamespace = null;
+  private Map<String, String> JSInfo = null;
 
-  private void setJSNamespace(String ns)
-  {
-    if (!Platform.isJS())
-    {
-      return;
-    }
-    Console.outPrintln("JSNamespace set to '" + ns + "'");
-    JSNamespace = ns;
-  }
+  private final String[] JSSavedKeys = { "main", "core", "width", "height",
+      "serverURL", "j2sPath", "console" };
 
-  public String getJSNamespace()
+  private final String JSSavedKeysPrefix = "js_";
+
+  private final String JSNamespaceKey = JSSavedKeysPrefix + "namespace";
+
+  public String getJSInfoValue(String key)
   {
-    return JSNamespace;
+    return JSInfo == null ? null : JSInfo.get(key);
   }
 
-  public void setJSNamespace()
+  public void setJSInfo()
   {
     if (!Platform.isJS())
     {
       return;
     }
-    String ns = null;
+    JSInfo = new HashMap<>();
+    String key = null;
+    String val = null;
     /**
-     * @j2sNative var namespace = J2S.thisApplet.__Info.namespace;
+     * @j2sNative if (J2S.thisApplet.__Info !== undefined) {
      * 
-     *            if (namespace === undefined)
+     *            Object.entries(J2S.thisApplet.__Info).forEach( entry => {
      * 
-     *            {
-     * 
-     *            System.out.println("No namespace given");
-     * 
-     *            }
+     *            key = entry[0];
      * 
-     *            else
-     * 
-     *            {
+     *            val = entry[1];
+     */
+    if (key != null && (key.startsWith(JSSavedKeysPrefix)
+            || Arrays.asList(JSSavedKeys).contains(key)))
+    {
+      JSInfo.put(key, val);
+
+      if (key.equals(JSNamespaceKey))
+      {
+        setJSNamespace(val);
+      }
+    }
+    /**
+     * @j2sNative }
      * 
-     *            ns = namespace;
+     *            );
      * 
      *            }
      */
-    setJSNamespace(ns);
   }
 
+  /**
+   * Namespace (if set) by JalviewJS
+   */
+  private String JSNamespace = null;
+
+  private void setJSNamespace(String ns)
+  {
+    if (!Platform.isJS())
+    {
+      return;
+    }
+    Console.outPrintln("JSNamespace set to '" + ns + "'");
+    JSNamespace = ns;
+  }
+
+  public String getJSNamespace()
+  {
+    return JSNamespace;
+  }
 }
index b33c9c7..8211dcb 100644 (file)
@@ -656,45 +656,99 @@ public class Desktop extends jalview.jbgui.GDesktop
 
     if (Platform.isJS())
     {
-      String ns = Jalview.getInstance().getJSNamespace();
+      final String ns = Jalview.getInstance().getJSNamespace();
       if (ns != null)
       {
-
-        String nsc = ns + (ns.length() > 0 ? ":" : "");
-        String splashId = nsc + "jalviewSplash";
+        final String jalviewjsDesktopElementId = "testApplet_LayeredPaneUI_10_8div";
+        final String nsc = ns + (ns.length() > 0 ? ":" : "");
+        final String nsu = ns + (ns.length() > 0 ? "_" : "");
+        final String splashId = nsc + "jalviewSplash";
+        final String splashClassActive = nsu + "jalviewSplashActive";
+        final String splashClassInactive = nsu + "jalviewSplashInactive";
+        final String splashClassHidden = nsu + "jalviewSplashHidden";
+        final String js_overflow = Jalview.getInstance()
+                .getJSInfoValue("js_overflow");
         /**
-         * @j2sNative let splash = document.getElementById(splashId);
+         * @j2sNative // splash element disappearance
+         * 
+         *            var splashElement = document.getElementById(splashId);
+         * 
+         *            if (splashElement !== undefined) {
+         * 
+         *            splashElement.classList.remove(splashClassActive);
+         * 
+         *            splashElement.classList.add(splashClassInactive);
          * 
-         *            if (splash != null) {
+         *            function sleep(ms) {
          * 
-         *            splash.style.display = "none";
+         *            return new Promise(resolve => setTimeout(resolve, ms));
          * 
          *            }
-         */
-
-        /**
-         * @j2sNative var overflow = J2S.thisApplet.__Info.overflow;
          * 
-         *            let desktop =
-         *            document.getElementById("jalviewjs_LayeredPaneUI_10_8div");
+         *            async function hideSplash() {
+         * 
+         *            await sleep(5000);
+         * 
+         *            splashElement.classList.add(splashClassHidden);
+         * 
+         *            }
+         * 
+         *            hideSplash();
+         * 
+         *            }
+         * 
+         *            // overflow setting
+         * 
+         *            async function changeVisibility() {
+         * 
+         *            var desktopElement = null;
          * 
-         *            if (desktop != null && overflow) {
+         *            var timeCount = 0;
          * 
-         *            System.out.println("###### Setting overflow to true");
+         *            var setCount = 0;
          * 
-         *            desktop.style.overflow = "visible";
+         *            var stayedSetCount = 0;
+         * 
+         *            while ((desktopElement == null || setCount < 5) &&
+         *            timeCount < 50 && stayedSetCount < 5) {
+         * 
+         *            await sleep(100);
+         * 
+         *            if (desktopElement == null) {
+         * 
+         *            desktopElement =
+         *            document.getElementById(jalviewjsDesktopElementId);
+         * 
+         *            }
+         * 
+         *            if (desktopElement !== undefined && desktopElement !==
+         *            null) {
+         * 
+         *            if (desktopElement.style.overflow == "hidden") {
+         * 
+         *            desktopElement.style.overflow = "visible";
+         * 
+         *            setCount++;
+         * 
+         *            stayedSetCount = 0;
          * 
          *            } else {
          * 
-         *            System.out.println("###### Setting overflow to false");
+         *            stayedSetCount++;
          * 
-         *            System.out.println("###### overflow=");
+         *            }
+         * 
+         *            }
          * 
-         *            System.out.println(overflow);
+         *            timeCount++;
+         * 
+         *            }
+         * 
+         *            }
          * 
-         *            System.out.println("###### desktop=");
+         *            if (new String(js_overflow).substring(0,4) === "true") {
          * 
-         *            console.log(desktop);
+         *            changeVisibility();
          * 
          *            }
          */
index a5c004f..52a1bcf 100644 (file)
@@ -667,7 +667,7 @@ public class Platform
          * if namespace is not defined then use the old style single first
          * parameter for arguments
          *
-         * @j2sNative var namespace = J2S.thisApplet.__Info.namespace;
+         * @j2sNative var namespace = J2S.thisApplet.__Info.js_namespace;
          * 
          *            if (namespace === undefined)
          * 
@@ -698,9 +698,9 @@ public class Platform
          * 
          *            var nsc = "";
          * 
-         *            if (J2S.thisApplet.__Info.namespace) {
+         *            if (namespace) {
          * 
-         *            ns = J2S.thisApplet.__Info.namespace;
+         *            ns = namespace;
          * 
          *            nsc = ns + ":";
          * 
index 3471709..65d0302 100644 (file)
@@ -1347,6 +1347,7 @@ java/util/zip/ZipConstants.js
 java/util/zip/ZipEntry.js
 java/util/zip/ZipInputStream.js
 javajs/api/BytePoster.js
+javajs/api/GenericCifDataParser.js
 javajs/api/GenericLineReader.js
 javajs/api/GenericOutputChannel.js
 javajs/api/JSONEncodable.js
@@ -1358,6 +1359,7 @@ javajs/util/AjaxURLStreamHandlerFactory.js
 javajs/util/BS.js
 javajs/util/Base64.js
 javajs/util/CU.js
+javajs/util/CifDataParser.js
 javajs/util/DF.js
 javajs/util/Encoding.js
 javajs/util/JSThread.js
@@ -1629,6 +1631,8 @@ org/apache/xerces/jaxp/datatype/XMLGregorianCalendarImpl.js
 org/jibble/epsgraphics/EpsDocument.js
 org/jibble/epsgraphics/EpsException.js
 org/jibble/epsgraphics/EpsGraphics2D.js
+org/jmol/adapter/readers/cif/CifReader.js
+org/jmol/adapter/readers/cif/MMCifReader.js
 org/jmol/adapter/readers/pdb/PdbReader.js
 org/jmol/adapter/smarter/Atom.js
 org/jmol/adapter/smarter/AtomIterator.js
diff --git a/utils/jalviewjs/site-resources/images/jalview_logo_small.svg b/utils/jalviewjs/site-resources/images/jalview_logo_small.svg
new file mode 100644 (file)
index 0000000..494aafc
--- /dev/null
@@ -0,0 +1 @@
+<svg enable-background="new 0 0 595.238 595.238" viewBox="0 0 85.33334 85.03162" xmlns="http://www.w3.org/2000/svg"><g stroke-width="6.118289" transform="matrix(.16344439 0 0 .16344439 0 -.301719)"><path d="m196.13701 197.95102h127.944v127.942h-127.944z" fill="#0084a9"/><g transform="translate(-38.788 -36.512996)"><path d="m38.788 38.359.035 324.03h64.364v-259.669h357.138l-64.37-64.361z" fill="#ad208e"/><path d="m202.144 201.678h357.136l-61.647-61.637h-357.152v222.272h61.663z" fill="#f78e1e"/><path d="m560.882 558.607-.034-324.033h-64.347v259.686l-358.64-.024 64.364 64.359z" fill="#009ddc"/><path d="m395.688 395.282h-356.784l61.631 61.647h356.794v-222.283h-61.641z" fill="#c1d82f"/></g></g></svg>
\ No newline at end of file
diff --git a/utils/jalviewjs/site-resources/jalview_bin_Jalview-corenamespace.html b/utils/jalviewjs/site-resources/jalview_bin_Jalview-corenamespace.html
new file mode 100644 (file)
index 0000000..bfcf8ea
--- /dev/null
@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+<html>
+<head>
+<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
+<title>SwingJS test Jalview</title><meta charset="utf-8" />
+<script src="swingjs/swingjs2.js"></script>
+<script>
+if (!self.SwingJS)alert('swingjs2.js was not found. It needs to be in swingjs folder in the same directory as ' + document.location.href)
+Info = {
+  code: null,
+  main: "jalview.bin.JalviewJS2",
+  core: "_jalview",
+  width: 850,
+  height: 550,
+  readyFunction: null,
+  serverURL: 'https://chemapps.stolaf.edu/jmol/jsmol/php/jsmol.php',
+  j2sPath: 'swingjs/j2s',
+  console:'sysoutdiv',
+  allowjavascript: true,
+  namespace: "jv"
+}
+</script>
+</head>
+<body>
+<script>
+SwingJS.getApplet('testApplet', Info)
+getClassList = function(){J2S._saveFile('_j2sclasslist.txt', Clazz.ClassFilesLoaded.sort().join('\n'))}
+</script>
+<div style="position:absolute;left:10px;top:10px;width:640px;height:1200px;">
+<div id="sysoutdiv" contentEditable="true" style="padding:5px;border:1px solid green;width:100%;height:95%;overflow:auto">
+<div id="jv:jalviewSplash" style="position:absolute;right:5px;top:5px;z-index:1000;">
+<img style="border-radius:50%;" src="images/jv.gif" />
+</div>
+</div>
+This is System.out. <a href="javascript:testApplet._clearConsole()">clear it</a>  <a href='javascript:J2S.getProfile()'>start/stop profiling</a><br>see <a href=___j2sflags.htm>___j2sflags.htm</a> for SwingJS URL command-line options<br><a href="javascript:getClassList()">get _j2sClassList.txt</a>
+</div>
+</body>
+</html>
index 4563a71..cf95a42 100644 (file)
@@ -17,20 +17,47 @@ Info = {
   j2sPath: 'swingjs/j2s',
   console:'sysoutdiv',
   allowjavascript: true,
-  namespace: "jv"
+  // all js_... values can be accessed in Jalview.getInstance().getJSInfoValue(key)
+  js_namespace: "jv",
+  js_overflow: true
 }
 </script>
+<style>
+@keyframes rotation {
+  from {
+    transform: rotate(0deg);
+  }
+  to {
+    transform: rotate(360deg);
+  }
+}
+.jv_jalviewSplashRotate {
+  animation: rotation 6s infinite cubic-bezier(0.4, 0.6, 0.6, 0.4);
+}
+.jv_jalviewSplashActive {
+  display: visible;
+  opacity: 100%;
+}
+.jv_jalviewSplashInactive {
+  opacity: 0%;
+  transition: opacity 1s;
+}
+.jv_jalviewSplashHidden {
+  display: none;
+}
+</style>
 </head>
 <body>
-<div id="jv:jalviewSplash" style="position:absolute;right:10px;top:10px;">
-<img src="images/jv.gif">
-</div>
 <script>
 SwingJS.getApplet('testApplet', Info)
 getClassList = function(){J2S._saveFile('_j2sclasslist.txt', Clazz.ClassFilesLoaded.sort().join('\n'))}
 </script>
 <div style="position:absolute;left:10px;top:10px;width:640px;height:1200px;">
-<div id="sysoutdiv" contentEditable="true" style="border:1px solid green;width:100%;height:95%;overflow:auto"></div>
+<div id="sysoutdiv" contentEditable="true" style="padding: 5px; border: 1px solid green; width: 100%; height: 95%; overflow: auto; font-family: 'Fira Mono', monospace; font-size: 8pt;">
+<div id="jv:jalviewSplash" class="jv_jalviewSplashRotate jv_jalviewSplashActive" style="position: absolute; right: 1rem; top: 1rem; z-index: 1000;">
+<img style="width; 2rem; height: 2rem;" src="images/jalview_logo_small.svg" />
+</div>
+</div>
 This is System.out. <a href="javascript:testApplet._clearConsole()">clear it</a>  <a href='javascript:J2S.getProfile()'>start/stop profiling</a><br>see <a href=___j2sflags.htm>___j2sflags.htm</a> for SwingJS URL command-line options<br><a href="javascript:getClassList()">get _j2sClassList.txt</a>
 </div>
 </body>