JAL-4059 Tidy getting the namespace, and save the namespace in the Jalview instance...
authorBen Soares <b.soares@dundee.ac.uk>
Fri, 10 Nov 2023 21:27:54 +0000 (21:27 +0000)
committerBen Soares <b.soares@dundee.ac.uk>
Fri, 10 Nov 2023 21:27:54 +0000 (21:27 +0000)
src/jalview/bin/Jalview.java
src/jalview/gui/Desktop.java
src/jalview/gui/SeqPanel.java
src/jalview/util/Platform.java

index ba9c5b0..65ffcab 100755 (executable)
@@ -309,6 +309,10 @@ public class Jalview implements JalviewObjectI
     {
       System.setSecurityManager(null);
     }
+    else
+    {
+      setJSNamespace();
+    }
 
     if (args == null || args.length == 0 || (args.length == 1
             && (args[0] == null || args[0].length() == 0)))
@@ -555,9 +559,8 @@ public class Jalview implements JalviewObjectI
       if (aparser.contains("help") || aparser.contains("h"))
       {
         /*
-         * Now using new usage statement.
-        showUsage();
-        */
+         * Now using new usage statement. showUsage();
+         */
         Console.outPrintln(Arg.usage());
         Jalview.exit(null, ExitCode.OK);
       }
@@ -659,8 +662,8 @@ public class Jalview implements JalviewObjectI
       setLookAndFeel();
 
     /*
-     * 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
+     * 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
      */
     boolean soDefault = !Platform.isJS();
     if (Cache.getDefault("USE_FULL_SO", soDefault))
@@ -1562,13 +1565,10 @@ public class Jalview implements JalviewObjectI
             ChannelProperties.getProperty("app_name"));
     System.setProperty("apple.laf.useScreenMenuBar", "true");
     /*
-     * broken native LAFs on (ARM?) macbooks
-    set = setQuaquaLookAndFeel();
-    if ((!set) || !UIManager.getLookAndFeel().getClass().toString()
-            .toLowerCase(Locale.ROOT).contains("quaqua"))
-    {
-      set = setVaquaLookAndFeel();
-    }
+     * broken native LAFs on (ARM?) macbooks set = setQuaquaLookAndFeel(); if
+     * ((!set) || !UIManager.getLookAndFeel().getClass().toString()
+     * .toLowerCase(Locale.ROOT).contains("quaqua")) { set = setVaquaLookAndFeel();
+     * }
      */
     set = setFlatLookAndFeel();
     return set;
