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;
import jalview.util.HttpUtils;
import jalview.util.IdUtils;
import jalview.util.IdUtils.IdType;
+import jalview.util.JalviewJSUtil;
import jalview.util.LaunchUtils;
import jalview.util.MessageManager;
import jalview.util.Platform;
{
static
{
- Platform.getURLCommandArguments();
+ JalviewJSUtil.getURLCommandArguments();
Platform.addJ2SDirectDatabaseCall("https://www.jalview.org");
Platform.addJ2SDirectDatabaseCall("http://www.jalview.org");
Platform.addJ2SDirectDatabaseCall("http://www.compbio.dundee.ac.uk");
}
else
{
- setJ2sInfo();
+ JalviewJSUtil.setJ2sInfo();
}
if (args == null || args.length == 0 || (args.length == 1
}
}
}
-
- /**
- * To be populated by Info={} hash set by instantiating JalviewJS
- */
- private Map<String, String> j2sInfo = null;
-
- /**
- * The non-j2s_-prefixed parameters to store
- */
- private final String[] j2sSavedKeys = { "main", "core", "width", "height",
- "serverURL", "j2sPath", "console" };
-
- /**
- * The prefix for non-named keys in the Info={} block
- */
- private static final String j2sParameterPrefix = "j2s_";
-
- /**
- * The Info key name for namespacing (query string parameters, class and id
- * values)
- */
- private static final String j2sNamespaceKey = j2sParameterPrefix
- + "namespace";
-
- /**
- * Get a value passed in from the Info={} hash. key should NOT use the
- * namespace prefix.
- *
- * @param key
- * key name without the j2s_ namespace in the Info={} hash.
- * @return value value from the Info={} hash.
- */
- public String getJ2sInfoValue(String key)
- {
- if (j2sInfo == null || key == null)
- {
- return null;
- }
- String j2sKey = Arrays.asList(j2sSavedKeys).contains(key) ? key
- : j2sParameterPrefix + key;
- return j2sInfo.get(j2sKey);
- }
-
- /**
- * Get and save parameters and values from the Info={} hash.
- */
- public void setJ2sInfo()
- {
- if (!Platform.isJS())
- {
- return;
- }
- j2sInfo = new HashMap<>();
- String key = null;
- String val = null;
- /**
- * @j2sNative if (J2S.thisApplet.__Info !== undefined) {
- *
- * Object.entries(J2S.thisApplet.__Info).forEach( entry => {
- *
- * key = entry[0];
- *
- * val = entry[1];
- */
- if (key != null && (key.startsWith(j2sParameterPrefix)
- || Arrays.asList(j2sSavedKeys).contains(key)))
- {
- j2sInfo.put(key, val);
-
- if (key.equals(j2sNamespaceKey))
- {
- setJ2sNamespace(val);
- }
- }
- /**
- * @j2sNative }
- *
- * );
- *
- * }
- */
- }
-
- /**
- * Namespace (if set) by JalviewJS
- */
- private String j2sNamespace = null;
-
- private void setJ2sNamespace(String ns)
- {
- if (!Platform.isJS())
- {
- return;
- }
- Console.outPrintln("j2sNamespace set to '" + ns + "'");
- j2sNamespace = ns;
- }
-
- public String getJ2sNamespace()
- {
- return j2sNamespace;
- }
}
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.bin;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.Timer;
+
+import jalview.util.JalviewJSUtil;
+import jalview.util.Platform;
+
+public class JalviewJS
+{
+ static
+ {
+ JalviewJSUtil.getURLCommandArguments();
+ Platform.addJ2SDirectDatabaseCall("https://www.jalview.org");
+ Platform.addJ2SDirectDatabaseCall("http://www.jalview.org");
+ Platform.addJ2SDirectDatabaseCall("http://www.compbio.dundee.ac.uk");
+ Platform.addJ2SDirectDatabaseCall("https://www.compbio.dundee.ac.uk");
+ }
+
+ public static void main(String[] args) throws Exception
+ {
+ Jalview.main(args);
+ // showFocusTimer();
+ }
+
+ protected static int focusTime = 0;
+
+ private static void showFocusTimer()
+ {
+ if (Platform.isJS())
+ {
+ Timer t = new Timer(100, new ActionListener()
+ {
+
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ String s = /** @j2sNative document.activeElement.id || */
+ null;
+
+ s += " " + (++focusTime);
+
+ /** @j2sNative document.title = s; */
+ }
+
+ });
+
+ t.setRepeats(true);
+ t.start();
+ }
+ }
+}
import jalview.util.IdUtils;
import jalview.util.IdUtils.IdType;
import jalview.util.ImageMaker.TYPE;
+import jalview.util.JalviewJSUtil;
import jalview.util.LaunchUtils;
import jalview.util.MessageManager;
import jalview.util.Platform;
if (Platform.isJS())
{
- final String ns = Jalview.getInstance().getJ2sNamespace();
+ final String ns = JalviewJSUtil.getJ2sNamespace();
if (ns != null)
{
final String jalviewjsDesktopElementId = "testApplet_LayeredPaneUI_10_8div";
final String splashClassActive = nsu + "jalviewjsSplashActive";
final String splashClassInactive = nsu + "jalviewjsSplashInactive";
final String splashClassHidden = nsu + "jalviewjsSplashHidden";
- final String j2s_overflow = Jalview.getInstance()
+ final String j2s_overflow = JalviewJSUtil
.getJ2sInfoValue("overflow");
/**
* @j2sNative // splash element disappearance
*
+ * function sleep(ms) {
+ *
+ * return new Promise(resolve => setTimeout(resolve, ms));
+ *
+ * }
+ *
* var splashElement = document.getElementById(splashId);
*
* if (splashElement !== undefined) {
*
* splashElement.classList.add(splashClassInactive);
*
- * function sleep(ms) {
- *
- * return new Promise(resolve => setTimeout(resolve, ms));
- *
- * }
- *
* async function hideSplash() {
*
* await sleep(5000);
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.util;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import jalview.bin.Console;
+import jalview.bin.argparser.ArgParser;
+
+public class JalviewJSUtil
+{
+ /**
+ * To be populated by Info={} hash set by instantiating JalviewJS
+ */
+ private static Map<String, String> j2sInfo = null;
+
+ /**
+ * The non-j2s_-prefixed parameters to store
+ */
+ private static final String[] j2sSavedKeys = { "main", "core", "width",
+ "height", "serverURL", "j2sPath", "console" };
+
+ /**
+ * The prefix for non-named keys in the Info={} block
+ */
+ private static final String j2sParameterPrefix = "j2s_";
+
+ /**
+ * The Info key name for namespacing (query string parameters, class and id
+ * values)
+ */
+ private static final String j2sNamespaceKey = j2sParameterPrefix
+ + "namespace";
+
+ /**
+ * Get a value passed in from the Info={} hash. key should NOT use the
+ * namespace prefix.
+ *
+ * @param key
+ * key name without the j2s_ namespace in the Info={} hash.
+ * @return value value from the Info={} hash.
+ */
+ public static String getJ2sInfoValue(String key)
+ {
+ if (j2sInfo == null || key == null)
+ {
+ return null;
+ }
+ String j2sKey = Arrays.asList(j2sSavedKeys).contains(key) ? key
+ : j2sParameterPrefix + key;
+ return j2sInfo.get(j2sKey);
+ }
+
+ /**
+ * Get and save parameters and values from the Info={} hash.
+ */
+ public static void setJ2sInfo()
+ {
+ if (!Platform.isJS())
+ {
+ return;
+ }
+ j2sInfo = new HashMap<>();
+ String key = null;
+ String val = null;
+ /**
+ * @j2sNative if (J2S.thisApplet.__Info !== undefined) {
+ *
+ * Object.entries(J2S.thisApplet.__Info).forEach( entry => {
+ *
+ * key = entry[0];
+ *
+ * val = entry[1];
+ */
+ if (key != null && (key.startsWith(j2sParameterPrefix)
+ || Arrays.asList(j2sSavedKeys).contains(key)))
+ {
+ j2sInfo.put(key, val);
+
+ if (key.equals(j2sNamespaceKey))
+ {
+ setJ2sNamespace(val);
+ }
+ }
+ /**
+ * @j2sNative }
+ *
+ * );
+ *
+ * }
+ */
+ }
+
+ /**
+ * Namespace (if set) by JalviewJS
+ */
+ private static String j2sNamespace = null;
+
+ private static void setJ2sNamespace(String ns)
+ {
+ if (!Platform.isJS())
+ {
+ return;
+ }
+ Console.outPrintln("j2sNamespace set to '" + ns + "'");
+ j2sNamespace = ns;
+ }
+
+ public static String getJ2sNamespace()
+ {
+ return j2sNamespace;
+ }
+
+ public static void getURLCommandArguments()
+ {
+
+ // setting ArgParser.ignoreNonStringValues allows non-string args to be
+ // set with, e.g., --wrap=hello
+ // which might be necessary for a querystring, plus we don't have access
+ // to Arg.hasOption(Opt.STRING)
+ if (Platform.isJS())
+ {
+ ArgParser.setIgnoreNonStringValues(true);
+ 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.j2s_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 (namespace) {
+ *
+ * ns = 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);
+ */
+ }
+ }
+ }
+
+}
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
-import jalview.bin.argparser.ArgParser;
import jalview.javascript.json.JSON;
/**
}
- public static void getURLCommandArguments()
- {
-
- // setting ArgParser.ignoreNonStringValues allows non-string args to be
- // set with, e.g., --wrap=hello
- // which might be necessary for a querystring, plus we don't have access
- // to Arg.hasOption(Opt.STRING)
- if (Platform.isJS())
- {
- ArgParser.setIgnoreNonStringValues(true);
- 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.j2s_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 (namespace) {
- *
- * ns = 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);
- */
- }
- }
- }
-
/**
* A (case sensitive) file path comparator that ignores the difference between
* / and \
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",
+ main: "jalview.bin.JalviewJS",
core: "_jalview",
width: 850,
height: 550,