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.FileLoader;
64 import jalview.io.HtmlSvgOutput;
65 import jalview.io.IdentifyFile;
66 import jalview.io.NewickFile;
67 import jalview.io.gff.SequenceOntologyFactory;
68 import jalview.schemes.ColourSchemeI;
69 import jalview.schemes.ColourSchemeProperty;
70 import jalview.util.MessageManager;
71 import jalview.util.Platform;
72 import jalview.ws.jws2.Jws2Discoverer;
75 * Main class for Jalview Application <br>
77 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
80 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
81 * jalview.bin.Jalview jalview.bin.Jalview
83 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
84 * embellish '*' to e.g. '*.jar')
93 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 if (aparser.contains("help") || aparser.contains("h"))
294 if (aparser.contains("nodisplay") || aparser.contains("nogui")
295 || aparser.contains("headless"))
297 System.setProperty("java.awt.headless", "true");
300 String usrPropsFile = aparser.getValue("props");
301 Cache.loadProperties(usrPropsFile); // must do this before
302 if (usrPropsFile != null)
305 "CMD [-props " + usrPropsFile + "] executed successfully!");
308 if (!Platform.isJS())
315 if (aparser.contains("help") || aparser.contains("h"))
320 if (aparser.contains("nodisplay") || aparser.contains("nogui")
321 || aparser.contains("headless"))
323 System.setProperty("java.awt.headless", "true");
328 final String jabawsUrl = aparser.getValue("jabaws");
329 if (jabawsUrl != null)
333 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
335 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
336 } catch (MalformedURLException e)
339 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
344 String defs = aparser.getValue("setprop");
347 int p = defs.indexOf('=');
350 System.err.println("Ignoring invalid setprop argument : " + defs);
354 System.out.println("Executing setprop argument: " + defs);
357 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
359 // DISABLED FOR SECURITY REASONS
360 // TODO: add a property to allow properties to be overriden by cli args
361 // Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
363 defs = aparser.getValue("setprop");
365 if (System.getProperty("java.awt.headless") != null
366 && System.getProperty("java.awt.headless").equals("true"))
370 System.setProperty("http.agent",
371 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
375 } catch (NoClassDefFoundError error)
377 error.printStackTrace();
378 System.out.println("\nEssential logging libraries not found."
379 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
388 * configure 'full' SO model if preferences say to, else use the default (full SO)
389 * - as JS currently doesn't have OBO parsing, it must use 'Lite' version
391 boolean soDefault = !Platform.isJS();
392 if (Cache.getDefault("USE_FULL_SO", soDefault))
394 SequenceOntologyFactory.setInstance(new SequenceOntology());
399 desktop = new Desktop();
400 desktop.setInBatchMode(true); // indicate we are starting up
404 JalviewTaskbar.setTaskbar(this);
405 } catch (Exception e)
407 Cache.log.info("Cannot set Taskbar");
408 Cache.log.error(e.getMessage());
409 // e.printStackTrace();
410 } catch (Throwable t)
412 Cache.log.info("Cannot set Taskbar");
413 Cache.log.error(t.getMessage());
414 // t.printStackTrace();
417 desktop.setVisible(true);
419 if (!Platform.isJS())
426 desktop.startServiceDiscovery();
427 if (!aparser.contains("nousagestats"))
429 startUsageStats(desktop);
433 System.err.println("CMD [-nousagestats] executed successfully!");
436 if (!aparser.contains("noquestionnaire"))
438 String url = aparser.getValue("questionnaire");
441 // Start the desktop questionnaire prompter with the specified
443 Cache.log.debug("Starting questionnaire url at " + url);
444 desktop.checkForQuestionnaire(url);
445 System.out.println("CMD questionnaire[-" + url
446 + "] executed successfully!");
450 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
452 // Start the desktop questionnaire prompter with the specified
455 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
457 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
459 "Starting questionnaire with default url: " + defurl);
460 desktop.checkForQuestionnaire(defurl);
467 .println("CMD [-noquestionnaire] executed successfully!");
470 if (!aparser.contains("nonews"))
472 desktop.checkForNews();
475 BioJsHTMLOutput.updateBioJS();
479 // Move any new getdown-launcher-new.jar into place over old
480 // getdown-launcher.jar
481 String appdirString = System.getProperty("getdownappdir");
482 if (appdirString != null && appdirString.length() > 0)
484 final File appdir = new File(appdirString);
490 LaunchUtil.upgradeGetdown(
491 new File(appdir, "getdown-launcher-old.jar"),
492 new File(appdir, "getdown-launcher.jar"),
493 new File(appdir, "getdown-launcher-new.jar"));
498 String file = null, data = null;
499 FileFormatI format = null;
500 DataSourceType protocol = null;
501 FileLoader fileLoader = new FileLoader(!headless);
503 String groovyscript = null; // script to execute after all loading is
504 // completed one way or another
505 // extract groovy argument and execute if necessary
506 groovyscript = aparser.getValue("groovy", true);
507 file = aparser.getValue("open", true);
509 if (file == null && desktop == null)
511 System.out.println("No files to open!");
515 // Finally, deal with the remaining input data.
520 desktop.setProgressBar(
522 .getString("status.processing_commandline_args"),
523 progress = System.currentTimeMillis());
525 System.out.println("CMD [-open " + file + "] executed successfully!");
527 if (!Platform.isJS())
529 * ignore in JavaScript -- can't just file existence - could load it?
534 if (!file.startsWith("http://") && !file.startsWith("https://"))
535 // BH 2019 added https check for Java
537 if (!(new File(file)).exists())
539 System.out.println("Can't find " + file);
548 protocol = AppletFormatAdapter.checkProtocol(file);
552 format = new IdentifyFile().identify(file, protocol);
553 } catch (FileFormatException e1)
558 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
562 System.out.println("error");
566 setCurrentAlignFrame(af);
567 data = aparser.getValue("colour", true);
570 data.replaceAll("%20", " ");
572 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
573 af.getViewport(), af.getViewport().getAlignment(), data);
578 "CMD [-color " + data + "] executed successfully!");
583 // Must maintain ability to use the groups flag
584 data = aparser.getValue("groups", true);
587 af.parseFeaturesFile(data,
588 AppletFormatAdapter.checkProtocol(data));
589 // System.out.println("Added " + data);
591 "CMD groups[-" + data + "] executed successfully!");
593 data = aparser.getValue("features", true);
596 af.parseFeaturesFile(data,
597 AppletFormatAdapter.checkProtocol(data));
598 // System.out.println("Added " + data);
600 "CMD [-features " + data + "] executed successfully!");
603 data = aparser.getValue("annotations", true);
606 af.loadJalviewDataFile(data, null, null, null);
607 // System.out.println("Added " + data);
609 "CMD [-annotations " + data + "] executed successfully!");
611 // set or clear the sortbytree flag.
612 if (aparser.contains("sortbytree"))
614 af.getViewport().setSortByTree(true);
615 if (af.getViewport().getSortByTree())
617 System.out.println("CMD [-sortbytree] executed successfully!");
620 if (aparser.contains("no-annotation"))
622 af.getViewport().setShowAnnotation(false);
623 if (!af.getViewport().isShowAnnotation())
625 System.out.println("CMD no-annotation executed successfully!");
628 if (aparser.contains("nosortbytree"))
630 af.getViewport().setSortByTree(false);
631 if (!af.getViewport().getSortByTree())
634 .println("CMD [-nosortbytree] executed successfully!");
637 data = aparser.getValue("tree", true);
643 "CMD [-tree " + data + "] executed successfully!");
644 NewickFile nf = new NewickFile(data,
645 AppletFormatAdapter.checkProtocol(data));
647 .setCurrentTree(af.showNewickTree(nf, data).getTree());
648 } catch (IOException ex)
650 System.err.println("Couldn't add tree " + data);
651 ex.printStackTrace(System.err);
654 // TODO - load PDB structure(s) to alignment JAL-629
655 // (associate with identical sequence in alignment, or a specified
657 if (groovyscript != null)
659 // Execute the groovy script after we've done all the rendering stuff
660 // and before any images or figures are generated.
661 System.out.println("Executing script " + groovyscript);
662 executeGroovyScript(groovyscript, af);
663 System.out.println("CMD groovy[" + groovyscript
664 + "] executed successfully!");
667 String imageName = "unnamed.png";
668 while (aparser.getSize() > 1)
670 String outputFormat = aparser.nextValue();
671 file = aparser.nextValue();
673 if (outputFormat.equalsIgnoreCase("png"))
675 af.createPNG(new File(file));
676 imageName = (new File(file)).getName();
677 System.out.println("Creating PNG image: " + file);
680 else if (outputFormat.equalsIgnoreCase("svg"))
682 File imageFile = new File(file);
683 imageName = imageFile.getName();
684 af.createSVG(imageFile);
685 System.out.println("Creating SVG image: " + file);
688 else if (outputFormat.equalsIgnoreCase("html"))
690 File imageFile = new File(file);
691 imageName = imageFile.getName();
692 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
693 htmlSVG.exportHTML(file);
695 System.out.println("Creating HTML image: " + file);
698 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
702 System.err.println("The output html file must not be null");
707 BioJsHTMLOutput.refreshVersionInfo(
708 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
709 } catch (URISyntaxException e)
713 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
714 bjs.exportHTML(file);
716 .println("Creating BioJS MSA Viwer HTML file: " + file);
719 else if (outputFormat.equalsIgnoreCase("imgMap"))
721 af.createImageMap(new File(file), imageName);
722 System.out.println("Creating image map: " + file);
725 else if (outputFormat.equalsIgnoreCase("eps"))
727 File outputFile = new File(file);
729 "Creating EPS file: " + outputFile.getAbsolutePath());
730 af.createEPS(outputFile);
734 af.saveAlignment(file, format);
735 if (af.isSaveAlignmentSuccessful())
737 System.out.println("Written alignment in " + format
738 + " format to " + file);
742 System.out.println("Error writing file " + file + " in "
743 + format + " format!!");
748 while (aparser.getSize() > 0)
750 System.out.println("Unknown arg: " + aparser.nextValue());
754 AlignFrame startUpAlframe = null;
755 // We'll only open the default file if the desktop is visible.
757 // ////////////////////
759 if (!Platform.isJS() && !headless && file == null
760 && Cache.getDefault("SHOW_STARTUP_FILE", true))
767 file = Cache.getDefault("STARTUP_FILE",
768 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
769 + "/examples/exampleFile_2_7.jar");
771 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
773 // hardwire upgrade of the startup file
774 file.replace("_2_3.jar", "_2_7.jar");
775 // and remove the stale setting
776 Cache.removeProperty("STARTUP_FILE");
779 protocol = DataSourceType.FILE;
781 if (file.indexOf("http:") > -1)
783 protocol = DataSourceType.URL;
786 if (file.endsWith(".jar"))
788 format = FileFormat.Jalview;
794 format = new IdentifyFile().identify(file, protocol);
795 } catch (FileFormatException e)
801 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
803 // extract groovy arguments before anything else.
806 // Once all other stuff is done, execute any groovy scripts (in order)
807 if (groovyscript != null)
809 if (Cache.groovyJarsPresent())
811 System.out.println("Executing script " + groovyscript);
812 executeGroovyScript(groovyscript, startUpAlframe);
817 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
821 // and finally, turn off batch mode indicator - if the desktop still exists
826 desktop.setProgressBar(null, progress);
828 desktop.setInBatchMode(false);
832 private static void setLookAndFeel()
834 // property laf = "crossplatform", "system", "gtk", "metal", "nimbus" or
836 // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac,
838 String lafProp = System.getProperty("laf");
839 String lafSetting = Cache.getDefault("PREFERRED_LAF", null);
845 else if (lafSetting != null)
849 boolean lafSet = false;
852 case "crossplatform":
853 lafSet = setCrossPlatformLookAndFeel();
856 Cache.log.error("Could not set requested laf=" + laf);
860 lafSet = setSystemLookAndFeel();
863 Cache.log.error("Could not set requested laf=" + laf);
867 lafSet = setGtkLookAndFeel();
870 Cache.log.error("Could not set requested laf=" + laf);
874 lafSet = setMetalLookAndFeel();
877 Cache.log.error("Could not set requested laf=" + laf);
881 lafSet = setNimbusLookAndFeel();
884 Cache.log.error("Could not set requested laf=" + laf);
888 lafSet = setQuaquaLookAndFeel();
891 Cache.log.error("Could not set requested laf=" + laf);
895 lafSet = setVaquaLookAndFeel();
898 Cache.log.error("Could not set requested laf=" + laf);
902 lafSet = setMacLookAndFeel();
905 Cache.log.error("Could not set requested laf=" + laf);
911 Cache.log.error("Requested laf=" + laf + " not implemented");
915 setSystemLookAndFeel();
916 if (Platform.isLinux())
918 setMetalLookAndFeel();
920 if (Platform.isMac())
927 private static boolean setCrossPlatformLookAndFeel()
932 UIManager.setLookAndFeel(
933 UIManager.getCrossPlatformLookAndFeelClassName());
935 } catch (Exception ex)
937 Cache.log.error("Unexpected Look and Feel Exception");
938 Cache.log.error(ex.getMessage());
939 Cache.log.debug(Cache.getStackTraceString(ex));
944 private static boolean setSystemLookAndFeel()
949 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
951 } catch (Exception ex)
953 Cache.log.error("Unexpected Look and Feel Exception");
954 Cache.log.error(ex.getMessage());
955 Cache.log.debug(Cache.getStackTraceString(ex));
960 private static boolean setSpecificLookAndFeel(String name,
961 String className, boolean nameStartsWith)
966 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
968 if (info.getName() != null && nameStartsWith
969 ? info.getName().toLowerCase()
970 .startsWith(name.toLowerCase())
971 : info.getName().toLowerCase().equals(name.toLowerCase()))
973 className = info.getClassName();
977 UIManager.setLookAndFeel(className);
979 } catch (Exception ex)
981 Cache.log.error("Unexpected Look and Feel Exception");
982 Cache.log.error(ex.getMessage());
983 Cache.log.debug(Cache.getStackTraceString(ex));
988 private static boolean setGtkLookAndFeel()
990 return setSpecificLookAndFeel("gtk",
991 "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", true);
994 private static boolean setMetalLookAndFeel()
996 return setSpecificLookAndFeel("metal",
997 "javax.swing.plaf.metal.MetalLookAndFeel", false);
1000 private static boolean setNimbusLookAndFeel()
1002 return setSpecificLookAndFeel("nimbus",
1003 "javax.swing.plaf.nimbus.NimbusLookAndFeel", false);
1006 private static boolean setQuaquaLookAndFeel()
1008 return setSpecificLookAndFeel("quaqua",
1009 ch.randelshofer.quaqua.QuaquaManager.getLookAndFeel().getClass()
1014 private static boolean setVaquaLookAndFeel()
1016 return setSpecificLookAndFeel("vaqua",
1017 "org.violetlib.aqua.AquaLookAndFeel", false);
1020 private static boolean setMacLookAndFeel()
1022 boolean set = false;
1023 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
1025 System.setProperty("apple.laf.useScreenMenuBar", "true");
1026 set = setQuaquaLookAndFeel();
1027 if ((!set) || !UIManager.getLookAndFeel().getClass().toString()
1028 .toLowerCase().contains("quaqua"))
1030 set = setVaquaLookAndFeel();
1035 private static void showUsage()
1038 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1039 + "-nodisplay\tRun Jalview without User Interface.\n"
1040 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1041 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1042 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1043 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1044 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1045 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1046 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1047 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1048 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1049 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1050 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1051 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1052 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1053 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1054 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1055 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1056 + "-html FILE\tCreate HTML file from alignment.\n"
1057 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1058 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1059 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1060 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1061 + "-noquestionnaire\tTurn off questionnaire check.\n"
1062 + "-nonews\tTurn off check for Jalview news.\n"
1063 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1064 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1066 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1067 // after all other properties files have been read\n\t
1068 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1069 // passed in correctly)"
1070 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1071 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1072 + "-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"
1073 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1076 private static void startUsageStats(final Desktop desktop)
1079 * start a User Config prompt asking if we can log usage statistics.
1081 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
1082 "USAGESTATS", "Jalview Usage Statistics",
1083 "Do you want to help make Jalview better by enabling "
1084 + "the collection of usage statistics with Google Analytics ?"
1085 + "\n\n(you can enable or disable usage tracking in the preferences)",
1092 "Initialising googletracker for usage stats.");
1093 Cache.initGoogleTracker();
1094 Cache.log.debug("Tracking enabled.");
1101 Cache.log.debug("Not enabling Google Tracking.");
1104 desktop.addDialogThread(prompter);
1108 * Locate the given string as a file and pass it to the groovy interpreter.
1110 * @param groovyscript
1111 * the script to execute
1112 * @param jalviewContext
1113 * the Jalview Desktop object passed in to the groovy binding as the
1116 private void executeGroovyScript(String groovyscript, AlignFrame af)
1119 * for scripts contained in files
1126 if (groovyscript.trim().equals("STDIN"))
1128 // read from stdin into a tempfile and execute it
1131 tfile = File.createTempFile("jalview", "groovy");
1132 PrintWriter outfile = new PrintWriter(
1133 new OutputStreamWriter(new FileOutputStream(tfile)));
1134 BufferedReader br = new BufferedReader(
1135 new InputStreamReader(System.in));
1137 while ((line = br.readLine()) != null)
1139 outfile.write(line + "\n");
1145 } catch (Exception ex)
1147 System.err.println("Failed to read from STDIN into tempfile "
1148 + ((tfile == null) ? "(tempfile wasn't created)"
1149 : tfile.toString()));
1150 ex.printStackTrace();
1155 sfile = tfile.toURI().toURL();
1156 } catch (Exception x)
1159 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1161 x.printStackTrace();
1169 sfile = new URI(groovyscript).toURL();
1170 } catch (Exception x)
1172 tfile = new File(groovyscript);
1173 if (!tfile.exists())
1175 System.err.println("File '" + groovyscript + "' does not exist.");
1178 if (!tfile.canRead())
1180 System.err.println("File '" + groovyscript + "' cannot be read.");
1183 if (tfile.length() < 1)
1185 System.err.println("File '" + groovyscript + "' is empty.");
1190 sfile = tfile.getAbsoluteFile().toURI().toURL();
1191 } catch (Exception ex)
1193 System.err.println("Failed to create a file URL for "
1194 + tfile.getAbsoluteFile());
1201 Map<String, java.lang.Object> vbinding = new HashMap<>();
1202 vbinding.put("Jalview", this);
1205 vbinding.put("currentAlFrame", af);
1207 Binding gbinding = new Binding(vbinding);
1208 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1209 gse.run(sfile.toString(), gbinding);
1210 if ("STDIN".equals(groovyscript))
1212 // delete temp file that we made -
1213 // only if it was successfully executed
1216 } catch (Exception e)
1218 System.err.println("Exception Whilst trying to execute file " + sfile
1219 + " as a groovy script.");
1220 e.printStackTrace(System.err);
1225 public static boolean isHeadlessMode()
1227 String isheadless = System.getProperty("java.awt.headless");
1228 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1235 public AlignFrame[] getAlignFrames()
1237 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1238 : Desktop.getAlignFrames();
1243 * Quit method delegates to Desktop.quit - unless running in headless mode
1244 * when it just ends the JVM
1248 if (desktop != null)
1258 public static AlignFrame getCurrentAlignFrame()
1260 return Jalview.currentAlignFrame;
1263 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1265 Jalview.currentAlignFrame = currentAlignFrame;