@@ -1587,49 +1587,50 @@ public class Jalview implements JalviewObjectI
   }
 
   /*
-  private static void showUsage()
-  {
-    jalview.bin.Console.outPrintln(
-            "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
-                    + "-nodisplay\tRun Jalview without User Interface.\n"
-                    + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
-                    + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
-                    + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
-                    + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
-                    + "-features FILE\tUse the given file to mark features on the alignment.\n"
-                    + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
-                    + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
-                    + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
-                    + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
-                    + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
-                    + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
-                    + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
-                    + "-json FILE\tCreate alignment file FILE in JSON format.\n"
-                    + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
-                    + "-png FILE\tCreate PNG image FILE from alignment.\n"
-                    + "-svg FILE\tCreate SVG image FILE from alignment.\n"
-                    + "-html FILE\tCreate HTML file from alignment.\n"
-                    + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
-                    + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
-                    + "-eps FILE\tCreate EPS file FILE from alignment.\n"
-                    + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
-                    + "-noquestionnaire\tTurn off questionnaire check.\n"
-                    + "-nonews\tTurn off check for Jalview news.\n"
-                    + "-nousagestats\tTurn off analytics tracking for this session.\n"
-                    + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
-                    // +
-                    // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
-                    // after all other properties files have been read\n\t
-                    // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
-                    // passed in correctly)"
-                    + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
-                    + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
-                    + "-groovy FILE\tExecute groovy script in FILE, after all other arguments have been processed (if FILE is the text 'STDIN' then the file will be read from STDIN)\n"
-                    + "-jvmmempc=PERCENT\tOnly available with standalone executable jar or jalview.bin.Launcher. Limit maximum heap size (memory) to PERCENT% of total physical memory detected. This defaults to 90 if total physical memory can be detected. See https://www.jalview.org/help/html/memory.html for more details.\n"
-                    + "-jvmmemmax=MAXMEMORY\tOnly available with standalone executable jar or jalview.bin.Launcher. Limit maximum heap size (memory) to MAXMEMORY. MAXMEMORY can be specified in bytes, kilobytes(k), megabytes(m), gigabytes(g) or if you're lucky enough, terabytes(t). This defaults to 32g if total physical memory can be detected, or to 8g if total physical memory cannot be detected. See https://www.jalview.org/help/html/memory.html for more details.\n"
-                    + "\n~Read documentation in Application or visit https://www.jalview.org for description of Features and Annotations file~\n\n");
-  }
-  */
+   * private static void showUsage() { jalview.bin.Console.outPrintln(
+   * "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n" +
+   * "-nodisplay\tRun Jalview without User Interface.\n" +
+   * "-props FILE\tUse the given Jalview properties file instead of users default.\n"
+   * + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n" +
+   * "-annotations FILE\tAdd precalculated annotations to the alignment.\n" +
+   * "-tree FILE\tLoad the given newick format tree file onto the alignment\n" +
+   * "-features FILE\tUse the given file to mark features on the alignment.\n" +
+   * "-fasta FILE\tCreate alignment file FILE in Fasta format.\n" +
+   * "-clustal FILE\tCreate alignment file FILE in Clustal format.\n" +
+   * "-pfam FILE\tCreate alignment file FILE in PFAM format.\n" +
+   * "-msf FILE\tCreate alignment file FILE in MSF format.\n" +
+   * "-pileup FILE\tCreate alignment file FILE in Pileup format\n" +
+   * "-pir FILE\tCreate alignment file FILE in PIR format.\n" +
+   * "-blc FILE\tCreate alignment file FILE in BLC format.\n" +
+   * "-json FILE\tCreate alignment file FILE in JSON format.\n" +
+   * "-jalview FILE\tCreate alignment file FILE in Jalview format.\n" +
+   * "-png FILE\tCreate PNG image FILE from alignment.\n" +
+   * "-svg FILE\tCreate SVG image FILE from alignment.\n" +
+   * "-html FILE\tCreate HTML file from alignment.\n" +
+   * "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n" +
+   * "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n" +
+   * "-eps FILE\tCreate EPS file FILE from alignment.\n" +
+   * "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
+   * + "-noquestionnaire\tTurn off questionnaire check.\n" +
+   * "-nonews\tTurn off check for Jalview news.\n" +
+   * "-nousagestats\tTurn off analytics tracking for this session.\n" +
+   * "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
+   * // + // "-setprop PROPERTY=VALUE\tSet the given Jalview property, // after
+   * all other properties files have been read\n\t // (quote the 'PROPERTY=VALUE'
+   * pair to ensure spaces are // passed in correctly)" +
+   * "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
+   * +
+   * "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
+   * +
+   * "-groovy FILE\tExecute groovy script in FILE, after all other arguments have been processed (if FILE is the text 'STDIN' then the file will be read from STDIN)\n"
+   * +
+   * "-jvmmempc=PERCENT\tOnly available with standalone executable jar or jalview.bin.Launcher. Limit maximum heap size (memory) to PERCENT% of total physical memory detected. This defaults to 90 if total physical memory can be detected. See https://www.jalview.org/help/html/memory.html for more details.\n"
+   * +
+   * "-jvmmemmax=MAXMEMORY\tOnly available with standalone executable jar or jalview.bin.Launcher. Limit maximum heap size (memory) to MAXMEMORY. MAXMEMORY can be specified in bytes, kilobytes(k), megabytes(m), gigabytes(g) or if you're lucky enough, terabytes(t). This defaults to 32g if total physical memory can be detected, or to 8g if total physical memory cannot be detected. See https://www.jalview.org/help/html/memory.html for more details.\n"
+   * +
+   * "\n~Read documentation in Application or visit https://www.jalview.org for description of Features and Annotations file~\n\n"
+   * ); }
+   */
 
   private static void startUsageStats(final Desktop desktop)
   {
@@ -2097,4 +2098,53 @@ public class Jalview implements JalviewObjectI
     }
   }
 
