2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import java.io.BufferedReader;
25 import java.io.FileOutputStream;
26 import java.io.IOException;
27 import java.io.InputStreamReader;
28 import java.io.OutputStreamWriter;
29 import java.io.PrintWriter;
30 import java.net.MalformedURLException;
32 import java.net.URISyntaxException;
34 import java.security.AllPermission;
35 import java.security.CodeSource;
36 import java.security.PermissionCollection;
37 import java.security.Permissions;
38 import java.security.Policy;
39 import java.util.HashMap;
41 import java.util.Vector;
43 import javax.swing.LookAndFeel;
44 import javax.swing.UIManager;
46 import com.threerings.getdown.util.LaunchUtil;
48 import groovy.lang.Binding;
49 import groovy.util.GroovyScriptEngine;
50 import jalview.api.AlignCalcWorkerI;
51 import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
52 import jalview.ext.so.SequenceOntology;
53 import jalview.gui.AlignFrame;
54 import jalview.gui.AlignViewport;
55 import jalview.gui.Desktop;
56 import jalview.gui.Preferences;
57 import jalview.gui.PromptUserConfig;
58 import jalview.io.AppletFormatAdapter;
59 import jalview.io.BioJsHTMLOutput;
60 import jalview.io.DataSourceType;
61 import jalview.io.FileFormat;
62 import jalview.io.FileFormatException;
63 import jalview.io.FileFormatI;
64 import jalview.io.FileFormats;
65 import jalview.io.FileLoader;
66 import jalview.io.HtmlSvgOutput;
67 import jalview.io.IdentifyFile;
68 import jalview.io.NewickFile;
69 import jalview.io.gff.SequenceOntologyFactory;
70 import jalview.schemes.ColourSchemeI;
71 import jalview.schemes.ColourSchemeProperty;
72 import jalview.util.MessageManager;
73 import jalview.util.Platform;
74 import jalview.ws.jws2.Jws2Discoverer;
75 //import netscape.javascript.JSObject;
78 * Main class for Jalview Application <br>
80 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
83 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
84 * jalview.bin.Jalview jalview.bin.Jalview
86 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
87 * embellish '*' to e.g. '*.jar')
92 public class Jalview implements ApplicationSingletonI
95 // for testing those nasty messages you cannot ever find.
98 // System.setOut(new PrintStream(new ByteArrayOutputStream())
101 // public void println(Object o)
105 // System.err.println(o);
111 public static Jalview getInstance()
113 return (Jalview) ApplicationSingletonProvider
114 .getInstance(Jalview.class);
121 private boolean headless;
123 private Desktop desktop;
125 public AlignFrame currentAlignFrame;
127 public String appletResourcePath;
129 public String j2sAppletID;
131 private boolean noCalculation, noMenuBar, noStatus;
133 private boolean noAnnotation;
135 public boolean getStartCalculations()
137 return !noCalculation;
140 public boolean getAllowMenuBar()
145 public boolean getShowStatus()
150 public boolean getShowAnnotation()
152 return !noAnnotation;
157 if (Platform.isJS()) {
158 Platform.getURLCommandArguments();
159 } else /** @j2sIgnore */
161 // grab all the rights we can for the JVM
162 Policy.setPolicy(new Policy()
165 public PermissionCollection getPermissions(CodeSource codesource)
167 Permissions perms = new Permissions();
168 perms.add(new AllPermission());
173 public void refresh()
181 * keep track of feature fetching tasks.
189 * TODO: generalise to track all jalview events to orchestrate batch processing
193 private int queued = 0;
195 private int running = 0;
197 public FeatureFetcher()
202 public void addFetcher(final AlignFrame af,
203 final Vector<String> dasSources)
205 final long id = System.currentTimeMillis();
207 final FeatureFetcher us = this;
208 new Thread(new Runnable()
220 af.setProgressBar(MessageManager
221 .getString("status.das_features_being_retrived"), id);
222 af.featureSettings_actionPerformed(null);
223 af.setProgressBar(null, id);
232 public synchronized boolean allFinished()
234 return queued == 0 && running == 0;
239 private final static boolean doPlatformLogging = false;
242 * main class for Jalview application
245 * open <em>filename</em>
247 public static void main(String[] args)
249 if (doPlatformLogging)
251 Platform.startJavaLogging();
253 getInstance().doMain(args);
259 void doMain(String[] args)
262 boolean isJS = Platform.isJS();
265 System.setSecurityManager(null);
269 .println("Java version: " + System.getProperty("java.version"));
270 System.out.println("Java Home: " + System.getProperty("java.home"));
271 System.out.println(System.getProperty("os.arch") + " "
272 + System.getProperty("os.name") + " "
273 + System.getProperty("os.version"));
274 String val = System.getProperty("sys.install4jVersion");
277 System.out.println("Install4j version: " + val);
279 val = System.getProperty("installer_template_version");
282 System.out.println("Install4j template version: " + val);
284 val = System.getProperty("launcher_version");
287 System.out.println("Launcher version: " + val);
290 // report Jalview version
291 Cache.getInstance().loadBuildProperties(true);
293 ArgsParser aparser = new ArgsParser(args);
296 String usrPropsFile = aparser.getValue("props");
298 Cache.loadProperties(usrPropsFile); // must do this before
302 j2sAppletID = Platform.getAppID(null);
303 Preferences.setAppletDefaults();
304 Cache.loadProperties(usrPropsFile); // again, because we
305 // might be changing defaults here?
306 appletResourcePath = (String) aparser.getAppletValue("resourcepath",
317 if (usrPropsFile != null)
320 "CMD [-props " + usrPropsFile + "] executed successfully!");
322 if (aparser.contains("help") || aparser.contains("h"))
328 if (aparser.contains("nodisplay") || aparser.contains("nogui")
329 || aparser.contains("headless"))
331 System.setProperty("java.awt.headless", "true");
338 final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
339 if (jabawsUrl != null)
343 Jws2Discoverer.getInstance().setPreferredUrl(jabawsUrl);
345 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
346 } catch (MalformedURLException e)
349 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
354 String defs = aparser.getValue(ArgsParser.SETPROP);
357 int p = defs.indexOf('=');
360 System.err.println("Ignoring invalid setprop argument : " + defs);
364 System.out.println("Executing setprop argument: " + defs);
367 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
370 defs = aparser.getValue("setprop");
372 if (System.getProperty("java.awt.headless") != null
373 && System.getProperty("java.awt.headless").equals("true"))
377 System.setProperty("http.agent",
378 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
382 } catch (NoClassDefFoundError error)
384 error.printStackTrace();
385 System.out.println("\nEssential logging libraries not found."
386 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
395 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
396 } catch (Exception ex)
398 System.err.println("Unexpected Look and Feel Exception");
399 ex.printStackTrace();
401 if (Platform.isMac())
404 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
407 "com.apple.mrj.application.apple.menu.about.name",
409 System.setProperty("apple.laf.useScreenMenuBar", "true");
410 if (lookAndFeel != null)
414 UIManager.setLookAndFeel(lookAndFeel);
415 } catch (Throwable e)
418 "Failed to set QuaQua look and feel: " + e.toString());
421 if (lookAndFeel == null
422 || !(lookAndFeel.getClass().isAssignableFrom(
423 UIManager.getLookAndFeel().getClass()))
424 || !UIManager.getLookAndFeel().getClass().toString()
425 .toLowerCase().contains("quaqua"))
430 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
431 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
432 } catch (Throwable e)
435 "Failed to reset look and feel: " + e.toString());
441 * configure 'full' SO model if preferences say to, else use the default (full SO)
442 * - as JS currently doesn't have OBO parsing, it must use 'Lite' version
444 boolean soDefault = !isJS;
445 if (Cache.getDefault("USE_FULL_SO", soDefault))
447 SequenceOntologyFactory.setSequenceOntology(new SequenceOntology());
454 desktop = Desktop.getInstance();
455 desktop.setInBatchMode(true); // indicate we are starting up
458 JalviewTaskbar.setTaskbar(this);
459 } catch (Throwable t)
461 System.out.println("Error setting Taskbar: " + t.getMessage());
463 desktop.setVisible(true);
472 desktop.startServiceDiscovery();
473 if (!aparser.contains("nousagestats"))
475 startUsageStats(desktop);
479 System.err.println("CMD [-nousagestats] executed successfully!");
482 if (!aparser.contains("noquestionnaire"))
484 String url = aparser.getValue("questionnaire");
487 // Start the desktop questionnaire prompter with the specified
489 Cache.log.debug("Starting questionnaire url at " + url);
490 desktop.checkForQuestionnaire(url);
491 System.out.println("CMD questionnaire[-" + url
492 + "] executed successfully!");
496 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
498 // Start the desktop questionnaire prompter with the specified
501 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
503 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
505 "Starting questionnaire with default url: " + defurl);
506 desktop.checkForQuestionnaire(defurl);
513 .println("CMD [-noquestionnaire] executed successfully!");
516 if (!aparser.contains("nonews"))
518 desktop.checkForNews();
521 BioJsHTMLOutput.updateBioJS();
524 parseArguments(aparser, true);
528 * Parse all command-line String[] arguments as well as all JavaScript-derived parameters from Info.
530 * We allow for this method to be run from JavaScript. Basically allowing simple scripting.
535 public void parseArguments(ArgsParser aparser, boolean isStartup)
538 String groovyscript = null; // script to execute after all loading is
539 boolean isJS = Platform.isJS();
543 // Move any new getdown-launcher-new.jar into place over old
544 // getdown-launcher.jar
545 String appdirString = System.getProperty("getdownappdir");
546 if (appdirString != null && appdirString.length() > 0)
548 final File appdir = new File(appdirString);
554 LaunchUtil.upgradeGetdown(
555 new File(appdir, "getdown-launcher-old.jar"),
556 new File(appdir, "getdown-launcher.jar"),
557 new File(appdir, "getdown-launcher-new.jar"));
562 // completed one way or another
563 // extract groovy argument and execute if necessary
564 groovyscript = aparser.getValue("groovy", true);
568 String file = aparser.getValue("open", true);
570 if (!isJS && file == null && desktop == null)
572 System.out.println("No files to open!");
576 // time to open a file.
579 DataSourceType protocol = null;
580 FileLoader fileLoader = new FileLoader(!headless);
581 FileFormatI format = null;
582 // Finally, deal with the remaining input data.
583 AlignFrame af = null;
589 desktop.setProgressBar(
591 .getString("status.processing_commandline_args"),
592 progress = System.currentTimeMillis());
594 System.out.println("CMD [-open " + file + "] executed successfully!");
596 if (!Platform.isJS())
598 * ignore in JavaScript -- can't just file existence - could load it?
603 if (!file.startsWith("http://") && !file.startsWith("https://"))
604 // BH 2019 added https check for Java
606 if (!(new File(file)).exists())
608 System.out.println("Can't find " + file);
616 String fileFormat = (isJS
617 ? (String) aparser.getAppletValue("format", null, true)
619 protocol = AppletFormatAdapter.checkProtocol(file);
622 format = (fileFormat != null
623 ? FileFormats.getInstance().forName(fileFormat)
627 format = new IdentifyFile().identify(file, protocol);
629 } catch (FileFormatException e1)
634 if (aparser.contains(ArgsParser.NOMENUBAR))
637 System.out.println("CMD [nomenu] executed successfully!");
640 if (aparser.contains(ArgsParser.NOSTATUS))
643 System.out.println("CMD [nostatus] executed successfully!");
646 if (aparser.contains(ArgsParser.NOANNOTATION)
647 || aparser.contains(ArgsParser.NOANNOTATION2))
650 System.out.println("CMD no-annotation executed successfully!");
652 if (aparser.contains(ArgsParser.NOCALCULATION))
654 noCalculation = true;
655 System.out.println("CMD [nocalculation] executed successfully!");
658 af = new FileLoader(!headless).LoadFileWaitTillLoaded(file, protocol,
662 System.out.println("error");
667 // JalviewLite interface for JavaScript allows second file open
668 String file2 = aparser.getValue(ArgsParser.OPEN2, true);
671 protocol = AppletFormatAdapter.checkProtocol(file2);
674 format = new IdentifyFile().identify(file2, protocol);
675 } catch (FileFormatException e1)
679 AlignFrame af2 = new FileLoader(!headless)
680 .LoadFileWaitTillLoaded(file2, protocol, format);
683 System.out.println("error");
687 AlignViewport.openLinkedAlignmentAs(af,
688 af.getViewport().getAlignment(),
689 af2.getViewport().getAlignment(), "",
690 AlignViewport.SPLIT_FRAME);
692 "CMD [-open2 " + file2 + "] executed successfully!");
695 setCurrentAlignFrame(af);
697 String data = aparser.getValue(ArgsParser.COLOUR, true);
700 data.replaceAll("%20", " ");
702 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
703 af.getViewport(), af.getViewport().getAlignment(), data);
708 "CMD [-color " + data + "] executed successfully!");
713 // Must maintain ability to use the groups flag
714 data = aparser.getValue(ArgsParser.GROUPS, true);
717 af.parseFeaturesFile(data,
718 AppletFormatAdapter.checkProtocol(data));
719 // System.out.println("Added " + data);
721 "CMD groups[-" + data + "] executed successfully!");
723 data = aparser.getValue(ArgsParser.FEATURES, true);
726 af.parseFeaturesFile(data,
727 AppletFormatAdapter.checkProtocol(data));
728 // System.out.println("Added " + data);
730 "CMD [-features " + data + "] executed successfully!");
732 data = aparser.getValue(ArgsParser.ANNOTATIONS, true);
735 af.loadJalviewDataFile(data, null, null, null);
736 // System.out.println("Added " + data);
738 "CMD [-annotations " + data + "] executed successfully!");
741 // JavaScript feature
743 if (aparser.contains(ArgsParser.SHOWOVERVIEW))
745 af.overviewMenuItem_actionPerformed(null);
746 System.out.println("CMD [showoverview] executed successfully!");
749 // set or clear the sortbytree flag.
750 if (aparser.contains(ArgsParser.SORTBYTREE))
752 af.getViewport().setSortByTree(true);
753 if (af.getViewport().getSortByTree())
755 System.out.println("CMD [-sortbytree] executed successfully!");
759 boolean doUpdateAnnotation = false;
761 * we do this earlier in JalviewJS because of a complication with
764 * For now, just fixing this in JalviewJS.
771 if (aparser.contains(ArgsParser.NOANNOTATION)
772 || aparser.contains(ArgsParser.NOANNOTATION2))
774 af.getViewport().setShowAnnotation(false);
775 if (!af.getViewport().isShowAnnotation())
777 doUpdateAnnotation = true;
779 .println("CMD no-annotation executed successfully!");
784 if (aparser.contains(ArgsParser.NOSORTBYTREE))
786 af.getViewport().setSortByTree(false);
787 if (!af.getViewport().getSortByTree())
789 doUpdateAnnotation = true;
791 .println("CMD [-nosortbytree] executed successfully!");
794 if (doUpdateAnnotation)
796 af.setMenusForViewport();
797 af.alignPanel.updateLayout();
800 data = aparser.getValue(ArgsParser.TREE, true);
805 NewickFile nf = new NewickFile(data,
806 AppletFormatAdapter.checkProtocol(data));
808 .setCurrentTree(af.showNewickTree(nf, data).getTree());
810 "CMD [-tree " + data + "] executed successfully!");
811 } catch (IOException ex)
813 System.err.println("Couldn't add tree " + data);
814 ex.printStackTrace(System.err);
817 // TODO - load PDB structure(s) to alignment JAL-629
818 // (associate with identical sequence in alignment, or a specified
823 new JalviewJSApp(this, aparser, af);
832 if (groovyscript != null)
834 // Execute the groovy script after we've done all the rendering
836 // and before any images or figures are generated.
837 System.out.println("Executing script " + groovyscript);
838 executeGroovyScript(groovyscript, af);
839 System.out.println("CMD groovy[" + groovyscript
840 + "] executed successfully!");
843 createOutputFiles(aparser, af, format);
849 if (!isJS && !headless && Cache.getDefault("SHOW_STARTUP_FILE", true))
857 // We'll only open the default file if the desktop is visible.
859 // ////////////////////
861 file = Cache.getDefault("STARTUP_FILE",
862 Cache.getDefault("www.jalview.org",
863 "http://www.jalview.org")
864 + "/examples/exampleFile_2_7.jar");
866 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
868 // hardwire upgrade of the startup file
869 file.replace("_2_3.jar", "_2_7.jar");
870 // and remove the stale setting
871 Cache.removeProperty("STARTUP_FILE");
874 protocol = DataSourceType.FILE;
876 if (file.indexOf("http:") > -1)
878 protocol = DataSourceType.URL;
881 if (file.endsWith(".jar"))
883 format = FileFormat.Jalview;
889 format = new IdentifyFile().identify(file, protocol);
890 } catch (FileFormatException e)
896 af = fileLoader.LoadFileWaitTillLoaded(file, protocol, format);
900 // extract groovy arguments before anything else.
901 // Once all other stuff is done, execute any groovy scripts (in order)
902 if (!isJS && groovyscript != null)
904 if (Cache.groovyJarsPresent())
906 System.out.println("Executing script " + groovyscript);
907 executeGroovyScript(groovyscript, af);
912 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
917 // and finally, turn off batch mode indicator - if the desktop still exists
922 desktop.setProgressBar(null, progress);
924 desktop.setInBatchMode(false);
931 * Writes an output file for each format (if any) specified in the
932 * command-line arguments. Supported formats are currently
941 * A format parameter should be followed by a parameter specifying the output
942 * file name. {@code imgMap} parameters should follow those for the
943 * corresponding alignment image output.
949 private void createOutputFiles(ArgsParser aparser, AlignFrame af,
952 while (aparser.getSize() >= 2)
954 String outputFormat = aparser.nextValue();
957 switch (outputFormat.toLowerCase())
960 imageFile = new File(aparser.nextValue());
961 af.createPNG(imageFile);
963 "Creating PNG image: " + imageFile.getAbsolutePath());
966 imageFile = new File(aparser.nextValue());
967 af.createSVG(imageFile);
969 "Creating SVG image: " + imageFile.getAbsolutePath());
972 imageFile = new File(aparser.nextValue());
974 "Creating EPS file: " + imageFile.getAbsolutePath());
975 af.createEPS(imageFile);
978 fname = new File(aparser.nextValue()).getAbsolutePath();
981 BioJsHTMLOutput.refreshVersionInfo(
982 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
983 } catch (URISyntaxException e)
987 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
988 bjs.exportHTML(fname);
989 System.out.println("Creating BioJS MSA Viwer HTML file: " + fname);
992 fname = new File(aparser.nextValue()).getAbsolutePath();
993 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
994 htmlSVG.exportHTML(fname);
995 System.out.println("Creating HTML image: " + fname);
998 imageFile = new File(aparser.nextValue());
999 af.alignPanel.makePNGImageMap(imageFile, "unnamed.png");
1001 "Creating image map: " + imageFile.getAbsolutePath());
1004 if (!Platform.isJS()) /** @j2sIgnore */
1006 // skipping outputFormat?
1007 System.out.println("Unknown arg: " + outputFormat);
1008 fname = new File(aparser.nextValue()).getAbsolutePath();
1009 af.saveAlignment(fname, format);
1010 if (af.isSaveAlignmentSuccessful())
1013 "Written alignment in " + format + " format to " + fname);
1017 System.out.println("Error writing file " + fname + " in " + format
1023 while (aparser.getSize() > 0)
1025 System.out.println("Unknown arg: " + aparser.nextValue());
1029 private static void showUsage()
1032 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1033 + "-nodisplay\tRun Jalview without User Interface.\n"
1034 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1035 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1036 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1037 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1038 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1039 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1040 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1041 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1042 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1043 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1044 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1045 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1046 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1047 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1048 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1049 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1050 + "-html FILE\tCreate HTML file from alignment.\n"
1051 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1052 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1053 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1054 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1055 + "-noquestionnaire\tTurn off questionnaire check.\n"
1056 + "-nonews\tTurn off check for Jalview news.\n"
1057 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1058 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1060 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1061 // after all other properties files have been read\n\t
1062 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1063 // passed in correctly)"
1064 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1065 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1066 + "-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"
1067 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1070 private static void startUsageStats(final Desktop desktop)
1073 * start a User Config prompt asking if we can log usage statistics.
1075 PromptUserConfig prompter = new PromptUserConfig(Desktop.getDesktopPane(),
1076 "USAGESTATS", "Jalview Usage Statistics",
1077 "Do you want to help make Jalview better by enabling "
1078 + "the collection of usage statistics with Google Analytics ?"
1079 + "\n\n(you can enable or disable usage tracking in the preferences)",
1086 "Initialising googletracker for usage stats.");
1087 Cache.initGoogleTracker();
1088 Cache.log.debug("Tracking enabled.");
1095 Cache.log.debug("Not enabling Google Tracking.");
1098 desktop.addDialogThread(prompter);
1102 * Locate the given string as a file and pass it to the groovy interpreter.
1104 * @param groovyscript
1105 * the script to execute
1106 * @param jalviewContext
1107 * the Jalview Desktop object passed in to the groovy binding as the
1110 private void executeGroovyScript(String groovyscript, AlignFrame af)
1113 * for scripts contained in files
1120 if (groovyscript.trim().equals("STDIN"))
1122 // read from stdin into a tempfile and execute it
1125 tfile = File.createTempFile("jalview", "groovy");
1126 PrintWriter outfile = new PrintWriter(
1127 new OutputStreamWriter(new FileOutputStream(tfile)));
1128 BufferedReader br = new BufferedReader(
1129 new InputStreamReader(System.in));
1131 while ((line = br.readLine()) != null)
1133 outfile.write(line + "\n");
1139 } catch (Exception ex)
1141 System.err.println("Failed to read from STDIN into tempfile "
1142 + ((tfile == null) ? "(tempfile wasn't created)"
1143 : tfile.toString()));
1144 ex.printStackTrace();
1149 sfile = tfile.toURI().toURL();
1150 } catch (Exception x)
1153 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1155 x.printStackTrace();
1163 sfile = new URI(groovyscript).toURL();
1164 } catch (Exception x)
1166 tfile = new File(groovyscript);
1167 if (!tfile.exists())
1169 System.err.println("File '" + groovyscript + "' does not exist.");
1172 if (!tfile.canRead())
1174 System.err.println("File '" + groovyscript + "' cannot be read.");
1177 if (tfile.length() < 1)
1179 System.err.println("File '" + groovyscript + "' is empty.");
1184 sfile = tfile.getAbsoluteFile().toURI().toURL();
1185 } catch (Exception ex)
1187 System.err.println("Failed to create a file URL for "
1188 + tfile.getAbsoluteFile());
1195 Map<String, java.lang.Object> vbinding = new HashMap<>();
1196 vbinding.put("Jalview", this);
1199 vbinding.put("currentAlFrame", af);
1201 Binding gbinding = new Binding(vbinding);
1202 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1203 gse.run(sfile.toString(), gbinding);
1204 if ("STDIN".equals(groovyscript))
1206 // delete temp file that we made -
1207 // only if it was successfully executed
1210 } catch (Exception e)
1212 System.err.println("Exception Whilst trying to execute file " + sfile
1213 + " as a groovy script.");
1214 e.printStackTrace(System.err);
1219 public static boolean isHeadlessMode()
1221 String isheadless = System.getProperty("java.awt.headless");
1222 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1229 public AlignFrame[] getAlignFrames()
1231 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1232 : Desktop.getAlignFrames();
1237 * Quit method delegates to Desktop.quit - unless running in headless mode
1238 * when it just ends the JVM
1242 if (desktop != null)
1252 public static AlignFrame getCurrentAlignFrame()
1254 return Jalview.getInstance().currentAlignFrame;
1257 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1259 Jalview.getInstance().currentAlignFrame = currentAlignFrame;
1263 public void notifyWorker(AlignCalcWorkerI worker, String status)
1265 // System.out.println("Jalview worker " + worker.getClass().getSimpleName()