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.ChannelProperties;
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();
98 // singleton instance of this class
100 private static Jalview instance;
102 private Desktop desktop;
104 public static AlignFrame currentAlignFrame;
108 if (!Platform.isJS())
115 // grab all the rights we can for the JVM
116 Policy.setPolicy(new Policy()
119 public PermissionCollection getPermissions(CodeSource codesource)
121 Permissions perms = new Permissions();
122 perms.add(new AllPermission());
127 public void refresh()
135 * keep track of feature fetching tasks.
143 * TODO: generalise to track all jalview events to orchestrate batch processing
147 private int queued = 0;
149 private int running = 0;
151 public FeatureFetcher()
156 public void addFetcher(final AlignFrame af,
157 final Vector<String> dasSources)
159 final long id = System.currentTimeMillis();
161 final FeatureFetcher us = this;
162 new Thread(new Runnable()
174 af.setProgressBar(MessageManager
175 .getString("status.das_features_being_retrived"), id);
176 af.featureSettings_actionPerformed(null);
177 af.setProgressBar(null, id);
186 public synchronized boolean allFinished()
188 return queued == 0 && running == 0;
193 public static Jalview getInstance()
199 * main class for Jalview application
202 * open <em>filename</em>
204 public static void main(String[] args)
206 // setLogging(); // BH - for event debugging in JavaScript
207 instance = new Jalview();
208 instance.doMain(args);
211 private static void logClass(String name)
213 // BH - for event debugging in JavaScript
214 ConsoleHandler consoleHandler = new ConsoleHandler();
215 consoleHandler.setLevel(Level.ALL);
216 Logger logger = Logger.getLogger(name);
217 logger.setLevel(Level.ALL);
218 logger.addHandler(consoleHandler);
221 @SuppressWarnings("unused")
222 private static void setLogging()
230 System.out.println("not in js");
233 // BH - for event debugging in JavaScript (Java mode only)
234 if (!Platform.isJS())
241 Logger.getLogger("").setLevel(Level.ALL);
242 logClass("java.awt.EventDispatchThread");
243 logClass("java.awt.EventQueue");
244 logClass("java.awt.Component");
245 logClass("java.awt.focus.Component");
246 logClass("java.awt.focus.DefaultKeyboardFocusManager");
254 void doMain(String[] args)
257 if (!Platform.isJS())
259 System.setSecurityManager(null);
263 .println("Java version: " + System.getProperty("java.version"));
264 System.out.println("Java Home: " + System.getProperty("java.home"));
265 System.out.println(System.getProperty("os.arch") + " "
266 + System.getProperty("os.name") + " "
267 + System.getProperty("os.version"));
268 String val = System.getProperty("sys.install4jVersion");
271 System.out.println("Install4j version: " + val);
273 val = System.getProperty("installer_template_version");
276 System.out.println("Install4j template version: " + val);
278 val = System.getProperty("launcher_version");
281 System.out.println("Launcher version: " + val);
284 // report Jalview version
285 Cache.loadBuildProperties(true);
287 ArgsParser aparser = new ArgsParser(args);
288 boolean headless = false;
290 String usrPropsFile = aparser.getValue("props");
291 Cache.loadProperties(usrPropsFile); // must do this before
292 if (usrPropsFile != null)
295 "CMD [-props " + usrPropsFile + "] executed successfully!");
298 if (!Platform.isJS())
305 if (aparser.contains("help") || aparser.contains("h"))
310 if (aparser.contains("nodisplay") || aparser.contains("nogui")
311 || aparser.contains("headless"))
313 System.setProperty("java.awt.headless", "true");
318 final String jabawsUrl = aparser.getValue("jabaws");
319 if (jabawsUrl != null)
323 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
325 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
326 } catch (MalformedURLException e)
329 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
334 String defs = aparser.getValue("setprop");
337 int p = defs.indexOf('=');
340 System.err.println("Ignoring invalid setprop argument : " + defs);
344 System.out.println("Executing setprop argument: " + defs);
347 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
350 defs = aparser.getValue("setprop");
352 if (System.getProperty("java.awt.headless") != null
353 && System.getProperty("java.awt.headless").equals("true"))
357 System.setProperty("http.agent",
358 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
362 } catch (NoClassDefFoundError error)
364 error.printStackTrace();
365 System.out.println("\nEssential logging libraries not found."
366 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
372 // property laf = "crossplatform", "system", "gtk", "metal" or "mac"
373 // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac,
375 String lafProp = System.getProperty("laf");
376 String lafSetting = Cache.getDefault("PREFERRED_LAF", null);
382 else if (lafSetting != null)
386 boolean lafSet = false;
389 case "crossplatform":
390 lafSet = setCrossPlatformLookAndFeel();
393 System.err.println("Could not set requested laf=" + laf);
397 lafSet = setSystemLookAndFeel();
400 System.err.println("Could not set requested laf=" + laf);
404 lafSet = setGtkLookAndFeel();
406 System.err.println("Could not set requested laf=" + laf);
410 lafSet = setMetalLookAndFeel();
412 System.err.println("Could not set requested laf=" + laf);
416 lafSet = setNimbusLookAndFeel();
418 System.err.println("Could not set requested laf=" + laf);
422 lafSet = setQuaquaLookAndFeel();
424 System.err.println("Could not set requested laf=" + laf);
428 lafSet = setVaquaLookAndFeel();
430 System.err.println("Could not set requested laf=" + laf);
434 lafSet = setMacLookAndFeel();
437 System.err.println("Could not set requested laf=" + laf);
443 System.err.println("Requested laf=" + laf + " not implemented");
447 setSystemLookAndFeel();
448 if (Platform.isLinux() && !Platform.isJS())
450 setMetalLookAndFeel();
452 if (Platform.isAMacAndNotJS())
459 * configure 'full' SO model if preferences say to, else use the default (full SO)
460 * - as JS currently doesn't have OBO parsing, it must use 'Lite' version
462 boolean soDefault = !Platform.isJS();
463 if (Cache.getDefault("USE_FULL_SO", soDefault))
465 SequenceOntologyFactory.setInstance(new SequenceOntology());
471 desktop = new Desktop();
472 desktop.setInBatchMode(true); // indicate we are starting up
476 JalviewTaskbar.setTaskbar(this);
477 } catch (Throwable t)
479 System.out.println("Error setting Taskbar: " + t.getMessage());
482 desktop.setVisible(true);
484 if (!Platform.isJS())
491 desktop.startServiceDiscovery();
492 if (!aparser.contains("nousagestats"))
494 startUsageStats(desktop);
498 System.err.println("CMD [-nousagestats] executed successfully!");
501 if (!aparser.contains("noquestionnaire"))
503 String url = aparser.getValue("questionnaire");
506 // Start the desktop questionnaire prompter with the specified
508 Cache.log.debug("Starting questionnaire url at " + url);
509 desktop.checkForQuestionnaire(url);
510 System.out.println("CMD questionnaire[-" + url
511 + "] executed successfully!");
515 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
517 // Start the desktop questionnaire prompter with the specified
520 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
522 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
524 "Starting questionnaire with default url: " + defurl);
525 desktop.checkForQuestionnaire(defurl);
532 .println("CMD [-noquestionnaire] executed successfully!");
535 if (!aparser.contains("nonews"))
537 desktop.checkForNews();
540 BioJsHTMLOutput.updateBioJS();
544 // Move any new getdown-launcher-new.jar into place over old
545 // getdown-launcher.jar
546 String appdirString = System.getProperty("getdownappdir");
547 if (appdirString != null && appdirString.length() > 0)
549 final File appdir = new File(appdirString);
555 LaunchUtil.upgradeGetdown(
556 new File(appdir, "getdown-launcher-old.jar"),
557 new File(appdir, "getdown-launcher.jar"),
558 new File(appdir, "getdown-launcher-new.jar"));
563 String file = null, data = null;
564 FileFormatI format = null;
565 DataSourceType protocol = null;
566 FileLoader fileLoader = new FileLoader(!headless);
568 String groovyscript = null; // script to execute after all loading is
569 // completed one way or another
570 // extract groovy argument and execute if necessary
571 groovyscript = aparser.getValue("groovy", true);
572 file = aparser.getValue("open", true);
574 if (file == null && desktop == null)
576 System.out.println("No files to open!");
580 // Finally, deal with the remaining input data.
585 desktop.setProgressBar(
587 .getString("status.processing_commandline_args"),
588 progress = System.currentTimeMillis());
590 System.out.println("CMD [-open " + file + "] executed successfully!");
592 if (!Platform.isJS())
594 * ignore in JavaScript -- can't just file existence - could load it?
599 if (!file.startsWith("http://") && !file.startsWith("https://"))
600 // BH 2019 added https check for Java
602 if (!(new File(file)).exists())
604 System.out.println("Can't find " + file);
613 protocol = AppletFormatAdapter.checkProtocol(file);
617 format = new IdentifyFile().identify(file, protocol);
618 } catch (FileFormatException e1)
623 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
627 System.out.println("error");
631 setCurrentAlignFrame(af);
632 data = aparser.getValue("colour", true);
635 data.replaceAll("%20", " ");
637 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
638 af.getViewport(), af.getViewport().getAlignment(), data);
643 "CMD [-color " + data + "] executed successfully!");
648 // Must maintain ability to use the groups flag
649 data = aparser.getValue("groups", true);
652 af.parseFeaturesFile(data,
653 AppletFormatAdapter.checkProtocol(data));
654 // System.out.println("Added " + data);
656 "CMD groups[-" + data + "] executed successfully!");
658 data = aparser.getValue("features", true);
661 af.parseFeaturesFile(data,
662 AppletFormatAdapter.checkProtocol(data));
663 // System.out.println("Added " + data);
665 "CMD [-features " + data + "] executed successfully!");
668 data = aparser.getValue("annotations", true);
671 af.loadJalviewDataFile(data, null, null, null);
672 // System.out.println("Added " + data);
674 "CMD [-annotations " + data + "] executed successfully!");
676 // set or clear the sortbytree flag.
677 if (aparser.contains("sortbytree"))
679 af.getViewport().setSortByTree(true);
680 if (af.getViewport().getSortByTree())
682 System.out.println("CMD [-sortbytree] executed successfully!");
685 if (aparser.contains("no-annotation"))
687 af.getViewport().setShowAnnotation(false);
688 if (!af.getViewport().isShowAnnotation())
690 System.out.println("CMD no-annotation executed successfully!");
693 if (aparser.contains("nosortbytree"))
695 af.getViewport().setSortByTree(false);
696 if (!af.getViewport().getSortByTree())
699 .println("CMD [-nosortbytree] executed successfully!");
702 data = aparser.getValue("tree", true);
708 "CMD [-tree " + data + "] executed successfully!");
709 NewickFile nf = new NewickFile(data,
710 AppletFormatAdapter.checkProtocol(data));
712 .setCurrentTree(af.showNewickTree(nf, data).getTree());
713 } catch (IOException ex)
715 System.err.println("Couldn't add tree " + data);
716 ex.printStackTrace(System.err);
719 // TODO - load PDB structure(s) to alignment JAL-629
720 // (associate with identical sequence in alignment, or a specified
722 if (groovyscript != null)
724 // Execute the groovy script after we've done all the rendering stuff
725 // and before any images or figures are generated.
726 System.out.println("Executing script " + groovyscript);
727 executeGroovyScript(groovyscript, af);
728 System.out.println("CMD groovy[" + groovyscript
729 + "] executed successfully!");
732 String imageName = "unnamed.png";
733 while (aparser.getSize() > 1)
735 String outputFormat = aparser.nextValue();
736 file = aparser.nextValue();
738 if (outputFormat.equalsIgnoreCase("png"))
740 af.createPNG(new File(file));
741 imageName = (new File(file)).getName();
742 System.out.println("Creating PNG image: " + file);
745 else if (outputFormat.equalsIgnoreCase("svg"))
747 File imageFile = new File(file);
748 imageName = imageFile.getName();
749 af.createSVG(imageFile);
750 System.out.println("Creating SVG image: " + file);
753 else if (outputFormat.equalsIgnoreCase("html"))
755 File imageFile = new File(file);
756 imageName = imageFile.getName();
757 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
758 htmlSVG.exportHTML(file);
760 System.out.println("Creating HTML image: " + file);
763 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
767 System.err.println("The output html file must not be null");
772 BioJsHTMLOutput.refreshVersionInfo(
773 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
774 } catch (URISyntaxException e)
778 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
779 bjs.exportHTML(file);
781 .println("Creating BioJS MSA Viwer HTML file: " + file);
784 else if (outputFormat.equalsIgnoreCase("imgMap"))
786 af.createImageMap(new File(file), imageName);
787 System.out.println("Creating image map: " + file);
790 else if (outputFormat.equalsIgnoreCase("eps"))
792 File outputFile = new File(file);
794 "Creating EPS file: " + outputFile.getAbsolutePath());
795 af.createEPS(outputFile);
798 FileFormatI outFormat = null;
801 outFormat = FileFormats.getInstance().forName(outputFormat);
802 } catch (Exception formatP)
804 System.out.println("Couldn't parse " + outFormat
805 + " as a valid Jalview format string.");
807 if (outFormat != null)
809 if (!outFormat.isWritable())
812 "This version of Jalview does not support alignment export as "
817 af.saveAlignment(file, outFormat);
818 if (af.isSaveAlignmentSuccessful())
820 System.out.println("Written alignment in "
821 + outFormat.getName() + " format to " + file);
825 System.out.println("Error writing file " + file + " in "
826 + outFormat.getName() + " format!!");
833 while (aparser.getSize() > 0)
835 System.out.println("Unknown arg: " + aparser.nextValue());
839 AlignFrame startUpAlframe = null;
840 // We'll only open the default file if the desktop is visible.
842 // ////////////////////
844 if (!Platform.isJS() && !headless && file == null
845 && Cache.getDefault("SHOW_STARTUP_FILE", true))
852 file = Cache.getDefault("STARTUP_FILE",
853 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
854 + "/examples/exampleFile_2_7.jar");
856 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
858 // hardwire upgrade of the startup file
859 file.replace("_2_3.jar", "_2_7.jar");
860 // and remove the stale setting
861 Cache.removeProperty("STARTUP_FILE");
864 protocol = DataSourceType.FILE;
866 if (file.indexOf("http:") > -1)
868 protocol = DataSourceType.URL;
871 if (file.endsWith(".jar"))
873 format = FileFormat.Jalview;
879 format = new IdentifyFile().identify(file, protocol);
880 } catch (FileFormatException e)
886 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
888 // extract groovy arguments before anything else.
891 // Once all other stuff is done, execute any groovy scripts (in order)
892 if (groovyscript != null)
894 if (Cache.groovyJarsPresent())
896 System.out.println("Executing script " + groovyscript);
897 executeGroovyScript(groovyscript, startUpAlframe);
902 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
906 // and finally, turn off batch mode indicator - if the desktop still exists
911 desktop.setProgressBar(null, progress);
913 desktop.setInBatchMode(false);
917 private static boolean setCrossPlatformLookAndFeel()
919 return setGenericLookAndFeel(false);
922 private static boolean setSystemLookAndFeel()
924 return setGenericLookAndFeel(true);
927 private static boolean setGenericLookAndFeel(boolean system)
932 UIManager.setLookAndFeel(
933 system ? UIManager.getSystemLookAndFeelClassName()
934 : UIManager.getCrossPlatformLookAndFeelClassName());
936 } catch (Exception ex)
938 System.err.println("Unexpected Look and Feel Exception");
939 ex.printStackTrace();
944 private static boolean setSpecificLookAndFeel(String name,
945 String className, boolean nameStartsWith)
950 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
952 if (info.getName() != null && nameStartsWith
953 ? info.getName().toLowerCase()
954 .startsWith(name.toLowerCase())
955 : info.getName().toLowerCase().equals(name.toLowerCase()))
957 className = info.getClassName();
961 UIManager.setLookAndFeel(className);
963 } catch (Exception ex)
965 System.err.println("Unexpected Look and Feel Exception");
966 ex.printStackTrace();
971 private static boolean setGtkLookAndFeel()
973 return setSpecificLookAndFeel("gtk",
974 "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", true);
977 private static boolean setMetalLookAndFeel()
979 return setSpecificLookAndFeel("metal",
980 "javax.swing.plaf.metal.MetalLookAndFeel", false);
983 private static boolean setNimbusLookAndFeel()
985 return setSpecificLookAndFeel("nimbus",
986 "javax.swing.plaf.nimbus.NimbusLookAndFeel", false);
989 private static boolean setQuaquaLookAndFeel()
991 return setSpecificLookAndFeel("quaqua",
992 ch.randelshofer.quaqua.QuaquaManager.getLookAndFeel().getClass()
997 private static boolean setVaquaLookAndFeel()
999 return setSpecificLookAndFeel("vaqua",
1000 "org.violetlib.aqua.AquaLookAndFeel", false);
1003 private static boolean setMacLookAndFeel()
1005 boolean set = false;
1006 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
1007 ChannelProperties.getProperty("app_name"));
1008 System.setProperty("apple.laf.useScreenMenuBar", "true");
1009 set = setQuaquaLookAndFeel();
1010 if ((!set) || !UIManager.getLookAndFeel().getClass().toString()
1011 .toLowerCase().contains("quaqua"))
1013 set = setVaquaLookAndFeel();
1018 private static void showUsage()
1021 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1022 + "-nodisplay\tRun Jalview without User Interface.\n"
1023 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1024 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1025 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1026 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1027 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1028 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1029 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1030 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1031 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1032 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1033 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1034 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1035 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1036 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1037 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1038 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1039 + "-html FILE\tCreate HTML file from alignment.\n"
1040 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1041 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1042 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1043 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1044 + "-noquestionnaire\tTurn off questionnaire check.\n"
1045 + "-nonews\tTurn off check for Jalview news.\n"
1046 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1047 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1049 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1050 // after all other properties files have been read\n\t
1051 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1052 // passed in correctly)"
1053 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1054 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1055 + "-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"
1056 + "-jvmmempc=PERCENT\tOnly available with standalone executable jar or jalview.bin.Launcher. Limit maximum heap size (memory) to PERCENT% of total physical memory detected. This defaults to 90 if total physical memory can be detected. See https://www.jalview.org/help/html/memory.html for more details.\n"
1057 + "-jvmmemmax=MAXMEMORY\tOnly available with standalone executable jar or jalview.bin.Launcher. Limit maximum heap size (memory) to MAXMEMORY. MAXMEMORY can be specified in bytes, kilobytes(k), megabytes(m), gigabytes(g) or if you're lucky enough, terabytes(t). This defaults to 32g if total physical memory can be detected, or to 8g if total physical memory cannot be detected. See https://www.jalview.org/help/html/memory.html for more details.\n"
1058 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1061 private static void startUsageStats(final Desktop desktop)
1064 * start a User Config prompt asking if we can log usage statistics.
1066 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
1067 "USAGESTATS", "Jalview Usage Statistics",
1068 "Do you want to help make Jalview better by enabling "
1069 + "the collection of usage statistics with Google Analytics ?"
1070 + "\n\n(you can enable or disable usage tracking in the preferences)",
1077 "Initialising googletracker for usage stats.");
1078 Cache.initGoogleTracker();
1079 Cache.log.debug("Tracking enabled.");
1086 Cache.log.debug("Not enabling Google Tracking.");
1089 desktop.addDialogThread(prompter);
1093 * Locate the given string as a file and pass it to the groovy interpreter.
1095 * @param groovyscript
1096 * the script to execute
1097 * @param jalviewContext
1098 * the Jalview Desktop object passed in to the groovy binding as the
1101 private void executeGroovyScript(String groovyscript, AlignFrame af)
1104 * for scripts contained in files
1111 if (groovyscript.trim().equals("STDIN"))
1113 // read from stdin into a tempfile and execute it
1116 tfile = File.createTempFile("jalview", "groovy");
1117 PrintWriter outfile = new PrintWriter(
1118 new OutputStreamWriter(new FileOutputStream(tfile)));
1119 BufferedReader br = new BufferedReader(
1120 new InputStreamReader(System.in));
1122 while ((line = br.readLine()) != null)
1124 outfile.write(line + "\n");
1130 } catch (Exception ex)
1132 System.err.println("Failed to read from STDIN into tempfile "
1133 + ((tfile == null) ? "(tempfile wasn't created)"
1134 : tfile.toString()));
1135 ex.printStackTrace();
1140 sfile = tfile.toURI().toURL();
1141 } catch (Exception x)
1144 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1146 x.printStackTrace();
1154 sfile = new URI(groovyscript).toURL();
1155 } catch (Exception x)
1157 tfile = new File(groovyscript);
1158 if (!tfile.exists())
1160 System.err.println("File '" + groovyscript + "' does not exist.");
1163 if (!tfile.canRead())
1165 System.err.println("File '" + groovyscript + "' cannot be read.");
1168 if (tfile.length() < 1)
1170 System.err.println("File '" + groovyscript + "' is empty.");
1175 sfile = tfile.getAbsoluteFile().toURI().toURL();
1176 } catch (Exception ex)
1178 System.err.println("Failed to create a file URL for "
1179 + tfile.getAbsoluteFile());
1186 Map<String, java.lang.Object> vbinding = new HashMap<>();
1187 vbinding.put("Jalview", this);
1190 vbinding.put("currentAlFrame", af);
1192 Binding gbinding = new Binding(vbinding);
1193 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1194 gse.run(sfile.toString(), gbinding);
1195 if ("STDIN".equals(groovyscript))
1197 // delete temp file that we made -
1198 // only if it was successfully executed
1201 } catch (Exception e)
1203 System.err.println("Exception Whilst trying to execute file " + sfile
1204 + " as a groovy script.");
1205 e.printStackTrace(System.err);
1210 public static boolean isHeadlessMode()
1212 String isheadless = System.getProperty("java.awt.headless");
1213 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1220 public AlignFrame[] getAlignFrames()
1222 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1223 : Desktop.getAlignFrames();
1228 * Quit method delegates to Desktop.quit - unless running in headless mode
1229 * when it just ends the JVM
1233 if (desktop != null)
1243 public static AlignFrame getCurrentAlignFrame()
1245 return Jalview.currentAlignFrame;
1248 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1250 Jalview.currentAlignFrame = currentAlignFrame;