+  /**
+   * 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;
+  }
+
+  public void setJSNamespace()
+  {
+    if (!Platform.isJS())
+    {
+      return;
+    }
+    String ns = null;
+    /**
+     * @j2sNative var namespace = J2S.thisApplet.__Info.namespace;
+     * 
+     *            if (namespace === undefined)
+     * 
+     *            {
+     * 
+     *            System.out.println("No namespace given");
+     * 
+     *            }
+     * 
+     *            else
+     * 
+     *            {
+     * 
+     *            ns = namespace;
+     * 
+     *            }
+     */
+    setJSNamespace(ns);
+  }
+
 }
index c80a6ba..5a8c048 100644 (file)
@@ -450,8 +450,8 @@ public class Desktop extends jalview.jbgui.GDesktop
       if (LaunchUtils.getJavaVersion() >= 11)
       {
         /*
-         * Send this message to stderr as the warning that follows (due to
-         * reflection) also goes to stderr.
+         * Send this message to stderr as the warning that follows (due to reflection)
+         * also goes to stderr.
          */
         jalview.bin.Console.errPrintln(
                 "Linux platform only! You may have the following warning next: \"WARNING: An illegal reflective access operation has occurred\"\nThis is expected and cannot be avoided, sorry about that.");
@@ -551,12 +551,10 @@ public class Desktop extends jalview.jbgui.GDesktop
             Platform.isJS() ? desktop.getDesktopManager()
                     : new DefaultDesktopManager()));
     /*
-    (Platform.isWindowsAndNotJS() ? new DefaultDesktopManager()
-            : Platform.isAMacAndNotJS()
-                    ? new AquaInternalFrameManager(
-                            desktop.getDesktopManager())
-                    : desktop.getDesktopManager())));
-                    */
+     * (Platform.isWindowsAndNotJS() ? new DefaultDesktopManager() :
+     * Platform.isAMacAndNotJS() ? new AquaInternalFrameManager(
+     * desktop.getDesktopManager()) : desktop.getDesktopManager())));
+     */
 
     Rectangle dims = getLastKnownDimensions("");
     if (dims != null)
@@ -658,6 +656,22 @@ public class Desktop extends jalview.jbgui.GDesktop
 
     if (Platform.isJS())
     {
+      String ns = Jalview.getInstance().getJSNamespace();
+      if (ns != null)
+      {
+
+        String nsc = ns + (ns.length() > 0 ? ":" : "");
+        String splashId = nsc + "jalviewSplash";
+        /**
+         * @j2sNative let splash = document.getElementById(splashId);
+         * 
+         *            if (splash != null) {
+         * 
+         *            splash.style.display = "none";
+         * 
+         *            }
+         */
+      }
       // used for jalviewjsTest
       jalview.bin.Console.info("JALVIEWJS: CREATED DESKTOP");
     }
@@ -1288,7 +1302,7 @@ public class Desktop extends jalview.jbgui.GDesktop
       }
     }
     evt.dropComplete(success); // need this to ensure input focus is properly
-                               // transfered to any new windows created
+    // transfered to any new windows created
   }
 
   /**
@@ -2029,8 +2043,8 @@ public class Desktop extends jalview.jbgui.GDesktop
     JalviewFileChooser chooser = new JalviewFileChooser(
             Cache.getProperty("LAST_DIRECTORY"), suffix, desc,
             "Jalview Project", true, BackupFiles.getEnabled()); // last two
-                                                                // booleans:
-                                                                // allFiles,
+    // booleans:
+    // allFiles,
     // allowBackupFiles
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager.getString("label.restore_state"));
index 2caea17..bf36325 100644 (file)
@@ -1188,7 +1188,7 @@ public class SeqPanel extends JPanel
       }
       if (unshownFeatures > 0)
       {
-        tooltipText.append("<br/>").append("... ").append("<i>")
+        tooltipText.append("<br/>... <i>")
                 .append(MessageManager.formatMessage(
                         "label.features_not_shown", unshownFeatures))
                 .append("</i>");
index 0d59910..a5c004f 100644 (file)
@@ -625,12 +625,11 @@ public class Platform
     {
       jalview.bin.Console.outPrintln(
               "Platform adding known access-control-allow-origin * for domain "
-                      + domain);
-      /**
-       * @j2sNative
-       * 
-       *            J2S.addDirectDatabaseCall(domain);
-       */
+                      + domain);/**
+                                 * @j2sNative
+                                 * 
+                                 *            J2S.addDirectDatabaseCall(domain);
+                                 */
     }
 
   }
