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 jalview.ext.so.SequenceOntology;
24 import jalview.gui.AlignFrame;
25 import jalview.gui.Desktop;
26 import jalview.gui.PromptUserConfig;
27 import jalview.io.AppletFormatAdapter;
28 import jalview.io.BioJsHTMLOutput;
29 import jalview.io.DataSourceType;
30 import jalview.io.FileFormat;
31 import jalview.io.FileFormatException;
32 import jalview.io.FileFormatI;
33 import jalview.io.FileFormats;
34 import jalview.io.FileLoader;
35 import jalview.io.HtmlSvgOutput;
36 import jalview.io.IdentifyFile;
37 import jalview.io.NewickFile;
38 import jalview.io.gff.SequenceOntologyFactory;
39 import jalview.schemes.ColourSchemeI;
40 import jalview.schemes.ColourSchemeProperty;
41 import jalview.util.MessageManager;
42 import jalview.util.Platform;
43 import jalview.ws.jws2.Jws2Discoverer;
45 import java.io.BufferedReader;
47 import java.io.FileOutputStream;
48 import java.io.IOException;
49 import java.io.InputStreamReader;
50 import java.io.OutputStreamWriter;
51 import java.io.PrintWriter;
52 import java.net.MalformedURLException;
54 import java.net.URISyntaxException;
56 import java.security.AllPermission;
57 import java.security.CodeSource;
58 import java.security.PermissionCollection;
59 import java.security.Permissions;
60 import java.security.Policy;
61 import java.util.HashMap;
63 import java.util.Vector;
65 import javax.swing.UIManager;
66 import javax.swing.UIManager.LookAndFeelInfo;
68 import com.threerings.getdown.util.LaunchUtil;
70 import groovy.lang.Binding;
71 import groovy.util.GroovyScriptEngine;
72 import jalview.ext.so.SequenceOntology;
73 import jalview.gui.AlignFrame;
74 import jalview.gui.Desktop;
75 import jalview.gui.PromptUserConfig;
76 import jalview.io.AppletFormatAdapter;
77 import jalview.io.BioJsHTMLOutput;
78 import jalview.io.DataSourceType;
79 import jalview.io.FileFormat;
80 import jalview.io.FileFormatException;
81 import jalview.io.FileFormatI;
82 import jalview.io.FileLoader;
83 import jalview.io.HtmlSvgOutput;
84 import jalview.io.IdentifyFile;
85 import jalview.io.NewickFile;
86 import jalview.io.gff.SequenceOntologyFactory;
87 import jalview.schemes.ColourSchemeI;
88 import jalview.schemes.ColourSchemeProperty;
89 import jalview.util.MessageManager;
90 import jalview.util.Platform;
91 import jalview.ws.jws2.Jws2Discoverer;
94 * Main class for Jalview Application <br>
96 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
99 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
100 * jalview.bin.Jalview jalview.bin.Jalview
102 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
103 * embellish '*' to e.g. '*.jar')
106 * @version $Revision$
111 * singleton instance of this class
113 private static Jalview instance;
115 private Desktop desktop;
117 public static AlignFrame currentAlignFrame;
121 // grab all the rights we can the JVM
122 Policy.setPolicy(new Policy()
125 public PermissionCollection getPermissions(CodeSource codesource)
127 Permissions perms = new Permissions();
128 perms.add(new AllPermission());
133 public void refresh()
140 * keep track of feature fetching tasks.
148 * TODO: generalise to track all jalview events to orchestrate batch processing
152 private int queued = 0;
154 private int running = 0;
156 public FeatureFetcher()
161 public void addFetcher(final AlignFrame af,
162 final Vector<String> dasSources)
164 final long id = System.currentTimeMillis();
166 final FeatureFetcher us = this;
167 new Thread(new Runnable()
179 af.setProgressBar(MessageManager
180 .getString("status.das_features_being_retrived"), id);
181 af.featureSettings_actionPerformed(null);
182 af.setProgressBar(null, id);
191 public synchronized boolean allFinished()
193 return queued == 0 && running == 0;
198 public static Jalview getInstance()
204 * main class for Jalview application
207 * open <em>filename</em>
209 public static void main(String[] args)
211 instance = new Jalview();
212 instance.doMain(args);
218 void doMain(String[] args)
220 System.setSecurityManager(null);
222 .println("Java version: " + System.getProperty("java.version"));
223 System.out.println("Java Home: " + System.getProperty("java.home"));
224 System.out.println(System.getProperty("os.arch") + " "
225 + System.getProperty("os.name") + " "
226 + System.getProperty("os.version"));
227 String val = System.getProperty("sys.install4jVersion");
230 System.out.println("Install4j version: " + val);
232 val = System.getProperty("installer_template_version");
235 System.out.println("Install4j template version: " + val);
237 val = System.getProperty("launcher_version");
240 System.out.println("Launcher version: " + val);
243 // report Jalview version
244 Cache.loadBuildProperties(true);
246 ArgsParser aparser = new ArgsParser(args);
247 boolean headless = false;
249 if (aparser.contains("help") || aparser.contains("h"))
254 if (aparser.contains("nodisplay") || aparser.contains("nogui")
255 || aparser.contains("headless"))
257 System.setProperty("java.awt.headless", "true");
260 String usrPropsFile = aparser.getValue("props");
261 Cache.loadProperties(usrPropsFile); // must do this before
262 if (usrPropsFile != null)
265 "CMD [-props " + usrPropsFile + "] executed successfully!");
270 final String jabawsUrl = aparser.getValue("jabaws");
271 if (jabawsUrl != null)
275 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
277 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
278 } catch (MalformedURLException e)
281 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
285 String defs = aparser.getValue("setprop");
288 int p = defs.indexOf('=');
291 System.err.println("Ignoring invalid setprop argument : " + defs);
295 System.out.println("Executing setprop argument: " + defs);
296 // DISABLED FOR SECURITY REASONS
297 // TODO: add a property to allow properties to be overriden by cli args
298 // Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
300 defs = aparser.getValue("setprop");
302 if (System.getProperty("java.awt.headless") != null
303 && System.getProperty("java.awt.headless").equals("true"))
307 System.setProperty("http.agent",
308 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
312 } catch (NoClassDefFoundError error)
314 error.printStackTrace();
315 System.out.println("\nEssential logging libraries not found."
316 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
325 * configure 'full' SO model if preferences say to, else use the default (SO
328 if (Cache.getDefault("USE_FULL_SO", true))
330 SequenceOntologyFactory.setInstance(new SequenceOntology());
336 desktop = new Desktop();
337 desktop.setInBatchMode(true); // indicate we are starting up
341 JalviewTaskbar.setTaskbar(this);
342 } catch (Exception e)
344 Cache.log.info("Cannot set Taskbar");
345 Cache.log.error(e.getMessage());
346 // e.printStackTrace();
347 } catch (Throwable t)
349 Cache.log.info("Cannot set Taskbar");
350 Cache.log.error(t.getMessage());
351 // t.printStackTrace();
354 desktop.setVisible(true);
355 desktop.startServiceDiscovery();
356 if (!aparser.contains("nousagestats"))
358 startUsageStats(desktop);
362 System.err.println("CMD [-nousagestats] executed successfully!");
365 if (!aparser.contains("noquestionnaire"))
367 String url = aparser.getValue("questionnaire");
370 // Start the desktop questionnaire prompter with the specified
372 Cache.log.debug("Starting questionnaire url at " + url);
373 desktop.checkForQuestionnaire(url);
375 "CMD questionnaire[-" + url + "] executed successfully!");
379 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
381 // Start the desktop questionnaire prompter with the specified
384 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
386 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
388 "Starting questionnaire with default url: " + defurl);
389 desktop.checkForQuestionnaire(defurl);
395 System.err.println("CMD [-noquestionnaire] executed successfully!");
398 if (!aparser.contains("nonews"))
400 desktop.checkForNews();
403 BioJsHTMLOutput.updateBioJS();
406 // Move any new getdown-launcher-new.jar into place over old
407 // getdown-launcher.jar
408 String appdirString = System.getProperty("getdownappdir");
409 if (appdirString != null && appdirString.length() > 0)
411 final File appdir = new File(appdirString);
417 LaunchUtil.upgradeGetdown(
418 new File(appdir, "getdown-launcher-old.jar"),
419 new File(appdir, "getdown-launcher.jar"),
420 new File(appdir, "getdown-launcher-new.jar"));
425 String file = null, data = null;
426 FileFormatI format = null;
427 DataSourceType protocol = null;
428 FileLoader fileLoader = new FileLoader(!headless);
430 String groovyscript = null; // script to execute after all loading is
431 // completed one way or another
432 // extract groovy argument and execute if necessary
433 groovyscript = aparser.getValue("groovy", true);
434 file = aparser.getValue("open", true);
436 if (file == null && desktop == null)
438 System.out.println("No files to open!");
442 // Finally, deal with the remaining input data.
447 desktop.setProgressBar(
449 .getString("status.processing_commandline_args"),
450 progress = System.currentTimeMillis());
452 System.out.println("CMD [-open " + file + "] executed successfully!");
456 protocol = AppletFormatAdapter.checkProtocol(file);
458 if (protocol == DataSourceType.FILE)
460 if (!(new File(file)).exists())
462 System.out.println("Can't find " + file);
472 format = new IdentifyFile().identify(file, protocol);
473 } catch (FileFormatException e1)
478 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
482 System.out.println("error");
486 setCurrentAlignFrame(af);
487 data = aparser.getValue("colour", true);
490 data.replaceAll("%20", " ");
492 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
493 af.getViewport(), af.getViewport().getAlignment(), data);
498 "CMD [-color " + data + "] executed successfully!");
503 // Must maintain ability to use the groups flag
504 data = aparser.getValue("groups", true);
507 af.parseFeaturesFile(data,
508 AppletFormatAdapter.checkProtocol(data));
509 // System.out.println("Added " + data);
511 "CMD groups[-" + data + "] executed successfully!");
513 data = aparser.getValue("features", true);
516 af.parseFeaturesFile(data,
517 AppletFormatAdapter.checkProtocol(data));
518 // System.out.println("Added " + data);
520 "CMD [-features " + data + "] executed successfully!");
523 data = aparser.getValue("annotations", true);
526 af.loadJalviewDataFile(data, null, null, null);
527 // System.out.println("Added " + data);
529 "CMD [-annotations " + data + "] executed successfully!");
531 // set or clear the sortbytree flag.
532 if (aparser.contains("sortbytree"))
534 af.getViewport().setSortByTree(true);
535 if (af.getViewport().getSortByTree())
537 System.out.println("CMD [-sortbytree] executed successfully!");
540 if (aparser.contains("no-annotation"))
542 af.getViewport().setShowAnnotation(false);
543 if (!af.getViewport().isShowAnnotation())
545 System.out.println("CMD no-annotation executed successfully!");
548 if (aparser.contains("nosortbytree"))
550 af.getViewport().setSortByTree(false);
551 if (!af.getViewport().getSortByTree())
554 .println("CMD [-nosortbytree] executed successfully!");
557 data = aparser.getValue("tree", true);
563 "CMD [-tree " + data + "] executed successfully!");
564 NewickFile nf = new NewickFile(data,
565 AppletFormatAdapter.checkProtocol(data));
567 .setCurrentTree(af.showNewickTree(nf, data).getTree());
568 } catch (IOException ex)
570 System.err.println("Couldn't add tree " + data);
571 ex.printStackTrace(System.err);
574 // TODO - load PDB structure(s) to alignment JAL-629
575 // (associate with identical sequence in alignment, or a specified
577 if (groovyscript != null)
579 // Execute the groovy script after we've done all the rendering stuff
580 // and before any images or figures are generated.
581 System.out.println("Executing script " + groovyscript);
582 executeGroovyScript(groovyscript, af);
583 System.out.println("CMD groovy[" + groovyscript
584 + "] executed successfully!");
587 String imageName = "unnamed.png";
588 while (aparser.getSize() > 1)
590 String outputFormat = aparser.nextValue();
591 file = aparser.nextValue();
593 if (outputFormat.equalsIgnoreCase("png"))
595 af.createPNG(new File(file));
596 imageName = (new File(file)).getName();
597 System.out.println("Creating PNG image: " + file);
600 else if (outputFormat.equalsIgnoreCase("svg"))
602 File imageFile = new File(file);
603 imageName = imageFile.getName();
604 af.createSVG(imageFile);
605 System.out.println("Creating SVG image: " + file);
608 else if (outputFormat.equalsIgnoreCase("html"))
610 File imageFile = new File(file);
611 imageName = imageFile.getName();
612 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
613 htmlSVG.exportHTML(file);
615 System.out.println("Creating HTML image: " + file);
618 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
622 System.err.println("The output html file must not be null");
627 BioJsHTMLOutput.refreshVersionInfo(
628 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
629 } catch (URISyntaxException e)
633 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
634 bjs.exportHTML(file);
636 .println("Creating BioJS MSA Viwer HTML file: " + file);
639 else if (outputFormat.equalsIgnoreCase("imgMap"))
641 af.createImageMap(new File(file), imageName);
642 System.out.println("Creating image map: " + file);
645 else if (outputFormat.equalsIgnoreCase("eps"))
647 File outputFile = new File(file);
649 "Creating EPS file: " + outputFile.getAbsolutePath());
650 af.createEPS(outputFile);
653 FileFormatI outFormat=null;
655 outFormat = FileFormats.getInstance().forName(outputFormat);
656 } catch (Exception formatP) {
657 System.out.println("Couldn't parse "+outFormat+" as a valid Jalview format string.");
659 if (outFormat != null)
661 if (!outFormat.isWritable())
664 "This version of Jalview does not support alignment export as "
669 if (af.saveAlignment(file, outFormat))
671 System.out.println("Written alignment in " + format
672 + " format to " + file);
676 System.out.println("Error writing file " + file + " in "
677 + format + " format!!");
683 while (aparser.getSize() > 0)
685 System.out.println("Unknown arg: " + aparser.nextValue());
689 AlignFrame startUpAlframe = null;
690 // We'll only open the default file if the desktop is visible.
692 // ////////////////////
694 if (!headless && file == null
695 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
697 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
698 jalview.bin.Cache.getDefault("www.jalview.org",
699 "http://www.jalview.org")
700 + "/examples/exampleFile_2_7.jar");
702 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
704 // hardwire upgrade of the startup file
705 file.replace("_2_3.jar", "_2_7.jar");
706 // and remove the stale setting
707 jalview.bin.Cache.removeProperty("STARTUP_FILE");
710 protocol = DataSourceType.FILE;
712 if (file.indexOf("http:") > -1)
714 protocol = DataSourceType.URL;
717 if (file.endsWith(".jar"))
719 format = FileFormat.Jalview;
725 format = new IdentifyFile().identify(file, protocol);
726 } catch (FileFormatException e)
732 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
734 // extract groovy arguments before anything else.
737 // Once all other stuff is done, execute any groovy scripts (in order)
738 if (groovyscript != null)
740 if (Cache.groovyJarsPresent())
742 System.out.println("Executing script " + groovyscript);
743 executeGroovyScript(groovyscript, startUpAlframe);
748 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
752 // and finally, turn off batch mode indicator - if the desktop still exists
757 desktop.setProgressBar(null, progress);
759 desktop.setInBatchMode(false);
763 private static void setLookAndFeel()
765 // property laf = "crossplatform", "system", "gtk", "metal", "nimbus" or
767 // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac,
769 String lafProp = System.getProperty("laf");
770 String lafSetting = Cache.getDefault("PREFERRED_LAF", null);
776 else if (lafSetting != null)
780 boolean lafSet = false;
783 case "crossplatform":
784 lafSet = setCrossPlatformLookAndFeel();
787 Cache.log.error("Could not set requested laf=" + laf);
791 lafSet = setSystemLookAndFeel();
794 Cache.log.error("Could not set requested laf=" + laf);
798 lafSet = setGtkLookAndFeel();
801 Cache.log.error("Could not set requested laf=" + laf);
805 lafSet = setMetalLookAndFeel();
808 Cache.log.error("Could not set requested laf=" + laf);
812 lafSet = setNimbusLookAndFeel();
815 Cache.log.error("Could not set requested laf=" + laf);
819 lafSet = setQuaquaLookAndFeel();
822 Cache.log.error("Could not set requested laf=" + laf);
826 lafSet = setVaquaLookAndFeel();
829 Cache.log.error("Could not set requested laf=" + laf);
833 lafSet = setMacLookAndFeel();
836 Cache.log.error("Could not set requested laf=" + laf);
842 Cache.log.error("Requested laf=" + laf + " not implemented");
846 setSystemLookAndFeel();
847 if (Platform.isLinux())
849 setMetalLookAndFeel();
851 if (Platform.isAMac())
858 private static boolean setCrossPlatformLookAndFeel()
860 return setGenericLookAndFeel(false);
863 private static boolean setSystemLookAndFeel()
865 return setGenericLookAndFeel(true);
868 private static boolean setGenericLookAndFeel(boolean system)
873 UIManager.setLookAndFeel(
874 system ? UIManager.getSystemLookAndFeelClassName()
875 : UIManager.getCrossPlatformLookAndFeelClassName());
877 } catch (Exception ex)
879 Cache.log.error("Unexpected Look and Feel Exception");
880 Cache.log.error(ex.getMessage());
881 Cache.log.debug(Cache.getStackTraceString(ex));
886 private static boolean setSpecificLookAndFeel(String name,
887 String className, boolean nameStartsWith)
892 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
894 if (info.getName() != null && nameStartsWith
895 ? info.getName().toLowerCase()
896 .startsWith(name.toLowerCase())
897 : info.getName().toLowerCase().equals(name.toLowerCase()))
899 className = info.getClassName();
903 UIManager.setLookAndFeel(className);
905 } catch (Exception ex)
907 Cache.log.error("Unexpected Look and Feel Exception");
908 Cache.log.error(ex.getMessage());
909 Cache.log.debug(Cache.getStackTraceString(ex));
914 private static boolean setGtkLookAndFeel()
916 return setSpecificLookAndFeel("gtk",
917 "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", true);
920 private static boolean setMetalLookAndFeel()
922 return setSpecificLookAndFeel("metal",
923 "javax.swing.plaf.metal.MetalLookAndFeel", false);
926 private static boolean setNimbusLookAndFeel()
928 return setSpecificLookAndFeel("nimbus",
929 "javax.swing.plaf.nimbus.NimbusLookAndFeel", false);
932 private static boolean setQuaquaLookAndFeel()
934 return setSpecificLookAndFeel("quaqua",
935 ch.randelshofer.quaqua.QuaquaManager.getLookAndFeel().getClass()
940 private static boolean setVaquaLookAndFeel()
942 return setSpecificLookAndFeel("vaqua",
943 "org.violetlib.aqua.AquaLookAndFeel", false);
946 private static boolean setMacLookAndFeel()
949 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
951 System.setProperty("apple.laf.useScreenMenuBar", "true");
952 set = setQuaquaLookAndFeel();
953 if ((!set) || !UIManager.getLookAndFeel().getClass().toString()
954 .toLowerCase().contains("quaqua"))
956 set = setVaquaLookAndFeel();
961 private static void showUsage()
964 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
965 + "-nodisplay\tRun Jalview without User Interface.\n"
966 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
967 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
968 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
969 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
970 + "-features FILE\tUse the given file to mark features on the alignment.\n"
971 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
972 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
973 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
974 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
975 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
976 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
977 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
978 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
979 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
980 + "-png FILE\tCreate PNG image FILE from alignment.\n"
981 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
982 + "-html FILE\tCreate HTML file from alignment.\n"
983 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
984 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
985 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
986 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
987 + "-noquestionnaire\tTurn off questionnaire check.\n"
988 + "-nonews\tTurn off check for Jalview news.\n"
989 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
990 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
992 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
993 // after all other properties files have been read\n\t
994 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
995 // passed in correctly)"
996 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
997 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
998 + "-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"
999 + "-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"
1000 + "-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"
1001 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1004 private static void startUsageStats(final Desktop desktop)
1007 * start a User Config prompt asking if we can log usage statistics.
1009 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
1010 "USAGESTATS", "Jalview Usage Statistics",
1011 "Do you want to help make Jalview better by enabling "
1012 + "the collection of usage statistics with Google Analytics ?"
1013 + "\n\n(you can enable or disable usage tracking in the preferences)",
1020 "Initialising googletracker for usage stats.");
1021 Cache.initGoogleTracker();
1022 Cache.log.debug("Tracking enabled.");
1029 Cache.log.debug("Not enabling Google Tracking.");
1032 desktop.addDialogThread(prompter);
1036 * Locate the given string as a file and pass it to the groovy interpreter.
1038 * @param groovyscript
1039 * the script to execute
1040 * @param jalviewContext
1041 * the Jalview Desktop object passed in to the groovy binding as the
1044 private void executeGroovyScript(String groovyscript, AlignFrame af)
1047 * for scripts contained in files
1054 if (groovyscript.trim().equals("STDIN"))
1056 // read from stdin into a tempfile and execute it
1059 tfile = File.createTempFile("jalview", "groovy");
1060 PrintWriter outfile = new PrintWriter(
1061 new OutputStreamWriter(new FileOutputStream(tfile)));
1062 BufferedReader br = new BufferedReader(
1063 new InputStreamReader(System.in));
1065 while ((line = br.readLine()) != null)
1067 outfile.write(line + "\n");
1073 } catch (Exception ex)
1075 System.err.println("Failed to read from STDIN into tempfile "
1076 + ((tfile == null) ? "(tempfile wasn't created)"
1077 : tfile.toString()));
1078 ex.printStackTrace();
1083 sfile = tfile.toURI().toURL();
1084 } catch (Exception x)
1087 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1089 x.printStackTrace();
1097 sfile = new URI(groovyscript).toURL();
1098 } catch (Exception x)
1100 tfile = new File(groovyscript);
1101 if (!tfile.exists())
1103 System.err.println("File '" + groovyscript + "' does not exist.");
1106 if (!tfile.canRead())
1108 System.err.println("File '" + groovyscript + "' cannot be read.");
1111 if (tfile.length() < 1)
1113 System.err.println("File '" + groovyscript + "' is empty.");
1118 sfile = tfile.getAbsoluteFile().toURI().toURL();
1119 } catch (Exception ex)
1121 System.err.println("Failed to create a file URL for "
1122 + tfile.getAbsoluteFile());
1129 Map<String, java.lang.Object> vbinding = new HashMap<>();
1130 vbinding.put("Jalview", this);
1133 vbinding.put("currentAlFrame", af);
1135 Binding gbinding = new Binding(vbinding);
1136 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1137 gse.run(sfile.toString(), gbinding);
1138 if ("STDIN".equals(groovyscript))
1140 // delete temp file that we made -
1141 // only if it was successfully executed
1144 } catch (Exception e)
1146 System.err.println("Exception Whilst trying to execute file " + sfile
1147 + " as a groovy script.");
1148 e.printStackTrace(System.err);
1153 public static boolean isHeadlessMode()
1155 String isheadless = System.getProperty("java.awt.headless");
1156 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1163 public AlignFrame[] getAlignFrames()
1165 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1166 : Desktop.getAlignFrames();
1171 * Quit method delegates to Desktop.quit - unless running in headless mode
1172 * when it just ends the JVM
1176 if (desktop != null)
1186 public static AlignFrame getCurrentAlignFrame()
1188 return Jalview.currentAlignFrame;
1191 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1193 Jalview.currentAlignFrame = currentAlignFrame;