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 laf = System.getProperty("laf", "none");
375 boolean lafSet = false;
378 case "crossplatform":
379 lafSet = setCrossPlatformLookAndFeel();
382 System.err.println("Could not set requested laf=" + laf);
386 lafSet = setSystemLookAndFeel();
389 System.err.println("Could not set requested laf=" + laf);
393 lafSet = setGtkLookAndFeel();
395 System.err.println("Could not set requested laf=" + laf);
399 lafSet = setMetalLookAndFeel();
401 System.err.println("Could not set requested laf=" + laf);
405 lafSet = setNimbusLookAndFeel();
407 System.err.println("Could not set requested laf=" + laf);
411 lafSet = setMacLookAndFeel();
414 System.err.println("Could not set requested laf=" + laf);
420 System.err.println("Requested laf=" + laf + " not implemented");
424 setSystemLookAndFeel();
425 if (Platform.isLinux() && ! Platform.isJS()) {
426 setMetalLookAndFeel();
428 if (Platform.isAMacAndNotJS())
435 * configure 'full' SO model if preferences say to, else use the default (full SO)
436 * - as JS currently doesn't have OBO parsing, it must use 'Lite' version
438 boolean soDefault = !Platform.isJS();
439 if (Cache.getDefault("USE_FULL_SO", soDefault))
441 SequenceOntologyFactory.setInstance(new SequenceOntology());
446 desktop = new Desktop();
447 desktop.setInBatchMode(true); // indicate we are starting up
451 JalviewTaskbar.setTaskbar(this);
452 } catch (Throwable t)
454 System.out.println("Error setting Taskbar: " + t.getMessage());
457 desktop.setVisible(true);
459 if (!Platform.isJS())
466 desktop.startServiceDiscovery();
467 if (!aparser.contains("nousagestats"))
469 startUsageStats(desktop);
473 System.err.println("CMD [-nousagestats] executed successfully!");
476 if (!aparser.contains("noquestionnaire"))
478 String url = aparser.getValue("questionnaire");
481 // Start the desktop questionnaire prompter with the specified
483 Cache.log.debug("Starting questionnaire url at " + url);
484 desktop.checkForQuestionnaire(url);
485 System.out.println("CMD questionnaire[-" + url
486 + "] executed successfully!");
490 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
492 // Start the desktop questionnaire prompter with the specified
495 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
497 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
499 "Starting questionnaire with default url: " + defurl);
500 desktop.checkForQuestionnaire(defurl);
507 .println("CMD [-noquestionnaire] executed successfully!");
510 if (!aparser.contains("nonews"))
512 desktop.checkForNews();
515 BioJsHTMLOutput.updateBioJS();
519 // Move any new getdown-launcher-new.jar into place over old
520 // getdown-launcher.jar
521 String appdirString = System.getProperty("getdownappdir");
522 if (appdirString != null && appdirString.length() > 0)
524 final File appdir = new File(appdirString);
530 LaunchUtil.upgradeGetdown(
531 new File(appdir, "getdown-launcher-old.jar"),
532 new File(appdir, "getdown-launcher.jar"),
533 new File(appdir, "getdown-launcher-new.jar"));
538 String file = null, data = null;
539 FileFormatI format = null;
540 DataSourceType protocol = null;
541 FileLoader fileLoader = new FileLoader(!headless);
543 String groovyscript = null; // script to execute after all loading is
544 // completed one way or another
545 // extract groovy argument and execute if necessary
546 groovyscript = aparser.getValue("groovy", true);
547 file = aparser.getValue("open", true);
549 if (file == null && desktop == null)
551 System.out.println("No files to open!");
555 // Finally, deal with the remaining input data.
560 desktop.setProgressBar(
562 .getString("status.processing_commandline_args"),
563 progress = System.currentTimeMillis());
565 System.out.println("CMD [-open " + file + "] executed successfully!");
567 if (!Platform.isJS())
569 * ignore in JavaScript -- can't just file existence - could load it?
574 if (!file.startsWith("http://") && !file.startsWith("https://"))
575 // BH 2019 added https check for Java
577 if (!(new File(file)).exists())
579 System.out.println("Can't find " + file);
588 protocol = AppletFormatAdapter.checkProtocol(file);
592 format = new IdentifyFile().identify(file, protocol);
593 } catch (FileFormatException e1)
598 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
602 System.out.println("error");
606 setCurrentAlignFrame(af);
607 data = aparser.getValue("colour", true);
610 data.replaceAll("%20", " ");
612 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
613 af.getViewport(), af.getViewport().getAlignment(), data);
618 "CMD [-color " + data + "] executed successfully!");
623 // Must maintain ability to use the groups flag
624 data = aparser.getValue("groups", true);
627 af.parseFeaturesFile(data,
628 AppletFormatAdapter.checkProtocol(data));
629 // System.out.println("Added " + data);
631 "CMD groups[-" + data + "] executed successfully!");
633 data = aparser.getValue("features", true);
636 af.parseFeaturesFile(data,
637 AppletFormatAdapter.checkProtocol(data));
638 // System.out.println("Added " + data);
640 "CMD [-features " + data + "] executed successfully!");
643 data = aparser.getValue("annotations", true);
646 af.loadJalviewDataFile(data, null, null, null);
647 // System.out.println("Added " + data);
649 "CMD [-annotations " + data + "] executed successfully!");
651 // set or clear the sortbytree flag.
652 if (aparser.contains("sortbytree"))
654 af.getViewport().setSortByTree(true);
655 if (af.getViewport().getSortByTree())
657 System.out.println("CMD [-sortbytree] executed successfully!");
660 if (aparser.contains("no-annotation"))
662 af.getViewport().setShowAnnotation(false);
663 if (!af.getViewport().isShowAnnotation())
665 System.out.println("CMD no-annotation executed successfully!");
668 if (aparser.contains("nosortbytree"))
670 af.getViewport().setSortByTree(false);
671 if (!af.getViewport().getSortByTree())
674 .println("CMD [-nosortbytree] executed successfully!");
677 data = aparser.getValue("tree", true);
683 "CMD [-tree " + data + "] executed successfully!");
684 NewickFile nf = new NewickFile(data,
685 AppletFormatAdapter.checkProtocol(data));
687 .setCurrentTree(af.showNewickTree(nf, data).getTree());
688 } catch (IOException ex)
690 System.err.println("Couldn't add tree " + data);
691 ex.printStackTrace(System.err);
694 // TODO - load PDB structure(s) to alignment JAL-629
695 // (associate with identical sequence in alignment, or a specified
697 if (groovyscript != null)
699 // Execute the groovy script after we've done all the rendering stuff
700 // and before any images or figures are generated.
701 System.out.println("Executing script " + groovyscript);
702 executeGroovyScript(groovyscript, af);
703 System.out.println("CMD groovy[" + groovyscript
704 + "] executed successfully!");
707 String imageName = "unnamed.png";
708 while (aparser.getSize() > 1)
710 String outputFormat = aparser.nextValue();
711 file = aparser.nextValue();
713 if (outputFormat.equalsIgnoreCase("png"))
715 af.createPNG(new File(file));
716 imageName = (new File(file)).getName();
717 System.out.println("Creating PNG image: " + file);
720 else if (outputFormat.equalsIgnoreCase("svg"))
722 File imageFile = new File(file);
723 imageName = imageFile.getName();
724 af.createSVG(imageFile);
725 System.out.println("Creating SVG image: " + file);
728 else if (outputFormat.equalsIgnoreCase("html"))
730 File imageFile = new File(file);
731 imageName = imageFile.getName();
732 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
733 htmlSVG.exportHTML(file);
735 System.out.println("Creating HTML image: " + file);
738 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
742 System.err.println("The output html file must not be null");
747 BioJsHTMLOutput.refreshVersionInfo(
748 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
749 } catch (URISyntaxException e)
753 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
754 bjs.exportHTML(file);
756 .println("Creating BioJS MSA Viwer HTML file: " + file);
759 else if (outputFormat.equalsIgnoreCase("imgMap"))
761 af.createImageMap(new File(file), imageName);
762 System.out.println("Creating image map: " + file);
765 else if (outputFormat.equalsIgnoreCase("eps"))
767 File outputFile = new File(file);
769 "Creating EPS file: " + outputFile.getAbsolutePath());
770 af.createEPS(outputFile);
774 af.saveAlignment(file, format);
775 if (af.isSaveAlignmentSuccessful())
777 System.out.println("Written alignment in " + format
778 + " format to " + file);
782 System.out.println("Error writing file " + file + " in "
783 + format + " format!!");
788 while (aparser.getSize() > 0)
790 System.out.println("Unknown arg: " + aparser.nextValue());
794 AlignFrame startUpAlframe = null;
795 // We'll only open the default file if the desktop is visible.
797 // ////////////////////
799 if (!Platform.isJS() && !headless && file == null
800 && Cache.getDefault("SHOW_STARTUP_FILE", true))
807 file = Cache.getDefault("STARTUP_FILE",
808 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
809 + "/examples/exampleFile_2_7.jar");
811 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
813 // hardwire upgrade of the startup file
814 file.replace("_2_3.jar", "_2_7.jar");
815 // and remove the stale setting
816 Cache.removeProperty("STARTUP_FILE");
819 protocol = DataSourceType.FILE;
821 if (file.indexOf("http:") > -1)
823 protocol = DataSourceType.URL;
826 if (file.endsWith(".jar"))
828 format = FileFormat.Jalview;
834 format = new IdentifyFile().identify(file, protocol);
835 } catch (FileFormatException e)
841 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
843 // extract groovy arguments before anything else.
846 // Once all other stuff is done, execute any groovy scripts (in order)
847 if (groovyscript != null)
849 if (Cache.groovyJarsPresent())
851 System.out.println("Executing script " + groovyscript);
852 executeGroovyScript(groovyscript, startUpAlframe);
857 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
861 // and finally, turn off batch mode indicator - if the desktop still exists
866 desktop.setProgressBar(null, progress);
868 desktop.setInBatchMode(false);
872 private static boolean setCrossPlatformLookAndFeel()
877 UIManager.setLookAndFeel(
878 UIManager.getCrossPlatformLookAndFeelClassName());
880 } catch (Exception ex)
882 System.err.println("Unexpected Look and Feel Exception");
883 ex.printStackTrace();
888 private static boolean setSystemLookAndFeel()
893 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
895 } catch (Exception ex)
897 System.err.println("Unexpected Look and Feel Exception");
898 ex.printStackTrace();
903 private static boolean setGtkLookAndFeel()
906 String laf = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
909 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
910 if (info.getName() != null && info.getName().startsWith("Gtk")) {
911 laf = info.getClassName();
915 UIManager.setLookAndFeel(laf);
917 } catch (Exception ex)
919 System.err.println("Unexpected Look and Feel Exception");
920 ex.printStackTrace();
925 private static boolean setMetalLookAndFeel()
928 String laf = "javax.swing.plaf.metal.MetalLookAndFeel";
931 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
932 if (info.getName() != null && info.getName().equals("Metal")) {
933 laf = info.getClassName();
937 UIManager.setLookAndFeel(laf);
939 } catch (Exception ex)
941 System.err.println("Unexpected Look and Feel Exception");
942 ex.printStackTrace();
947 private static boolean setNimbusLookAndFeel()
950 String laf = "javax.swing.plaf.nimbus.NimbusLookAndFeel";
953 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
954 if (info.getName() != null && info.getName().equals("Nimbus")) {
955 laf = info.getClassName();
959 UIManager.setLookAndFeel(laf);
961 } catch (Exception ex)
963 System.err.println("Unexpected Look and Feel Exception");
964 ex.printStackTrace();
969 private static boolean setMacLookAndFeel()
972 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
974 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
976 System.setProperty("apple.laf.useScreenMenuBar", "true");
977 if (lookAndFeel != null)
981 UIManager.setLookAndFeel(lookAndFeel);
983 } catch (Throwable e)
986 "Failed to set QuaQua look and feel: " + e.toString());
989 if (lookAndFeel == null
990 || !(lookAndFeel.getClass().isAssignableFrom(
991 UIManager.getLookAndFeel().getClass()))
992 || !UIManager.getLookAndFeel().getClass().toString()
993 .toLowerCase().contains("quaqua"))
998 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
999 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
1001 } catch (Throwable e)
1004 .println("Failed to reset look and feel: " + e.toString());
1010 private static void showUsage()
1013 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1014 + "-nodisplay\tRun Jalview without User Interface.\n"
1015 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1016 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1017 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1018 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1019 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1020 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1021 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1022 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1023 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1024 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1025 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1026 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1027 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1028 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1029 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1030 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1031 + "-html FILE\tCreate HTML file from alignment.\n"
1032 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1033 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1034 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1035 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1036 + "-noquestionnaire\tTurn off questionnaire check.\n"
1037 + "-nonews\tTurn off check for Jalview news.\n"
1038 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1039 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1041 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1042 // after all other properties files have been read\n\t
1043 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1044 // passed in correctly)"
1045 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1046 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1047 + "-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"
1048 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1051 private static void startUsageStats(final Desktop desktop)
1054 * start a User Config prompt asking if we can log usage statistics.
1056 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
1057 "USAGESTATS", "Jalview Usage Statistics",
1058 "Do you want to help make Jalview better by enabling "
1059 + "the collection of usage statistics with Google Analytics ?"
1060 + "\n\n(you can enable or disable usage tracking in the preferences)",
1067 "Initialising googletracker for usage stats.");
1068 Cache.initGoogleTracker();
1069 Cache.log.debug("Tracking enabled.");
1076 Cache.log.debug("Not enabling Google Tracking.");
1079 desktop.addDialogThread(prompter);
1083 * Locate the given string as a file and pass it to the groovy interpreter.
1085 * @param groovyscript
1086 * the script to execute
1087 * @param jalviewContext
1088 * the Jalview Desktop object passed in to the groovy binding as the
1091 private void executeGroovyScript(String groovyscript, AlignFrame af)
1094 * for scripts contained in files
1101 if (groovyscript.trim().equals("STDIN"))
1103 // read from stdin into a tempfile and execute it
1106 tfile = File.createTempFile("jalview", "groovy");
1107 PrintWriter outfile = new PrintWriter(
1108 new OutputStreamWriter(new FileOutputStream(tfile)));
1109 BufferedReader br = new BufferedReader(
1110 new InputStreamReader(System.in));
1112 while ((line = br.readLine()) != null)
1114 outfile.write(line + "\n");
1120 } catch (Exception ex)
1122 System.err.println("Failed to read from STDIN into tempfile "
1123 + ((tfile == null) ? "(tempfile wasn't created)"
1124 : tfile.toString()));
1125 ex.printStackTrace();
1130 sfile = tfile.toURI().toURL();
1131 } catch (Exception x)
1134 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1136 x.printStackTrace();
1144 sfile = new URI(groovyscript).toURL();
1145 } catch (Exception x)
1147 tfile = new File(groovyscript);
1148 if (!tfile.exists())
1150 System.err.println("File '" + groovyscript + "' does not exist.");
1153 if (!tfile.canRead())
1155 System.err.println("File '" + groovyscript + "' cannot be read.");
1158 if (tfile.length() < 1)
1160 System.err.println("File '" + groovyscript + "' is empty.");
1165 sfile = tfile.getAbsoluteFile().toURI().toURL();
1166 } catch (Exception ex)
1168 System.err.println("Failed to create a file URL for "
1169 + tfile.getAbsoluteFile());
1176 Map<String, java.lang.Object> vbinding = new HashMap<>();
1177 vbinding.put("Jalview", this);
1180 vbinding.put("currentAlFrame", af);
1182 Binding gbinding = new Binding(vbinding);
1183 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1184 gse.run(sfile.toString(), gbinding);
1185 if ("STDIN".equals(groovyscript))
1187 // delete temp file that we made -
1188 // only if it was successfully executed
1191 } catch (Exception e)
1193 System.err.println("Exception Whilst trying to execute file " + sfile
1194 + " as a groovy script.");
1195 e.printStackTrace(System.err);
1200 public static boolean isHeadlessMode()
1202 String isheadless = System.getProperty("java.awt.headless");
1203 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1210 public AlignFrame[] getAlignFrames()
1212 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1213 : Desktop.getAlignFrames();
1218 * Quit method delegates to Desktop.quit - unless running in headless mode
1219 * when it just ends the JVM
1223 if (desktop != null)
1233 public static AlignFrame getCurrentAlignFrame()
1235 return Jalview.currentAlignFrame;
1238 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1240 Jalview.currentAlignFrame = currentAlignFrame;