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();
96 // singleton instance of this class
98 private static Jalview instance;
100 private Desktop desktop;
102 public static AlignFrame currentAlignFrame;
106 if (!Platform.isJS())
113 // grab all the rights we can for the JVM
114 Policy.setPolicy(new Policy()
117 public PermissionCollection getPermissions(CodeSource codesource)
119 Permissions perms = new Permissions();
120 perms.add(new AllPermission());
125 public void refresh()
133 * keep track of feature fetching tasks.
141 * TODO: generalise to track all jalview events to orchestrate batch processing
145 private int queued = 0;
147 private int running = 0;
149 public FeatureFetcher()
154 public void addFetcher(final AlignFrame af,
155 final Vector<String> dasSources)
157 final long id = System.currentTimeMillis();
159 final FeatureFetcher us = this;
160 new Thread(new Runnable()
172 af.setProgressBar(MessageManager
173 .getString("status.das_features_being_retrived"), id);
174 af.featureSettings_actionPerformed(null);
175 af.setProgressBar(null, id);
184 public synchronized boolean allFinished()
186 return queued == 0 && running == 0;
191 public static Jalview getInstance()
197 * main class for Jalview application
200 * open <em>filename</em>
202 public static void main(String[] args)
204 // setLogging(); // BH - for event debugging in JavaScript
205 instance = new Jalview();
206 instance.doMain(args);
209 private static void logClass(String name)
211 // BH - for event debugging in JavaScript
212 ConsoleHandler consoleHandler = new ConsoleHandler();
213 consoleHandler.setLevel(Level.ALL);
214 Logger logger = Logger.getLogger(name);
215 logger.setLevel(Level.ALL);
216 logger.addHandler(consoleHandler);
219 @SuppressWarnings("unused")
220 private static void setLogging()
228 System.out.println("not in js");
231 // BH - for event debugging in JavaScript (Java mode only)
232 if (!Platform.isJS())
239 Logger.getLogger("").setLevel(Level.ALL);
240 logClass("java.awt.EventDispatchThread");
241 logClass("java.awt.EventQueue");
242 logClass("java.awt.Component");
243 logClass("java.awt.focus.Component");
244 logClass("java.awt.focus.DefaultKeyboardFocusManager");
252 void doMain(String[] args)
255 if (!Platform.isJS())
257 System.setSecurityManager(null);
261 .println("Java version: " + System.getProperty("java.version"));
262 System.out.println("Java Home: " + System.getProperty("java.home"));
263 System.out.println(System.getProperty("os.arch") + " "
264 + System.getProperty("os.name") + " "
265 + System.getProperty("os.version"));
266 String val = System.getProperty("sys.install4jVersion");
269 System.out.println("Install4j version: " + val);
271 val = System.getProperty("installer_template_version");
274 System.out.println("Install4j template version: " + val);
276 val = System.getProperty("launcher_version");
279 System.out.println("Launcher version: " + val);
282 // report Jalview version
283 Cache.loadBuildProperties(true);
285 ArgsParser aparser = new ArgsParser(args);
286 boolean headless = false;
288 String usrPropsFile = aparser.getValue("props");
289 Cache.loadProperties(usrPropsFile); // must do this before
290 if (usrPropsFile != null)
293 "CMD [-props " + usrPropsFile + "] executed successfully!");
296 if (!Platform.isJS())
303 if (aparser.contains("help") || aparser.contains("h"))
308 if (aparser.contains("nodisplay") || aparser.contains("nogui")
309 || aparser.contains("headless"))
311 System.setProperty("java.awt.headless", "true");
316 final String jabawsUrl = aparser.getValue("jabaws");
317 if (jabawsUrl != null)
321 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
323 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
324 } catch (MalformedURLException e)
327 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
332 String defs = aparser.getValue("setprop");
335 int p = defs.indexOf('=');
338 System.err.println("Ignoring invalid setprop argument : " + defs);
342 System.out.println("Executing setprop argument: " + defs);
345 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
348 defs = aparser.getValue("setprop");
350 if (System.getProperty("java.awt.headless") != null
351 && System.getProperty("java.awt.headless").equals("true"))
355 System.setProperty("http.agent",
356 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
360 } catch (NoClassDefFoundError error)
362 error.printStackTrace();
363 System.out.println("\nEssential logging libraries not found."
364 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
370 // property laf = "crossplatform", "system", "gtk", "metal" or "mac"
371 // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac,
373 String lafProp = System.getProperty("laf");
374 String lafSetting = Cache.getDefault("PREFERRED_LAF", null);
380 else if (lafSetting != null)
384 boolean lafSet = false;
387 case "crossplatform":
388 lafSet = setCrossPlatformLookAndFeel();
391 System.err.println("Could not set requested laf=" + laf);
395 lafSet = setSystemLookAndFeel();
398 System.err.println("Could not set requested laf=" + laf);
402 lafSet = setGtkLookAndFeel();
404 System.err.println("Could not set requested laf=" + laf);
408 lafSet = setMetalLookAndFeel();
410 System.err.println("Could not set requested laf=" + laf);
414 lafSet = setNimbusLookAndFeel();
416 System.err.println("Could not set requested laf=" + laf);
420 lafSet = setQuaquaLookAndFeel();
422 System.err.println("Could not set requested laf=" + laf);
426 lafSet = setVaquaLookAndFeel();
428 System.err.println("Could not set requested laf=" + laf);
432 lafSet = setMacLookAndFeel();
435 System.err.println("Could not set requested laf=" + laf);
441 System.err.println("Requested laf=" + laf + " not implemented");
445 setSystemLookAndFeel();
446 if (Platform.isLinux() && !Platform.isJS())
448 setMetalLookAndFeel();
450 if (Platform.isAMacAndNotJS())
457 * configure 'full' SO model if preferences say to, else use the default (full SO)
458 * - as JS currently doesn't have OBO parsing, it must use 'Lite' version
460 boolean soDefault = !Platform.isJS();
461 if (Cache.getDefault("USE_FULL_SO", soDefault))
463 SequenceOntologyFactory.setInstance(new SequenceOntology());
468 desktop = new Desktop();
469 desktop.setInBatchMode(true); // indicate we are starting up
473 JalviewTaskbar.setTaskbar(this);
474 } catch (Throwable t)
476 System.out.println("Error setting Taskbar: " + t.getMessage());
479 desktop.setVisible(true);
481 if (!Platform.isJS())
488 desktop.startServiceDiscovery();
489 if (!aparser.contains("nousagestats"))
491 startUsageStats(desktop);
495 System.err.println("CMD [-nousagestats] executed successfully!");
498 if (!aparser.contains("noquestionnaire"))
500 String url = aparser.getValue("questionnaire");
503 // Start the desktop questionnaire prompter with the specified
505 Cache.log.debug("Starting questionnaire url at " + url);
506 desktop.checkForQuestionnaire(url);
507 System.out.println("CMD questionnaire[-" + url
508 + "] executed successfully!");
512 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
514 // Start the desktop questionnaire prompter with the specified
517 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
519 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
521 "Starting questionnaire with default url: " + defurl);
522 desktop.checkForQuestionnaire(defurl);
529 .println("CMD [-noquestionnaire] executed successfully!");
532 if (!aparser.contains("nonews"))
534 desktop.checkForNews();
537 BioJsHTMLOutput.updateBioJS();
541 // Move any new getdown-launcher-new.jar into place over old
542 // getdown-launcher.jar
543 String appdirString = System.getProperty("getdownappdir");
544 if (appdirString != null && appdirString.length() > 0)
546 final File appdir = new File(appdirString);
552 LaunchUtil.upgradeGetdown(
553 new File(appdir, "getdown-launcher-old.jar"),
554 new File(appdir, "getdown-launcher.jar"),
555 new File(appdir, "getdown-launcher-new.jar"));
560 String file = null, data = null;
561 FileFormatI format = null;
562 DataSourceType protocol = null;
563 FileLoader fileLoader = new FileLoader(!headless);
565 String groovyscript = null; // script to execute after all loading is
566 // completed one way or another
567 // extract groovy argument and execute if necessary
568 groovyscript = aparser.getValue("groovy", true);
569 file = aparser.getValue("open", true);
571 if (file == null && desktop == null)
573 System.out.println("No files to open!");
577 // Finally, deal with the remaining input data.
582 desktop.setProgressBar(
584 .getString("status.processing_commandline_args"),
585 progress = System.currentTimeMillis());
587 System.out.println("CMD [-open " + file + "] executed successfully!");
589 if (!Platform.isJS())
591 * ignore in JavaScript -- can't just file existence - could load it?
596 if (!file.startsWith("http://") && !file.startsWith("https://"))
597 // BH 2019 added https check for Java
599 if (!(new File(file)).exists())
601 System.out.println("Can't find " + file);
610 protocol = AppletFormatAdapter.checkProtocol(file);
614 format = new IdentifyFile().identify(file, protocol);
615 } catch (FileFormatException e1)
620 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
624 System.out.println("error");
628 setCurrentAlignFrame(af);
629 data = aparser.getValue("colour", true);
632 data.replaceAll("%20", " ");
634 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
635 af.getViewport(), af.getViewport().getAlignment(), data);
640 "CMD [-color " + data + "] executed successfully!");
645 // Must maintain ability to use the groups flag
646 data = aparser.getValue("groups", true);
649 af.parseFeaturesFile(data,
650 AppletFormatAdapter.checkProtocol(data));
651 // System.out.println("Added " + data);
653 "CMD groups[-" + data + "] executed successfully!");
655 data = aparser.getValue("features", true);
658 af.parseFeaturesFile(data,
659 AppletFormatAdapter.checkProtocol(data));
660 // System.out.println("Added " + data);
662 "CMD [-features " + data + "] executed successfully!");
665 data = aparser.getValue("annotations", true);
668 af.loadJalviewDataFile(data, null, null, null);
669 // System.out.println("Added " + data);
671 "CMD [-annotations " + data + "] executed successfully!");
673 // set or clear the sortbytree flag.
674 if (aparser.contains("sortbytree"))
676 af.getViewport().setSortByTree(true);
677 if (af.getViewport().getSortByTree())
679 System.out.println("CMD [-sortbytree] executed successfully!");
682 if (aparser.contains("no-annotation"))
684 af.getViewport().setShowAnnotation(false);
685 if (!af.getViewport().isShowAnnotation())
687 System.out.println("CMD no-annotation executed successfully!");
690 if (aparser.contains("nosortbytree"))
692 af.getViewport().setSortByTree(false);
693 if (!af.getViewport().getSortByTree())
696 .println("CMD [-nosortbytree] executed successfully!");
699 data = aparser.getValue("tree", true);
705 "CMD [-tree " + data + "] executed successfully!");
706 NewickFile nf = new NewickFile(data,
707 AppletFormatAdapter.checkProtocol(data));
709 .setCurrentTree(af.showNewickTree(nf, data).getTree());
710 } catch (IOException ex)
712 System.err.println("Couldn't add tree " + data);
713 ex.printStackTrace(System.err);
716 // TODO - load PDB structure(s) to alignment JAL-629
717 // (associate with identical sequence in alignment, or a specified
719 if (groovyscript != null)
721 // Execute the groovy script after we've done all the rendering stuff
722 // and before any images or figures are generated.
723 System.out.println("Executing script " + groovyscript);
724 executeGroovyScript(groovyscript, af);
725 System.out.println("CMD groovy[" + groovyscript
726 + "] executed successfully!");
729 String imageName = "unnamed.png";
730 while (aparser.getSize() > 1)
732 String outputFormat = aparser.nextValue();
733 file = aparser.nextValue();
735 if (outputFormat.equalsIgnoreCase("png"))
737 af.createPNG(new File(file));
738 imageName = (new File(file)).getName();
739 System.out.println("Creating PNG image: " + file);
742 else if (outputFormat.equalsIgnoreCase("svg"))
744 File imageFile = new File(file);
745 imageName = imageFile.getName();
746 af.createSVG(imageFile);
747 System.out.println("Creating SVG image: " + file);
750 else if (outputFormat.equalsIgnoreCase("html"))
752 File imageFile = new File(file);
753 imageName = imageFile.getName();
754 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
755 htmlSVG.exportHTML(file);
757 System.out.println("Creating HTML image: " + file);
760 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
764 System.err.println("The output html file must not be null");
769 BioJsHTMLOutput.refreshVersionInfo(
770 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
771 } catch (URISyntaxException e)
775 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
776 bjs.exportHTML(file);
778 .println("Creating BioJS MSA Viwer HTML file: " + file);
781 else if (outputFormat.equalsIgnoreCase("imgMap"))
783 af.createImageMap(new File(file), imageName);
784 System.out.println("Creating image map: " + file);
787 else if (outputFormat.equalsIgnoreCase("eps"))
789 File outputFile = new File(file);
791 "Creating EPS file: " + outputFile.getAbsolutePath());
792 af.createEPS(outputFile);
796 af.saveAlignment(file, format);
797 if (af.isSaveAlignmentSuccessful())
799 System.out.println("Written alignment in " + format
800 + " format to " + file);
804 System.out.println("Error writing file " + file + " in "
805 + format + " format!!");
810 while (aparser.getSize() > 0)
812 System.out.println("Unknown arg: " + aparser.nextValue());
816 AlignFrame startUpAlframe = null;
817 // We'll only open the default file if the desktop is visible.
819 // ////////////////////
821 if (!Platform.isJS() && !headless && file == null
822 && Cache.getDefault("SHOW_STARTUP_FILE", true))
829 file = Cache.getDefault("STARTUP_FILE",
830 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
831 + "/examples/exampleFile_2_7.jar");
833 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
835 // hardwire upgrade of the startup file
836 file.replace("_2_3.jar", "_2_7.jar");
837 // and remove the stale setting
838 Cache.removeProperty("STARTUP_FILE");
841 protocol = DataSourceType.FILE;
843 if (file.indexOf("http:") > -1)
845 protocol = DataSourceType.URL;
848 if (file.endsWith(".jar"))
850 format = FileFormat.Jalview;
856 format = new IdentifyFile().identify(file, protocol);
857 } catch (FileFormatException e)
863 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
865 // extract groovy arguments before anything else.
868 // Once all other stuff is done, execute any groovy scripts (in order)
869 if (groovyscript != null)
871 if (Cache.groovyJarsPresent())
873 System.out.println("Executing script " + groovyscript);
874 executeGroovyScript(groovyscript, startUpAlframe);
879 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
883 // and finally, turn off batch mode indicator - if the desktop still exists
888 desktop.setProgressBar(null, progress);
890 desktop.setInBatchMode(false);
894 private static boolean setCrossPlatformLookAndFeel()
896 return setGenericLookAndFeel(false);
899 private static boolean setSystemLookAndFeel()
901 return setGenericLookAndFeel(true);
904 private static boolean setGenericLookAndFeel(boolean system)
909 UIManager.setLookAndFeel(
910 system ? UIManager.getSystemLookAndFeelClassName()
911 : UIManager.getCrossPlatformLookAndFeelClassName());
913 } catch (Exception ex)
915 System.err.println("Unexpected Look and Feel Exception");
916 ex.printStackTrace();
921 private static boolean setSpecificLookAndFeel(String name,
922 String className, boolean nameStartsWith)
927 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
929 if (info.getName() != null && nameStartsWith
930 ? info.getName().toLowerCase()
931 .startsWith(name.toLowerCase())
932 : info.getName().toLowerCase().equals(name.toLowerCase()))
934 className = info.getClassName();
938 UIManager.setLookAndFeel(className);
940 } catch (Exception ex)
942 System.err.println("Unexpected Look and Feel Exception");
943 ex.printStackTrace();
948 private static boolean setGtkLookAndFeel()
950 return setSpecificLookAndFeel("gtk",
951 "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", true);
954 private static boolean setMetalLookAndFeel()
956 return setSpecificLookAndFeel("metal",
957 "javax.swing.plaf.metal.MetalLookAndFeel", false);
960 private static boolean setNimbusLookAndFeel()
962 return setSpecificLookAndFeel("nimbus",
963 "javax.swing.plaf.nimbus.NimbusLookAndFeel", false);
966 private static boolean setQuaquaLookAndFeel()
968 return setSpecificLookAndFeel("quaqua",
969 ch.randelshofer.quaqua.QuaquaManager.getLookAndFeel().getClass()
974 private static boolean setVaquaLookAndFeel()
976 return setSpecificLookAndFeel("vaqua",
977 "org.violetlib.aqua.AquaLookAndFeel", false);
980 private static boolean setMacLookAndFeel()
983 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
985 System.setProperty("apple.laf.useScreenMenuBar", "true");
986 set = setQuaquaLookAndFeel();
987 if ((!set) || !UIManager.getLookAndFeel().getClass().toString()
988 .toLowerCase().contains("quaqua"))
990 set = setVaquaLookAndFeel();
995 private static void showUsage()
998 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
999 + "-nodisplay\tRun Jalview without User Interface.\n"
1000 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1001 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1002 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1003 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1004 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1005 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1006 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1007 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1008 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1009 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1010 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1011 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1012 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1013 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1014 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1015 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1016 + "-html FILE\tCreate HTML file from alignment.\n"
1017 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1018 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1019 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1020 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1021 + "-noquestionnaire\tTurn off questionnaire check.\n"
1022 + "-nonews\tTurn off check for Jalview news.\n"
1023 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1024 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1026 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1027 // after all other properties files have been read\n\t
1028 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1029 // passed in correctly)"
1030 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1031 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1032 + "-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"
1033 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1036 private static void startUsageStats(final Desktop desktop)
1039 * start a User Config prompt asking if we can log usage statistics.
1041 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
1042 "USAGESTATS", "Jalview Usage Statistics",
1043 "Do you want to help make Jalview better by enabling "
1044 + "the collection of usage statistics with Google Analytics ?"
1045 + "\n\n(you can enable or disable usage tracking in the preferences)",
1052 "Initialising googletracker for usage stats.");
1053 Cache.initGoogleTracker();
1054 Cache.log.debug("Tracking enabled.");
1061 Cache.log.debug("Not enabling Google Tracking.");
1064 desktop.addDialogThread(prompter);
1068 * Locate the given string as a file and pass it to the groovy interpreter.
1070 * @param groovyscript
1071 * the script to execute
1072 * @param jalviewContext
1073 * the Jalview Desktop object passed in to the groovy binding as the
1076 private void executeGroovyScript(String groovyscript, AlignFrame af)
1079 * for scripts contained in files
1086 if (groovyscript.trim().equals("STDIN"))
1088 // read from stdin into a tempfile and execute it
1091 tfile = File.createTempFile("jalview", "groovy");
1092 PrintWriter outfile = new PrintWriter(
1093 new OutputStreamWriter(new FileOutputStream(tfile)));
1094 BufferedReader br = new BufferedReader(
1095 new InputStreamReader(System.in));
1097 while ((line = br.readLine()) != null)
1099 outfile.write(line + "\n");
1105 } catch (Exception ex)
1107 System.err.println("Failed to read from STDIN into tempfile "
1108 + ((tfile == null) ? "(tempfile wasn't created)"
1109 : tfile.toString()));
1110 ex.printStackTrace();
1115 sfile = tfile.toURI().toURL();
1116 } catch (Exception x)
1119 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1121 x.printStackTrace();
1129 sfile = new URI(groovyscript).toURL();
1130 } catch (Exception x)
1132 tfile = new File(groovyscript);
1133 if (!tfile.exists())
1135 System.err.println("File '" + groovyscript + "' does not exist.");
1138 if (!tfile.canRead())
1140 System.err.println("File '" + groovyscript + "' cannot be read.");
1143 if (tfile.length() < 1)
1145 System.err.println("File '" + groovyscript + "' is empty.");
1150 sfile = tfile.getAbsoluteFile().toURI().toURL();
1151 } catch (Exception ex)
1153 System.err.println("Failed to create a file URL for "
1154 + tfile.getAbsoluteFile());
1161 Map<String, java.lang.Object> vbinding = new HashMap<>();
1162 vbinding.put("Jalview", this);
1165 vbinding.put("currentAlFrame", af);
1167 Binding gbinding = new Binding(vbinding);
1168 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1169 gse.run(sfile.toString(), gbinding);
1170 if ("STDIN".equals(groovyscript))
1172 // delete temp file that we made -
1173 // only if it was successfully executed
1176 } catch (Exception e)
1178 System.err.println("Exception Whilst trying to execute file " + sfile
1179 + " as a groovy script.");
1180 e.printStackTrace(System.err);
1185 public static boolean isHeadlessMode()
1187 String isheadless = System.getProperty("java.awt.headless");
1188 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1195 public AlignFrame[] getAlignFrames()
1197 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1198 : Desktop.getAlignFrames();
1203 * Quit method delegates to Desktop.quit - unless running in headless mode
1204 * when it just ends the JVM
1208 if (desktop != null)
1218 public static AlignFrame getCurrentAlignFrame()
1220 return Jalview.currentAlignFrame;
1223 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1225 Jalview.currentAlignFrame = currentAlignFrame;