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;
43 import javax.swing.UIManager;
44 import javax.swing.UIManager.LookAndFeelInfo;
46 import com.threerings.getdown.util.LaunchUtil;
48 import groovy.lang.Binding;
49 import groovy.util.GroovyScriptEngine;
50 import jalview.ext.so.SequenceOntology;
51 import jalview.gui.AlignFrame;
52 import jalview.gui.Desktop;
53 import jalview.gui.PromptUserConfig;
54 import jalview.io.AppletFormatAdapter;
55 import jalview.io.BioJsHTMLOutput;
56 import jalview.io.DataSourceType;
57 import jalview.io.FileFormat;
58 import jalview.io.FileFormatException;
59 import jalview.io.FileFormatI;
60 import jalview.io.FileLoader;
61 import jalview.io.HtmlSvgOutput;
62 import jalview.io.IdentifyFile;
63 import jalview.io.NewickFile;
64 import jalview.io.gff.SequenceOntologyFactory;
65 import jalview.schemes.ColourSchemeI;
66 import jalview.schemes.ColourSchemeProperty;
67 import jalview.util.MessageManager;
68 import jalview.util.Platform;
69 import jalview.ws.jws2.Jws2Discoverer;
72 * Main class for Jalview Application <br>
74 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
77 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
78 * jalview.bin.Jalview jalview.bin.Jalview
80 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
81 * embellish '*' to e.g. '*.jar')
89 * singleton instance of this class
91 private static Jalview instance;
93 private Desktop desktop;
95 public static AlignFrame currentAlignFrame;
99 // grab all the rights we can the JVM
100 Policy.setPolicy(new Policy()
103 public PermissionCollection getPermissions(CodeSource codesource)
105 Permissions perms = new Permissions();
106 perms.add(new AllPermission());
111 public void refresh()
118 * keep track of feature fetching tasks.
126 * TODO: generalise to track all jalview events to orchestrate batch processing
130 private int queued = 0;
132 private int running = 0;
134 public FeatureFetcher()
139 public void addFetcher(final AlignFrame af,
140 final Vector<String> dasSources)
142 final long id = System.currentTimeMillis();
144 final FeatureFetcher us = this;
145 new Thread(new Runnable()
157 af.setProgressBar(MessageManager
158 .getString("status.das_features_being_retrived"), id);
159 af.featureSettings_actionPerformed(null);
160 af.setProgressBar(null, id);
169 public synchronized boolean allFinished()
171 return queued == 0 && running == 0;
176 public static Jalview getInstance()
182 * main class for Jalview application
185 * open <em>filename</em>
187 public static void main(String[] args)
189 instance = new Jalview();
190 instance.doMain(args);
196 void doMain(String[] args)
198 System.setSecurityManager(null);
200 .println("Java version: " + System.getProperty("java.version"));
201 System.out.println("Java Home: " + System.getProperty("java.home"));
202 System.out.println(System.getProperty("os.arch") + " "
203 + System.getProperty("os.name") + " "
204 + System.getProperty("os.version"));
205 String val = System.getProperty("sys.install4jVersion");
208 System.out.println("Install4j version: " + val);
210 val = System.getProperty("installer_template_version");
213 System.out.println("Install4j template version: " + val);
215 val = System.getProperty("launcher_version");
218 System.out.println("Launcher version: " + val);
221 // report Jalview version
222 Cache.loadBuildProperties(true);
224 ArgsParser aparser = new ArgsParser(args);
225 boolean headless = false;
227 if (aparser.contains("help") || aparser.contains("h"))
232 if (aparser.contains("nodisplay") || aparser.contains("nogui")
233 || aparser.contains("headless"))
235 System.setProperty("java.awt.headless", "true");
238 String usrPropsFile = aparser.getValue("props");
239 Cache.loadProperties(usrPropsFile); // must do this before
240 if (usrPropsFile != null)
243 "CMD [-props " + usrPropsFile + "] executed successfully!");
248 final String jabawsUrl = aparser.getValue("jabaws");
249 if (jabawsUrl != null)
253 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
255 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
256 } catch (MalformedURLException e)
259 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
263 String defs = aparser.getValue("setprop");
266 int p = defs.indexOf('=');
269 System.err.println("Ignoring invalid setprop argument : " + defs);
273 System.out.println("Executing setprop argument: " + defs);
274 // DISABLED FOR SECURITY REASONS
275 // TODO: add a property to allow properties to be overriden by cli args
276 // Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
278 defs = aparser.getValue("setprop");
280 if (System.getProperty("java.awt.headless") != null
281 && System.getProperty("java.awt.headless").equals("true"))
285 System.setProperty("http.agent",
286 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
290 } catch (NoClassDefFoundError error)
292 error.printStackTrace();
293 System.out.println("\nEssential logging libraries not found."
294 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
303 * configure 'full' SO model if preferences say to, else use the default (SO
306 if (Cache.getDefault("USE_FULL_SO", true))
308 SequenceOntologyFactory.setInstance(new SequenceOntology());
314 desktop = new Desktop();
315 desktop.setInBatchMode(true); // indicate we are starting up
319 JalviewTaskbar.setTaskbar(this);
320 } catch (Exception e)
322 Cache.log.info("Cannot set Taskbar");
323 Cache.log.error(e.getMessage());
324 // e.printStackTrace();
325 } catch (Throwable t)
327 Cache.log.info("Cannot set Taskbar");
328 Cache.log.error(t.getMessage());
329 // t.printStackTrace();
332 desktop.setVisible(true);
333 desktop.startServiceDiscovery();
334 if (!aparser.contains("nousagestats"))
336 startUsageStats(desktop);
340 System.err.println("CMD [-nousagestats] executed successfully!");
343 if (!aparser.contains("noquestionnaire"))
345 String url = aparser.getValue("questionnaire");
348 // Start the desktop questionnaire prompter with the specified
350 Cache.log.debug("Starting questionnaire url at " + url);
351 desktop.checkForQuestionnaire(url);
353 "CMD questionnaire[-" + url + "] executed successfully!");
357 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
359 // Start the desktop questionnaire prompter with the specified
362 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
364 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
366 "Starting questionnaire with default url: " + defurl);
367 desktop.checkForQuestionnaire(defurl);
373 System.err.println("CMD [-noquestionnaire] executed successfully!");
376 if (!aparser.contains("nonews"))
378 desktop.checkForNews();
381 BioJsHTMLOutput.updateBioJS();
384 // Move any new getdown-launcher-new.jar into place over old
385 // getdown-launcher.jar
386 String appdirString = System.getProperty("getdownappdir");
387 if (appdirString != null && appdirString.length() > 0)
389 final File appdir = new File(appdirString);
395 LaunchUtil.upgradeGetdown(
396 new File(appdir, "getdown-launcher-old.jar"),
397 new File(appdir, "getdown-launcher.jar"),
398 new File(appdir, "getdown-launcher-new.jar"));
403 String file = null, data = null;
404 FileFormatI format = null;
405 DataSourceType protocol = null;
406 FileLoader fileLoader = new FileLoader(!headless);
408 String groovyscript = null; // script to execute after all loading is
409 // completed one way or another
410 // extract groovy argument and execute if necessary
411 groovyscript = aparser.getValue("groovy", true);
412 file = aparser.getValue("open", true);
414 if (file == null && desktop == null)
416 System.out.println("No files to open!");
420 // Finally, deal with the remaining input data.
425 desktop.setProgressBar(
427 .getString("status.processing_commandline_args"),
428 progress = System.currentTimeMillis());
430 System.out.println("CMD [-open " + file + "] executed successfully!");
432 if (!file.startsWith("http://"))
434 if (!(new File(file)).exists())
436 System.out.println("Can't find " + file);
444 protocol = AppletFormatAdapter.checkProtocol(file);
448 format = new IdentifyFile().identify(file, protocol);
449 } catch (FileFormatException e1)
454 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
458 System.out.println("error");
462 setCurrentAlignFrame(af);
463 data = aparser.getValue("colour", true);
466 data.replaceAll("%20", " ");
468 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
469 af.getViewport(), af.getViewport().getAlignment(), data);
474 "CMD [-color " + data + "] executed successfully!");
479 // Must maintain ability to use the groups flag
480 data = aparser.getValue("groups", true);
483 af.parseFeaturesFile(data,
484 AppletFormatAdapter.checkProtocol(data));
485 // System.out.println("Added " + data);
487 "CMD groups[-" + data + "] executed successfully!");
489 data = aparser.getValue("features", true);
492 af.parseFeaturesFile(data,
493 AppletFormatAdapter.checkProtocol(data));
494 // System.out.println("Added " + data);
496 "CMD [-features " + data + "] executed successfully!");
499 data = aparser.getValue("annotations", true);
502 af.loadJalviewDataFile(data, null, null, null);
503 // System.out.println("Added " + data);
505 "CMD [-annotations " + data + "] executed successfully!");
507 // set or clear the sortbytree flag.
508 if (aparser.contains("sortbytree"))
510 af.getViewport().setSortByTree(true);
511 if (af.getViewport().getSortByTree())
513 System.out.println("CMD [-sortbytree] executed successfully!");
516 if (aparser.contains("no-annotation"))
518 af.getViewport().setShowAnnotation(false);
519 if (!af.getViewport().isShowAnnotation())
521 System.out.println("CMD no-annotation executed successfully!");
524 if (aparser.contains("nosortbytree"))
526 af.getViewport().setSortByTree(false);
527 if (!af.getViewport().getSortByTree())
530 .println("CMD [-nosortbytree] executed successfully!");
533 data = aparser.getValue("tree", true);
539 "CMD [-tree " + data + "] executed successfully!");
540 NewickFile nf = new NewickFile(data,
541 AppletFormatAdapter.checkProtocol(data));
543 .setCurrentTree(af.showNewickTree(nf, data).getTree());
544 } catch (IOException ex)
546 System.err.println("Couldn't add tree " + data);
547 ex.printStackTrace(System.err);
550 // TODO - load PDB structure(s) to alignment JAL-629
551 // (associate with identical sequence in alignment, or a specified
553 if (groovyscript != null)
555 // Execute the groovy script after we've done all the rendering stuff
556 // and before any images or figures are generated.
557 System.out.println("Executing script " + groovyscript);
558 executeGroovyScript(groovyscript, af);
559 System.out.println("CMD groovy[" + groovyscript
560 + "] executed successfully!");
563 String imageName = "unnamed.png";
564 while (aparser.getSize() > 1)
566 String outputFormat = aparser.nextValue();
567 file = aparser.nextValue();
569 if (outputFormat.equalsIgnoreCase("png"))
571 af.createPNG(new File(file));
572 imageName = (new File(file)).getName();
573 System.out.println("Creating PNG image: " + file);
576 else if (outputFormat.equalsIgnoreCase("svg"))
578 File imageFile = new File(file);
579 imageName = imageFile.getName();
580 af.createSVG(imageFile);
581 System.out.println("Creating SVG image: " + file);
584 else if (outputFormat.equalsIgnoreCase("html"))
586 File imageFile = new File(file);
587 imageName = imageFile.getName();
588 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
589 htmlSVG.exportHTML(file);
591 System.out.println("Creating HTML image: " + file);
594 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
598 System.err.println("The output html file must not be null");
603 BioJsHTMLOutput.refreshVersionInfo(
604 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
605 } catch (URISyntaxException e)
609 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
610 bjs.exportHTML(file);
612 .println("Creating BioJS MSA Viwer HTML file: " + file);
615 else if (outputFormat.equalsIgnoreCase("imgMap"))
617 af.createImageMap(new File(file), imageName);
618 System.out.println("Creating image map: " + file);
621 else if (outputFormat.equalsIgnoreCase("eps"))
623 File outputFile = new File(file);
625 "Creating EPS file: " + outputFile.getAbsolutePath());
626 af.createEPS(outputFile);
630 if (af.saveAlignment(file, format))
632 System.out.println("Written alignment in " + format
633 + " format to " + file);
637 System.out.println("Error writing file " + file + " in "
638 + format + " format!!");
643 while (aparser.getSize() > 0)
645 System.out.println("Unknown arg: " + aparser.nextValue());
649 AlignFrame startUpAlframe = null;
650 // We'll only open the default file if the desktop is visible.
652 // ////////////////////
654 if (!headless && file == null
655 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
657 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
658 jalview.bin.Cache.getDefault("www.jalview.org",
659 "http://www.jalview.org")
660 + "/examples/exampleFile_2_7.jar");
662 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
664 // hardwire upgrade of the startup file
665 file.replace("_2_3.jar", "_2_7.jar");
666 // and remove the stale setting
667 jalview.bin.Cache.removeProperty("STARTUP_FILE");
670 protocol = DataSourceType.FILE;
672 if (file.indexOf("http:") > -1)
674 protocol = DataSourceType.URL;
677 if (file.endsWith(".jar"))
679 format = FileFormat.Jalview;
685 format = new IdentifyFile().identify(file, protocol);
686 } catch (FileFormatException e)
692 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
694 // extract groovy arguments before anything else.
697 // Once all other stuff is done, execute any groovy scripts (in order)
698 if (groovyscript != null)
700 if (Cache.groovyJarsPresent())
702 System.out.println("Executing script " + groovyscript);
703 executeGroovyScript(groovyscript, startUpAlframe);
708 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
712 // and finally, turn off batch mode indicator - if the desktop still exists
717 desktop.setProgressBar(null, progress);
719 desktop.setInBatchMode(false);
723 private static void setLookAndFeel()
725 // property laf = "crossplatform", "system", "gtk", "metal", "nimbus" or
727 // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac,
729 String lafProp = System.getProperty("laf");
730 String lafSetting = Cache.getDefault("PREFERRED_LAF", null);
736 else if (lafSetting != null)
740 boolean lafSet = false;
743 case "crossplatform":
744 lafSet = setCrossPlatformLookAndFeel();
747 Cache.log.error("Could not set requested laf=" + laf);
751 lafSet = setSystemLookAndFeel();
754 Cache.log.error("Could not set requested laf=" + laf);
758 lafSet = setGtkLookAndFeel();
761 Cache.log.error("Could not set requested laf=" + laf);
765 lafSet = setMetalLookAndFeel();
768 Cache.log.error("Could not set requested laf=" + laf);
772 lafSet = setNimbusLookAndFeel();
775 Cache.log.error("Could not set requested laf=" + laf);
779 lafSet = setQuaquaLookAndFeel();
782 Cache.log.error("Could not set requested laf=" + laf);
786 lafSet = setVaquaLookAndFeel();
789 Cache.log.error("Could not set requested laf=" + laf);
793 lafSet = setMacLookAndFeel();
796 Cache.log.error("Could not set requested laf=" + laf);
802 Cache.log.error("Requested laf=" + laf + " not implemented");
806 setSystemLookAndFeel();
807 if (Platform.isLinux())
809 setMetalLookAndFeel();
811 if (Platform.isAMac())
818 private static boolean setCrossPlatformLookAndFeel()
823 UIManager.setLookAndFeel(
824 UIManager.getCrossPlatformLookAndFeelClassName());
826 } catch (Exception ex)
828 Cache.log.error("Unexpected Look and Feel Exception");
829 Cache.log.error(ex.getMessage());
830 Cache.log.debug(Cache.getStackTraceString(ex));
835 private static boolean setSystemLookAndFeel()
840 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
842 } catch (Exception ex)
844 Cache.log.error("Unexpected Look and Feel Exception");
845 Cache.log.error(ex.getMessage());
846 Cache.log.debug(Cache.getStackTraceString(ex));
851 private static boolean setSpecificLookAndFeel(String name,
852 String className, boolean nameStartsWith)
857 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
859 if (info.getName() != null && nameStartsWith
860 ? info.getName().toLowerCase()
861 .startsWith(name.toLowerCase())
862 : info.getName().toLowerCase().equals(name.toLowerCase()))
864 className = info.getClassName();
868 UIManager.setLookAndFeel(className);
870 } catch (Exception ex)
872 Cache.log.error("Unexpected Look and Feel Exception");
873 Cache.log.error(ex.getMessage());
874 Cache.log.debug(Cache.getStackTraceString(ex));
879 private static boolean setGtkLookAndFeel()
881 return setSpecificLookAndFeel("gtk",
882 "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", true);
885 private static boolean setMetalLookAndFeel()
887 return setSpecificLookAndFeel("metal",
888 "javax.swing.plaf.metal.MetalLookAndFeel", false);
891 private static boolean setNimbusLookAndFeel()
893 return setSpecificLookAndFeel("nimbus",
894 "javax.swing.plaf.nimbus.NimbusLookAndFeel", false);
897 private static boolean setQuaquaLookAndFeel()
899 return setSpecificLookAndFeel("quaqua",
900 ch.randelshofer.quaqua.QuaquaManager.getLookAndFeel().getClass()
905 private static boolean setVaquaLookAndFeel()
907 return setSpecificLookAndFeel("vaqua",
908 "org.violetlib.aqua.AquaLookAndFeel", false);
911 private static boolean setMacLookAndFeel()
914 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
916 System.setProperty("apple.laf.useScreenMenuBar", "true");
917 set = setQuaquaLookAndFeel();
918 if ((!set) || !UIManager.getLookAndFeel().getClass().toString()
919 .toLowerCase().contains("quaqua"))
921 set = setVaquaLookAndFeel();
926 private static void showUsage()
929 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
930 + "-nodisplay\tRun Jalview without User Interface.\n"
931 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
932 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
933 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
934 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
935 + "-features FILE\tUse the given file to mark features on the alignment.\n"
936 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
937 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
938 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
939 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
940 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
941 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
942 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
943 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
944 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
945 + "-png FILE\tCreate PNG image FILE from alignment.\n"
946 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
947 + "-html FILE\tCreate HTML file from alignment.\n"
948 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
949 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
950 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
951 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
952 + "-noquestionnaire\tTurn off questionnaire check.\n"
953 + "-nonews\tTurn off check for Jalview news.\n"
954 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
955 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
957 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
958 // after all other properties files have been read\n\t
959 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
960 // passed in correctly)"
961 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
962 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
963 + "-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"
964 + "-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"
965 + "-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"
966 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
969 private static void startUsageStats(final Desktop desktop)
972 * start a User Config prompt asking if we can log usage statistics.
974 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
975 "USAGESTATS", "Jalview Usage Statistics",
976 "Do you want to help make Jalview better by enabling "
977 + "the collection of usage statistics with Google Analytics ?"
978 + "\n\n(you can enable or disable usage tracking in the preferences)",
985 "Initialising googletracker for usage stats.");
986 Cache.initGoogleTracker();
987 Cache.log.debug("Tracking enabled.");
994 Cache.log.debug("Not enabling Google Tracking.");
997 desktop.addDialogThread(prompter);
1001 * Locate the given string as a file and pass it to the groovy interpreter.
1003 * @param groovyscript
1004 * the script to execute
1005 * @param jalviewContext
1006 * the Jalview Desktop object passed in to the groovy binding as the
1009 private void executeGroovyScript(String groovyscript, AlignFrame af)
1012 * for scripts contained in files
1019 if (groovyscript.trim().equals("STDIN"))
1021 // read from stdin into a tempfile and execute it
1024 tfile = File.createTempFile("jalview", "groovy");
1025 PrintWriter outfile = new PrintWriter(
1026 new OutputStreamWriter(new FileOutputStream(tfile)));
1027 BufferedReader br = new BufferedReader(
1028 new InputStreamReader(System.in));
1030 while ((line = br.readLine()) != null)
1032 outfile.write(line + "\n");
1038 } catch (Exception ex)
1040 System.err.println("Failed to read from STDIN into tempfile "
1041 + ((tfile == null) ? "(tempfile wasn't created)"
1042 : tfile.toString()));
1043 ex.printStackTrace();
1048 sfile = tfile.toURI().toURL();
1049 } catch (Exception x)
1052 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1054 x.printStackTrace();
1062 sfile = new URI(groovyscript).toURL();
1063 } catch (Exception x)
1065 tfile = new File(groovyscript);
1066 if (!tfile.exists())
1068 System.err.println("File '" + groovyscript + "' does not exist.");
1071 if (!tfile.canRead())
1073 System.err.println("File '" + groovyscript + "' cannot be read.");
1076 if (tfile.length() < 1)
1078 System.err.println("File '" + groovyscript + "' is empty.");
1083 sfile = tfile.getAbsoluteFile().toURI().toURL();
1084 } catch (Exception ex)
1086 System.err.println("Failed to create a file URL for "
1087 + tfile.getAbsoluteFile());
1094 Map<String, java.lang.Object> vbinding = new HashMap<>();
1095 vbinding.put("Jalview", this);
1098 vbinding.put("currentAlFrame", af);
1100 Binding gbinding = new Binding(vbinding);
1101 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1102 gse.run(sfile.toString(), gbinding);
1103 if ("STDIN".equals(groovyscript))
1105 // delete temp file that we made -
1106 // only if it was successfully executed
1109 } catch (Exception e)
1111 System.err.println("Exception Whilst trying to execute file " + sfile
1112 + " as a groovy script.");
1113 e.printStackTrace(System.err);
1118 public static boolean isHeadlessMode()
1120 String isheadless = System.getProperty("java.awt.headless");
1121 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1128 public AlignFrame[] getAlignFrames()
1130 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1131 : Desktop.getAlignFrames();
1136 * Quit method delegates to Desktop.quit - unless running in headless mode
1137 * when it just ends the JVM
1141 if (desktop != null)
1151 public static AlignFrame getCurrentAlignFrame()
1153 return Jalview.currentAlignFrame;
1156 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1158 Jalview.currentAlignFrame = currentAlignFrame;