@@ -645,104 +644,114 @@ public class Platform
     if (Platform.isJS())
     {
       ArgParser.setIgnoreNonStringValues(true);
-    }
-    try
-    {
-      // extra spaces between lines of javascript to avoid eclipse comment
-      // munging into one line
-
-      /**
-       * Retrieve the first query field as command arguments to Jalview. Include
-       * only if prior to "?j2s" or "&j2s" or "#". Assign the applet's
-       * __Info.args element to this value.
-       * 
-       * if a querystringnamespace has been given in Info={...}. Use this
-       * namespace to find arguments and values in the querystring parameters.
-       * Arguments that do not take a value do not need to have a value in the
-       * querystring. If they do they will be ignored. Note, this means you
-       * cannot do 'debug=false' instead of 'nodebug'. If querystringnamepsace
-       * is an empty string ("") then no colon (":") will be expected.
-       * 
-       * if querystringnamespace is not defined then use the old style single
-       * first parameter for arguments
-       *
-       * @j2sNative var querystringnamespace =
-       *            J2S.thisApplet.__Info.querystringnamespace;
-       * 
-       *            if (querystringnamespace === undefined)
-       * 
-       *            {
-       * 
-       *            System.out.println("No querystringnamespace given");
-       * 
-       *            var a =
-       *            decodeURI((document.location.href.replace("&","?").split("?j2s")[0]
-       *            + "?").split("?")[1].split("#")[0]);
-       * 
-       *            a && (System.out.println("URL arguments detected were "+a))
-       *            && (J2S.thisApplet.__Info.urlargs = a.split(" "));
-       * 
-       *            (!J2S.thisApplet.__Info.args || J2S.thisApplet.__Info.args
-       *            == "" || J2S.thisApplet.__Info.args == "??") &&
-       *            (J2S.thisApplet.__Info.args = a) && (System.out.println("URL
-       *            arguments were passed to J2S main."));
-       * 
-       *            }
-       * 
-       *            else // querystringnamespace is defined
-       * 
-       *            {
-       * 
-       *            var qsnsc = "";
-       * 
-       *            if (J2S.thisApplet.__Info.querystringnamespace) {
-       * 
-       *            qsnsc = J2S.thisApplet.__Info.querystringnamespace + ":";
-       * 
-       *            }
-       * 
-       *            System.out.println("querystringnamespace is '"+qsnsc+"'");
-       * 
-       *            var qsParams = new URLSearchParams(window.location.search);
-       * 
-       *            var qsargs = [];
-       * 
-       *            for (var param of qsParams) {
-       * 
-       *            var key = param[0];
-       * 
-       *            var val = param[1];
-       * 
-       *            if (key.startsWith(qsnsc)) {
-       * 
-       *            var arg = key.substring(qsnsc.length);
-       * 
-       *            qsargs.push("--" + arg + "=" + val);
-       * 
-       *            System.out.println("Setting arg '"+arg+"' to '"+val+"'");
-       * 
-       *            }
-       * 
-       *            }
-       * 
-       *            qsargs && (System.out.println("URL parameters detected were
-       *            "+qsargs.join(" "))) && (J2S.thisApplet.__Info.urlargs =
-       *            qsargs);
-       * 
-       *            (!J2S.thisApplet.__Info.args || J2S.thisApplet.__Info.args
-       *            == "" || J2S.thisApplet.__Info.args == "??") &&
-       *            (J2S.thisApplet.__Info.args = qsargs.join(" ")) &&
-       *            (System.out.println("URL parameters were passed to J2S
-       *            main."));
-       * 
-       *            }
-       */
-    } catch (Throwable t)
-    {
-      /**
-       * @j2sNative console.log("Problem looking for arguments");
-       *            console.log(t);
-       */
+      try
+      {
+
+        String ns = null;
+
+        // extra spaces between lines of javascript to avoid eclipse comment
+        // munging into one line
+
+        /**
+         * Retrieve the first query field as command arguments to Jalview.
+         * Include only if prior to "?j2s" or "&j2s" or "#". Assign the applet's
+         * __Info.args element to this value.
+         * 
+         * if a namespace has been given in Info={...}. Use this namespace to
+         * find arguments and values in the querystring parameters. Arguments
+         * that do not take a value do not need to have a value in the
+         * querystring. If they do they will be ignored. Note, this means you
+         * cannot do 'debug=false' instead of 'nodebug'. If querystringnamepsace
+         * is an empty string ("") then no colon (":") will be expected.
+         * 
+         * if namespace is not defined then use the old style single first
+         * parameter for arguments
+         *
+         * @j2sNative var namespace = J2S.thisApplet.__Info.namespace;
+         * 
+         *            if (namespace === undefined)
+         * 
+         *            {
+         * 
+         *            System.out.println("No namespace given");
+         * 
+         *            var a =
+         *            decodeURI((document.location.href.replace("&","?").split("?j2s")[0]
+         *            + "?").split("?")[1].split("#")[0]);
+         * 
+         *            a && (System.out.println("URL arguments detected were
+         *            "+a)) && (J2S.thisApplet.__Info.urlargs = a.split(" "));
+         * 
+         *            (!J2S.thisApplet.__Info.args || J2S.thisApplet.__Info.args
+         *            == "" || J2S.thisApplet.__Info.args == "??") &&
+         *            (J2S.thisApplet.__Info.args = a) &&
+         *            (System.out.println("URL arguments were passed to J2S
+         *            main."));
+         * 
+         *            }
+         * 
+         *            else // namespace is defined
+         * 
+         *            {
+         * 
+         *            ns = "";
+         * 
+         *            var nsc = "";
+         * 
+         *            if (J2S.thisApplet.__Info.namespace) {
+         * 
+         *            ns = J2S.thisApplet.__Info.namespace;
+         * 
+         *            nsc = ns + ":";
+         * 
+         *            }
+         * 
+         *            System.out.println("Querystring namespace is '" + nsc +
+         *            "'");
+         * 
+         *            var qsParams = new
+         *            URLSearchParams(window.location.search);
+         * 
+         *            var qsargs = [];
+         * 
+         *            for (var param of qsParams) {
+         * 
+         *            var key = param[0];
+         * 
+         *            var val = param[1];
+         * 
+         *            if (key.startsWith(nsc)) {
+         * 
+         *            var arg = key.substring(nsc.length);
+         * 
+         *            qsargs.push("--" + arg + "=" + val);
+         * 
+         *            System.out.println("Setting arg '"+arg+"' to '"+val+"'");
+         * 
+         *            }
+         * 
+         *            }
+         * 
+         *            qsargs && (System.out.println("URL parameters detected
+         *            were "+qsargs.join(" "))) &&
+         *            (J2S.thisApplet.__Info.urlargs = qsargs);
+         * 
+         *            (!J2S.thisApplet.__Info.args || J2S.thisApplet.__Info.args
+         *            == "" || J2S.thisApplet.__Info.args == "??") &&
+         *            (J2S.thisApplet.__Info.args = qsargs.join(" ")) &&
+         *            (System.out.println("URL parameters were passed to J2S
+         *            main."));
+         * 
+         *            }
+         */
+      } catch (Throwable t)
+      {
+        /**
+         * @j2sNative System.err.println("Problem looking for arguments");
+         *            console.log("Problem looking for arguments");
+         *            console.log(t);
+         */
+      }
     }
   }
 
@@ -776,4 +785,5 @@ public class Platform
   {
     return CONSOLEWIDTH;
   }
-}
+
+}
\ No newline at end of file