{
private ArgsParser aparser;
- private String j2sAppletID;
-
private boolean debug;
private String[] ret = new String[1];
// be '|', but many sequence IDS include
// pipes.
+
public JalviewJSApp(ArgsParser aparser)
{
this.aparser = aparser;
- this.j2sAppletID = (String) aparser.getAppletValue("j2sAppletID",
- "Jalview", true);
Platform.setAppClass(this);
}
loadPdbFiles(af);
}
- public String getAppID(String frameType)
- {
- return j2sAppletID + (frameType == null ? "" : "-" + frameType);
- }
-
// TODO BH 2019
//
// These are methods that are in JalviewLite that various classes call
}
- Jalview jalview = Jalview.getInstance();
- jalview.doSendCallback(_listener,
+ doSendCallback(_listener,
new Object[]
- { src, setid, jalview.arrayToSeparatorList(seqs),
- jalview.arrayToSeparatorList(cols) });
+ { src, setid, arrayToSeparatorList(seqs),
+ arrayToSeparatorList(cols) });
}
public boolean isFor(AlignFrame af, String listener)
{
}
- static
- {
- Platform.getURLCommandArguments();
- }
-
private boolean headless;
private Desktop desktop;
public String appletResourcePath;
- JalviewJSApp app; // JalviewJS-specific JavaScript interface
-
+ public String j2sAppletID;
+
private boolean noCalculation, noMenuBar, noStatus;
private boolean noAnnotation;
static
{
- if (!Platform.isJS())
- /**
- * Java only
- *
- * @j2sIgnore
- */
+ if (Platform.isJS()) {
+ Platform.getURLCommandArguments();
+ } else /** @j2sIgnore */
{
// grab all the rights we can for the JVM
Policy.setPolicy(new Policy()
if (isJS)
{
- app = new JalviewJSApp(aparser);
- Preferences.setAppletDefaults();
- Cache.loadProperties(usrPropsFile); // again, because we
- // might be changing defaults here?
- appletResourcePath = (String) aparser.getAppletValue("resourcepath", null, true);
+ j2sAppletID = Platform.getAppID(null);
+ Preferences.setAppletDefaults();
+ Cache.loadProperties(usrPropsFile); // again, because we
+ // might be changing defaults here?
+ appletResourcePath = (String) aparser.getAppletValue("resourcepath",
+ null, true);
}
else
/**
* 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();
+ boolean soDefault = !isJS;
if (Cache.getDefault("USE_FULL_SO", soDefault))
{
SequenceOntologyFactory.setSequenceOntology(new SequenceOntology());
}
desktop.setVisible(true);
- if (!Platform.isJS())
+ if (!isJS)
/**
* Java only
*
BioJsHTMLOutput.updateBioJS();
}
}
-
parseArguments(aparser, true);
-
}
/**
+ * Parse all command-line String[] arguments as well as all JavaScript-derived parameters from Info.
+ *
+ * We allow for this method to be run from JavaScript. Basically allowing simple scripting.
*
* @param aparser
* @param isStartup
String file = aparser.getValue("open", true);
- if (file == null && desktop == null)
+ if (!isJS && file == null && desktop == null)
{
System.out.println("No files to open!");
System.exit(1);
}
+ // time to open a file.
+
long progress = -1;
DataSourceType protocol = null;
FileLoader fileLoader = new FileLoader(!headless);
FileFormatI format = null;
// Finally, deal with the remaining input data.
+ JalviewJSApp jsApp = null;
+ AlignFrame af = null;
+
if (file != null)
{
if (!headless)
}
}
}
- String fileFormat = (isJS ? (String) aparser.getAppletValue("format", null, true)
+ String fileFormat = (isJS
+ ? (String) aparser.getAppletValue("format", null, true)
: null);
protocol = AppletFormatAdapter.checkProtocol(file);
try
System.out.println("CMD [nocalculation] executed successfully!");
}
- AlignFrame af = new FileLoader(!headless).LoadFileWaitTillLoaded(file,
- protocol, format);
+ af = new FileLoader(!headless).LoadFileWaitTillLoaded(file, protocol,
+ format);
if (af == null)
{
System.out.println("error");
// TODO - load PDB structure(s) to alignment JAL-629
// (associate with identical sequence in alignment, or a specified
// sequence)
-
+
if (isJS)
{
- app.load(af);
+ jsApp = new JalviewJSApp(aparser);
+ jsApp.load(af);
}
else
/**
}
}
}
-
- AlignFrame startUpAlframe = null;
- // We'll only open the default file if the desktop is visible.
- // And the user
- // ////////////////////
-
- if (!isJS && !headless && file == null
- && Cache.getDefault("SHOW_STARTUP_FILE", true))
- /**
- * Java only
- *
- * @j2sIgnore
- */
+ else
{
- file = Cache.getDefault("STARTUP_FILE",
- Cache.getDefault("www.jalview.org", "http://www.jalview.org")
- + "/examples/exampleFile_2_7.jar");
- if (file.equals(
- "http://www.jalview.org/examples/exampleFile_2_3.jar"))
+ if (!isJS && !headless && Cache.getDefault("SHOW_STARTUP_FILE", true))
+ /**
+ * Java only
+ *
+ * @j2sIgnore
+ */
{
- // hardwire upgrade of the startup file
- file.replace("_2_3.jar", "_2_7.jar");
- // and remove the stale setting
- Cache.removeProperty("STARTUP_FILE");
- }
- protocol = DataSourceType.FILE;
+ // We'll only open the default file if the desktop is visible.
+ // And the user
+ // ////////////////////
- if (file.indexOf("http:") > -1)
- {
- protocol = DataSourceType.URL;
- }
+ file = Cache.getDefault("STARTUP_FILE",
+ Cache.getDefault("www.jalview.org",
+ "http://www.jalview.org")
+ + "/examples/exampleFile_2_7.jar");
+ if (file.equals(
+ "http://www.jalview.org/examples/exampleFile_2_3.jar"))
+ {
+ // hardwire upgrade of the startup file
+ file.replace("_2_3.jar", "_2_7.jar");
+ // and remove the stale setting
+ Cache.removeProperty("STARTUP_FILE");
+ }
- if (file.endsWith(".jar"))
- {
- format = FileFormat.Jalview;
- }
- else
- {
- try
+ protocol = DataSourceType.FILE;
+
+ if (file.indexOf("http:") > -1)
{
- format = new IdentifyFile().identify(file, protocol);
- } catch (FileFormatException e)
+ protocol = DataSourceType.URL;
+ }
+
+ if (file.endsWith(".jar"))
{
- // TODO what?
+ format = FileFormat.Jalview;
+ }
+ else
+ {
+ try
+ {
+ format = new IdentifyFile().identify(file, protocol);
+ } catch (FileFormatException e)
+ {
+ // TODO what?
+ }
}
- }
- startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
- format);
+ af = fileLoader.LoadFileWaitTillLoaded(file, protocol, format);
+ }
}
-
// extract groovy arguments before anything else.
// Once all other stuff is done, execute any groovy scripts (in order)
- if (groovyscript != null)
+ if (!isJS && groovyscript != null)
{
if (Cache.groovyJarsPresent())
{
System.out.println("Executing script " + groovyscript);
- executeGroovyScript(groovyscript, startUpAlframe);
+ executeGroovyScript(groovyscript, af);
}
else
{
if (isJS && isStartup)
{
- app.callInitCallback();
+ jsApp.callInitCallback();
}
}
"Creating image map: " + imageFile.getAbsolutePath());
continue;
}
- if (!Platform.isJS())
+ if (!Platform.isJS()) /** @j2sIgnore */
{
// skipping outputFormat?
System.out.println("Unknown arg: " + outputFormat);
+ " format!!");
}
}
- while (aparser.getSize() > 0)
- {
- System.out.println("Unknown arg: " + aparser.nextValue());
- }
break;
}
-
+ while (aparser.getSize() > 0)
+ {
+ System.out.println("Unknown arg: " + aparser.nextValue());
+ }
}
private static void showUsage()
}
- /**
- * Get the SwingJS applet ID and combine that with the frameType
- *
- * @param frameType
- * "alignment", "desktop", etc., or null
- * @return
- */
- public static String getAppID(String frameType)
- {
- return (Platform.isJS() ? getInstance().app.getAppID(frameType) : null);
- }
-
- public String doSendCallback(Object callback, Object[] data) {
- return (Platform.isJS() ? app.doSendCallback(callback, data) : null);
- }
-
public void notifyWorker(AlignCalcWorkerI worker, String status)
{
// System.out.println("Jalview worker " + worker.getClass().getSimpleName()
// + " " + status);
}
-
- public Object arrayToSeparatorList(String[] seqs)
- {
- return (Platform.isJS() ? app.arrayToSeparatorList(seqs) : null);
- }
-
}
// BH 2019.07.26 we allow for an embedded
// undecorated overview with defined size
- frame.setName(Jalview.getAppID("overview"));
+ frame.setName(Platform.getAppID("overview"));
//
Dimension dim = Platform.getDimIfEmbedded(frame, -1, -1);
if (dim != null && dim.width == 0)
import jalview.analysis.GeneticCodes;
import jalview.api.SplitContainerI;
import jalview.bin.Cache;
-import jalview.bin.Jalview;
import jalview.gui.JvSwingUtils;
import jalview.gui.Preferences;
import jalview.io.FileFormats;
{
// for Web-page embedding using id=align-frame-div
- setName(Jalview.getAppID("alignment"));
+ setName(Platform.getAppID("alignment"));
jbInit();
package jalview.jbgui;
import jalview.api.AlignmentViewPanel;
-import jalview.bin.Jalview;
import jalview.io.FileFormatException;
import jalview.util.MessageManager;
import jalview.util.Platform;
private void jbInit() throws Exception
{
- setName(Jalview.getAppID("desktop"));
+ setName(Platform.getAppID("desktop"));
FileMenu.setText(MessageManager.getString("action.file"));
HelpMenu.setText(MessageManager.getString("action.help"));
inputLocalFileMenuItem
*/
package jalview.jbgui;
-import jalview.bin.Jalview;
import jalview.util.ImageMaker.TYPE;
import jalview.util.MessageManager;
+import jalview.util.Platform;
import java.awt.BorderLayout;
import java.awt.Color;
private void jbInit() throws Exception
{
- setName(Jalview.getAppID("pca"));
+ setName(Platform.getAppID("pca"));
this.getContentPane().setLayout(new BorderLayout());
JPanel jPanel2 = new JPanel();
jPanel2.setLayout(new FlowLayout());
package jalview.jbgui;
import jalview.api.structures.JalviewStructureDisplayI;
-import jalview.bin.Jalview;
import jalview.gui.ColourMenuHelper.ColourChangeListener;
import jalview.util.ImageMaker.TYPE;
import jalview.util.MessageManager;
+import jalview.util.Platform;
import java.awt.BorderLayout;
import java.awt.GridLayout;
private void jbInit() throws Exception
{
- setName(Jalview.getAppID("structureviewer"));
+ setName(Platform.getAppID("structureviewer"));
JMenuBar menuBar = new JMenuBar();
this.setJMenuBar(menuBar);
*/
package jalview.jbgui;
-import jalview.bin.Jalview;
import jalview.util.ImageMaker.TYPE;
import jalview.util.MessageManager;
+import jalview.util.Platform;
import java.awt.BorderLayout;
import java.awt.Color;
private void jbInit() throws Exception
{
- setName(Jalview.getAppID("tree"));
+ setName(Platform.getAppID("tree"));
this.getContentPane().setLayout(borderLayout1);
this.setBackground(Color.white);
this.setFont(new java.awt.Font("Verdana", 0, 12));
import com.stevesoft.pat.Regex;
+import jalview.bin.Jalview;
import jalview.javascript.json.JSON;
import swingjs.api.JSUtilI;
isWin = null;
private static Boolean isHeadless = null;
-
+
private static swingjs.api.JSUtilI jsutil;
- static {
- if (isJS) {
+ static
+ {
+ if (isJS)
+ {
try
{
- // this is ok - it's a highly embedded method in Java; the deprecation is
+ // this is ok - it's a highly embedded method in Java; the deprecation
+ // is
// really a recommended best practice.
jsutil = ((JSUtilI) Class.forName("swingjs.JSUtil").newInstance());
} catch (InstantiationException | IllegalAccessException
{
e.printStackTrace();
}
- }
+ }
}
// private static Boolean isHeadless = null;
return (isNoJSWin == null ? (isNoJSWin = !isJS && isWin()) : isNoJSWin);
}
- /**
- *
- * @return true if we are running in non-interactive no UI mode
- */
- public static boolean isHeadless()
- {
- if (isHeadless == null)
- {
- isHeadless = "true".equals(System.getProperty("java.awt.headless"));
- }
- return isHeadless;
- }
+ /**
+ *
+ * @return true if we are running in non-interactive no UI mode
+ */
+ public static boolean isHeadless()
+ {
+ if (isHeadless == null)
+ {
+ isHeadless = "true".equals(System.getProperty("java.awt.headless"));
+ }
+ return isHeadless;
+ }
/**
*
{
return s == null ? null : s.replace("\\", "\\\\");
}
-
+
/**
* Answers true if the mouse event has Meta-down (Command key on Mac) or
* Ctrl-down (on other o/s). Note this answers _false_ if the Ctrl key is
}
}
-
public static void cacheFileData(File file)
{
if (isJS)
}
return null;
}
-
+
public static String getFileAsString(String url)
{
if (isJS && url != null)
return false;
}
-
public static void addJ2SBinaryType(String ext)
{
if (isJS)
jsutil.addBinaryFileType(ext);
}
}
-
+
/**
* Encode the URI using JavaScript encodeURIComponent
*
return (isJS ? (String) jsutil.getAppletAttribute("_uniqueId") : null);
}
-
/**
* Read the Info block for this applet.
*
public static Object parseJSON(String json) throws ParseException
{
- return (isJS() ? JSON.parse(json)
- : new JSONParser().parse(json));
+ return (isJS() ? JSON.parse(json) : new JSONParser().parse(json));
}
public static Object parseJSON(Reader r)
* @param is
* @param outFile
* @throws IOException
- * if the file cannot be created or there is a problem
- * reading the input stream.
+ * if the file cannot be created or there is a problem reading the
+ * input stream.
*/
public static void streamToFile(InputStream is, File outFile)
throws IOException
jsutil.addDirectDatabaseCall(domain);
System.out.println(
- "Platform adding known access-control-allow-origin * for domain "
- + domain);
+ "Platform adding known access-control-allow-origin * for domain "
+ + domain);
}
}
+ /**
+ * Allow for URL-line command arguments. Untested.
+ *
+ */
public static void getURLCommandArguments()
{
+ try {
/**
* 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
* decodeURI((document.location.href.replace("&","?").split("?j2s")[0]
* + "?").split("?")[1].split("#")[0]); a &&
* (J2S.thisApplet.__Info.args = a.split(" "));
+ *
+ * System.out.println("URL arguments: " + a);
*/
-
+ } catch (Throwable t) {
+ }
}
/**
- * A (case sensitive) file path comparator that ignores the difference between /
- * and \
+ * A (case sensitive) file path comparator that ignores the difference between
+ * / and \
*
* @param path1
* @param path2
return p1.equals(p2);
}
+ ///////////// JAL-3253 Applet additions //////////////
-
-///////////// JAL-3253 Applet additions //////////////
-
-
/**
* Retrieve the object's embedded size from a div's style on a page if
* embedded in SwingJS.
}
}
-
/**
* load a resource -- probably a core file -- if and only if a particular
* class has not been instantialized. We use a String here because if we used
public static String getUserPath(String subpath)
{
char sep = File.separatorChar;
- return System.getProperty("user.home") + sep + subpath.replace('/', sep);
+ return System.getProperty("user.home") + sep
+ + subpath.replace('/', sep);
}
/**
*/
public static boolean isFileOlderThanThreshold(File file, int noOfDays)
{
- if (isJS()) {
- // not meaningful in SwingJS -- this is a session-specific temp file. It doesn't have a timestamp.
+ if (isJS())
+ {
+ // not meaningful in SwingJS -- this is a session-specific temp file. It
+ // doesn't have a timestamp.
return false;
}
Path filePath = file.toPath();
{
return failValue;
}
- if (isJS) {
- int val = /** @j2sNative 1 ? parseInt(input) : */ 0;
+ if (isJS)
+ {
+ int val = /** @j2sNative 1 ? parseInt(input) : */
+ 0;
return (val == val + 0 ? val : failValue);
}
// JavaScript does not support Regex ? lookahead
return (isJS ? jsutil.getAppletInfoAsMap() : null);
}
+ /**
+ * Get the SwingJS applet ID and combine that with the frameType
+ *
+ * @param frameType
+ * "alignment", "desktop", etc., or null
+ * @return
+ */
+ public static String getAppID(String frameType)
+ {
+ String id = Jalview.getInstance().j2sAppletID;
+ if (id == null)
+ {
+ Jalview.getInstance().j2sAppletID = id = (String) jsutil
+ .getAppletAttribute("_id");
+ }
+ return id + (frameType == null ? "" : "-" + frameType);
+ }
+
}