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.UIManager;
47 import javax.swing.UIManager.LookAndFeelInfo;
49 import com.threerings.getdown.util.LaunchUtil;
51 import groovy.lang.Binding;
52 import groovy.util.GroovyScriptEngine;
53 import jalview.ext.so.SequenceOntology;
54 import jalview.gui.AlignFrame;
55 import jalview.gui.Desktop;
56 import jalview.gui.PromptUserConfig;
57 import jalview.io.AppletFormatAdapter;
58 import jalview.io.BioJsHTMLOutput;
59 import jalview.io.DataSourceType;
60 import jalview.io.FileFormat;
61 import jalview.io.FileFormatException;
62 import jalview.io.FileFormatI;
63 import jalview.io.FileFormats;
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.HttpUtils;
72 import jalview.util.MessageManager;
73 import jalview.util.Platform;
74 import jalview.ws.jws2.Jws2Discoverer;
77 * Main class for Jalview Application <br>
79 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
82 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
83 * jalview.bin.Jalview jalview.bin.Jalview
85 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
86 * embellish '*' to e.g. '*.jar')
95 Platform.getURLCommandArguments();
99 * singleton instance of this class
101 private static Jalview instance;
103 private Desktop desktop;
105 public static AlignFrame currentAlignFrame;
109 if (!Platform.isJS())
116 // grab all the rights we can for the JVM
117 Policy.setPolicy(new Policy()
120 public PermissionCollection getPermissions(CodeSource codesource)
122 Permissions perms = new Permissions();
123 perms.add(new AllPermission());
128 public void refresh()
136 * keep track of feature fetching tasks.
144 * TODO: generalise to track all jalview events to orchestrate batch processing
148 private int queued = 0;
150 private int running = 0;
152 public FeatureFetcher()
157 public void addFetcher(final AlignFrame af,
158 final Vector<String> dasSources)
160 final long id = System.currentTimeMillis();
162 final FeatureFetcher us = this;
163 new Thread(new Runnable()
175 af.setProgressBar(MessageManager
176 .getString("status.das_features_being_retrived"), id);
177 af.featureSettings_actionPerformed(null);
178 af.setProgressBar(null, id);
187 public synchronized boolean allFinished()
189 return queued == 0 && running == 0;
194 public static Jalview getInstance()
200 * main class for Jalview application
203 * open <em>filename</em>
205 public static void main(String[] args)
207 // setLogging(); // BH - for event debugging in JavaScript
208 instance = new Jalview();
209 instance.doMain(args);
212 private static void logClass(String name)
214 // BH - for event debugging in JavaScript
215 ConsoleHandler consoleHandler = new ConsoleHandler();
216 consoleHandler.setLevel(Level.ALL);
217 Logger logger = Logger.getLogger(name);
218 logger.setLevel(Level.ALL);
219 logger.addHandler(consoleHandler);
222 @SuppressWarnings("unused")
223 private static void setLogging()
231 System.out.println("not in js");
234 // BH - for event debugging in JavaScript (Java mode only)
235 if (!Platform.isJS())
242 Logger.getLogger("").setLevel(Level.ALL);
243 logClass("java.awt.EventDispatchThread");
244 logClass("java.awt.EventQueue");
245 logClass("java.awt.Component");
246 logClass("java.awt.focus.Component");
247 logClass("java.awt.focus.DefaultKeyboardFocusManager");
255 void doMain(String[] args)
258 if (!Platform.isJS())
260 System.setSecurityManager(null);
264 .println("Java version: " + System.getProperty("java.version"));
265 System.out.println("Java Home: " + System.getProperty("java.home"));
266 System.out.println(System.getProperty("os.arch") + " "
267 + System.getProperty("os.name") + " "
268 + System.getProperty("os.version"));
269 String val = System.getProperty("sys.install4jVersion");
272 System.out.println("Install4j version: " + val);
274 val = System.getProperty("installer_template_version");
277 System.out.println("Install4j template version: " + val);
279 val = System.getProperty("launcher_version");
282 System.out.println("Launcher version: " + val);
285 // report Jalview version
286 Cache.loadBuildProperties(true);
288 ArgsParser aparser = new ArgsParser(args);
289 boolean headless = false;
291 String usrPropsFile = aparser.getValue("props");
292 Cache.loadProperties(usrPropsFile); // must do this before
293 if (usrPropsFile != null)
296 "CMD [-props " + usrPropsFile + "] executed successfully!");
299 if (!Platform.isJS())
306 if (aparser.contains("help") || aparser.contains("h"))
311 if (aparser.contains("nodisplay") || aparser.contains("nogui")
312 || aparser.contains("headless"))
314 System.setProperty("java.awt.headless", "true");
319 final String jabawsUrl = aparser.getValue("jabaws");
320 if (jabawsUrl != null)
324 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
326 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
327 } catch (MalformedURLException e)
330 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
335 String defs = aparser.getValue("setprop");
338 int p = defs.indexOf('=');
341 System.err.println("Ignoring invalid setprop argument : " + defs);
345 System.out.println("Executing setprop argument: " + defs);
348 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
350 // DISABLED FOR SECURITY REASONS
351 // TODO: add a property to allow properties to be overriden by cli args
352 // Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
354 defs = aparser.getValue("setprop");
356 if (System.getProperty("java.awt.headless") != null
357 && System.getProperty("java.awt.headless").equals("true"))
361 System.setProperty("http.agent",
362 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
366 } catch (NoClassDefFoundError error)
368 error.printStackTrace();
369 System.out.println("\nEssential logging libraries not found."
370 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
379 * configure 'full' SO model if preferences say to, else use the default (full SO)
380 * - as JS currently doesn't have OBO parsing, it must use 'Lite' version
382 boolean soDefault = !Platform.isJS();
383 if (Cache.getDefault("USE_FULL_SO", soDefault))
385 SequenceOntologyFactory.setInstance(new SequenceOntology());
390 Desktop.nosplash = aparser.contains("nosplash");
391 desktop = new Desktop();
392 desktop.setInBatchMode(true); // indicate we are starting up
396 JalviewTaskbar.setTaskbar(this);
397 } catch (Exception e)
399 Cache.log.info("Cannot set Taskbar");
400 Cache.log.error(e.getMessage());
401 // e.printStackTrace();
402 } catch (Throwable t)
404 Cache.log.info("Cannot set Taskbar");
405 Cache.log.error(t.getMessage());
406 // t.printStackTrace();
409 // set Proxy settings before all the internet calls
410 Cache.setProxyPropertiesFromPreferences();
412 desktop.setVisible(true);
414 if (!Platform.isJS())
421 if (!aparser.contains("nowebservicediscovery"))
423 desktop.startServiceDiscovery();
425 if (!aparser.contains("nousagestats"))
427 startUsageStats(desktop);
431 System.err.println("CMD [-nousagestats] executed successfully!");
434 if (!aparser.contains("noquestionnaire"))
436 String url = aparser.getValue("questionnaire");
439 // Start the desktop questionnaire prompter with the specified
441 Cache.log.debug("Starting questionnaire url at " + url);
442 desktop.checkForQuestionnaire(url);
443 System.out.println("CMD questionnaire[-" + url
444 + "] executed successfully!");
448 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
450 // Start the desktop questionnaire prompter with the specified
453 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
455 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
457 "Starting questionnaire with default url: " + defurl);
458 desktop.checkForQuestionnaire(defurl);
465 .println("CMD [-noquestionnaire] executed successfully!");
468 if (!aparser.contains("nonews"))
470 desktop.checkForNews();
473 BioJsHTMLOutput.updateBioJS();
477 // Move any new getdown-launcher-new.jar into place over old
478 // getdown-launcher.jar
479 String appdirString = System.getProperty("getdownappdir");
480 if (appdirString != null && appdirString.length() > 0)
482 final File appdir = new File(appdirString);
488 LaunchUtil.upgradeGetdown(
489 new File(appdir, "getdown-launcher-old.jar"),
490 new File(appdir, "getdown-launcher.jar"),
491 new File(appdir, "getdown-launcher-new.jar"));
496 String file = null, data = null;
497 FileFormatI format = null;
498 DataSourceType protocol = null;
499 FileLoader fileLoader = new FileLoader(!headless);
501 String groovyscript = null; // script to execute after all loading is
502 // completed one way or another
503 // extract groovy argument and execute if necessary
504 groovyscript = aparser.getValue("groovy", true);
505 file = aparser.getValue("open", true);
507 if (file == null && desktop == null)
509 System.out.println("No files to open!");
513 // Finally, deal with the remaining input data.
518 desktop.setProgressBar(
520 .getString("status.processing_commandline_args"),
521 progress = System.currentTimeMillis());
523 System.out.println("CMD [-open " + file + "] executed successfully!");
525 if (!Platform.isJS())
527 * ignore in JavaScript -- can't just file existence - could load it?
532 if (!HttpUtils.startsWithHttpOrHttps(file))
534 if (!(new File(file)).exists())
536 System.out.println("Can't find " + file);
545 protocol = AppletFormatAdapter.checkProtocol(file);
549 format = new IdentifyFile().identify(file, protocol);
550 } catch (FileFormatException e1)
555 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
559 System.out.println("error");
563 setCurrentAlignFrame(af);
564 data = aparser.getValue("colour", true);
567 data.replaceAll("%20", " ");
569 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
570 af.getViewport(), af.getViewport().getAlignment(), data);
575 "CMD [-color " + data + "] executed successfully!");
580 // Must maintain ability to use the groups flag
581 data = aparser.getValue("groups", true);
584 af.parseFeaturesFile(data,
585 AppletFormatAdapter.checkProtocol(data));
586 // System.out.println("Added " + data);
588 "CMD groups[-" + data + "] executed successfully!");
590 data = aparser.getValue("features", true);
593 af.parseFeaturesFile(data,
594 AppletFormatAdapter.checkProtocol(data));
595 // System.out.println("Added " + data);
597 "CMD [-features " + data + "] executed successfully!");
600 data = aparser.getValue("annotations", true);
603 af.loadJalviewDataFile(data, null, null, null);
604 // System.out.println("Added " + data);
606 "CMD [-annotations " + data + "] executed successfully!");
608 // set or clear the sortbytree flag.
609 if (aparser.contains("sortbytree"))
611 af.getViewport().setSortByTree(true);
612 if (af.getViewport().getSortByTree())
614 System.out.println("CMD [-sortbytree] executed successfully!");
617 if (aparser.contains("no-annotation"))
619 af.getViewport().setShowAnnotation(false);
620 if (!af.getViewport().isShowAnnotation())
622 System.out.println("CMD no-annotation executed successfully!");
625 if (aparser.contains("nosortbytree"))
627 af.getViewport().setSortByTree(false);
628 if (!af.getViewport().getSortByTree())
631 .println("CMD [-nosortbytree] executed successfully!");
634 data = aparser.getValue("tree", true);
640 "CMD [-tree " + data + "] executed successfully!");
641 NewickFile nf = new NewickFile(data,
642 AppletFormatAdapter.checkProtocol(data));
644 .setCurrentTree(af.showNewickTree(nf, data).getTree());
645 } catch (IOException ex)
647 System.err.println("Couldn't add tree " + data);
648 ex.printStackTrace(System.err);
651 // TODO - load PDB structure(s) to alignment JAL-629
652 // (associate with identical sequence in alignment, or a specified
654 if (groovyscript != null)
656 // Execute the groovy script after we've done all the rendering stuff
657 // and before any images or figures are generated.
658 System.out.println("Executing script " + groovyscript);
659 executeGroovyScript(groovyscript, af);
660 System.out.println("CMD groovy[" + groovyscript
661 + "] executed successfully!");
664 String imageName = "unnamed.png";
665 while (aparser.getSize() > 1)
667 String outputFormat = aparser.nextValue();
668 file = aparser.nextValue();
670 if (outputFormat.equalsIgnoreCase("png"))
672 af.createPNG(new File(file));
673 imageName = (new File(file)).getName();
674 System.out.println("Creating PNG image: " + file);
677 else if (outputFormat.equalsIgnoreCase("svg"))
679 File imageFile = new File(file);
680 imageName = imageFile.getName();
681 af.createSVG(imageFile);
682 System.out.println("Creating SVG image: " + file);
685 else if (outputFormat.equalsIgnoreCase("html"))
687 File imageFile = new File(file);
688 imageName = imageFile.getName();
689 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
690 htmlSVG.exportHTML(file);
692 System.out.println("Creating HTML image: " + file);
695 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
699 System.err.println("The output html file must not be null");
704 BioJsHTMLOutput.refreshVersionInfo(
705 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
706 } catch (URISyntaxException e)
710 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
711 bjs.exportHTML(file);
713 .println("Creating BioJS MSA Viwer HTML file: " + file);
716 else if (outputFormat.equalsIgnoreCase("imgMap"))
718 af.createImageMap(new File(file), imageName);
719 System.out.println("Creating image map: " + file);
722 else if (outputFormat.equalsIgnoreCase("eps"))
724 File outputFile = new File(file);
726 "Creating EPS file: " + outputFile.getAbsolutePath());
727 af.createEPS(outputFile);
730 FileFormatI outFormat = null;
733 outFormat = FileFormats.getInstance().forName(outputFormat);
734 } catch (Exception formatP)
736 System.out.println("Couldn't parse " + outFormat
737 + " as a valid Jalview format string.");
739 if (outFormat != null)
741 if (!outFormat.isWritable())
744 "This version of Jalview does not support alignment export as "
749 af.saveAlignment(file, outFormat);
750 if (af.isSaveAlignmentSuccessful())
752 System.out.println("Written alignment in "
753 + outFormat.getName() + " format to " + file);
757 System.out.println("Error writing file " + file + " in "
758 + outFormat.getName() + " format!!");
765 while (aparser.getSize() > 0)
767 System.out.println("Unknown arg: " + aparser.nextValue());
771 AlignFrame startUpAlframe = null;
772 // We'll only open the default file if the desktop is visible.
774 // ////////////////////
776 if (!Platform.isJS() && !headless && file == null
777 && Cache.getDefault("SHOW_STARTUP_FILE", true))
784 file = Cache.getDefault("STARTUP_FILE",
785 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
786 + "/examples/exampleFile_2_7.jar");
788 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
790 // hardwire upgrade of the startup file
791 file.replace("_2_3.jar", "_2_7.jar");
792 // and remove the stale setting
793 Cache.removeProperty("STARTUP_FILE");
796 protocol = AppletFormatAdapter.checkProtocol(file);
798 if (file.endsWith(".jar"))
800 format = FileFormat.Jalview;
806 format = new IdentifyFile().identify(file, protocol);
807 } catch (FileFormatException e)
813 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
815 // extract groovy arguments before anything else.
818 // Once all other stuff is done, execute any groovy scripts (in order)
819 if (groovyscript != null)
821 if (Cache.groovyJarsPresent())
823 System.out.println("Executing script " + groovyscript);
824 executeGroovyScript(groovyscript, startUpAlframe);
829 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
833 // and finally, turn off batch mode indicator - if the desktop still exists
838 desktop.setProgressBar(null, progress);
840 desktop.setInBatchMode(false);
844 private static void setLookAndFeel()
846 // property laf = "crossplatform", "system", "gtk", "metal", "nimbus" or
848 // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac,
850 String lafProp = System.getProperty("laf");
851 String lafSetting = Cache.getDefault("PREFERRED_LAF", null);
857 else if (lafSetting != null)
861 boolean lafSet = false;
864 case "crossplatform":
865 lafSet = setCrossPlatformLookAndFeel();
868 Cache.log.error("Could not set requested laf=" + laf);
872 lafSet = setSystemLookAndFeel();
875 Cache.log.error("Could not set requested laf=" + laf);
879 lafSet = setGtkLookAndFeel();
882 Cache.log.error("Could not set requested laf=" + laf);
886 lafSet = setMetalLookAndFeel();
889 Cache.log.error("Could not set requested laf=" + laf);
893 lafSet = setNimbusLookAndFeel();
896 Cache.log.error("Could not set requested laf=" + laf);
900 lafSet = setQuaquaLookAndFeel();
903 Cache.log.error("Could not set requested laf=" + laf);
907 lafSet = setVaquaLookAndFeel();
910 Cache.log.error("Could not set requested laf=" + laf);
914 lafSet = setMacLookAndFeel();
917 Cache.log.error("Could not set requested laf=" + laf);
923 Cache.log.error("Requested laf=" + laf + " not implemented");
927 setSystemLookAndFeel();
928 if (Platform.isLinux())
930 setMetalLookAndFeel();
932 if (Platform.isMac())
939 private static boolean setCrossPlatformLookAndFeel()
944 UIManager.setLookAndFeel(
945 UIManager.getCrossPlatformLookAndFeelClassName());
947 } catch (Exception ex)
949 Cache.log.error("Unexpected Look and Feel Exception");
950 Cache.log.error(ex.getMessage());
951 Cache.log.debug(Cache.getStackTraceString(ex));
956 private static boolean setSystemLookAndFeel()
961 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
963 } catch (Exception ex)
965 Cache.log.error("Unexpected Look and Feel Exception");
966 Cache.log.error(ex.getMessage());
967 Cache.log.debug(Cache.getStackTraceString(ex));
972 private static boolean setSpecificLookAndFeel(String name,
973 String className, boolean nameStartsWith)
978 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
980 if (info.getName() != null && nameStartsWith
981 ? info.getName().toLowerCase()
982 .startsWith(name.toLowerCase())
983 : info.getName().toLowerCase().equals(name.toLowerCase()))
985 className = info.getClassName();
989 UIManager.setLookAndFeel(className);
991 } catch (Exception ex)
993 Cache.log.error("Unexpected Look and Feel Exception");
994 Cache.log.error(ex.getMessage());
995 Cache.log.debug(Cache.getStackTraceString(ex));
1000 private static boolean setGtkLookAndFeel()
1002 return setSpecificLookAndFeel("gtk",
1003 "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", true);
1006 private static boolean setMetalLookAndFeel()
1008 return setSpecificLookAndFeel("metal",
1009 "javax.swing.plaf.metal.MetalLookAndFeel", false);
1012 private static boolean setNimbusLookAndFeel()
1014 return setSpecificLookAndFeel("nimbus",
1015 "javax.swing.plaf.nimbus.NimbusLookAndFeel", false);
1018 private static boolean setQuaquaLookAndFeel()
1020 return setSpecificLookAndFeel("quaqua",
1021 ch.randelshofer.quaqua.QuaquaManager.getLookAndFeel().getClass()
1026 private static boolean setVaquaLookAndFeel()
1028 return setSpecificLookAndFeel("vaqua",
1029 "org.violetlib.aqua.AquaLookAndFeel", false);
1032 private static boolean setMacLookAndFeel()
1034 boolean set = false;
1035 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
1037 System.setProperty("apple.laf.useScreenMenuBar", "true");
1038 set = setQuaquaLookAndFeel();
1039 if ((!set) || !UIManager.getLookAndFeel().getClass().toString()
1040 .toLowerCase().contains("quaqua"))
1042 set = setVaquaLookAndFeel();
1047 private static void showUsage()
1050 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1051 + "-nodisplay\tRun Jalview without User Interface.\n"
1052 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1053 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1054 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1055 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1056 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1057 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1058 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1059 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1060 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1061 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1062 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1063 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1064 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1065 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1066 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1067 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1068 + "-html FILE\tCreate HTML file from alignment.\n"
1069 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1070 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1071 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1072 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1073 + "-noquestionnaire\tTurn off questionnaire check.\n"
1074 + "-nonews\tTurn off check for Jalview news.\n"
1075 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1076 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1078 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1079 // after all other properties files have been read\n\t
1080 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1081 // passed in correctly)"
1082 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1083 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1084 + "-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"
1085 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1088 private static void startUsageStats(final Desktop desktop)
1091 * start a User Config prompt asking if we can log usage statistics.
1093 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
1094 "USAGESTATS", "Jalview Usage Statistics",
1095 "Do you want to help make Jalview better by enabling "
1096 + "the collection of usage statistics with Google Analytics ?"
1097 + "\n\n(you can enable or disable usage tracking in the preferences)",
1104 "Initialising googletracker for usage stats.");
1105 Cache.initGoogleTracker();
1106 Cache.log.debug("Tracking enabled.");
1113 Cache.log.debug("Not enabling Google Tracking.");
1116 desktop.addDialogThread(prompter);
1120 * Locate the given string as a file and pass it to the groovy interpreter.
1122 * @param groovyscript
1123 * the script to execute
1124 * @param jalviewContext
1125 * the Jalview Desktop object passed in to the groovy binding as the
1128 private void executeGroovyScript(String groovyscript, AlignFrame af)
1131 * for scripts contained in files
1138 if (groovyscript.trim().equals("STDIN"))
1140 // read from stdin into a tempfile and execute it
1143 tfile = File.createTempFile("jalview", "groovy");
1144 PrintWriter outfile = new PrintWriter(
1145 new OutputStreamWriter(new FileOutputStream(tfile)));
1146 BufferedReader br = new BufferedReader(
1147 new InputStreamReader(System.in));
1149 while ((line = br.readLine()) != null)
1151 outfile.write(line + "\n");
1157 } catch (Exception ex)
1159 System.err.println("Failed to read from STDIN into tempfile "
1160 + ((tfile == null) ? "(tempfile wasn't created)"
1161 : tfile.toString()));
1162 ex.printStackTrace();
1167 sfile = tfile.toURI().toURL();
1168 } catch (Exception x)
1171 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1173 x.printStackTrace();
1181 sfile = new URI(groovyscript).toURL();
1182 } catch (Exception x)
1184 tfile = new File(groovyscript);
1185 if (!tfile.exists())
1187 System.err.println("File '" + groovyscript + "' does not exist.");
1190 if (!tfile.canRead())
1192 System.err.println("File '" + groovyscript + "' cannot be read.");
1195 if (tfile.length() < 1)
1197 System.err.println("File '" + groovyscript + "' is empty.");
1202 sfile = tfile.getAbsoluteFile().toURI().toURL();
1203 } catch (Exception ex)
1205 System.err.println("Failed to create a file URL for "
1206 + tfile.getAbsoluteFile());
1213 Map<String, java.lang.Object> vbinding = new HashMap<>();
1214 vbinding.put("Jalview", this);
1217 vbinding.put("currentAlFrame", af);
1219 Binding gbinding = new Binding(vbinding);
1220 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1221 gse.run(sfile.toString(), gbinding);
1222 if ("STDIN".equals(groovyscript))
1224 // delete temp file that we made -
1225 // only if it was successfully executed
1228 } catch (Exception e)
1230 System.err.println("Exception Whilst trying to execute file " + sfile
1231 + " as a groovy script.");
1232 e.printStackTrace(System.err);
1237 public static boolean isHeadlessMode()
1239 String isheadless = System.getProperty("java.awt.headless");
1240 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1247 public AlignFrame[] getAlignFrames()
1249 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1250 : Desktop.getAlignFrames();
1255 * Quit method delegates to Desktop.quit - unless running in headless mode
1256 * when it just ends the JVM
1260 if (desktop != null)
1270 public static AlignFrame getCurrentAlignFrame()
1272 return Jalview.currentAlignFrame;
1275 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1277 Jalview.currentAlignFrame = currentAlignFrame;