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;
42 import java.util.logging.ConsoleHandler;
43 import java.util.logging.Level;
44 import java.util.logging.Logger;
46 import javax.swing.LookAndFeel;
47 import javax.swing.UIManager;
48 import javax.swing.UIManager.LookAndFeelInfo;
50 import com.threerings.getdown.util.LaunchUtil;
52 import groovy.lang.Binding;
53 import groovy.util.GroovyScriptEngine;
54 import jalview.ext.so.SequenceOntology;
55 import jalview.gui.AlignFrame;
56 import jalview.gui.Desktop;
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.FileLoader;
65 import jalview.io.HtmlSvgOutput;
66 import jalview.io.IdentifyFile;
67 import jalview.io.NewickFile;
68 import jalview.io.gff.SequenceOntologyFactory;
69 import jalview.schemes.ColourSchemeI;
70 import jalview.schemes.ColourSchemeProperty;
71 import jalview.util.MessageManager;
72 import jalview.util.Platform;
73 import jalview.ws.jws2.Jws2Discoverer;
76 * Main class for Jalview Application <br>
78 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
81 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
82 * jalview.bin.Jalview jalview.bin.Jalview
84 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
85 * embellish '*' to e.g. '*.jar')
94 Platform.getURLCommandArguments();
97 // singleton instance of this class
99 private static Jalview instance;
101 private Desktop desktop;
103 public static AlignFrame currentAlignFrame;
107 if (!Platform.isJS())
114 // grab all the rights we can for the JVM
115 Policy.setPolicy(new Policy()
118 public PermissionCollection getPermissions(CodeSource codesource)
120 Permissions perms = new Permissions();
121 perms.add(new AllPermission());
126 public void refresh()
134 * keep track of feature fetching tasks.
142 * TODO: generalise to track all jalview events to orchestrate batch processing
146 private int queued = 0;
148 private int running = 0;
150 public FeatureFetcher()
155 public void addFetcher(final AlignFrame af,
156 final Vector<String> dasSources)
158 final long id = System.currentTimeMillis();
160 final FeatureFetcher us = this;
161 new Thread(new Runnable()
173 af.setProgressBar(MessageManager
174 .getString("status.das_features_being_retrived"), id);
175 af.featureSettings_actionPerformed(null);
176 af.setProgressBar(null, id);
185 public synchronized boolean allFinished()
187 return queued == 0 && running == 0;
192 public static Jalview getInstance()
198 * main class for Jalview application
201 * open <em>filename</em>
203 public static void main(String[] args)
205 // setLogging(); // BH - for event debugging in JavaScript
206 instance = new Jalview();
207 instance.doMain(args);
210 private static void logClass(String name)
212 // BH - for event debugging in JavaScript
213 ConsoleHandler consoleHandler = new ConsoleHandler();
214 consoleHandler.setLevel(Level.ALL);
215 Logger logger = Logger.getLogger(name);
216 logger.setLevel(Level.ALL);
217 logger.addHandler(consoleHandler);
220 @SuppressWarnings("unused")
221 private static void setLogging()
229 System.out.println("not in js");
232 // BH - for event debugging in JavaScript (Java mode only)
233 if (!Platform.isJS())
240 Logger.getLogger("").setLevel(Level.ALL);
241 logClass("java.awt.EventDispatchThread");
242 logClass("java.awt.EventQueue");
243 logClass("java.awt.Component");
244 logClass("java.awt.focus.Component");
245 logClass("java.awt.focus.DefaultKeyboardFocusManager");
253 void doMain(String[] args)
256 if (!Platform.isJS())
258 System.setSecurityManager(null);
262 .println("Java version: " + System.getProperty("java.version"));
263 System.out.println("Java Home: " + System.getProperty("java.home"));
264 System.out.println(System.getProperty("os.arch") + " "
265 + System.getProperty("os.name") + " "
266 + System.getProperty("os.version"));
267 String val = System.getProperty("sys.install4jVersion");
270 System.out.println("Install4j version: " + val);
272 val = System.getProperty("installer_template_version");
275 System.out.println("Install4j template version: " + val);
277 val = System.getProperty("launcher_version");
280 System.out.println("Launcher version: " + val);
283 // report Jalview version
284 Cache.loadBuildProperties(true);
286 ArgsParser aparser = new ArgsParser(args);
287 boolean headless = false;
289 String usrPropsFile = aparser.getValue("props");
290 Cache.loadProperties(usrPropsFile); // must do this before
291 if (usrPropsFile != null)
294 "CMD [-props " + usrPropsFile + "] executed successfully!");
297 if (!Platform.isJS())
304 if (aparser.contains("help") || aparser.contains("h"))
309 if (aparser.contains("nodisplay") || aparser.contains("nogui")
310 || aparser.contains("headless"))
312 System.setProperty("java.awt.headless", "true");
317 final String jabawsUrl = aparser.getValue("jabaws");
318 if (jabawsUrl != null)
322 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
324 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
325 } catch (MalformedURLException e)
328 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
333 String defs = aparser.getValue("setprop");
336 int p = defs.indexOf('=');
339 System.err.println("Ignoring invalid setprop argument : " + defs);
343 System.out.println("Executing setprop argument: " + defs);
346 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
349 defs = aparser.getValue("setprop");
351 if (System.getProperty("java.awt.headless") != null
352 && System.getProperty("java.awt.headless").equals("true"))
356 System.setProperty("http.agent",
357 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
361 } catch (NoClassDefFoundError error)
363 error.printStackTrace();
364 System.out.println("\nEssential logging libraries not found."
365 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
371 // property laf = "crossplatform", "system", "gtk", "metal" or "mac"
372 // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac,
374 String lafProp = System.getProperty("laf");
375 String lafSetting = Cache.getDefault("PREFERRED_LAF", null);
377 if (lafProp != null) {
379 } else if (lafSetting != null) {
382 boolean lafSet = false;
385 case "crossplatform":
386 lafSet = setCrossPlatformLookAndFeel();
389 System.err.println("Could not set requested laf=" + laf);
393 lafSet = setSystemLookAndFeel();
396 System.err.println("Could not set requested laf=" + laf);
400 lafSet = setGtkLookAndFeel();
402 System.err.println("Could not set requested laf=" + laf);
406 lafSet = setMetalLookAndFeel();
408 System.err.println("Could not set requested laf=" + laf);
412 lafSet = setNimbusLookAndFeel();
414 System.err.println("Could not set requested laf=" + laf);
418 lafSet = setMacLookAndFeel();
421 System.err.println("Could not set requested laf=" + laf);
427 System.err.println("Requested laf=" + laf + " not implemented");
431 setSystemLookAndFeel();
432 if (Platform.isLinux() && ! Platform.isJS()) {
433 setMetalLookAndFeel();
435 if (Platform.isAMacAndNotJS())
442 * configure 'full' SO model if preferences say to, else use the default (full SO)
443 * - as JS currently doesn't have OBO parsing, it must use 'Lite' version
445 boolean soDefault = !Platform.isJS();
446 if (Cache.getDefault("USE_FULL_SO", soDefault))
448 SequenceOntologyFactory.setInstance(new SequenceOntology());
453 desktop = new Desktop();
454 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());
464 desktop.setVisible(true);
466 if (!Platform.isJS())
473 desktop.startServiceDiscovery();
474 if (!aparser.contains("nousagestats"))
476 startUsageStats(desktop);
480 System.err.println("CMD [-nousagestats] executed successfully!");
483 if (!aparser.contains("noquestionnaire"))
485 String url = aparser.getValue("questionnaire");
488 // Start the desktop questionnaire prompter with the specified
490 Cache.log.debug("Starting questionnaire url at " + url);
491 desktop.checkForQuestionnaire(url);
492 System.out.println("CMD questionnaire[-" + url
493 + "] executed successfully!");
497 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
499 // Start the desktop questionnaire prompter with the specified
502 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
504 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
506 "Starting questionnaire with default url: " + defurl);
507 desktop.checkForQuestionnaire(defurl);
514 .println("CMD [-noquestionnaire] executed successfully!");
517 if (!aparser.contains("nonews"))
519 desktop.checkForNews();
522 BioJsHTMLOutput.updateBioJS();
526 // Move any new getdown-launcher-new.jar into place over old
527 // getdown-launcher.jar
528 String appdirString = System.getProperty("getdownappdir");
529 if (appdirString != null && appdirString.length() > 0)
531 final File appdir = new File(appdirString);
537 LaunchUtil.upgradeGetdown(
538 new File(appdir, "getdown-launcher-old.jar"),
539 new File(appdir, "getdown-launcher.jar"),
540 new File(appdir, "getdown-launcher-new.jar"));
545 String file = null, data = null;
546 FileFormatI format = null;
547 DataSourceType protocol = null;
548 FileLoader fileLoader = new FileLoader(!headless);
550 String groovyscript = null; // script to execute after all loading is
551 // completed one way or another
552 // extract groovy argument and execute if necessary
553 groovyscript = aparser.getValue("groovy", true);
554 file = aparser.getValue("open", true);
556 if (file == null && desktop == null)
558 System.out.println("No files to open!");
562 // Finally, deal with the remaining input data.
567 desktop.setProgressBar(
569 .getString("status.processing_commandline_args"),
570 progress = System.currentTimeMillis());
572 System.out.println("CMD [-open " + file + "] executed successfully!");
574 if (!Platform.isJS())
576 * ignore in JavaScript -- can't just file existence - could load it?
581 if (!file.startsWith("http://") && !file.startsWith("https://"))
582 // BH 2019 added https check for Java
584 if (!(new File(file)).exists())
586 System.out.println("Can't find " + file);
595 protocol = AppletFormatAdapter.checkProtocol(file);
599 format = new IdentifyFile().identify(file, protocol);
600 } catch (FileFormatException e1)
605 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
609 System.out.println("error");
613 setCurrentAlignFrame(af);
614 data = aparser.getValue("colour", true);
617 data.replaceAll("%20", " ");
619 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
620 af.getViewport(), af.getViewport().getAlignment(), data);
625 "CMD [-color " + data + "] executed successfully!");
630 // Must maintain ability to use the groups flag
631 data = aparser.getValue("groups", true);
634 af.parseFeaturesFile(data,
635 AppletFormatAdapter.checkProtocol(data));
636 // System.out.println("Added " + data);
638 "CMD groups[-" + data + "] executed successfully!");
640 data = aparser.getValue("features", true);
643 af.parseFeaturesFile(data,
644 AppletFormatAdapter.checkProtocol(data));
645 // System.out.println("Added " + data);
647 "CMD [-features " + data + "] executed successfully!");
650 data = aparser.getValue("annotations", true);
653 af.loadJalviewDataFile(data, null, null, null);
654 // System.out.println("Added " + data);
656 "CMD [-annotations " + data + "] executed successfully!");
658 // set or clear the sortbytree flag.
659 if (aparser.contains("sortbytree"))
661 af.getViewport().setSortByTree(true);
662 if (af.getViewport().getSortByTree())
664 System.out.println("CMD [-sortbytree] executed successfully!");
667 if (aparser.contains("no-annotation"))
669 af.getViewport().setShowAnnotation(false);
670 if (!af.getViewport().isShowAnnotation())
672 System.out.println("CMD no-annotation executed successfully!");
675 if (aparser.contains("nosortbytree"))
677 af.getViewport().setSortByTree(false);
678 if (!af.getViewport().getSortByTree())
681 .println("CMD [-nosortbytree] executed successfully!");
684 data = aparser.getValue("tree", true);
690 "CMD [-tree " + data + "] executed successfully!");
691 NewickFile nf = new NewickFile(data,
692 AppletFormatAdapter.checkProtocol(data));
694 .setCurrentTree(af.showNewickTree(nf, data).getTree());
695 } catch (IOException ex)
697 System.err.println("Couldn't add tree " + data);
698 ex.printStackTrace(System.err);
701 // TODO - load PDB structure(s) to alignment JAL-629
702 // (associate with identical sequence in alignment, or a specified
704 if (groovyscript != null)
706 // Execute the groovy script after we've done all the rendering stuff
707 // and before any images or figures are generated.
708 System.out.println("Executing script " + groovyscript);
709 executeGroovyScript(groovyscript, af);
710 System.out.println("CMD groovy[" + groovyscript
711 + "] executed successfully!");
714 String imageName = "unnamed.png";
715 while (aparser.getSize() > 1)
717 String outputFormat = aparser.nextValue();
718 file = aparser.nextValue();
720 if (outputFormat.equalsIgnoreCase("png"))
722 af.createPNG(new File(file));
723 imageName = (new File(file)).getName();
724 System.out.println("Creating PNG image: " + file);
727 else if (outputFormat.equalsIgnoreCase("svg"))
729 File imageFile = new File(file);
730 imageName = imageFile.getName();
731 af.createSVG(imageFile);
732 System.out.println("Creating SVG image: " + file);
735 else if (outputFormat.equalsIgnoreCase("html"))
737 File imageFile = new File(file);
738 imageName = imageFile.getName();
739 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
740 htmlSVG.exportHTML(file);
742 System.out.println("Creating HTML image: " + file);
745 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
749 System.err.println("The output html file must not be null");
754 BioJsHTMLOutput.refreshVersionInfo(
755 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
756 } catch (URISyntaxException e)
760 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
761 bjs.exportHTML(file);
763 .println("Creating BioJS MSA Viwer HTML file: " + file);
766 else if (outputFormat.equalsIgnoreCase("imgMap"))
768 af.createImageMap(new File(file), imageName);
769 System.out.println("Creating image map: " + file);
772 else if (outputFormat.equalsIgnoreCase("eps"))
774 File outputFile = new File(file);
776 "Creating EPS file: " + outputFile.getAbsolutePath());
777 af.createEPS(outputFile);
781 af.saveAlignment(file, format);
782 if (af.isSaveAlignmentSuccessful())
784 System.out.println("Written alignment in " + format
785 + " format to " + file);
789 System.out.println("Error writing file " + file + " in "
790 + format + " format!!");
795 while (aparser.getSize() > 0)
797 System.out.println("Unknown arg: " + aparser.nextValue());
801 AlignFrame startUpAlframe = null;
802 // We'll only open the default file if the desktop is visible.
804 // ////////////////////
806 if (!Platform.isJS() && !headless && file == null
807 && Cache.getDefault("SHOW_STARTUP_FILE", true))
814 file = Cache.getDefault("STARTUP_FILE",
815 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
816 + "/examples/exampleFile_2_7.jar");
818 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
820 // hardwire upgrade of the startup file
821 file.replace("_2_3.jar", "_2_7.jar");
822 // and remove the stale setting
823 Cache.removeProperty("STARTUP_FILE");
826 protocol = DataSourceType.FILE;
828 if (file.indexOf("http:") > -1)
830 protocol = DataSourceType.URL;
833 if (file.endsWith(".jar"))
835 format = FileFormat.Jalview;
841 format = new IdentifyFile().identify(file, protocol);
842 } catch (FileFormatException e)
848 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
850 // extract groovy arguments before anything else.
853 // Once all other stuff is done, execute any groovy scripts (in order)
854 if (groovyscript != null)
856 if (Cache.groovyJarsPresent())
858 System.out.println("Executing script " + groovyscript);
859 executeGroovyScript(groovyscript, startUpAlframe);
864 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
868 // and finally, turn off batch mode indicator - if the desktop still exists
873 desktop.setProgressBar(null, progress);
875 desktop.setInBatchMode(false);
879 private static boolean setCrossPlatformLookAndFeel()
884 UIManager.setLookAndFeel(
885 UIManager.getCrossPlatformLookAndFeelClassName());
887 } catch (Exception ex)
889 System.err.println("Unexpected Look and Feel Exception");
890 ex.printStackTrace();
895 private static boolean setSystemLookAndFeel()
900 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
902 } catch (Exception ex)
904 System.err.println("Unexpected Look and Feel Exception");
905 ex.printStackTrace();
910 private static boolean setGtkLookAndFeel()
913 String laf = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
916 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
917 if (info.getName() != null && info.getName().startsWith("Gtk")) {
918 laf = info.getClassName();
922 UIManager.setLookAndFeel(laf);
924 } catch (Exception ex)
926 System.err.println("Unexpected Look and Feel Exception");
927 ex.printStackTrace();
932 private static boolean setMetalLookAndFeel()
935 String laf = "javax.swing.plaf.metal.MetalLookAndFeel";
938 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
939 if (info.getName() != null && info.getName().equals("Metal")) {
940 laf = info.getClassName();
944 UIManager.setLookAndFeel(laf);
946 } catch (Exception ex)
948 System.err.println("Unexpected Look and Feel Exception");
949 ex.printStackTrace();
954 private static boolean setNimbusLookAndFeel()
957 String laf = "javax.swing.plaf.nimbus.NimbusLookAndFeel";
960 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
961 if (info.getName() != null && info.getName().equals("Nimbus")) {
962 laf = info.getClassName();
966 UIManager.setLookAndFeel(laf);
968 } catch (Exception ex)
970 System.err.println("Unexpected Look and Feel Exception");
971 ex.printStackTrace();
976 private static boolean setMacLookAndFeel()
979 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
981 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
983 System.setProperty("apple.laf.useScreenMenuBar", "true");
984 if (lookAndFeel != null)
988 UIManager.setLookAndFeel(lookAndFeel);
990 } catch (Throwable e)
993 "Failed to set QuaQua look and feel: " + e.toString());
996 if (lookAndFeel == null
997 || !(lookAndFeel.getClass().isAssignableFrom(
998 UIManager.getLookAndFeel().getClass()))
999 || !UIManager.getLookAndFeel().getClass().toString()
1000 .toLowerCase().contains("quaqua"))
1005 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
1006 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
1008 } catch (Throwable e)
1011 .println("Failed to reset look and feel: " + e.toString());
1017 private static void showUsage()
1020 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1021 + "-nodisplay\tRun Jalview without User Interface.\n"
1022 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1023 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1024 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1025 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1026 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1027 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1028 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1029 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1030 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1031 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1032 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1033 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1034 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1035 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1036 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1037 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1038 + "-html FILE\tCreate HTML file from alignment.\n"
1039 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1040 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1041 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1042 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1043 + "-noquestionnaire\tTurn off questionnaire check.\n"
1044 + "-nonews\tTurn off check for Jalview news.\n"
1045 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1046 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1048 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1049 // after all other properties files have been read\n\t
1050 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1051 // passed in correctly)"
1052 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1053 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1054 + "-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"
1055 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1058 private static void startUsageStats(final Desktop desktop)
1061 * start a User Config prompt asking if we can log usage statistics.
1063 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
1064 "USAGESTATS", "Jalview Usage Statistics",
1065 "Do you want to help make Jalview better by enabling "
1066 + "the collection of usage statistics with Google Analytics ?"
1067 + "\n\n(you can enable or disable usage tracking in the preferences)",
1074 "Initialising googletracker for usage stats.");
1075 Cache.initGoogleTracker();
1076 Cache.log.debug("Tracking enabled.");
1083 Cache.log.debug("Not enabling Google Tracking.");
1086 desktop.addDialogThread(prompter);
1090 * Locate the given string as a file and pass it to the groovy interpreter.
1092 * @param groovyscript
1093 * the script to execute
1094 * @param jalviewContext
1095 * the Jalview Desktop object passed in to the groovy binding as the
1098 private void executeGroovyScript(String groovyscript, AlignFrame af)
1101 * for scripts contained in files
1108 if (groovyscript.trim().equals("STDIN"))
1110 // read from stdin into a tempfile and execute it
1113 tfile = File.createTempFile("jalview", "groovy");
1114 PrintWriter outfile = new PrintWriter(
1115 new OutputStreamWriter(new FileOutputStream(tfile)));
1116 BufferedReader br = new BufferedReader(
1117 new InputStreamReader(System.in));
1119 while ((line = br.readLine()) != null)
1121 outfile.write(line + "\n");
1127 } catch (Exception ex)
1129 System.err.println("Failed to read from STDIN into tempfile "
1130 + ((tfile == null) ? "(tempfile wasn't created)"
1131 : tfile.toString()));
1132 ex.printStackTrace();
1137 sfile = tfile.toURI().toURL();
1138 } catch (Exception x)
1141 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1143 x.printStackTrace();
1151 sfile = new URI(groovyscript).toURL();
1152 } catch (Exception x)
1154 tfile = new File(groovyscript);
1155 if (!tfile.exists())
1157 System.err.println("File '" + groovyscript + "' does not exist.");
1160 if (!tfile.canRead())
1162 System.err.println("File '" + groovyscript + "' cannot be read.");
1165 if (tfile.length() < 1)
1167 System.err.println("File '" + groovyscript + "' is empty.");
1172 sfile = tfile.getAbsoluteFile().toURI().toURL();
1173 } catch (Exception ex)
1175 System.err.println("Failed to create a file URL for "
1176 + tfile.getAbsoluteFile());
1183 Map<String, java.lang.Object> vbinding = new HashMap<>();
1184 vbinding.put("Jalview", this);
1187 vbinding.put("currentAlFrame", af);
1189 Binding gbinding = new Binding(vbinding);
1190 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1191 gse.run(sfile.toString(), gbinding);
1192 if ("STDIN".equals(groovyscript))
1194 // delete temp file that we made -
1195 // only if it was successfully executed
1198 } catch (Exception e)
1200 System.err.println("Exception Whilst trying to execute file " + sfile
1201 + " as a groovy script.");
1202 e.printStackTrace(System.err);
1207 public static boolean isHeadlessMode()
1209 String isheadless = System.getProperty("java.awt.headless");
1210 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1217 public AlignFrame[] getAlignFrames()
1219 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1220 : Desktop.getAlignFrames();
1225 * Quit method delegates to Desktop.quit - unless running in headless mode
1226 * when it just ends the JVM
1230 if (desktop != null)
1240 public static AlignFrame getCurrentAlignFrame()
1242 return Jalview.currentAlignFrame;
1245 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1247 Jalview.currentAlignFrame = currentAlignFrame;