JAL-4059 Tidy getting the namespace, and save the namespace in the Jalview instance...
[jalview.git] / src / jalview / bin / Jalview.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);
+  }
+
 }